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
214,800
moodle/moodle
backup/util/factories/convert_factory.class.php
convert_factory.get_converter
public static function get_converter($name, $tempdir, $logger = null) { global $CFG; $name = clean_param($name, PARAM_SAFEDIR); $classfile = "$CFG->dirroot/backup/converter/$name/lib.php"; $classname = "{$name}_converter"; if (!file_exists($classfile)) { throw new coding_exception("Converter factory error: class file not found $classfile"); } require_once($classfile); if (!class_exists($classname)) { throw new coding_exception("Converter factory error: class not found $classname"); } return new $classname($tempdir, $logger); }
php
public static function get_converter($name, $tempdir, $logger = null) { global $CFG; $name = clean_param($name, PARAM_SAFEDIR); $classfile = "$CFG->dirroot/backup/converter/$name/lib.php"; $classname = "{$name}_converter"; if (!file_exists($classfile)) { throw new coding_exception("Converter factory error: class file not found $classfile"); } require_once($classfile); if (!class_exists($classname)) { throw new coding_exception("Converter factory error: class not found $classname"); } return new $classname($tempdir, $logger); }
[ "public", "static", "function", "get_converter", "(", "$", "name", ",", "$", "tempdir", ",", "$", "logger", "=", "null", ")", "{", "global", "$", "CFG", ";", "$", "name", "=", "clean_param", "(", "$", "name", ",", "PARAM_SAFEDIR", ")", ";", "$", "classfile", "=", "\"$CFG->dirroot/backup/converter/$name/lib.php\"", ";", "$", "classname", "=", "\"{$name}_converter\"", ";", "if", "(", "!", "file_exists", "(", "$", "classfile", ")", ")", "{", "throw", "new", "coding_exception", "(", "\"Converter factory error: class file not found $classfile\"", ")", ";", "}", "require_once", "(", "$", "classfile", ")", ";", "if", "(", "!", "class_exists", "(", "$", "classname", ")", ")", "{", "throw", "new", "coding_exception", "(", "\"Converter factory error: class not found $classname\"", ")", ";", "}", "return", "new", "$", "classname", "(", "$", "tempdir", ",", "$", "logger", ")", ";", "}" ]
Instantinates the given converter operating on a given directory @throws coding_exception @param $name The converter name @param $tempdir The temp directory to operate on @param base_logger|null if the conversion should be logged, use this logger @return base_converter
[ "Instantinates", "the", "given", "converter", "operating", "on", "a", "given", "directory" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/util/factories/convert_factory.class.php#L41-L59
214,801
moodle/moodle
question/behaviour/rendererbase.php
qbehaviour_renderer.manual_comment
public function manual_comment(question_attempt $qa, question_display_options $options) { if ($options->manualcomment == question_display_options::EDITABLE) { return $this->manual_comment_fields($qa, $options); } else if ($options->manualcomment == question_display_options::VISIBLE) { return $this->manual_comment_view($qa, $options); } else { return ''; } }
php
public function manual_comment(question_attempt $qa, question_display_options $options) { if ($options->manualcomment == question_display_options::EDITABLE) { return $this->manual_comment_fields($qa, $options); } else if ($options->manualcomment == question_display_options::VISIBLE) { return $this->manual_comment_view($qa, $options); } else { return ''; } }
[ "public", "function", "manual_comment", "(", "question_attempt", "$", "qa", ",", "question_display_options", "$", "options", ")", "{", "if", "(", "$", "options", "->", "manualcomment", "==", "question_display_options", "::", "EDITABLE", ")", "{", "return", "$", "this", "->", "manual_comment_fields", "(", "$", "qa", ",", "$", "options", ")", ";", "}", "else", "if", "(", "$", "options", "->", "manualcomment", "==", "question_display_options", "::", "VISIBLE", ")", "{", "return", "$", "this", "->", "manual_comment_view", "(", "$", "qa", ",", "$", "options", ")", ";", "}", "else", "{", "return", "''", ";", "}", "}" ]
Display the manual comment, and a link to edit it, if appropriate. @param question_attempt $qa a question attempt. @param question_display_options $options controls what should and should not be displayed. @return string HTML fragment.
[ "Display", "the", "manual", "comment", "and", "a", "link", "to", "edit", "it", "if", "appropriate", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/behaviour/rendererbase.php#L210-L220
214,802
moodle/moodle
question/behaviour/rendererbase.php
qbehaviour_renderer.submit_button
protected function submit_button(question_attempt $qa, question_display_options $options) { if (!$qa->get_state()->is_active()) { return ''; } $attributes = array( 'type' => 'submit', 'id' => $qa->get_behaviour_field_name('submit'), 'name' => $qa->get_behaviour_field_name('submit'), 'value' => get_string('check', 'question'), 'class' => 'submit btn btn-secondary', ); if ($options->readonly) { $attributes['disabled'] = 'disabled'; } $output = html_writer::empty_tag('input', $attributes); if (!$options->readonly) { $this->page->requires->js_init_call('M.core_question_engine.init_submit_button', array($attributes['id'], $qa->get_slot())); } return $output; }
php
protected function submit_button(question_attempt $qa, question_display_options $options) { if (!$qa->get_state()->is_active()) { return ''; } $attributes = array( 'type' => 'submit', 'id' => $qa->get_behaviour_field_name('submit'), 'name' => $qa->get_behaviour_field_name('submit'), 'value' => get_string('check', 'question'), 'class' => 'submit btn btn-secondary', ); if ($options->readonly) { $attributes['disabled'] = 'disabled'; } $output = html_writer::empty_tag('input', $attributes); if (!$options->readonly) { $this->page->requires->js_init_call('M.core_question_engine.init_submit_button', array($attributes['id'], $qa->get_slot())); } return $output; }
[ "protected", "function", "submit_button", "(", "question_attempt", "$", "qa", ",", "question_display_options", "$", "options", ")", "{", "if", "(", "!", "$", "qa", "->", "get_state", "(", ")", "->", "is_active", "(", ")", ")", "{", "return", "''", ";", "}", "$", "attributes", "=", "array", "(", "'type'", "=>", "'submit'", ",", "'id'", "=>", "$", "qa", "->", "get_behaviour_field_name", "(", "'submit'", ")", ",", "'name'", "=>", "$", "qa", "->", "get_behaviour_field_name", "(", "'submit'", ")", ",", "'value'", "=>", "get_string", "(", "'check'", ",", "'question'", ")", ",", "'class'", "=>", "'submit btn btn-secondary'", ",", ")", ";", "if", "(", "$", "options", "->", "readonly", ")", "{", "$", "attributes", "[", "'disabled'", "]", "=", "'disabled'", ";", "}", "$", "output", "=", "html_writer", "::", "empty_tag", "(", "'input'", ",", "$", "attributes", ")", ";", "if", "(", "!", "$", "options", "->", "readonly", ")", "{", "$", "this", "->", "page", "->", "requires", "->", "js_init_call", "(", "'M.core_question_engine.init_submit_button'", ",", "array", "(", "$", "attributes", "[", "'id'", "]", ",", "$", "qa", "->", "get_slot", "(", ")", ")", ")", ";", "}", "return", "$", "output", ";", "}" ]
Several behaviours need a submit button, so put the common code here. The button is disabled if the question is displayed read-only. @param question_display_options $options controls what should and should not be displayed. @return string HTML fragment.
[ "Several", "behaviours", "need", "a", "submit", "button", "so", "put", "the", "common", "code", "here", ".", "The", "button", "is", "disabled", "if", "the", "question", "is", "displayed", "read", "-", "only", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/behaviour/rendererbase.php#L228-L248
214,803
moodle/moodle
auth/email/auth.php
auth_plugin_email.user_signup_with_confirmation
public function user_signup_with_confirmation($user, $notify=true, $confirmationurl = null) { global $CFG, $DB, $SESSION; require_once($CFG->dirroot.'/user/profile/lib.php'); require_once($CFG->dirroot.'/user/lib.php'); $plainpassword = $user->password; $user->password = hash_internal_user_password($user->password); if (empty($user->calendartype)) { $user->calendartype = $CFG->calendartype; } $user->id = user_create_user($user, false, false); user_add_password_history($user->id, $plainpassword); // Save any custom profile field information. profile_save_data($user); // Save wantsurl against user's profile, so we can return them there upon confirmation. if (!empty($SESSION->wantsurl)) { set_user_preference('auth_email_wantsurl', $SESSION->wantsurl, $user); } // Trigger event. \core\event\user_created::create_from_userid($user->id)->trigger(); if (! send_confirmation_email($user, $confirmationurl)) { print_error('auth_emailnoemail', 'auth_email'); } if ($notify) { global $CFG, $PAGE, $OUTPUT; $emailconfirm = get_string('emailconfirm'); $PAGE->navbar->add($emailconfirm); $PAGE->set_title($emailconfirm); $PAGE->set_heading($PAGE->course->fullname); echo $OUTPUT->header(); notice(get_string('emailconfirmsent', '', $user->email), "$CFG->wwwroot/index.php"); } else { return true; } }
php
public function user_signup_with_confirmation($user, $notify=true, $confirmationurl = null) { global $CFG, $DB, $SESSION; require_once($CFG->dirroot.'/user/profile/lib.php'); require_once($CFG->dirroot.'/user/lib.php'); $plainpassword = $user->password; $user->password = hash_internal_user_password($user->password); if (empty($user->calendartype)) { $user->calendartype = $CFG->calendartype; } $user->id = user_create_user($user, false, false); user_add_password_history($user->id, $plainpassword); // Save any custom profile field information. profile_save_data($user); // Save wantsurl against user's profile, so we can return them there upon confirmation. if (!empty($SESSION->wantsurl)) { set_user_preference('auth_email_wantsurl', $SESSION->wantsurl, $user); } // Trigger event. \core\event\user_created::create_from_userid($user->id)->trigger(); if (! send_confirmation_email($user, $confirmationurl)) { print_error('auth_emailnoemail', 'auth_email'); } if ($notify) { global $CFG, $PAGE, $OUTPUT; $emailconfirm = get_string('emailconfirm'); $PAGE->navbar->add($emailconfirm); $PAGE->set_title($emailconfirm); $PAGE->set_heading($PAGE->course->fullname); echo $OUTPUT->header(); notice(get_string('emailconfirmsent', '', $user->email), "$CFG->wwwroot/index.php"); } else { return true; } }
[ "public", "function", "user_signup_with_confirmation", "(", "$", "user", ",", "$", "notify", "=", "true", ",", "$", "confirmationurl", "=", "null", ")", "{", "global", "$", "CFG", ",", "$", "DB", ",", "$", "SESSION", ";", "require_once", "(", "$", "CFG", "->", "dirroot", ".", "'/user/profile/lib.php'", ")", ";", "require_once", "(", "$", "CFG", "->", "dirroot", ".", "'/user/lib.php'", ")", ";", "$", "plainpassword", "=", "$", "user", "->", "password", ";", "$", "user", "->", "password", "=", "hash_internal_user_password", "(", "$", "user", "->", "password", ")", ";", "if", "(", "empty", "(", "$", "user", "->", "calendartype", ")", ")", "{", "$", "user", "->", "calendartype", "=", "$", "CFG", "->", "calendartype", ";", "}", "$", "user", "->", "id", "=", "user_create_user", "(", "$", "user", ",", "false", ",", "false", ")", ";", "user_add_password_history", "(", "$", "user", "->", "id", ",", "$", "plainpassword", ")", ";", "// Save any custom profile field information.", "profile_save_data", "(", "$", "user", ")", ";", "// Save wantsurl against user's profile, so we can return them there upon confirmation.", "if", "(", "!", "empty", "(", "$", "SESSION", "->", "wantsurl", ")", ")", "{", "set_user_preference", "(", "'auth_email_wantsurl'", ",", "$", "SESSION", "->", "wantsurl", ",", "$", "user", ")", ";", "}", "// Trigger event.", "\\", "core", "\\", "event", "\\", "user_created", "::", "create_from_userid", "(", "$", "user", "->", "id", ")", "->", "trigger", "(", ")", ";", "if", "(", "!", "send_confirmation_email", "(", "$", "user", ",", "$", "confirmationurl", ")", ")", "{", "print_error", "(", "'auth_emailnoemail'", ",", "'auth_email'", ")", ";", "}", "if", "(", "$", "notify", ")", "{", "global", "$", "CFG", ",", "$", "PAGE", ",", "$", "OUTPUT", ";", "$", "emailconfirm", "=", "get_string", "(", "'emailconfirm'", ")", ";", "$", "PAGE", "->", "navbar", "->", "add", "(", "$", "emailconfirm", ")", ";", "$", "PAGE", "->", "set_title", "(", "$", "emailconfirm", ")", ";", "$", "PAGE", "->", "set_heading", "(", "$", "PAGE", "->", "course", "->", "fullname", ")", ";", "echo", "$", "OUTPUT", "->", "header", "(", ")", ";", "notice", "(", "get_string", "(", "'emailconfirmsent'", ",", "''", ",", "$", "user", "->", "email", ")", ",", "\"$CFG->wwwroot/index.php\"", ")", ";", "}", "else", "{", "return", "true", ";", "}", "}" ]
Sign up a new user ready for confirmation. Password is passed in plaintext. A custom confirmationurl could be used. @param object $user new user object @param boolean $notify print notice with link and terminate @param string $confirmationurl user confirmation URL @return boolean true if everything well ok and $notify is set to true @throws moodle_exception @since Moodle 3.2
[ "Sign", "up", "a", "new", "user", "ready", "for", "confirmation", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/auth/email/auth.php#L115-L156
214,804
moodle/moodle
favourites/classes/local/service/user_favourite_service.php
user_favourite_service.delete_favourite
public function delete_favourite(string $component, string $itemtype, int $itemid, \context $context) { if (!in_array($component, \core_component::get_component_names())) { throw new \moodle_exception("Invalid component name '$component'"); } // Business logic: check the user owns the favourite. try { $favourite = $this->repo->find_favourite($this->userid, $component, $itemtype, $itemid, $context->id); } catch (\moodle_exception $e) { throw new \moodle_exception("Favourite does not exist for the user. Cannot delete."); } $this->repo->delete($favourite->id); }
php
public function delete_favourite(string $component, string $itemtype, int $itemid, \context $context) { if (!in_array($component, \core_component::get_component_names())) { throw new \moodle_exception("Invalid component name '$component'"); } // Business logic: check the user owns the favourite. try { $favourite = $this->repo->find_favourite($this->userid, $component, $itemtype, $itemid, $context->id); } catch (\moodle_exception $e) { throw new \moodle_exception("Favourite does not exist for the user. Cannot delete."); } $this->repo->delete($favourite->id); }
[ "public", "function", "delete_favourite", "(", "string", "$", "component", ",", "string", "$", "itemtype", ",", "int", "$", "itemid", ",", "\\", "context", "$", "context", ")", "{", "if", "(", "!", "in_array", "(", "$", "component", ",", "\\", "core_component", "::", "get_component_names", "(", ")", ")", ")", "{", "throw", "new", "\\", "moodle_exception", "(", "\"Invalid component name '$component'\"", ")", ";", "}", "// Business logic: check the user owns the favourite.", "try", "{", "$", "favourite", "=", "$", "this", "->", "repo", "->", "find_favourite", "(", "$", "this", "->", "userid", ",", "$", "component", ",", "$", "itemtype", ",", "$", "itemid", ",", "$", "context", "->", "id", ")", ";", "}", "catch", "(", "\\", "moodle_exception", "$", "e", ")", "{", "throw", "new", "\\", "moodle_exception", "(", "\"Favourite does not exist for the user. Cannot delete.\"", ")", ";", "}", "$", "this", "->", "repo", "->", "delete", "(", "$", "favourite", "->", "id", ")", ";", "}" ]
Delete a favourite item from an area and from within a context. E.g. delete a favourite course from the area 'core_course', 'course' with itemid 3 and from within the CONTEXT_USER context. @param string $component the frankenstyle component name. @param string $itemtype the type of the favourited item. @param int $itemid the id of the item which was favourited (not the favourite's id). @param \context $context the context of the item which was favourited. @throws \moodle_exception if the user does not control the favourite, or it doesn't exist.
[ "Delete", "a", "favourite", "item", "from", "an", "area", "and", "from", "within", "a", "context", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/favourites/classes/local/service/user_favourite_service.php#L169-L182
214,805
moodle/moodle
favourites/classes/local/service/user_favourite_service.php
user_favourite_service.favourite_exists
public function favourite_exists(string $component, string $itemtype, int $itemid, \context $context) : bool { return $this->repo->exists_by( [ 'userid' => $this->userid, 'component' => $component, 'itemtype' => $itemtype, 'itemid' => $itemid, 'contextid' => $context->id ] ); }
php
public function favourite_exists(string $component, string $itemtype, int $itemid, \context $context) : bool { return $this->repo->exists_by( [ 'userid' => $this->userid, 'component' => $component, 'itemtype' => $itemtype, 'itemid' => $itemid, 'contextid' => $context->id ] ); }
[ "public", "function", "favourite_exists", "(", "string", "$", "component", ",", "string", "$", "itemtype", ",", "int", "$", "itemid", ",", "\\", "context", "$", "context", ")", ":", "bool", "{", "return", "$", "this", "->", "repo", "->", "exists_by", "(", "[", "'userid'", "=>", "$", "this", "->", "userid", ",", "'component'", "=>", "$", "component", ",", "'itemtype'", "=>", "$", "itemtype", ",", "'itemid'", "=>", "$", "itemid", ",", "'contextid'", "=>", "$", "context", "->", "id", "]", ")", ";", "}" ]
Check whether an item has been marked as a favourite in the respective area. @param string $component the frankenstyle component name. @param string $itemtype the type of the favourited item. @param int $itemid the id of the item which was favourited (not the favourite's id). @param \context $context the context of the item which was favourited. @return bool true if the item is favourited, false otherwise.
[ "Check", "whether", "an", "item", "has", "been", "marked", "as", "a", "favourite", "in", "the", "respective", "area", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/favourites/classes/local/service/user_favourite_service.php#L193-L203
214,806
moodle/moodle
favourites/classes/local/service/user_favourite_service.php
user_favourite_service.get_favourite
public function get_favourite(string $component, string $itemtype, int $itemid, \context $context) { try { return $this->repo->find_favourite( $this->userid, $component, $itemtype, $itemid, $context->id ); } catch (\dml_missing_record_exception $e) { return null; } }
php
public function get_favourite(string $component, string $itemtype, int $itemid, \context $context) { try { return $this->repo->find_favourite( $this->userid, $component, $itemtype, $itemid, $context->id ); } catch (\dml_missing_record_exception $e) { return null; } }
[ "public", "function", "get_favourite", "(", "string", "$", "component", ",", "string", "$", "itemtype", ",", "int", "$", "itemid", ",", "\\", "context", "$", "context", ")", "{", "try", "{", "return", "$", "this", "->", "repo", "->", "find_favourite", "(", "$", "this", "->", "userid", ",", "$", "component", ",", "$", "itemtype", ",", "$", "itemid", ",", "$", "context", "->", "id", ")", ";", "}", "catch", "(", "\\", "dml_missing_record_exception", "$", "e", ")", "{", "return", "null", ";", "}", "}" ]
Get the favourite. @param string $component the frankenstyle component name. @param string $itemtype the type of the favourited item. @param int $itemid the id of the item which was favourited (not the favourite's id). @param \context $context the context of the item which was favourited. @return favourite|null
[ "Get", "the", "favourite", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/favourites/classes/local/service/user_favourite_service.php#L214-L226
214,807
moodle/moodle
favourites/classes/local/service/user_favourite_service.php
user_favourite_service.count_favourites_by_type
public function count_favourites_by_type(string $component, string $itemtype, \context $context = null) { $criteria = [ 'userid' => $this->userid, 'component' => $component, 'itemtype' => $itemtype ]; if ($context) { $criteria['contextid'] = $context->id; } return $this->repo->count_by($criteria); }
php
public function count_favourites_by_type(string $component, string $itemtype, \context $context = null) { $criteria = [ 'userid' => $this->userid, 'component' => $component, 'itemtype' => $itemtype ]; if ($context) { $criteria['contextid'] = $context->id; } return $this->repo->count_by($criteria); }
[ "public", "function", "count_favourites_by_type", "(", "string", "$", "component", ",", "string", "$", "itemtype", ",", "\\", "context", "$", "context", "=", "null", ")", "{", "$", "criteria", "=", "[", "'userid'", "=>", "$", "this", "->", "userid", ",", "'component'", "=>", "$", "component", ",", "'itemtype'", "=>", "$", "itemtype", "]", ";", "if", "(", "$", "context", ")", "{", "$", "criteria", "[", "'contextid'", "]", "=", "$", "context", "->", "id", ";", "}", "return", "$", "this", "->", "repo", "->", "count_by", "(", "$", "criteria", ")", ";", "}" ]
Count the favourite by item type. @param string $component the frankenstyle component name. @param string $itemtype the type of the favourited item. @param \context|null $context the context of the item which was favourited. @return int
[ "Count", "the", "favourite", "by", "item", "type", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/favourites/classes/local/service/user_favourite_service.php#L236-L248
214,808
moodle/moodle
auth/cas/CAS/CAS/PGTStorage/File.php
CAS_PGTStorage_File.getPGTIouFilename
function getPGTIouFilename($pgt_iou) { phpCAS::traceBegin(); $filename = $this->getPath()."phpcas-".hash("sha256", $pgt_iou); // $filename = $this->getPath().$pgt_iou.'.plain'; phpCAS::trace("Sha256 filename:" . $filename); phpCAS::traceEnd(); return $filename; }
php
function getPGTIouFilename($pgt_iou) { phpCAS::traceBegin(); $filename = $this->getPath()."phpcas-".hash("sha256", $pgt_iou); // $filename = $this->getPath().$pgt_iou.'.plain'; phpCAS::trace("Sha256 filename:" . $filename); phpCAS::traceEnd(); return $filename; }
[ "function", "getPGTIouFilename", "(", "$", "pgt_iou", ")", "{", "phpCAS", "::", "traceBegin", "(", ")", ";", "$", "filename", "=", "$", "this", "->", "getPath", "(", ")", ".", "\"phpcas-\"", ".", "hash", "(", "\"sha256\"", ",", "$", "pgt_iou", ")", ";", "// $filename = $this->getPath().$pgt_iou.'.plain';", "phpCAS", "::", "trace", "(", "\"Sha256 filename:\"", ".", "$", "filename", ")", ";", "phpCAS", "::", "traceEnd", "(", ")", ";", "return", "$", "filename", ";", "}" ]
This method returns the filename corresponding to a PGT Iou. @param string $pgt_iou the PGT iou. @return a filename @private
[ "This", "method", "returns", "the", "filename", "corresponding", "to", "a", "PGT", "Iou", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/auth/cas/CAS/CAS/PGTStorage/File.php#L180-L188
214,809
moodle/moodle
auth/cas/CAS/CAS/PGTStorage/File.php
CAS_PGTStorage_File.write
function write($pgt,$pgt_iou) { phpCAS::traceBegin(); $fname = $this->getPGTIouFilename($pgt_iou); if (!file_exists($fname)) { touch($fname); // Chmod will fail on windows @chmod($fname, 0600); if ($f=fopen($fname, "w")) { if (fputs($f, $pgt) === false) { phpCAS::error('could not write PGT to `'.$fname.'\''); } phpCAS::trace('Successful write of PGT to `'.$fname.'\''); fclose($f); } else { phpCAS::error('could not open `'.$fname.'\''); } } else { phpCAS::error('File exists: `'.$fname.'\''); } phpCAS::traceEnd(); }
php
function write($pgt,$pgt_iou) { phpCAS::traceBegin(); $fname = $this->getPGTIouFilename($pgt_iou); if (!file_exists($fname)) { touch($fname); // Chmod will fail on windows @chmod($fname, 0600); if ($f=fopen($fname, "w")) { if (fputs($f, $pgt) === false) { phpCAS::error('could not write PGT to `'.$fname.'\''); } phpCAS::trace('Successful write of PGT to `'.$fname.'\''); fclose($f); } else { phpCAS::error('could not open `'.$fname.'\''); } } else { phpCAS::error('File exists: `'.$fname.'\''); } phpCAS::traceEnd(); }
[ "function", "write", "(", "$", "pgt", ",", "$", "pgt_iou", ")", "{", "phpCAS", "::", "traceBegin", "(", ")", ";", "$", "fname", "=", "$", "this", "->", "getPGTIouFilename", "(", "$", "pgt_iou", ")", ";", "if", "(", "!", "file_exists", "(", "$", "fname", ")", ")", "{", "touch", "(", "$", "fname", ")", ";", "// Chmod will fail on windows", "@", "chmod", "(", "$", "fname", ",", "0600", ")", ";", "if", "(", "$", "f", "=", "fopen", "(", "$", "fname", ",", "\"w\"", ")", ")", "{", "if", "(", "fputs", "(", "$", "f", ",", "$", "pgt", ")", "===", "false", ")", "{", "phpCAS", "::", "error", "(", "'could not write PGT to `'", ".", "$", "fname", ".", "'\\''", ")", ";", "}", "phpCAS", "::", "trace", "(", "'Successful write of PGT to `'", ".", "$", "fname", ".", "'\\''", ")", ";", "fclose", "(", "$", "f", ")", ";", "}", "else", "{", "phpCAS", "::", "error", "(", "'could not open `'", ".", "$", "fname", ".", "'\\''", ")", ";", "}", "}", "else", "{", "phpCAS", "::", "error", "(", "'File exists: `'", ".", "$", "fname", ".", "'\\''", ")", ";", "}", "phpCAS", "::", "traceEnd", "(", ")", ";", "}" ]
This method stores a PGT and its corresponding PGT Iou into a file. Echoes a warning on error. @param string $pgt the PGT @param string $pgt_iou the PGT iou @return void @public
[ "This", "method", "stores", "a", "PGT", "and", "its", "corresponding", "PGT", "Iou", "into", "a", "file", ".", "Echoes", "a", "warning", "on", "error", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/auth/cas/CAS/CAS/PGTStorage/File.php#L201-L222
214,810
moodle/moodle
auth/cas/CAS/CAS/PGTStorage/File.php
CAS_PGTStorage_File.read
function read($pgt_iou) { phpCAS::traceBegin(); $pgt = false; $fname = $this->getPGTIouFilename($pgt_iou); if (file_exists($fname)) { if (!($f=fopen($fname, "r"))) { phpCAS::error('could not open `'.$fname.'\''); } else { if (($pgt=fgets($f)) === false) { phpCAS::error('could not read PGT from `'.$fname.'\''); } phpCAS::trace('Successful read of PGT to `'.$fname.'\''); fclose($f); } // delete the PGT file @unlink($fname); } else { phpCAS::error('No such file `'.$fname.'\''); } phpCAS::traceEnd($pgt); return $pgt; }
php
function read($pgt_iou) { phpCAS::traceBegin(); $pgt = false; $fname = $this->getPGTIouFilename($pgt_iou); if (file_exists($fname)) { if (!($f=fopen($fname, "r"))) { phpCAS::error('could not open `'.$fname.'\''); } else { if (($pgt=fgets($f)) === false) { phpCAS::error('could not read PGT from `'.$fname.'\''); } phpCAS::trace('Successful read of PGT to `'.$fname.'\''); fclose($f); } // delete the PGT file @unlink($fname); } else { phpCAS::error('No such file `'.$fname.'\''); } phpCAS::traceEnd($pgt); return $pgt; }
[ "function", "read", "(", "$", "pgt_iou", ")", "{", "phpCAS", "::", "traceBegin", "(", ")", ";", "$", "pgt", "=", "false", ";", "$", "fname", "=", "$", "this", "->", "getPGTIouFilename", "(", "$", "pgt_iou", ")", ";", "if", "(", "file_exists", "(", "$", "fname", ")", ")", "{", "if", "(", "!", "(", "$", "f", "=", "fopen", "(", "$", "fname", ",", "\"r\"", ")", ")", ")", "{", "phpCAS", "::", "error", "(", "'could not open `'", ".", "$", "fname", ".", "'\\''", ")", ";", "}", "else", "{", "if", "(", "(", "$", "pgt", "=", "fgets", "(", "$", "f", ")", ")", "===", "false", ")", "{", "phpCAS", "::", "error", "(", "'could not read PGT from `'", ".", "$", "fname", ".", "'\\''", ")", ";", "}", "phpCAS", "::", "trace", "(", "'Successful read of PGT to `'", ".", "$", "fname", ".", "'\\''", ")", ";", "fclose", "(", "$", "f", ")", ";", "}", "// delete the PGT file", "@", "unlink", "(", "$", "fname", ")", ";", "}", "else", "{", "phpCAS", "::", "error", "(", "'No such file `'", ".", "$", "fname", ".", "'\\''", ")", ";", "}", "phpCAS", "::", "traceEnd", "(", "$", "pgt", ")", ";", "return", "$", "pgt", ";", "}" ]
This method reads a PGT corresponding to a PGT Iou and deletes the corresponding file. @param string $pgt_iou the PGT iou @return the corresponding PGT, or FALSE on error @public
[ "This", "method", "reads", "a", "PGT", "corresponding", "to", "a", "PGT", "Iou", "and", "deletes", "the", "corresponding", "file", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/auth/cas/CAS/CAS/PGTStorage/File.php#L234-L256
214,811
moodle/moodle
lib/scssphp/SourceMap/SourceMapGenerator.php
SourceMapGenerator.generateJson
public function generateJson() { $sourceMap = array(); $mappings = $this->generateMappings(); // File version (always the first entry in the object) and must be a positive integer. $sourceMap['version'] = self::VERSION; // An optional name of the generated code that this source map is associated with. $file = $this->options['sourceMapFilename']; if ($file) { $sourceMap['file'] = $file; } // An optional source root, useful for relocating source files on a server or removing repeated values in the // 'sources' entry. This value is prepended to the individual entries in the 'source' field. $root = $this->options['sourceRoot']; if ($root) { $sourceMap['sourceRoot'] = $root; } // A list of original sources used by the 'mappings' entry. $sourceMap['sources'] = array(); foreach ($this->sources as $source_uri => $source_filename) { $sourceMap['sources'][] = $this->normalizeFilename($source_filename); } // A list of symbol names used by the 'mappings' entry. $sourceMap['names'] = array(); // A string with the encoded mapping data. $sourceMap['mappings'] = $mappings; if ($this->options['outputSourceFiles']) { // An optional list of source content, useful when the 'source' can't be hosted. // The contents are listed in the same order as the sources above. // 'null' may be used if some original sources should be retrieved by name. $sourceMap['sourcesContent'] = $this->getSourcesContent(); } // less.js compat fixes if (count($sourceMap['sources']) && empty($sourceMap['sourceRoot'])) { unset($sourceMap['sourceRoot']); } return json_encode($sourceMap); }
php
public function generateJson() { $sourceMap = array(); $mappings = $this->generateMappings(); // File version (always the first entry in the object) and must be a positive integer. $sourceMap['version'] = self::VERSION; // An optional name of the generated code that this source map is associated with. $file = $this->options['sourceMapFilename']; if ($file) { $sourceMap['file'] = $file; } // An optional source root, useful for relocating source files on a server or removing repeated values in the // 'sources' entry. This value is prepended to the individual entries in the 'source' field. $root = $this->options['sourceRoot']; if ($root) { $sourceMap['sourceRoot'] = $root; } // A list of original sources used by the 'mappings' entry. $sourceMap['sources'] = array(); foreach ($this->sources as $source_uri => $source_filename) { $sourceMap['sources'][] = $this->normalizeFilename($source_filename); } // A list of symbol names used by the 'mappings' entry. $sourceMap['names'] = array(); // A string with the encoded mapping data. $sourceMap['mappings'] = $mappings; if ($this->options['outputSourceFiles']) { // An optional list of source content, useful when the 'source' can't be hosted. // The contents are listed in the same order as the sources above. // 'null' may be used if some original sources should be retrieved by name. $sourceMap['sourcesContent'] = $this->getSourcesContent(); } // less.js compat fixes if (count($sourceMap['sources']) && empty($sourceMap['sourceRoot'])) { unset($sourceMap['sourceRoot']); } return json_encode($sourceMap); }
[ "public", "function", "generateJson", "(", ")", "{", "$", "sourceMap", "=", "array", "(", ")", ";", "$", "mappings", "=", "$", "this", "->", "generateMappings", "(", ")", ";", "// File version (always the first entry in the object) and must be a positive integer.", "$", "sourceMap", "[", "'version'", "]", "=", "self", "::", "VERSION", ";", "// An optional name of the generated code that this source map is associated with.", "$", "file", "=", "$", "this", "->", "options", "[", "'sourceMapFilename'", "]", ";", "if", "(", "$", "file", ")", "{", "$", "sourceMap", "[", "'file'", "]", "=", "$", "file", ";", "}", "// An optional source root, useful for relocating source files on a server or removing repeated values in the", "// 'sources' entry. This value is prepended to the individual entries in the 'source' field.", "$", "root", "=", "$", "this", "->", "options", "[", "'sourceRoot'", "]", ";", "if", "(", "$", "root", ")", "{", "$", "sourceMap", "[", "'sourceRoot'", "]", "=", "$", "root", ";", "}", "// A list of original sources used by the 'mappings' entry.", "$", "sourceMap", "[", "'sources'", "]", "=", "array", "(", ")", ";", "foreach", "(", "$", "this", "->", "sources", "as", "$", "source_uri", "=>", "$", "source_filename", ")", "{", "$", "sourceMap", "[", "'sources'", "]", "[", "]", "=", "$", "this", "->", "normalizeFilename", "(", "$", "source_filename", ")", ";", "}", "// A list of symbol names used by the 'mappings' entry.", "$", "sourceMap", "[", "'names'", "]", "=", "array", "(", ")", ";", "// A string with the encoded mapping data.", "$", "sourceMap", "[", "'mappings'", "]", "=", "$", "mappings", ";", "if", "(", "$", "this", "->", "options", "[", "'outputSourceFiles'", "]", ")", "{", "// An optional list of source content, useful when the 'source' can't be hosted.", "// The contents are listed in the same order as the sources above.", "// 'null' may be used if some original sources should be retrieved by name.", "$", "sourceMap", "[", "'sourcesContent'", "]", "=", "$", "this", "->", "getSourcesContent", "(", ")", ";", "}", "// less.js compat fixes", "if", "(", "count", "(", "$", "sourceMap", "[", "'sources'", "]", ")", "&&", "empty", "(", "$", "sourceMap", "[", "'sourceRoot'", "]", ")", ")", "{", "unset", "(", "$", "sourceMap", "[", "'sourceRoot'", "]", ")", ";", "}", "return", "json_encode", "(", "$", "sourceMap", ")", ";", "}" ]
Generates the JSON source map @return string @see https://docs.google.com/document/d/1U1RGAehQwRypUTovF1KRlpiOFze0b-_2gc6fAH0KY0k/edit#
[ "Generates", "the", "JSON", "source", "map" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/scssphp/SourceMap/SourceMapGenerator.php#L157-L206
214,812
moodle/moodle
lib/scssphp/SourceMap/SourceMapGenerator.php
SourceMapGenerator.getSourcesContent
protected function getSourcesContent() { if (empty($this->sources)) { return null; } $content = array(); foreach ($this->sources as $sourceFile) { $content[] = file_get_contents($sourceFile); } return $content; }
php
protected function getSourcesContent() { if (empty($this->sources)) { return null; } $content = array(); foreach ($this->sources as $sourceFile) { $content[] = file_get_contents($sourceFile); } return $content; }
[ "protected", "function", "getSourcesContent", "(", ")", "{", "if", "(", "empty", "(", "$", "this", "->", "sources", ")", ")", "{", "return", "null", ";", "}", "$", "content", "=", "array", "(", ")", ";", "foreach", "(", "$", "this", "->", "sources", "as", "$", "sourceFile", ")", "{", "$", "content", "[", "]", "=", "file_get_contents", "(", "$", "sourceFile", ")", ";", "}", "return", "$", "content", ";", "}" ]
Returns the sources contents @return array|null
[ "Returns", "the", "sources", "contents" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/scssphp/SourceMap/SourceMapGenerator.php#L213-L226
214,813
moodle/moodle
lib/classes/chart_series.php
chart_series.set_type
public function set_type($type) { if (!in_array($type, [self::TYPE_DEFAULT, self::TYPE_LINE])) { throw new coding_exception('Invalid serie type.'); } $this->type = $type; }
php
public function set_type($type) { if (!in_array($type, [self::TYPE_DEFAULT, self::TYPE_LINE])) { throw new coding_exception('Invalid serie type.'); } $this->type = $type; }
[ "public", "function", "set_type", "(", "$", "type", ")", "{", "if", "(", "!", "in_array", "(", "$", "type", ",", "[", "self", "::", "TYPE_DEFAULT", ",", "self", "::", "TYPE_LINE", "]", ")", ")", "{", "throw", "new", "coding_exception", "(", "'Invalid serie type.'", ")", ";", "}", "$", "this", "->", "type", "=", "$", "type", ";", "}" ]
Set the type of the series. @param string $type Constant value from self::TYPE_*.
[ "Set", "the", "type", "of", "the", "series", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/chart_series.php#L236-L241
214,814
moodle/moodle
grade/report/singleview/classes/local/ui/exclude.php
exclude.determine_format
public function determine_format() { return new checkbox_attribute( $this->get_name(), $this->get_label(), $this->is_checked(), $this->is_disabled() ); }
php
public function determine_format() { return new checkbox_attribute( $this->get_name(), $this->get_label(), $this->is_checked(), $this->is_disabled() ); }
[ "public", "function", "determine_format", "(", ")", "{", "return", "new", "checkbox_attribute", "(", "$", "this", "->", "get_name", "(", ")", ",", "$", "this", "->", "get_label", "(", ")", ",", "$", "this", "->", "is_checked", "(", ")", ",", "$", "this", "->", "is_disabled", "(", ")", ")", ";", "}" ]
Generate the element used to render the UI @return element
[ "Generate", "the", "element", "used", "to", "render", "the", "UI" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/grade/report/singleview/classes/local/ui/exclude.php#L69-L76
214,815
moodle/moodle
grade/report/singleview/classes/local/ui/exclude.php
exclude.set
public function set($value) { if (empty($this->grade->id)) { if (empty($value)) { return false; } $gradeitem = $this->grade->grade_item; // Fill in arbitrary grade to be excluded. $gradeitem->update_final_grade( $this->grade->userid, null, 'singleview', null, FORMAT_MOODLE ); $gradeparams = array( 'userid' => $this->grade->userid, 'itemid' => $this->grade->itemid ); $this->grade = grade_grade::fetch($gradeparams); $this->grade->grade_item = $gradeitem; } $state = $value == 0 ? false : true; $this->grade->set_excluded($state); $this->grade->grade_item->get_parent_category()->force_regrading(); return false; }
php
public function set($value) { if (empty($this->grade->id)) { if (empty($value)) { return false; } $gradeitem = $this->grade->grade_item; // Fill in arbitrary grade to be excluded. $gradeitem->update_final_grade( $this->grade->userid, null, 'singleview', null, FORMAT_MOODLE ); $gradeparams = array( 'userid' => $this->grade->userid, 'itemid' => $this->grade->itemid ); $this->grade = grade_grade::fetch($gradeparams); $this->grade->grade_item = $gradeitem; } $state = $value == 0 ? false : true; $this->grade->set_excluded($state); $this->grade->grade_item->get_parent_category()->force_regrading(); return false; }
[ "public", "function", "set", "(", "$", "value", ")", "{", "if", "(", "empty", "(", "$", "this", "->", "grade", "->", "id", ")", ")", "{", "if", "(", "empty", "(", "$", "value", ")", ")", "{", "return", "false", ";", "}", "$", "gradeitem", "=", "$", "this", "->", "grade", "->", "grade_item", ";", "// Fill in arbitrary grade to be excluded.", "$", "gradeitem", "->", "update_final_grade", "(", "$", "this", "->", "grade", "->", "userid", ",", "null", ",", "'singleview'", ",", "null", ",", "FORMAT_MOODLE", ")", ";", "$", "gradeparams", "=", "array", "(", "'userid'", "=>", "$", "this", "->", "grade", "->", "userid", ",", "'itemid'", "=>", "$", "this", "->", "grade", "->", "itemid", ")", ";", "$", "this", "->", "grade", "=", "grade_grade", "::", "fetch", "(", "$", "gradeparams", ")", ";", "$", "this", "->", "grade", "->", "grade_item", "=", "$", "gradeitem", ";", "}", "$", "state", "=", "$", "value", "==", "0", "?", "false", ":", "true", ";", "$", "this", "->", "grade", "->", "set_excluded", "(", "$", "state", ")", ";", "$", "this", "->", "grade", "->", "grade_item", "->", "get_parent_category", "(", ")", "->", "force_regrading", "(", ")", ";", "return", "false", ";", "}" ]
Set the value that was changed in the form. @param string $value The value to set. @return mixed string|bool An error message or false.
[ "Set", "the", "value", "that", "was", "changed", "in", "the", "form", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/grade/report/singleview/classes/local/ui/exclude.php#L96-L124
214,816
moodle/moodle
lib/lessphp/Tree/Ruleset.php
Less_Tree_Ruleset.EvalMixinCalls
private function EvalMixinCalls( $ruleset, $env, &$rsRuleCnt ){ for($i=0; $i < $rsRuleCnt; $i++){ $rule = $ruleset->rules[$i]; if( $rule instanceof Less_Tree_Mixin_Call ){ $rule = $rule->compile($env); $temp = array(); foreach($rule as $r){ if( ($r instanceof Less_Tree_Rule) && $r->variable ){ // do not pollute the scope if the variable is // already there. consider returning false here // but we need a way to "return" variable from mixins if( !$ruleset->variable($r->name) ){ $temp[] = $r; } }else{ $temp[] = $r; } } $temp_count = count($temp)-1; array_splice($ruleset->rules, $i, 1, $temp); $rsRuleCnt += $temp_count; $i += $temp_count; $ruleset->resetCache(); }elseif( $rule instanceof Less_Tree_RulesetCall ){ $rule = $rule->compile($env); $rules = array(); foreach($rule->rules as $r){ if( ($r instanceof Less_Tree_Rule) && $r->variable ){ continue; } $rules[] = $r; } array_splice($ruleset->rules, $i, 1, $rules); $temp_count = count($rules); $rsRuleCnt += $temp_count - 1; $i += $temp_count-1; $ruleset->resetCache(); } } }
php
private function EvalMixinCalls( $ruleset, $env, &$rsRuleCnt ){ for($i=0; $i < $rsRuleCnt; $i++){ $rule = $ruleset->rules[$i]; if( $rule instanceof Less_Tree_Mixin_Call ){ $rule = $rule->compile($env); $temp = array(); foreach($rule as $r){ if( ($r instanceof Less_Tree_Rule) && $r->variable ){ // do not pollute the scope if the variable is // already there. consider returning false here // but we need a way to "return" variable from mixins if( !$ruleset->variable($r->name) ){ $temp[] = $r; } }else{ $temp[] = $r; } } $temp_count = count($temp)-1; array_splice($ruleset->rules, $i, 1, $temp); $rsRuleCnt += $temp_count; $i += $temp_count; $ruleset->resetCache(); }elseif( $rule instanceof Less_Tree_RulesetCall ){ $rule = $rule->compile($env); $rules = array(); foreach($rule->rules as $r){ if( ($r instanceof Less_Tree_Rule) && $r->variable ){ continue; } $rules[] = $r; } array_splice($ruleset->rules, $i, 1, $rules); $temp_count = count($rules); $rsRuleCnt += $temp_count - 1; $i += $temp_count-1; $ruleset->resetCache(); } } }
[ "private", "function", "EvalMixinCalls", "(", "$", "ruleset", ",", "$", "env", ",", "&", "$", "rsRuleCnt", ")", "{", "for", "(", "$", "i", "=", "0", ";", "$", "i", "<", "$", "rsRuleCnt", ";", "$", "i", "++", ")", "{", "$", "rule", "=", "$", "ruleset", "->", "rules", "[", "$", "i", "]", ";", "if", "(", "$", "rule", "instanceof", "Less_Tree_Mixin_Call", ")", "{", "$", "rule", "=", "$", "rule", "->", "compile", "(", "$", "env", ")", ";", "$", "temp", "=", "array", "(", ")", ";", "foreach", "(", "$", "rule", "as", "$", "r", ")", "{", "if", "(", "(", "$", "r", "instanceof", "Less_Tree_Rule", ")", "&&", "$", "r", "->", "variable", ")", "{", "// do not pollute the scope if the variable is", "// already there. consider returning false here", "// but we need a way to \"return\" variable from mixins", "if", "(", "!", "$", "ruleset", "->", "variable", "(", "$", "r", "->", "name", ")", ")", "{", "$", "temp", "[", "]", "=", "$", "r", ";", "}", "}", "else", "{", "$", "temp", "[", "]", "=", "$", "r", ";", "}", "}", "$", "temp_count", "=", "count", "(", "$", "temp", ")", "-", "1", ";", "array_splice", "(", "$", "ruleset", "->", "rules", ",", "$", "i", ",", "1", ",", "$", "temp", ")", ";", "$", "rsRuleCnt", "+=", "$", "temp_count", ";", "$", "i", "+=", "$", "temp_count", ";", "$", "ruleset", "->", "resetCache", "(", ")", ";", "}", "elseif", "(", "$", "rule", "instanceof", "Less_Tree_RulesetCall", ")", "{", "$", "rule", "=", "$", "rule", "->", "compile", "(", "$", "env", ")", ";", "$", "rules", "=", "array", "(", ")", ";", "foreach", "(", "$", "rule", "->", "rules", "as", "$", "r", ")", "{", "if", "(", "(", "$", "r", "instanceof", "Less_Tree_Rule", ")", "&&", "$", "r", "->", "variable", ")", "{", "continue", ";", "}", "$", "rules", "[", "]", "=", "$", "r", ";", "}", "array_splice", "(", "$", "ruleset", "->", "rules", ",", "$", "i", ",", "1", ",", "$", "rules", ")", ";", "$", "temp_count", "=", "count", "(", "$", "rules", ")", ";", "$", "rsRuleCnt", "+=", "$", "temp_count", "-", "1", ";", "$", "i", "+=", "$", "temp_count", "-", "1", ";", "$", "ruleset", "->", "resetCache", "(", ")", ";", "}", "}", "}" ]
Compile Less_Tree_Mixin_Call objects @param Less_Tree_Ruleset $ruleset @param integer $rsRuleCnt
[ "Compile", "Less_Tree_Mixin_Call", "objects" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/lessphp/Tree/Ruleset.php#L142-L187
214,817
moodle/moodle
lib/lessphp/Tree/Ruleset.php
Less_Tree_Ruleset.matchCondition
public function matchCondition( $args, $env ){ $lastSelector = end($this->selectors); if( !$lastSelector->evaldCondition ){ return false; } if( $lastSelector->condition && !$lastSelector->condition->compile( $env->copyEvalEnv( $env->frames ) ) ){ return false; } return true; }
php
public function matchCondition( $args, $env ){ $lastSelector = end($this->selectors); if( !$lastSelector->evaldCondition ){ return false; } if( $lastSelector->condition && !$lastSelector->condition->compile( $env->copyEvalEnv( $env->frames ) ) ){ return false; } return true; }
[ "public", "function", "matchCondition", "(", "$", "args", ",", "$", "env", ")", "{", "$", "lastSelector", "=", "end", "(", "$", "this", "->", "selectors", ")", ";", "if", "(", "!", "$", "lastSelector", "->", "evaldCondition", ")", "{", "return", "false", ";", "}", "if", "(", "$", "lastSelector", "->", "condition", "&&", "!", "$", "lastSelector", "->", "condition", "->", "compile", "(", "$", "env", "->", "copyEvalEnv", "(", "$", "env", "->", "frames", ")", ")", ")", "{", "return", "false", ";", "}", "return", "true", ";", "}" ]
lets you call a css selector with a guard
[ "lets", "you", "call", "a", "css", "selector", "with", "a", "guard" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/lessphp/Tree/Ruleset.php#L282-L292
214,818
moodle/moodle
mod/workshop/form/numerrors/lib.php
workshop_numerrors_strategy.prepare_form_fields
protected function prepare_form_fields(array $dims, array $maps) { $formdata = new stdclass(); $key = 0; foreach ($dims as $dimension) { $formdata->{'dimensionid__idx_' . $key} = $dimension->id; $formdata->{'description__idx_' . $key} = $dimension->description; $formdata->{'description__idx_' . $key.'format'} = $dimension->descriptionformat; $formdata->{'grade0__idx_' . $key} = $dimension->grade0; $formdata->{'grade1__idx_' . $key} = $dimension->grade1; $formdata->{'weight__idx_' . $key} = $dimension->weight; $key++; } foreach ($maps as $nonegative => $map) { $formdata->{'map__idx_' . $nonegative} = $map->grade; } return $formdata; }
php
protected function prepare_form_fields(array $dims, array $maps) { $formdata = new stdclass(); $key = 0; foreach ($dims as $dimension) { $formdata->{'dimensionid__idx_' . $key} = $dimension->id; $formdata->{'description__idx_' . $key} = $dimension->description; $formdata->{'description__idx_' . $key.'format'} = $dimension->descriptionformat; $formdata->{'grade0__idx_' . $key} = $dimension->grade0; $formdata->{'grade1__idx_' . $key} = $dimension->grade1; $formdata->{'weight__idx_' . $key} = $dimension->weight; $key++; } foreach ($maps as $nonegative => $map) { $formdata->{'map__idx_' . $nonegative} = $map->grade; } return $formdata; }
[ "protected", "function", "prepare_form_fields", "(", "array", "$", "dims", ",", "array", "$", "maps", ")", "{", "$", "formdata", "=", "new", "stdclass", "(", ")", ";", "$", "key", "=", "0", ";", "foreach", "(", "$", "dims", "as", "$", "dimension", ")", "{", "$", "formdata", "->", "{", "'dimensionid__idx_'", ".", "$", "key", "}", "=", "$", "dimension", "->", "id", ";", "$", "formdata", "->", "{", "'description__idx_'", ".", "$", "key", "}", "=", "$", "dimension", "->", "description", ";", "$", "formdata", "->", "{", "'description__idx_'", ".", "$", "key", ".", "'format'", "}", "=", "$", "dimension", "->", "descriptionformat", ";", "$", "formdata", "->", "{", "'grade0__idx_'", ".", "$", "key", "}", "=", "$", "dimension", "->", "grade0", ";", "$", "formdata", "->", "{", "'grade1__idx_'", ".", "$", "key", "}", "=", "$", "dimension", "->", "grade1", ";", "$", "formdata", "->", "{", "'weight__idx_'", ".", "$", "key", "}", "=", "$", "dimension", "->", "weight", ";", "$", "key", "++", ";", "}", "foreach", "(", "$", "maps", "as", "$", "nonegative", "=>", "$", "map", ")", "{", "$", "formdata", "->", "{", "'map__idx_'", ".", "$", "nonegative", "}", "=", "$", "map", "->", "grade", ";", "}", "return", "$", "formdata", ";", "}" ]
Prepares the database data to be used by the mform @param array $dims Array of raw dimension records as returned by {@link load_fields()} @param array $maps Array of raw mapping records as returned by {@link load_mappings()} @return array Array of fields data to be used by the mform set_data
[ "Prepares", "the", "database", "data", "to", "be", "used", "by", "the", "mform" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/workshop/form/numerrors/lib.php#L447-L466
214,819
moodle/moodle
mod/workshop/form/numerrors/lib.php
workshop_numerrors_strategy.errors_to_grade
protected function errors_to_grade($numerrors) { $grade = 100.00000; for ($i = 1; $i <= $numerrors; $i++) { if (isset($this->mappings[$i])) { $grade = $this->mappings[$i]->grade; } } if ($grade > 100.00000) { $grade = 100.00000; } if ($grade < 0.00000) { $grade = 0.00000; } return grade_floatval($grade); }
php
protected function errors_to_grade($numerrors) { $grade = 100.00000; for ($i = 1; $i <= $numerrors; $i++) { if (isset($this->mappings[$i])) { $grade = $this->mappings[$i]->grade; } } if ($grade > 100.00000) { $grade = 100.00000; } if ($grade < 0.00000) { $grade = 0.00000; } return grade_floatval($grade); }
[ "protected", "function", "errors_to_grade", "(", "$", "numerrors", ")", "{", "$", "grade", "=", "100.00000", ";", "for", "(", "$", "i", "=", "1", ";", "$", "i", "<=", "$", "numerrors", ";", "$", "i", "++", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "mappings", "[", "$", "i", "]", ")", ")", "{", "$", "grade", "=", "$", "this", "->", "mappings", "[", "$", "i", "]", "->", "grade", ";", "}", "}", "if", "(", "$", "grade", ">", "100.00000", ")", "{", "$", "grade", "=", "100.00000", ";", "}", "if", "(", "$", "grade", "<", "0.00000", ")", "{", "$", "grade", "=", "0.00000", ";", "}", "return", "grade_floatval", "(", "$", "grade", ")", ";", "}" ]
Returns a grade 0.00000 to 100.00000 for the given number of errors This is where we use the mapping table defined by the teacher. If a grade for the given number of errors (negative assertions) is not defined, the most recently defined one is used. Example of the defined mapping: Number of errors | Grade 0 | 100% (always) 1 | - (not defined) 2 | 80% 3 | 60% 4 | - 5 | 30% 6 | 0% With this mapping, one error is mapped to 100% grade and 4 errors is mapped to 60%. @param mixed $numerrors Number of errors @return float Raw grade (0.00000 to 100.00000) for the given number of negative assertions
[ "Returns", "a", "grade", "0", ".", "00000", "to", "100", ".", "00000", "for", "the", "given", "number", "of", "errors" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/workshop/form/numerrors/lib.php#L605-L619
214,820
moodle/moodle
enrol/imsenterprise/lib.php
enrol_imsenterprise_plugin.full_tag_found_in_cache
protected function full_tag_found_in_cache($tagname, $latestline) { // Return entire element if found. Otherwise return false. if (strpos(strtolower($latestline), '</'.strtolower($tagname).'>') === false) { return false; } else if (preg_match('{(<'.$tagname.'\b.*?>.*?</'.$tagname.'>)}is', $this->xmlcache, $matches)) { return $matches[1]; } else { return false; } }
php
protected function full_tag_found_in_cache($tagname, $latestline) { // Return entire element if found. Otherwise return false. if (strpos(strtolower($latestline), '</'.strtolower($tagname).'>') === false) { return false; } else if (preg_match('{(<'.$tagname.'\b.*?>.*?</'.$tagname.'>)}is', $this->xmlcache, $matches)) { return $matches[1]; } else { return false; } }
[ "protected", "function", "full_tag_found_in_cache", "(", "$", "tagname", ",", "$", "latestline", ")", "{", "// Return entire element if found. Otherwise return false.", "if", "(", "strpos", "(", "strtolower", "(", "$", "latestline", ")", ",", "'</'", ".", "strtolower", "(", "$", "tagname", ")", ".", "'>'", ")", "===", "false", ")", "{", "return", "false", ";", "}", "else", "if", "(", "preg_match", "(", "'{(<'", ".", "$", "tagname", ".", "'\\b.*?>.*?</'", ".", "$", "tagname", ".", "'>)}is'", ",", "$", "this", "->", "xmlcache", ",", "$", "matches", ")", ")", "{", "return", "$", "matches", "[", "1", "]", ";", "}", "else", "{", "return", "false", ";", "}", "}" ]
Check if a complete tag is found in the cached data, which usually happens when the end of the tag has only just been loaded into the cache. @param string $tagname Name of tag to look for @param string $latestline The very last line in the cache (used for speeding up the match) @return bool|string false, or the contents of the tag (including start and end).
[ "Check", "if", "a", "complete", "tag", "is", "found", "in", "the", "cached", "data", "which", "usually", "happens", "when", "the", "end", "of", "the", "tag", "has", "only", "just", "been", "loaded", "into", "the", "cache", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/enrol/imsenterprise/lib.php#L256-L265
214,821
moodle/moodle
enrol/imsenterprise/lib.php
enrol_imsenterprise_plugin.get_category_from_group
private function get_category_from_group($categories) { global $DB; if (empty($categories)) { $catid = $this->get_default_category_id(); } else { $createnewcategories = $this->get_config('createnewcategories'); $categoryseparator = trim($this->get_config('categoryseparator')); $nestedcategories = trim($this->get_config('nestedcategories')); $searchbyidnumber = trim($this->get_config('categoryidnumber')); if (!empty($categoryseparator)) { $sep = '{\\'.$categoryseparator.'}'; } $catid = 0; $fullnestedcatname = ''; foreach ($categories as $categoryinfo) { if ($searchbyidnumber) { $values = preg_split($sep, $categoryinfo, -1, PREG_SPLIT_NO_EMPTY); if (count($values) < 2) { $this->log_line('Category ' . $categoryinfo . ' missing name or idnumber. Using default category instead.'); $catid = $this->get_default_category_id(); break; } $categoryname = $values[0]; $categoryidnumber = $values[1]; } else { $categoryname = $categoryinfo; $categoryidnumber = null; if (empty($categoryname)) { $this->log_line('Category ' . $categoryinfo . ' missing name. Using default category instead.'); $catid = $this->get_default_category_id(); break; } } if (!empty($fullnestedcatname)) { $fullnestedcatname .= ' / '; } $fullnestedcatname .= $categoryname; $parentid = $catid; // Check if category exist. $params = array(); if ($searchbyidnumber) { $params['idnumber'] = $categoryidnumber; } else { $params['name'] = $categoryname; } if ($nestedcategories) { $params['parent'] = $parentid; } if ($catid = $DB->get_field('course_categories', 'id', $params)) { continue; // This category already exists. } // If we're allowed to create new categories, let's create this one. if ($createnewcategories) { $newcat = new stdClass(); $newcat->name = $categoryname; $newcat->visible = 0; $newcat->parent = $parentid; $newcat->idnumber = $categoryidnumber; $newcat = core_course_category::create($newcat); $catid = $newcat->id; $this->log_line("Created new (hidden) category '$fullnestedcatname'"); } else { // If not found and not allowed to create, stick with default. $this->log_line('Category ' . $categoryinfo . ' not found in Moodle database. Using default category instead.'); $catid = $this->get_default_category_id(); break; } } } return $catid; }
php
private function get_category_from_group($categories) { global $DB; if (empty($categories)) { $catid = $this->get_default_category_id(); } else { $createnewcategories = $this->get_config('createnewcategories'); $categoryseparator = trim($this->get_config('categoryseparator')); $nestedcategories = trim($this->get_config('nestedcategories')); $searchbyidnumber = trim($this->get_config('categoryidnumber')); if (!empty($categoryseparator)) { $sep = '{\\'.$categoryseparator.'}'; } $catid = 0; $fullnestedcatname = ''; foreach ($categories as $categoryinfo) { if ($searchbyidnumber) { $values = preg_split($sep, $categoryinfo, -1, PREG_SPLIT_NO_EMPTY); if (count($values) < 2) { $this->log_line('Category ' . $categoryinfo . ' missing name or idnumber. Using default category instead.'); $catid = $this->get_default_category_id(); break; } $categoryname = $values[0]; $categoryidnumber = $values[1]; } else { $categoryname = $categoryinfo; $categoryidnumber = null; if (empty($categoryname)) { $this->log_line('Category ' . $categoryinfo . ' missing name. Using default category instead.'); $catid = $this->get_default_category_id(); break; } } if (!empty($fullnestedcatname)) { $fullnestedcatname .= ' / '; } $fullnestedcatname .= $categoryname; $parentid = $catid; // Check if category exist. $params = array(); if ($searchbyidnumber) { $params['idnumber'] = $categoryidnumber; } else { $params['name'] = $categoryname; } if ($nestedcategories) { $params['parent'] = $parentid; } if ($catid = $DB->get_field('course_categories', 'id', $params)) { continue; // This category already exists. } // If we're allowed to create new categories, let's create this one. if ($createnewcategories) { $newcat = new stdClass(); $newcat->name = $categoryname; $newcat->visible = 0; $newcat->parent = $parentid; $newcat->idnumber = $categoryidnumber; $newcat = core_course_category::create($newcat); $catid = $newcat->id; $this->log_line("Created new (hidden) category '$fullnestedcatname'"); } else { // If not found and not allowed to create, stick with default. $this->log_line('Category ' . $categoryinfo . ' not found in Moodle database. Using default category instead.'); $catid = $this->get_default_category_id(); break; } } } return $catid; }
[ "private", "function", "get_category_from_group", "(", "$", "categories", ")", "{", "global", "$", "DB", ";", "if", "(", "empty", "(", "$", "categories", ")", ")", "{", "$", "catid", "=", "$", "this", "->", "get_default_category_id", "(", ")", ";", "}", "else", "{", "$", "createnewcategories", "=", "$", "this", "->", "get_config", "(", "'createnewcategories'", ")", ";", "$", "categoryseparator", "=", "trim", "(", "$", "this", "->", "get_config", "(", "'categoryseparator'", ")", ")", ";", "$", "nestedcategories", "=", "trim", "(", "$", "this", "->", "get_config", "(", "'nestedcategories'", ")", ")", ";", "$", "searchbyidnumber", "=", "trim", "(", "$", "this", "->", "get_config", "(", "'categoryidnumber'", ")", ")", ";", "if", "(", "!", "empty", "(", "$", "categoryseparator", ")", ")", "{", "$", "sep", "=", "'{\\\\'", ".", "$", "categoryseparator", ".", "'}'", ";", "}", "$", "catid", "=", "0", ";", "$", "fullnestedcatname", "=", "''", ";", "foreach", "(", "$", "categories", "as", "$", "categoryinfo", ")", "{", "if", "(", "$", "searchbyidnumber", ")", "{", "$", "values", "=", "preg_split", "(", "$", "sep", ",", "$", "categoryinfo", ",", "-", "1", ",", "PREG_SPLIT_NO_EMPTY", ")", ";", "if", "(", "count", "(", "$", "values", ")", "<", "2", ")", "{", "$", "this", "->", "log_line", "(", "'Category '", ".", "$", "categoryinfo", ".", "' missing name or idnumber. Using default category instead.'", ")", ";", "$", "catid", "=", "$", "this", "->", "get_default_category_id", "(", ")", ";", "break", ";", "}", "$", "categoryname", "=", "$", "values", "[", "0", "]", ";", "$", "categoryidnumber", "=", "$", "values", "[", "1", "]", ";", "}", "else", "{", "$", "categoryname", "=", "$", "categoryinfo", ";", "$", "categoryidnumber", "=", "null", ";", "if", "(", "empty", "(", "$", "categoryname", ")", ")", "{", "$", "this", "->", "log_line", "(", "'Category '", ".", "$", "categoryinfo", ".", "' missing name. Using default category instead.'", ")", ";", "$", "catid", "=", "$", "this", "->", "get_default_category_id", "(", ")", ";", "break", ";", "}", "}", "if", "(", "!", "empty", "(", "$", "fullnestedcatname", ")", ")", "{", "$", "fullnestedcatname", ".=", "' / '", ";", "}", "$", "fullnestedcatname", ".=", "$", "categoryname", ";", "$", "parentid", "=", "$", "catid", ";", "// Check if category exist.", "$", "params", "=", "array", "(", ")", ";", "if", "(", "$", "searchbyidnumber", ")", "{", "$", "params", "[", "'idnumber'", "]", "=", "$", "categoryidnumber", ";", "}", "else", "{", "$", "params", "[", "'name'", "]", "=", "$", "categoryname", ";", "}", "if", "(", "$", "nestedcategories", ")", "{", "$", "params", "[", "'parent'", "]", "=", "$", "parentid", ";", "}", "if", "(", "$", "catid", "=", "$", "DB", "->", "get_field", "(", "'course_categories'", ",", "'id'", ",", "$", "params", ")", ")", "{", "continue", ";", "// This category already exists.", "}", "// If we're allowed to create new categories, let's create this one.", "if", "(", "$", "createnewcategories", ")", "{", "$", "newcat", "=", "new", "stdClass", "(", ")", ";", "$", "newcat", "->", "name", "=", "$", "categoryname", ";", "$", "newcat", "->", "visible", "=", "0", ";", "$", "newcat", "->", "parent", "=", "$", "parentid", ";", "$", "newcat", "->", "idnumber", "=", "$", "categoryidnumber", ";", "$", "newcat", "=", "core_course_category", "::", "create", "(", "$", "newcat", ")", ";", "$", "catid", "=", "$", "newcat", "->", "id", ";", "$", "this", "->", "log_line", "(", "\"Created new (hidden) category '$fullnestedcatname'\"", ")", ";", "}", "else", "{", "// If not found and not allowed to create, stick with default.", "$", "this", "->", "log_line", "(", "'Category '", ".", "$", "categoryinfo", ".", "' not found in Moodle database. Using default category instead.'", ")", ";", "$", "catid", "=", "$", "this", "->", "get_default_category_id", "(", ")", ";", "break", ";", "}", "}", "}", "return", "$", "catid", ";", "}" ]
Find the category using idnumber or name. @param array $categories List of categories @return int id of category found.
[ "Find", "the", "category", "using", "idnumber", "or", "name", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/enrol/imsenterprise/lib.php#L891-L971
214,822
moodle/moodle
lib/simplepie/library/SimplePie/XML/Declaration/Parser.php
SimplePie_XML_Declaration_Parser.skip_whitespace
public function skip_whitespace() { $whitespace = strspn($this->data, "\x09\x0A\x0D\x20", $this->position); $this->position += $whitespace; return $whitespace; }
php
public function skip_whitespace() { $whitespace = strspn($this->data, "\x09\x0A\x0D\x20", $this->position); $this->position += $whitespace; return $whitespace; }
[ "public", "function", "skip_whitespace", "(", ")", "{", "$", "whitespace", "=", "strspn", "(", "$", "this", "->", "data", ",", "\"\\x09\\x0A\\x0D\\x20\"", ",", "$", "this", "->", "position", ")", ";", "$", "this", "->", "position", "+=", "$", "whitespace", ";", "return", "$", "whitespace", ";", "}" ]
Advance past any whitespace @return int Number of whitespace characters passed
[ "Advance", "past", "any", "whitespace" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/simplepie/library/SimplePie/XML/Declaration/Parser.php#L164-L169
214,823
moodle/moodle
mod/workshop/form/rubric/edit_form.php
workshop_edit_rubric_strategy_form.validation_inner
protected function validation_inner($data, $files) { $errors = array(); // Iterate over all submitted dimensions (criteria). for ($i = 0; isset($data['dimensionid__idx_'.$i]); $i++) { $dimgrades = array(); if (0 == strlen(trim($data['description__idx_'.$i.'_editor']['text']))) { // The description text is empty and this criterion will be deleted. continue; } // Make sure the levels grades are unique within the criterion. $atleastonelevel = false; for ($j = 0; isset($data['levelid__idx_'.$i.'__idy_'.$j]); $j++) { if (0 == strlen(trim($data['definition__idx_'.$i.'__idy_'.$j]))) { // The level definition is empty and will not be saved. continue; } $atleastonelevel = true; $levelgrade = $data['grade__idx_'.$i.'__idy_'.$j]; if (isset($dimgrades[$levelgrade])) { // This grade has already been set for another level. $k = $dimgrades[$levelgrade]; $errors['level__idx_'.$i.'__idy_'.$j] = $errors['level__idx_'.$i.'__idy_'.$k] = get_string('mustbeunique', 'workshopform_rubric'); } else { $dimgrades[$levelgrade] = $j; } } if (!$atleastonelevel) { $errors['level__idx_'.$i.'__idy_0'] = get_string('mustdefinelevel', 'workshopform_rubric'); } } return $errors; }
php
protected function validation_inner($data, $files) { $errors = array(); // Iterate over all submitted dimensions (criteria). for ($i = 0; isset($data['dimensionid__idx_'.$i]); $i++) { $dimgrades = array(); if (0 == strlen(trim($data['description__idx_'.$i.'_editor']['text']))) { // The description text is empty and this criterion will be deleted. continue; } // Make sure the levels grades are unique within the criterion. $atleastonelevel = false; for ($j = 0; isset($data['levelid__idx_'.$i.'__idy_'.$j]); $j++) { if (0 == strlen(trim($data['definition__idx_'.$i.'__idy_'.$j]))) { // The level definition is empty and will not be saved. continue; } $atleastonelevel = true; $levelgrade = $data['grade__idx_'.$i.'__idy_'.$j]; if (isset($dimgrades[$levelgrade])) { // This grade has already been set for another level. $k = $dimgrades[$levelgrade]; $errors['level__idx_'.$i.'__idy_'.$j] = $errors['level__idx_'.$i.'__idy_'.$k] = get_string('mustbeunique', 'workshopform_rubric'); } else { $dimgrades[$levelgrade] = $j; } } if (!$atleastonelevel) { $errors['level__idx_'.$i.'__idy_0'] = get_string('mustdefinelevel', 'workshopform_rubric'); } } return $errors; }
[ "protected", "function", "validation_inner", "(", "$", "data", ",", "$", "files", ")", "{", "$", "errors", "=", "array", "(", ")", ";", "// Iterate over all submitted dimensions (criteria).", "for", "(", "$", "i", "=", "0", ";", "isset", "(", "$", "data", "[", "'dimensionid__idx_'", ".", "$", "i", "]", ")", ";", "$", "i", "++", ")", "{", "$", "dimgrades", "=", "array", "(", ")", ";", "if", "(", "0", "==", "strlen", "(", "trim", "(", "$", "data", "[", "'description__idx_'", ".", "$", "i", ".", "'_editor'", "]", "[", "'text'", "]", ")", ")", ")", "{", "// The description text is empty and this criterion will be deleted.", "continue", ";", "}", "// Make sure the levels grades are unique within the criterion.", "$", "atleastonelevel", "=", "false", ";", "for", "(", "$", "j", "=", "0", ";", "isset", "(", "$", "data", "[", "'levelid__idx_'", ".", "$", "i", ".", "'__idy_'", ".", "$", "j", "]", ")", ";", "$", "j", "++", ")", "{", "if", "(", "0", "==", "strlen", "(", "trim", "(", "$", "data", "[", "'definition__idx_'", ".", "$", "i", ".", "'__idy_'", ".", "$", "j", "]", ")", ")", ")", "{", "// The level definition is empty and will not be saved.", "continue", ";", "}", "$", "atleastonelevel", "=", "true", ";", "$", "levelgrade", "=", "$", "data", "[", "'grade__idx_'", ".", "$", "i", ".", "'__idy_'", ".", "$", "j", "]", ";", "if", "(", "isset", "(", "$", "dimgrades", "[", "$", "levelgrade", "]", ")", ")", "{", "// This grade has already been set for another level.", "$", "k", "=", "$", "dimgrades", "[", "$", "levelgrade", "]", ";", "$", "errors", "[", "'level__idx_'", ".", "$", "i", ".", "'__idy_'", ".", "$", "j", "]", "=", "$", "errors", "[", "'level__idx_'", ".", "$", "i", ".", "'__idy_'", ".", "$", "k", "]", "=", "get_string", "(", "'mustbeunique'", ",", "'workshopform_rubric'", ")", ";", "}", "else", "{", "$", "dimgrades", "[", "$", "levelgrade", "]", "=", "$", "j", ";", "}", "}", "if", "(", "!", "$", "atleastonelevel", ")", "{", "$", "errors", "[", "'level__idx_'", ".", "$", "i", ".", "'__idy_0'", "]", "=", "get_string", "(", "'mustdefinelevel'", ",", "'workshopform_rubric'", ")", ";", "}", "}", "return", "$", "errors", ";", "}" ]
Provide validation rules for the rubric editor form. @param array $data @param array $files @return array
[ "Provide", "validation", "rules", "for", "the", "rubric", "editor", "form", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/workshop/form/rubric/edit_form.php#L114-L154
214,824
moodle/moodle
question/engine/questionattemptstep.php
question_attempt_step.set_qt_var
public function set_qt_var($name, $value) { if ($name[0] != '_') { throw new coding_exception('Cannot set question type data ' . $name . ' on an attempt step. You can only set variables with names begining with _.'); } $this->data[$name] = $value; }
php
public function set_qt_var($name, $value) { if ($name[0] != '_') { throw new coding_exception('Cannot set question type data ' . $name . ' on an attempt step. You can only set variables with names begining with _.'); } $this->data[$name] = $value; }
[ "public", "function", "set_qt_var", "(", "$", "name", ",", "$", "value", ")", "{", "if", "(", "$", "name", "[", "0", "]", "!=", "'_'", ")", "{", "throw", "new", "coding_exception", "(", "'Cannot set question type data '", ".", "$", "name", ".", "' on an attempt step. You can only set variables with names begining with _.'", ")", ";", "}", "$", "this", "->", "data", "[", "$", "name", "]", "=", "$", "value", ";", "}" ]
Set a cached question type variable. @param string $name the name of the variable to set. Must match _[a-z][a-z0-9]*. @param string $value the value to set.
[ "Set", "a", "cached", "question", "type", "variable", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/engine/questionattemptstep.php#L204-L210
214,825
moodle/moodle
question/engine/questionattemptstep.php
question_attempt_step.prepare_response_files_draft_itemid
public function prepare_response_files_draft_itemid($name, $contextid) { list($draftid, $notused) = $this->prepare_response_files_draft_itemid_with_text( $name, $contextid, null); return $draftid; }
php
public function prepare_response_files_draft_itemid($name, $contextid) { list($draftid, $notused) = $this->prepare_response_files_draft_itemid_with_text( $name, $contextid, null); return $draftid; }
[ "public", "function", "prepare_response_files_draft_itemid", "(", "$", "name", ",", "$", "contextid", ")", "{", "list", "(", "$", "draftid", ",", "$", "notused", ")", "=", "$", "this", "->", "prepare_response_files_draft_itemid_with_text", "(", "$", "name", ",", "$", "contextid", ",", "null", ")", ";", "return", "$", "draftid", ";", "}" ]
Prepare a draft file are for the files belonging the a response variable of this step. @param string $name the variable name the files belong to. @param int $contextid the id of the context the quba belongs to. @return int the draft itemid.
[ "Prepare", "a", "draft", "file", "are", "for", "the", "files", "belonging", "the", "a", "response", "variable", "of", "this", "step", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/engine/questionattemptstep.php#L244-L248
214,826
moodle/moodle
question/engine/questionattemptstep.php
question_attempt_step.prepare_response_files_draft_itemid_with_text
public function prepare_response_files_draft_itemid_with_text($name, $contextid, $text) { $draftid = 0; // Will be filled in by file_prepare_draft_area. $newtext = file_prepare_draft_area($draftid, $contextid, 'question', 'response_' . $name, $this->id, null, $text); return array($draftid, $newtext); }
php
public function prepare_response_files_draft_itemid_with_text($name, $contextid, $text) { $draftid = 0; // Will be filled in by file_prepare_draft_area. $newtext = file_prepare_draft_area($draftid, $contextid, 'question', 'response_' . $name, $this->id, null, $text); return array($draftid, $newtext); }
[ "public", "function", "prepare_response_files_draft_itemid_with_text", "(", "$", "name", ",", "$", "contextid", ",", "$", "text", ")", "{", "$", "draftid", "=", "0", ";", "// Will be filled in by file_prepare_draft_area.", "$", "newtext", "=", "file_prepare_draft_area", "(", "$", "draftid", ",", "$", "contextid", ",", "'question'", ",", "'response_'", ".", "$", "name", ",", "$", "this", "->", "id", ",", "null", ",", "$", "text", ")", ";", "return", "array", "(", "$", "draftid", ",", "$", "newtext", ")", ";", "}" ]
Prepare a draft file are for the files belonging the a response variable of this step, while rewriting the URLs in some text. @param string $name the variable name the files belong to. @param int $contextid the id of the context the quba belongs to. @param string $text the text to update the URLs in. @return array(int, string) the draft itemid and the text with URLs rewritten.
[ "Prepare", "a", "draft", "file", "are", "for", "the", "files", "belonging", "the", "a", "response", "variable", "of", "this", "step", "while", "rewriting", "the", "URLs", "in", "some", "text", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/engine/questionattemptstep.php#L259-L264
214,827
moodle/moodle
question/engine/questionattemptstep.php
question_attempt_step.get_qt_data
public function get_qt_data() { $result = array(); foreach ($this->data as $name => $value) { if ($name[0] != '-' && $name[0] != ':') { $result[$name] = $value; } } return $result; }
php
public function get_qt_data() { $result = array(); foreach ($this->data as $name => $value) { if ($name[0] != '-' && $name[0] != ':') { $result[$name] = $value; } } return $result; }
[ "public", "function", "get_qt_data", "(", ")", "{", "$", "result", "=", "array", "(", ")", ";", "foreach", "(", "$", "this", "->", "data", "as", "$", "name", "=>", "$", "value", ")", "{", "if", "(", "$", "name", "[", "0", "]", "!=", "'-'", "&&", "$", "name", "[", "0", "]", "!=", "':'", ")", "{", "$", "result", "[", "$", "name", "]", "=", "$", "value", ";", "}", "}", "return", "$", "result", ";", "}" ]
Get all the question type variables. @param array name => value pairs.
[ "Get", "all", "the", "question", "type", "variables", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/engine/questionattemptstep.php#L287-L295
214,828
moodle/moodle
question/engine/questionattemptstep.php
question_attempt_step.set_behaviour_var
public function set_behaviour_var($name, $value) { if ($name[0] != '_') { throw new coding_exception('Cannot set question type data ' . $name . ' on an attempt step. You can only set variables with names begining with _.'); } return $this->data['-' . $name] = $value; }
php
public function set_behaviour_var($name, $value) { if ($name[0] != '_') { throw new coding_exception('Cannot set question type data ' . $name . ' on an attempt step. You can only set variables with names begining with _.'); } return $this->data['-' . $name] = $value; }
[ "public", "function", "set_behaviour_var", "(", "$", "name", ",", "$", "value", ")", "{", "if", "(", "$", "name", "[", "0", "]", "!=", "'_'", ")", "{", "throw", "new", "coding_exception", "(", "'Cannot set question type data '", ".", "$", "name", ".", "' on an attempt step. You can only set variables with names begining with _.'", ")", ";", "}", "return", "$", "this", "->", "data", "[", "'-'", ".", "$", "name", "]", "=", "$", "value", ";", "}" ]
Set a cached behaviour variable. @param string $name the name of the variable to set. Must match _[a-z][a-z0-9]*. @param string $value the value to set.
[ "Set", "a", "cached", "behaviour", "variable", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/engine/questionattemptstep.php#L321-L327
214,829
moodle/moodle
question/engine/questionattemptstep.php
question_attempt_step.get_behaviour_data
public function get_behaviour_data() { $result = array(); foreach ($this->data as $name => $value) { if ($name[0] == '-') { $result[substr($name, 1)] = $value; } } return $result; }
php
public function get_behaviour_data() { $result = array(); foreach ($this->data as $name => $value) { if ($name[0] == '-') { $result[substr($name, 1)] = $value; } } return $result; }
[ "public", "function", "get_behaviour_data", "(", ")", "{", "$", "result", "=", "array", "(", ")", ";", "foreach", "(", "$", "this", "->", "data", "as", "$", "name", "=>", "$", "value", ")", "{", "if", "(", "$", "name", "[", "0", "]", "==", "'-'", ")", "{", "$", "result", "[", "substr", "(", "$", "name", ",", "1", ")", "]", "=", "$", "value", ";", "}", "}", "return", "$", "result", ";", "}" ]
Get all the behaviour variables. @param array name => value pairs.
[ "Get", "all", "the", "behaviour", "variables", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/engine/questionattemptstep.php#L333-L341
214,830
moodle/moodle
question/engine/questionattemptstep.php
question_attempt_step_subquestion_adapter.add_prefix
public function add_prefix($field) { if (substr($field, 0, 2) === '!_') { return '-_' . $this->extraprefix . substr($field, 2); } else if (substr($field, 0, 1) === '-') { return '-' . $this->extraprefix . substr($field, 1); } else if (substr($field, 0, 1) === '_') { return '_' . $this->extraprefix . substr($field, 1); } else { return $this->extraprefix . $field; } }
php
public function add_prefix($field) { if (substr($field, 0, 2) === '!_') { return '-_' . $this->extraprefix . substr($field, 2); } else if (substr($field, 0, 1) === '-') { return '-' . $this->extraprefix . substr($field, 1); } else if (substr($field, 0, 1) === '_') { return '_' . $this->extraprefix . substr($field, 1); } else { return $this->extraprefix . $field; } }
[ "public", "function", "add_prefix", "(", "$", "field", ")", "{", "if", "(", "substr", "(", "$", "field", ",", "0", ",", "2", ")", "===", "'!_'", ")", "{", "return", "'-_'", ".", "$", "this", "->", "extraprefix", ".", "substr", "(", "$", "field", ",", "2", ")", ";", "}", "else", "if", "(", "substr", "(", "$", "field", ",", "0", ",", "1", ")", "===", "'-'", ")", "{", "return", "'-'", ".", "$", "this", "->", "extraprefix", ".", "substr", "(", "$", "field", ",", "1", ")", ";", "}", "else", "if", "(", "substr", "(", "$", "field", ",", "0", ",", "1", ")", "===", "'_'", ")", "{", "return", "'_'", ".", "$", "this", "->", "extraprefix", ".", "substr", "(", "$", "field", ",", "1", ")", ";", "}", "else", "{", "return", "$", "this", "->", "extraprefix", ".", "$", "field", ";", "}", "}" ]
Add the extra prefix to a field name. @param string $field the plain field name. @return string the field name with the extra bit of prefix added.
[ "Add", "the", "extra", "prefix", "to", "a", "field", "name", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/engine/questionattemptstep.php#L624-L634
214,831
moodle/moodle
question/engine/questionattemptstep.php
question_attempt_step_subquestion_adapter.remove_prefix
public function remove_prefix($field) { if (preg_match('~^(-?_?)' . preg_quote($this->extraprefix, '~') . '(.*)$~', $field, $matches)) { return $matches[1] . $matches[2]; } else { return null; } }
php
public function remove_prefix($field) { if (preg_match('~^(-?_?)' . preg_quote($this->extraprefix, '~') . '(.*)$~', $field, $matches)) { return $matches[1] . $matches[2]; } else { return null; } }
[ "public", "function", "remove_prefix", "(", "$", "field", ")", "{", "if", "(", "preg_match", "(", "'~^(-?_?)'", ".", "preg_quote", "(", "$", "this", "->", "extraprefix", ",", "'~'", ")", ".", "'(.*)$~'", ",", "$", "field", ",", "$", "matches", ")", ")", "{", "return", "$", "matches", "[", "1", "]", ".", "$", "matches", "[", "2", "]", ";", "}", "else", "{", "return", "null", ";", "}", "}" ]
Remove the extra prefix from a field name if it is present. @param string $field the extended field name. @return string the field name with the extra bit of prefix removed, or null if the extre prefix was not present.
[ "Remove", "the", "extra", "prefix", "from", "a", "field", "name", "if", "it", "is", "present", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/engine/questionattemptstep.php#L642-L648
214,832
moodle/moodle
question/engine/questionattemptstep.php
question_attempt_step_subquestion_adapter.filter_array
public function filter_array($data) { $result = array(); foreach ($data as $fullname => $value) { if ($name = $this->remove_prefix($fullname)) { $result[$name] = $value; } } return $result; }
php
public function filter_array($data) { $result = array(); foreach ($data as $fullname => $value) { if ($name = $this->remove_prefix($fullname)) { $result[$name] = $value; } } return $result; }
[ "public", "function", "filter_array", "(", "$", "data", ")", "{", "$", "result", "=", "array", "(", ")", ";", "foreach", "(", "$", "data", "as", "$", "fullname", "=>", "$", "value", ")", "{", "if", "(", "$", "name", "=", "$", "this", "->", "remove_prefix", "(", "$", "fullname", ")", ")", "{", "$", "result", "[", "$", "name", "]", "=", "$", "value", ";", "}", "}", "return", "$", "result", ";", "}" ]
Filter some data to keep only those entries where the key contains extraprefix, and remove the extra prefix from the reutrned arrary. @param array $data some of the data stored in this step. @return array the data with the keys ajusted using {@link remove_prefix()}.
[ "Filter", "some", "data", "to", "keep", "only", "those", "entries", "where", "the", "key", "contains", "extraprefix", "and", "remove", "the", "extra", "prefix", "from", "the", "reutrned", "arrary", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/engine/questionattemptstep.php#L656-L664
214,833
moodle/moodle
repository/youtube/lib.php
repository_youtube.init_youtube_service
private function init_youtube_service() { global $CFG; if (!isset($this->service)) { require_once($CFG->libdir . '/google/lib.php'); $this->client = get_google_client(); $this->client->setDeveloperKey($this->apikey); $this->client->setScopes(array(Google_Service_YouTube::YOUTUBE_READONLY)); $this->service = new Google_Service_YouTube($this->client); } }
php
private function init_youtube_service() { global $CFG; if (!isset($this->service)) { require_once($CFG->libdir . '/google/lib.php'); $this->client = get_google_client(); $this->client->setDeveloperKey($this->apikey); $this->client->setScopes(array(Google_Service_YouTube::YOUTUBE_READONLY)); $this->service = new Google_Service_YouTube($this->client); } }
[ "private", "function", "init_youtube_service", "(", ")", "{", "global", "$", "CFG", ";", "if", "(", "!", "isset", "(", "$", "this", "->", "service", ")", ")", "{", "require_once", "(", "$", "CFG", "->", "libdir", ".", "'/google/lib.php'", ")", ";", "$", "this", "->", "client", "=", "get_google_client", "(", ")", ";", "$", "this", "->", "client", "->", "setDeveloperKey", "(", "$", "this", "->", "apikey", ")", ";", "$", "this", "->", "client", "->", "setScopes", "(", "array", "(", "Google_Service_YouTube", "::", "YOUTUBE_READONLY", ")", ")", ";", "$", "this", "->", "service", "=", "new", "Google_Service_YouTube", "(", "$", "this", "->", "client", ")", ";", "}", "}" ]
Init all the youtube client service stuff. Instead of instantiating the service in the constructor, we delay it until really neeed because it's really memory hungry (2MB). That way the editor or any other artifact requiring repository instantiation can do it in a cheap way. Sort of lazy loading the plugin.
[ "Init", "all", "the", "youtube", "client", "service", "stuff", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/repository/youtube/lib.php#L83-L93
214,834
moodle/moodle
repository/youtube/lib.php
repository_youtube.set_option
public function set_option($options = array()) { if (!empty($options['apikey'])) { set_config('apikey', trim($options['apikey']), 'youtube'); } unset($options['apikey']); return parent::set_option($options); }
php
public function set_option($options = array()) { if (!empty($options['apikey'])) { set_config('apikey', trim($options['apikey']), 'youtube'); } unset($options['apikey']); return parent::set_option($options); }
[ "public", "function", "set_option", "(", "$", "options", "=", "array", "(", ")", ")", "{", "if", "(", "!", "empty", "(", "$", "options", "[", "'apikey'", "]", ")", ")", "{", "set_config", "(", "'apikey'", ",", "trim", "(", "$", "options", "[", "'apikey'", "]", ")", ",", "'youtube'", ")", ";", "}", "unset", "(", "$", "options", "[", "'apikey'", "]", ")", ";", "return", "parent", "::", "set_option", "(", "$", "options", ")", ";", "}" ]
Save apikey in config table. @param array $options @return boolean
[ "Save", "apikey", "in", "config", "table", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/repository/youtube/lib.php#L100-L106
214,835
moodle/moodle
repository/youtube/lib.php
repository_youtube.get_option
public function get_option($config = '') { if ($config === 'apikey') { return trim(get_config('youtube', 'apikey')); } else { $options['apikey'] = trim(get_config('youtube', 'apikey')); } return parent::get_option($config); }
php
public function get_option($config = '') { if ($config === 'apikey') { return trim(get_config('youtube', 'apikey')); } else { $options['apikey'] = trim(get_config('youtube', 'apikey')); } return parent::get_option($config); }
[ "public", "function", "get_option", "(", "$", "config", "=", "''", ")", "{", "if", "(", "$", "config", "===", "'apikey'", ")", "{", "return", "trim", "(", "get_config", "(", "'youtube'", ",", "'apikey'", ")", ")", ";", "}", "else", "{", "$", "options", "[", "'apikey'", "]", "=", "trim", "(", "get_config", "(", "'youtube'", ",", "'apikey'", ")", ")", ";", "}", "return", "parent", "::", "get_option", "(", "$", "config", ")", ";", "}" ]
Get apikey from config table. @param string $config @return mixed
[ "Get", "apikey", "from", "config", "table", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/repository/youtube/lib.php#L114-L121
214,836
moodle/moodle
repository/youtube/lib.php
repository_youtube.search
public function search($search_text, $page = 0) { global $SESSION; $sort = optional_param('youtube_sort', '', PARAM_TEXT); $sess_keyword = 'youtube_'.$this->id.'_keyword'; $sess_sort = 'youtube_'.$this->id.'_sort'; // This is the request of another page for the last search, retrieve the cached keyword and sort if ($page && !$search_text && isset($SESSION->{$sess_keyword})) { $search_text = $SESSION->{$sess_keyword}; } if ($page && !$sort && isset($SESSION->{$sess_sort})) { $sort = $SESSION->{$sess_sort}; } if (!$sort) { $sort = 'relevance'; // default } // Save this search in session $SESSION->{$sess_keyword} = $search_text; $SESSION->{$sess_sort} = $sort; $this->keyword = $search_text; $ret = array(); $ret['nologin'] = true; $ret['page'] = (int)$page; if ($ret['page'] < 1) { $ret['page'] = 1; } $start = ($ret['page'] - 1) * self::YOUTUBE_THUMBS_PER_PAGE + 1; $max = self::YOUTUBE_THUMBS_PER_PAGE; $ret['list'] = $this->_get_collection($search_text, $start, $max, $sort); $ret['norefresh'] = true; $ret['nosearch'] = true; // If the number of results is smaller than $max, it means we reached the last page. $ret['pages'] = (count($ret['list']) < $max) ? $ret['page'] : -1; return $ret; }
php
public function search($search_text, $page = 0) { global $SESSION; $sort = optional_param('youtube_sort', '', PARAM_TEXT); $sess_keyword = 'youtube_'.$this->id.'_keyword'; $sess_sort = 'youtube_'.$this->id.'_sort'; // This is the request of another page for the last search, retrieve the cached keyword and sort if ($page && !$search_text && isset($SESSION->{$sess_keyword})) { $search_text = $SESSION->{$sess_keyword}; } if ($page && !$sort && isset($SESSION->{$sess_sort})) { $sort = $SESSION->{$sess_sort}; } if (!$sort) { $sort = 'relevance'; // default } // Save this search in session $SESSION->{$sess_keyword} = $search_text; $SESSION->{$sess_sort} = $sort; $this->keyword = $search_text; $ret = array(); $ret['nologin'] = true; $ret['page'] = (int)$page; if ($ret['page'] < 1) { $ret['page'] = 1; } $start = ($ret['page'] - 1) * self::YOUTUBE_THUMBS_PER_PAGE + 1; $max = self::YOUTUBE_THUMBS_PER_PAGE; $ret['list'] = $this->_get_collection($search_text, $start, $max, $sort); $ret['norefresh'] = true; $ret['nosearch'] = true; // If the number of results is smaller than $max, it means we reached the last page. $ret['pages'] = (count($ret['list']) < $max) ? $ret['page'] : -1; return $ret; }
[ "public", "function", "search", "(", "$", "search_text", ",", "$", "page", "=", "0", ")", "{", "global", "$", "SESSION", ";", "$", "sort", "=", "optional_param", "(", "'youtube_sort'", ",", "''", ",", "PARAM_TEXT", ")", ";", "$", "sess_keyword", "=", "'youtube_'", ".", "$", "this", "->", "id", ".", "'_keyword'", ";", "$", "sess_sort", "=", "'youtube_'", ".", "$", "this", "->", "id", ".", "'_sort'", ";", "// This is the request of another page for the last search, retrieve the cached keyword and sort", "if", "(", "$", "page", "&&", "!", "$", "search_text", "&&", "isset", "(", "$", "SESSION", "->", "{", "$", "sess_keyword", "}", ")", ")", "{", "$", "search_text", "=", "$", "SESSION", "->", "{", "$", "sess_keyword", "}", ";", "}", "if", "(", "$", "page", "&&", "!", "$", "sort", "&&", "isset", "(", "$", "SESSION", "->", "{", "$", "sess_sort", "}", ")", ")", "{", "$", "sort", "=", "$", "SESSION", "->", "{", "$", "sess_sort", "}", ";", "}", "if", "(", "!", "$", "sort", ")", "{", "$", "sort", "=", "'relevance'", ";", "// default", "}", "// Save this search in session", "$", "SESSION", "->", "{", "$", "sess_keyword", "}", "=", "$", "search_text", ";", "$", "SESSION", "->", "{", "$", "sess_sort", "}", "=", "$", "sort", ";", "$", "this", "->", "keyword", "=", "$", "search_text", ";", "$", "ret", "=", "array", "(", ")", ";", "$", "ret", "[", "'nologin'", "]", "=", "true", ";", "$", "ret", "[", "'page'", "]", "=", "(", "int", ")", "$", "page", ";", "if", "(", "$", "ret", "[", "'page'", "]", "<", "1", ")", "{", "$", "ret", "[", "'page'", "]", "=", "1", ";", "}", "$", "start", "=", "(", "$", "ret", "[", "'page'", "]", "-", "1", ")", "*", "self", "::", "YOUTUBE_THUMBS_PER_PAGE", "+", "1", ";", "$", "max", "=", "self", "::", "YOUTUBE_THUMBS_PER_PAGE", ";", "$", "ret", "[", "'list'", "]", "=", "$", "this", "->", "_get_collection", "(", "$", "search_text", ",", "$", "start", ",", "$", "max", ",", "$", "sort", ")", ";", "$", "ret", "[", "'norefresh'", "]", "=", "true", ";", "$", "ret", "[", "'nosearch'", "]", "=", "true", ";", "// If the number of results is smaller than $max, it means we reached the last page.", "$", "ret", "[", "'pages'", "]", "=", "(", "count", "(", "$", "ret", "[", "'list'", "]", ")", "<", "$", "max", ")", "?", "$", "ret", "[", "'page'", "]", ":", "-", "1", ";", "return", "$", "ret", ";", "}" ]
Return search results @param string $search_text @return array
[ "Return", "search", "results" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/repository/youtube/lib.php#L132-L168
214,837
moodle/moodle
repository/youtube/lib.php
repository_youtube._get_collection
private function _get_collection($keyword, $start, $max, $sort) { global $SESSION; // The new API doesn't use "page" numbers for browsing through results. // It uses a prev and next token in each set that you need to use to // request the next page of results. $sesspagetoken = 'youtube_'.$this->id.'_nextpagetoken'; $pagetoken = ''; if ($start > 1 && isset($SESSION->{$sesspagetoken})) { $pagetoken = $SESSION->{$sesspagetoken}; } $list = array(); $error = null; try { $this->init_youtube_service(); // About to use the service, ensure it's loaded. $response = $this->service->search->listSearch('id,snippet', array( 'q' => $keyword, 'maxResults' => $max, 'order' => $sort, 'pageToken' => $pagetoken, 'type' => 'video', 'videoEmbeddable' => 'true', )); // Track the next page token for the next request (when a user // scrolls down in the file picker for more videos). $SESSION->{$sesspagetoken} = $response['nextPageToken']; foreach ($response['items'] as $result) { $title = $result->snippet->title; $source = 'http://www.youtube.com/v/' . $result->id->videoId . '#' . $title; $thumb = $result->snippet->getThumbnails()->getDefault(); $list[] = array( 'shorttitle' => $title, 'thumbnail_title' => $result->snippet->description, 'title' => $title.'.avi', // This is a hack so we accept this file by extension. 'thumbnail' => $thumb->url, 'thumbnail_width' => (int)$thumb->width, 'thumbnail_height' => (int)$thumb->height, 'size' => '', 'date' => '', 'source' => $source, ); } } catch (Google_Service_Exception $e) { // If we throw the google exception as-is, we may expose the apikey // to end users. The full message in the google exception includes // the apikey param, so we take just the part pertaining to the // actual error. $error = $e->getErrors()[0]['message']; throw new moodle_exception('apierror', 'repository_youtube', '', $error); } return $list; }
php
private function _get_collection($keyword, $start, $max, $sort) { global $SESSION; // The new API doesn't use "page" numbers for browsing through results. // It uses a prev and next token in each set that you need to use to // request the next page of results. $sesspagetoken = 'youtube_'.$this->id.'_nextpagetoken'; $pagetoken = ''; if ($start > 1 && isset($SESSION->{$sesspagetoken})) { $pagetoken = $SESSION->{$sesspagetoken}; } $list = array(); $error = null; try { $this->init_youtube_service(); // About to use the service, ensure it's loaded. $response = $this->service->search->listSearch('id,snippet', array( 'q' => $keyword, 'maxResults' => $max, 'order' => $sort, 'pageToken' => $pagetoken, 'type' => 'video', 'videoEmbeddable' => 'true', )); // Track the next page token for the next request (when a user // scrolls down in the file picker for more videos). $SESSION->{$sesspagetoken} = $response['nextPageToken']; foreach ($response['items'] as $result) { $title = $result->snippet->title; $source = 'http://www.youtube.com/v/' . $result->id->videoId . '#' . $title; $thumb = $result->snippet->getThumbnails()->getDefault(); $list[] = array( 'shorttitle' => $title, 'thumbnail_title' => $result->snippet->description, 'title' => $title.'.avi', // This is a hack so we accept this file by extension. 'thumbnail' => $thumb->url, 'thumbnail_width' => (int)$thumb->width, 'thumbnail_height' => (int)$thumb->height, 'size' => '', 'date' => '', 'source' => $source, ); } } catch (Google_Service_Exception $e) { // If we throw the google exception as-is, we may expose the apikey // to end users. The full message in the google exception includes // the apikey param, so we take just the part pertaining to the // actual error. $error = $e->getErrors()[0]['message']; throw new moodle_exception('apierror', 'repository_youtube', '', $error); } return $list; }
[ "private", "function", "_get_collection", "(", "$", "keyword", ",", "$", "start", ",", "$", "max", ",", "$", "sort", ")", "{", "global", "$", "SESSION", ";", "// The new API doesn't use \"page\" numbers for browsing through results.", "// It uses a prev and next token in each set that you need to use to", "// request the next page of results.", "$", "sesspagetoken", "=", "'youtube_'", ".", "$", "this", "->", "id", ".", "'_nextpagetoken'", ";", "$", "pagetoken", "=", "''", ";", "if", "(", "$", "start", ">", "1", "&&", "isset", "(", "$", "SESSION", "->", "{", "$", "sesspagetoken", "}", ")", ")", "{", "$", "pagetoken", "=", "$", "SESSION", "->", "{", "$", "sesspagetoken", "}", ";", "}", "$", "list", "=", "array", "(", ")", ";", "$", "error", "=", "null", ";", "try", "{", "$", "this", "->", "init_youtube_service", "(", ")", ";", "// About to use the service, ensure it's loaded.", "$", "response", "=", "$", "this", "->", "service", "->", "search", "->", "listSearch", "(", "'id,snippet'", ",", "array", "(", "'q'", "=>", "$", "keyword", ",", "'maxResults'", "=>", "$", "max", ",", "'order'", "=>", "$", "sort", ",", "'pageToken'", "=>", "$", "pagetoken", ",", "'type'", "=>", "'video'", ",", "'videoEmbeddable'", "=>", "'true'", ",", ")", ")", ";", "// Track the next page token for the next request (when a user", "// scrolls down in the file picker for more videos).", "$", "SESSION", "->", "{", "$", "sesspagetoken", "}", "=", "$", "response", "[", "'nextPageToken'", "]", ";", "foreach", "(", "$", "response", "[", "'items'", "]", "as", "$", "result", ")", "{", "$", "title", "=", "$", "result", "->", "snippet", "->", "title", ";", "$", "source", "=", "'http://www.youtube.com/v/'", ".", "$", "result", "->", "id", "->", "videoId", ".", "'#'", ".", "$", "title", ";", "$", "thumb", "=", "$", "result", "->", "snippet", "->", "getThumbnails", "(", ")", "->", "getDefault", "(", ")", ";", "$", "list", "[", "]", "=", "array", "(", "'shorttitle'", "=>", "$", "title", ",", "'thumbnail_title'", "=>", "$", "result", "->", "snippet", "->", "description", ",", "'title'", "=>", "$", "title", ".", "'.avi'", ",", "// This is a hack so we accept this file by extension.", "'thumbnail'", "=>", "$", "thumb", "->", "url", ",", "'thumbnail_width'", "=>", "(", "int", ")", "$", "thumb", "->", "width", ",", "'thumbnail_height'", "=>", "(", "int", ")", "$", "thumb", "->", "height", ",", "'size'", "=>", "''", ",", "'date'", "=>", "''", ",", "'source'", "=>", "$", "source", ",", ")", ";", "}", "}", "catch", "(", "Google_Service_Exception", "$", "e", ")", "{", "// If we throw the google exception as-is, we may expose the apikey", "// to end users. The full message in the google exception includes", "// the apikey param, so we take just the part pertaining to the", "// actual error.", "$", "error", "=", "$", "e", "->", "getErrors", "(", ")", "[", "0", "]", "[", "'message'", "]", ";", "throw", "new", "moodle_exception", "(", "'apierror'", ",", "'repository_youtube'", ",", "''", ",", "$", "error", ")", ";", "}", "return", "$", "list", ";", "}" ]
Private method to get youtube search results @param string $keyword @param int $start @param int $max max results @param string $sort @throws moodle_exception If the google API returns an error. @return array
[ "Private", "method", "to", "get", "youtube", "search", "results" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/repository/youtube/lib.php#L179-L235
214,838
moodle/moodle
repository/youtube/lib.php
repository_youtube.print_login
public function print_login($ajax = true) { $ret = array(); $search = new stdClass(); $search->type = 'text'; $search->id = 'youtube_search'; $search->name = 's'; $search->label = get_string('search', 'repository_youtube').': '; $sort = new stdClass(); $sort->type = 'select'; $sort->options = array( (object)array( 'value' => 'relevance', 'label' => get_string('sortrelevance', 'repository_youtube') ), (object)array( 'value' => 'date', 'label' => get_string('sortpublished', 'repository_youtube') ), (object)array( 'value' => 'rating', 'label' => get_string('sortrating', 'repository_youtube') ), (object)array( 'value' => 'viewCount', 'label' => get_string('sortviewcount', 'repository_youtube') ) ); $sort->id = 'youtube_sort'; $sort->name = 'youtube_sort'; $sort->label = get_string('sortby', 'repository_youtube').': '; $ret['login'] = array($search, $sort); $ret['login_btn_label'] = get_string('search'); $ret['login_btn_action'] = 'search'; $ret['allowcaching'] = true; // indicates that login form can be cached in filepicker.js return $ret; }
php
public function print_login($ajax = true) { $ret = array(); $search = new stdClass(); $search->type = 'text'; $search->id = 'youtube_search'; $search->name = 's'; $search->label = get_string('search', 'repository_youtube').': '; $sort = new stdClass(); $sort->type = 'select'; $sort->options = array( (object)array( 'value' => 'relevance', 'label' => get_string('sortrelevance', 'repository_youtube') ), (object)array( 'value' => 'date', 'label' => get_string('sortpublished', 'repository_youtube') ), (object)array( 'value' => 'rating', 'label' => get_string('sortrating', 'repository_youtube') ), (object)array( 'value' => 'viewCount', 'label' => get_string('sortviewcount', 'repository_youtube') ) ); $sort->id = 'youtube_sort'; $sort->name = 'youtube_sort'; $sort->label = get_string('sortby', 'repository_youtube').': '; $ret['login'] = array($search, $sort); $ret['login_btn_label'] = get_string('search'); $ret['login_btn_action'] = 'search'; $ret['allowcaching'] = true; // indicates that login form can be cached in filepicker.js return $ret; }
[ "public", "function", "print_login", "(", "$", "ajax", "=", "true", ")", "{", "$", "ret", "=", "array", "(", ")", ";", "$", "search", "=", "new", "stdClass", "(", ")", ";", "$", "search", "->", "type", "=", "'text'", ";", "$", "search", "->", "id", "=", "'youtube_search'", ";", "$", "search", "->", "name", "=", "'s'", ";", "$", "search", "->", "label", "=", "get_string", "(", "'search'", ",", "'repository_youtube'", ")", ".", "': '", ";", "$", "sort", "=", "new", "stdClass", "(", ")", ";", "$", "sort", "->", "type", "=", "'select'", ";", "$", "sort", "->", "options", "=", "array", "(", "(", "object", ")", "array", "(", "'value'", "=>", "'relevance'", ",", "'label'", "=>", "get_string", "(", "'sortrelevance'", ",", "'repository_youtube'", ")", ")", ",", "(", "object", ")", "array", "(", "'value'", "=>", "'date'", ",", "'label'", "=>", "get_string", "(", "'sortpublished'", ",", "'repository_youtube'", ")", ")", ",", "(", "object", ")", "array", "(", "'value'", "=>", "'rating'", ",", "'label'", "=>", "get_string", "(", "'sortrating'", ",", "'repository_youtube'", ")", ")", ",", "(", "object", ")", "array", "(", "'value'", "=>", "'viewCount'", ",", "'label'", "=>", "get_string", "(", "'sortviewcount'", ",", "'repository_youtube'", ")", ")", ")", ";", "$", "sort", "->", "id", "=", "'youtube_sort'", ";", "$", "sort", "->", "name", "=", "'youtube_sort'", ";", "$", "sort", "->", "label", "=", "get_string", "(", "'sortby'", ",", "'repository_youtube'", ")", ".", "': '", ";", "$", "ret", "[", "'login'", "]", "=", "array", "(", "$", "search", ",", "$", "sort", ")", ";", "$", "ret", "[", "'login_btn_label'", "]", "=", "get_string", "(", "'search'", ")", ";", "$", "ret", "[", "'login_btn_action'", "]", "=", "'search'", ";", "$", "ret", "[", "'allowcaching'", "]", "=", "true", ";", "// indicates that login form can be cached in filepicker.js", "return", "$", "ret", ";", "}" ]
Generate search form
[ "Generate", "search", "form" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/repository/youtube/lib.php#L251-L286
214,839
moodle/moodle
repository/youtube/lib.php
repository_youtube.type_config_form
public static function type_config_form($mform, $classname = 'repository') { parent::type_config_form($mform, $classname); $apikey = get_config('youtube', 'apikey'); if (empty($apikey)) { $apikey = ''; } $mform->addElement('text', 'apikey', get_string('apikey', 'repository_youtube'), array('value' => $apikey, 'size' => '40')); $mform->setType('apikey', PARAM_RAW_TRIMMED); $mform->addRule('apikey', get_string('required'), 'required', null, 'client'); $mform->addElement('static', null, '', get_string('information', 'repository_youtube')); }
php
public static function type_config_form($mform, $classname = 'repository') { parent::type_config_form($mform, $classname); $apikey = get_config('youtube', 'apikey'); if (empty($apikey)) { $apikey = ''; } $mform->addElement('text', 'apikey', get_string('apikey', 'repository_youtube'), array('value' => $apikey, 'size' => '40')); $mform->setType('apikey', PARAM_RAW_TRIMMED); $mform->addRule('apikey', get_string('required'), 'required', null, 'client'); $mform->addElement('static', null, '', get_string('information', 'repository_youtube')); }
[ "public", "static", "function", "type_config_form", "(", "$", "mform", ",", "$", "classname", "=", "'repository'", ")", "{", "parent", "::", "type_config_form", "(", "$", "mform", ",", "$", "classname", ")", ";", "$", "apikey", "=", "get_config", "(", "'youtube'", ",", "'apikey'", ")", ";", "if", "(", "empty", "(", "$", "apikey", ")", ")", "{", "$", "apikey", "=", "''", ";", "}", "$", "mform", "->", "addElement", "(", "'text'", ",", "'apikey'", ",", "get_string", "(", "'apikey'", ",", "'repository_youtube'", ")", ",", "array", "(", "'value'", "=>", "$", "apikey", ",", "'size'", "=>", "'40'", ")", ")", ";", "$", "mform", "->", "setType", "(", "'apikey'", ",", "PARAM_RAW_TRIMMED", ")", ";", "$", "mform", "->", "addRule", "(", "'apikey'", ",", "get_string", "(", "'required'", ")", ",", "'required'", ",", "null", ",", "'client'", ")", ";", "$", "mform", "->", "addElement", "(", "'static'", ",", "null", ",", "''", ",", "get_string", "(", "'information'", ",", "'repository_youtube'", ")", ")", ";", "}" ]
Add plugin settings input to Moodle form. @param object $mform @param string $classname
[ "Add", "plugin", "settings", "input", "to", "Moodle", "form", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/repository/youtube/lib.php#L318-L330
214,840
moodle/moodle
lib/horde/framework/Horde/Imap/Client/Socket/Pop3.php
Horde_Imap_Client_Socket_Pop3._pop3Cache
protected function _pop3Cache( $type, $index = self::MBOX_CACHE, $data = null ) { if (isset($this->_temp['pop3cache'][$index][$type])) { if ($type == 'msg') { rewind($this->_temp['pop3cache'][$index][$type]); } return $this->_temp['pop3cache'][$index][$type]; } switch ($type) { case 'hdr': case 'top': $data = null; if (($type == 'top') || $this->_capability('TOP')) { try { $res = $this->_sendLine('TOP ' . $index . ' 0', array( 'multiline' => 'stream' )); rewind($res['data']); $data = stream_get_contents($res['data']); fclose($res['data']); } catch (Horde_Imap_Client_Exception $e) { $this->_temp['no_top'] = true; if ($type == 'top') { return null; } } } if (is_null($data)) { $data = Horde_Mime_Part::getRawPartText(stream_get_contents($this->_pop3Cache('msg', $index)), 'header', 0); } break; case 'hdrob': $data = Horde_Mime_Headers::parseHeaders($this->_pop3Cache('hdr', $index)); break; case 'msg': $res = $this->_sendLine('RETR ' . $index, array( 'multiline' => 'stream' )); $data = $res['data']; rewind($data); break; case 'size': case 'uidl': $data = array(); try { $res = $this->_sendLine(($type == 'size') ? 'LIST' : 'UIDL', array( 'multiline' => 'array' )); foreach ($res['data'] as $val) { $resp_data = explode(' ', $val, 2); $data[$resp_data[0]] = $resp_data[1]; } } catch (Horde_Imap_Client_Exception $e) { if ($type == 'uidl') { $this->_temp['no_uidl'] = true; } } break; case 'stat': $resp = $this->_sendLine('STAT'); $resp_data = explode(' ', $resp['resp'], 2); $data = array('msgs' => $resp_data[0], 'size' => $resp_data[1]); break; } $this->_temp['pop3cache'][$index][$type] = $data; return $data; }
php
protected function _pop3Cache( $type, $index = self::MBOX_CACHE, $data = null ) { if (isset($this->_temp['pop3cache'][$index][$type])) { if ($type == 'msg') { rewind($this->_temp['pop3cache'][$index][$type]); } return $this->_temp['pop3cache'][$index][$type]; } switch ($type) { case 'hdr': case 'top': $data = null; if (($type == 'top') || $this->_capability('TOP')) { try { $res = $this->_sendLine('TOP ' . $index . ' 0', array( 'multiline' => 'stream' )); rewind($res['data']); $data = stream_get_contents($res['data']); fclose($res['data']); } catch (Horde_Imap_Client_Exception $e) { $this->_temp['no_top'] = true; if ($type == 'top') { return null; } } } if (is_null($data)) { $data = Horde_Mime_Part::getRawPartText(stream_get_contents($this->_pop3Cache('msg', $index)), 'header', 0); } break; case 'hdrob': $data = Horde_Mime_Headers::parseHeaders($this->_pop3Cache('hdr', $index)); break; case 'msg': $res = $this->_sendLine('RETR ' . $index, array( 'multiline' => 'stream' )); $data = $res['data']; rewind($data); break; case 'size': case 'uidl': $data = array(); try { $res = $this->_sendLine(($type == 'size') ? 'LIST' : 'UIDL', array( 'multiline' => 'array' )); foreach ($res['data'] as $val) { $resp_data = explode(' ', $val, 2); $data[$resp_data[0]] = $resp_data[1]; } } catch (Horde_Imap_Client_Exception $e) { if ($type == 'uidl') { $this->_temp['no_uidl'] = true; } } break; case 'stat': $resp = $this->_sendLine('STAT'); $resp_data = explode(' ', $resp['resp'], 2); $data = array('msgs' => $resp_data[0], 'size' => $resp_data[1]); break; } $this->_temp['pop3cache'][$index][$type] = $data; return $data; }
[ "protected", "function", "_pop3Cache", "(", "$", "type", ",", "$", "index", "=", "self", "::", "MBOX_CACHE", ",", "$", "data", "=", "null", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "_temp", "[", "'pop3cache'", "]", "[", "$", "index", "]", "[", "$", "type", "]", ")", ")", "{", "if", "(", "$", "type", "==", "'msg'", ")", "{", "rewind", "(", "$", "this", "->", "_temp", "[", "'pop3cache'", "]", "[", "$", "index", "]", "[", "$", "type", "]", ")", ";", "}", "return", "$", "this", "->", "_temp", "[", "'pop3cache'", "]", "[", "$", "index", "]", "[", "$", "type", "]", ";", "}", "switch", "(", "$", "type", ")", "{", "case", "'hdr'", ":", "case", "'top'", ":", "$", "data", "=", "null", ";", "if", "(", "(", "$", "type", "==", "'top'", ")", "||", "$", "this", "->", "_capability", "(", "'TOP'", ")", ")", "{", "try", "{", "$", "res", "=", "$", "this", "->", "_sendLine", "(", "'TOP '", ".", "$", "index", ".", "' 0'", ",", "array", "(", "'multiline'", "=>", "'stream'", ")", ")", ";", "rewind", "(", "$", "res", "[", "'data'", "]", ")", ";", "$", "data", "=", "stream_get_contents", "(", "$", "res", "[", "'data'", "]", ")", ";", "fclose", "(", "$", "res", "[", "'data'", "]", ")", ";", "}", "catch", "(", "Horde_Imap_Client_Exception", "$", "e", ")", "{", "$", "this", "->", "_temp", "[", "'no_top'", "]", "=", "true", ";", "if", "(", "$", "type", "==", "'top'", ")", "{", "return", "null", ";", "}", "}", "}", "if", "(", "is_null", "(", "$", "data", ")", ")", "{", "$", "data", "=", "Horde_Mime_Part", "::", "getRawPartText", "(", "stream_get_contents", "(", "$", "this", "->", "_pop3Cache", "(", "'msg'", ",", "$", "index", ")", ")", ",", "'header'", ",", "0", ")", ";", "}", "break", ";", "case", "'hdrob'", ":", "$", "data", "=", "Horde_Mime_Headers", "::", "parseHeaders", "(", "$", "this", "->", "_pop3Cache", "(", "'hdr'", ",", "$", "index", ")", ")", ";", "break", ";", "case", "'msg'", ":", "$", "res", "=", "$", "this", "->", "_sendLine", "(", "'RETR '", ".", "$", "index", ",", "array", "(", "'multiline'", "=>", "'stream'", ")", ")", ";", "$", "data", "=", "$", "res", "[", "'data'", "]", ";", "rewind", "(", "$", "data", ")", ";", "break", ";", "case", "'size'", ":", "case", "'uidl'", ":", "$", "data", "=", "array", "(", ")", ";", "try", "{", "$", "res", "=", "$", "this", "->", "_sendLine", "(", "(", "$", "type", "==", "'size'", ")", "?", "'LIST'", ":", "'UIDL'", ",", "array", "(", "'multiline'", "=>", "'array'", ")", ")", ";", "foreach", "(", "$", "res", "[", "'data'", "]", "as", "$", "val", ")", "{", "$", "resp_data", "=", "explode", "(", "' '", ",", "$", "val", ",", "2", ")", ";", "$", "data", "[", "$", "resp_data", "[", "0", "]", "]", "=", "$", "resp_data", "[", "1", "]", ";", "}", "}", "catch", "(", "Horde_Imap_Client_Exception", "$", "e", ")", "{", "if", "(", "$", "type", "==", "'uidl'", ")", "{", "$", "this", "->", "_temp", "[", "'no_uidl'", "]", "=", "true", ";", "}", "}", "break", ";", "case", "'stat'", ":", "$", "resp", "=", "$", "this", "->", "_sendLine", "(", "'STAT'", ")", ";", "$", "resp_data", "=", "explode", "(", "' '", ",", "$", "resp", "[", "'resp'", "]", ",", "2", ")", ";", "$", "data", "=", "array", "(", "'msgs'", "=>", "$", "resp_data", "[", "0", "]", ",", "'size'", "=>", "$", "resp_data", "[", "1", "]", ")", ";", "break", ";", "}", "$", "this", "->", "_temp", "[", "'pop3cache'", "]", "[", "$", "index", "]", "[", "$", "type", "]", "=", "$", "data", ";", "return", "$", "data", ";", "}" ]
Retrieve locally cached message data. @param string $type Either 'hdr', 'hdrob', 'msg', 'size', 'stat', 'top', or 'uidl'. @param integer $index The message index. @param mixed $data Additional information needed. @return mixed The cached data. 'msg' returns a stream resource. All other types return strings. @throws Horde_Imap_Client_Exception
[ "Retrieve", "locally", "cached", "message", "data", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/horde/framework/Horde/Imap/Client/Socket/Pop3.php#L1043-L1119
214,841
moodle/moodle
lib/horde/framework/Horde/Imap/Client/Socket/Pop3.php
Horde_Imap_Client_Socket_Pop3._processString
protected function _processString($str, $opts) { if (!empty($opts['length'])) { return substr($str, empty($opts['start']) ? 0 : $opts['start'], $opts['length']); } elseif (!empty($opts['start'])) { return substr($str, $opts['start']); } return $str; }
php
protected function _processString($str, $opts) { if (!empty($opts['length'])) { return substr($str, empty($opts['start']) ? 0 : $opts['start'], $opts['length']); } elseif (!empty($opts['start'])) { return substr($str, $opts['start']); } return $str; }
[ "protected", "function", "_processString", "(", "$", "str", ",", "$", "opts", ")", "{", "if", "(", "!", "empty", "(", "$", "opts", "[", "'length'", "]", ")", ")", "{", "return", "substr", "(", "$", "str", ",", "empty", "(", "$", "opts", "[", "'start'", "]", ")", "?", "0", ":", "$", "opts", "[", "'start'", "]", ",", "$", "opts", "[", "'length'", "]", ")", ";", "}", "elseif", "(", "!", "empty", "(", "$", "opts", "[", "'start'", "]", ")", ")", "{", "return", "substr", "(", "$", "str", ",", "$", "opts", "[", "'start'", "]", ")", ";", "}", "return", "$", "str", ";", "}" ]
Process a string response based on criteria options. @param string $str The original string. @param array $opts The criteria options. @return string The requested string.
[ "Process", "a", "string", "response", "based", "on", "criteria", "options", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/horde/framework/Horde/Imap/Client/Socket/Pop3.php#L1129-L1138
214,842
moodle/moodle
lib/horde/framework/Horde/Imap/Client/Socket/Pop3.php
Horde_Imap_Client_Socket_Pop3._sendLine
protected function _sendLine($cmd, $options = array()) { if (!empty($options['debug'])) { $this->_debug->client($options['debug']); } if ($this->_debug->debug) { $timer = new Horde_Support_Timer(); $timer->push(); } try { $this->_connection->write($cmd, empty($options['debug'])); } catch (Horde_Imap_Client_Exception $e) { throw $e; } $resp = $this->_getResponse( empty($options['multiline']) ? false : $options['multiline'] ); if ($this->_debug->debug) { $this->_debug->info(sprintf( 'Command took %s seconds.', round($timer->pop(), 4) )); } return $resp; }
php
protected function _sendLine($cmd, $options = array()) { if (!empty($options['debug'])) { $this->_debug->client($options['debug']); } if ($this->_debug->debug) { $timer = new Horde_Support_Timer(); $timer->push(); } try { $this->_connection->write($cmd, empty($options['debug'])); } catch (Horde_Imap_Client_Exception $e) { throw $e; } $resp = $this->_getResponse( empty($options['multiline']) ? false : $options['multiline'] ); if ($this->_debug->debug) { $this->_debug->info(sprintf( 'Command took %s seconds.', round($timer->pop(), 4) )); } return $resp; }
[ "protected", "function", "_sendLine", "(", "$", "cmd", ",", "$", "options", "=", "array", "(", ")", ")", "{", "if", "(", "!", "empty", "(", "$", "options", "[", "'debug'", "]", ")", ")", "{", "$", "this", "->", "_debug", "->", "client", "(", "$", "options", "[", "'debug'", "]", ")", ";", "}", "if", "(", "$", "this", "->", "_debug", "->", "debug", ")", "{", "$", "timer", "=", "new", "Horde_Support_Timer", "(", ")", ";", "$", "timer", "->", "push", "(", ")", ";", "}", "try", "{", "$", "this", "->", "_connection", "->", "write", "(", "$", "cmd", ",", "empty", "(", "$", "options", "[", "'debug'", "]", ")", ")", ";", "}", "catch", "(", "Horde_Imap_Client_Exception", "$", "e", ")", "{", "throw", "$", "e", ";", "}", "$", "resp", "=", "$", "this", "->", "_getResponse", "(", "empty", "(", "$", "options", "[", "'multiline'", "]", ")", "?", "false", ":", "$", "options", "[", "'multiline'", "]", ")", ";", "if", "(", "$", "this", "->", "_debug", "->", "debug", ")", "{", "$", "this", "->", "_debug", "->", "info", "(", "sprintf", "(", "'Command took %s seconds.'", ",", "round", "(", "$", "timer", "->", "pop", "(", ")", ",", "4", ")", ")", ")", ";", "}", "return", "$", "resp", ";", "}" ]
Perform a command on the server. A connection to the server must have already been made. @param string $cmd The command to execute. @param array $options Additional options: <pre> - debug: (string) When debugging, send this string instead of the actual command/data sent. DEFAULT: Raw data output to debug stream. - multiline: (mixed) 'array', 'none', or 'stream'. </pre> @return array See _getResponse(). @throws Horde_Imap_Client_Exception
[ "Perform", "a", "command", "on", "the", "server", ".", "A", "connection", "to", "the", "server", "must", "have", "already", "been", "made", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/horde/framework/Horde/Imap/Client/Socket/Pop3.php#L1332-L1361
214,843
moodle/moodle
lib/horde/framework/Horde/Imap/Client/Socket/Pop3.php
Horde_Imap_Client_Socket_Pop3._getSeqIds
protected function _getSeqIds(Horde_Imap_Client_Ids $ids) { if (!count($ids)) { $status = $this->status($this->_selected, Horde_Imap_Client::STATUS_MESSAGES); return range(1, $status['messages']); } elseif ($ids->sequence) { return $ids->ids; } return array_keys(array_intersect($this->_pop3Cache('uidl'), $ids->ids)); }
php
protected function _getSeqIds(Horde_Imap_Client_Ids $ids) { if (!count($ids)) { $status = $this->status($this->_selected, Horde_Imap_Client::STATUS_MESSAGES); return range(1, $status['messages']); } elseif ($ids->sequence) { return $ids->ids; } return array_keys(array_intersect($this->_pop3Cache('uidl'), $ids->ids)); }
[ "protected", "function", "_getSeqIds", "(", "Horde_Imap_Client_Ids", "$", "ids", ")", "{", "if", "(", "!", "count", "(", "$", "ids", ")", ")", "{", "$", "status", "=", "$", "this", "->", "status", "(", "$", "this", "->", "_selected", ",", "Horde_Imap_Client", "::", "STATUS_MESSAGES", ")", ";", "return", "range", "(", "1", ",", "$", "status", "[", "'messages'", "]", ")", ";", "}", "elseif", "(", "$", "ids", "->", "sequence", ")", "{", "return", "$", "ids", "->", "ids", ";", "}", "return", "array_keys", "(", "array_intersect", "(", "$", "this", "->", "_pop3Cache", "(", "'uidl'", ")", ",", "$", "ids", "->", "ids", ")", ")", ";", "}" ]
Returns a list of sequence IDs. @param Horde_Imap_Client_Ids $ids The ID list. @return array A list of sequence IDs.
[ "Returns", "a", "list", "of", "sequence", "IDs", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/horde/framework/Horde/Imap/Client/Socket/Pop3.php#L1499-L1509
214,844
moodle/moodle
mod/assign/feedback/editpdf/classes/event/observer.php
observer.queue_conversion
protected static function queue_conversion($event) { global $DB; $submissionid = $event->other['submissionid']; $submissionattempt = $event->other['submissionattempt']; $fields = array( 'submissionid' => $submissionid, 'submissionattempt' => $submissionattempt); $record = (object) $fields; $exists = $DB->get_record('assignfeedback_editpdf_queue', $fields); if (!$exists) { $DB->insert_record('assignfeedback_editpdf_queue', $record); } else { // This submission attempt was already queued, so just reset the existing failure counter to ensure it gets processed. $exists->attemptedconversions = 0; $DB->update_record('assignfeedback_editpdf_queue', $exists); } }
php
protected static function queue_conversion($event) { global $DB; $submissionid = $event->other['submissionid']; $submissionattempt = $event->other['submissionattempt']; $fields = array( 'submissionid' => $submissionid, 'submissionattempt' => $submissionattempt); $record = (object) $fields; $exists = $DB->get_record('assignfeedback_editpdf_queue', $fields); if (!$exists) { $DB->insert_record('assignfeedback_editpdf_queue', $record); } else { // This submission attempt was already queued, so just reset the existing failure counter to ensure it gets processed. $exists->attemptedconversions = 0; $DB->update_record('assignfeedback_editpdf_queue', $exists); } }
[ "protected", "static", "function", "queue_conversion", "(", "$", "event", ")", "{", "global", "$", "DB", ";", "$", "submissionid", "=", "$", "event", "->", "other", "[", "'submissionid'", "]", ";", "$", "submissionattempt", "=", "$", "event", "->", "other", "[", "'submissionattempt'", "]", ";", "$", "fields", "=", "array", "(", "'submissionid'", "=>", "$", "submissionid", ",", "'submissionattempt'", "=>", "$", "submissionattempt", ")", ";", "$", "record", "=", "(", "object", ")", "$", "fields", ";", "$", "exists", "=", "$", "DB", "->", "get_record", "(", "'assignfeedback_editpdf_queue'", ",", "$", "fields", ")", ";", "if", "(", "!", "$", "exists", ")", "{", "$", "DB", "->", "insert_record", "(", "'assignfeedback_editpdf_queue'", ",", "$", "record", ")", ";", "}", "else", "{", "// This submission attempt was already queued, so just reset the existing failure counter to ensure it gets processed.", "$", "exists", "->", "attemptedconversions", "=", "0", ";", "$", "DB", "->", "update_record", "(", "'assignfeedback_editpdf_queue'", ",", "$", "exists", ")", ";", "}", "}" ]
Queue the submission for processing. @param \mod_assign\event\base $event The submission created/updated event.
[ "Queue", "the", "submission", "for", "processing", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/assign/feedback/editpdf/classes/event/observer.php#L53-L69
214,845
moodle/moodle
lib/tablelib.php
flexible_table.export_class_instance
function export_class_instance($exportclass = null) { if (!is_null($exportclass)) { $this->started_output = true; $this->exportclass = $exportclass; $this->exportclass->table = $this; } else if (is_null($this->exportclass) && !empty($this->download)) { $this->exportclass = new table_dataformat_export_format($this, $this->download); if (!$this->exportclass->document_started()) { $this->exportclass->start_document($this->filename, $this->sheettitle); } } return $this->exportclass; }
php
function export_class_instance($exportclass = null) { if (!is_null($exportclass)) { $this->started_output = true; $this->exportclass = $exportclass; $this->exportclass->table = $this; } else if (is_null($this->exportclass) && !empty($this->download)) { $this->exportclass = new table_dataformat_export_format($this, $this->download); if (!$this->exportclass->document_started()) { $this->exportclass->start_document($this->filename, $this->sheettitle); } } return $this->exportclass; }
[ "function", "export_class_instance", "(", "$", "exportclass", "=", "null", ")", "{", "if", "(", "!", "is_null", "(", "$", "exportclass", ")", ")", "{", "$", "this", "->", "started_output", "=", "true", ";", "$", "this", "->", "exportclass", "=", "$", "exportclass", ";", "$", "this", "->", "exportclass", "->", "table", "=", "$", "this", ";", "}", "else", "if", "(", "is_null", "(", "$", "this", "->", "exportclass", ")", "&&", "!", "empty", "(", "$", "this", "->", "download", ")", ")", "{", "$", "this", "->", "exportclass", "=", "new", "table_dataformat_export_format", "(", "$", "this", ",", "$", "this", "->", "download", ")", ";", "if", "(", "!", "$", "this", "->", "exportclass", "->", "document_started", "(", ")", ")", "{", "$", "this", "->", "exportclass", "->", "start_document", "(", "$", "this", "->", "filename", ",", "$", "this", "->", "sheettitle", ")", ";", "}", "}", "return", "$", "this", "->", "exportclass", ";", "}" ]
Get, and optionally set, the export class. @param $exportclass (optional) if passed, set the table to use this export class. @return table_default_export_format_parent the export class in use (after any set).
[ "Get", "and", "optionally", "set", "the", "export", "class", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/tablelib.php#L186-L198
214,846
moodle/moodle
lib/tablelib.php
flexible_table.is_downloadable
function is_downloadable($downloadable = null) { if ($downloadable !== null) { $this->downloadable = $downloadable; } return $this->downloadable; }
php
function is_downloadable($downloadable = null) { if ($downloadable !== null) { $this->downloadable = $downloadable; } return $this->downloadable; }
[ "function", "is_downloadable", "(", "$", "downloadable", "=", "null", ")", "{", "if", "(", "$", "downloadable", "!==", "null", ")", "{", "$", "this", "->", "downloadable", "=", "$", "downloadable", ";", "}", "return", "$", "this", "->", "downloadable", ";", "}" ]
Probably don't need to call this directly. Calling is_downloading with a param automatically sets table as downloadable. @param bool $downloadable optional param to set whether data from table is downloadable. If ommitted this function can be used to get current state of table. @return bool whether table data is set to be downloadable.
[ "Probably", "don", "t", "need", "to", "call", "this", "directly", ".", "Calling", "is_downloading", "with", "a", "param", "automatically", "sets", "table", "as", "downloadable", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/tablelib.php#L209-L214
214,847
moodle/moodle
lib/tablelib.php
flexible_table.sortable
function sortable($bool, $defaultcolumn = NULL, $defaultorder = SORT_ASC) { $this->is_sortable = $bool; $this->sort_default_column = $defaultcolumn; $this->sort_default_order = $defaultorder; }
php
function sortable($bool, $defaultcolumn = NULL, $defaultorder = SORT_ASC) { $this->is_sortable = $bool; $this->sort_default_column = $defaultcolumn; $this->sort_default_order = $defaultorder; }
[ "function", "sortable", "(", "$", "bool", ",", "$", "defaultcolumn", "=", "NULL", ",", "$", "defaultorder", "=", "SORT_ASC", ")", "{", "$", "this", "->", "is_sortable", "=", "$", "bool", ";", "$", "this", "->", "sort_default_column", "=", "$", "defaultcolumn", ";", "$", "this", "->", "sort_default_order", "=", "$", "defaultorder", ";", "}" ]
Sets the is_sortable variable to the given boolean, sort_default_column to the given string, and the sort_default_order to the given integer. @param bool $bool @param string $defaultcolumn @param int $defaultorder @return void
[ "Sets", "the", "is_sortable", "variable", "to", "the", "given", "boolean", "sort_default_column", "to", "the", "given", "string", "and", "the", "sort_default_order", "to", "the", "given", "integer", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/tablelib.php#L248-L252
214,848
moodle/moodle
lib/tablelib.php
flexible_table.is_sortable
function is_sortable($column = null) { if (empty($column)) { return $this->is_sortable; } if (!$this->is_sortable) { return false; } return !in_array($column, $this->column_nosort); }
php
function is_sortable($column = null) { if (empty($column)) { return $this->is_sortable; } if (!$this->is_sortable) { return false; } return !in_array($column, $this->column_nosort); }
[ "function", "is_sortable", "(", "$", "column", "=", "null", ")", "{", "if", "(", "empty", "(", "$", "column", ")", ")", "{", "return", "$", "this", "->", "is_sortable", ";", "}", "if", "(", "!", "$", "this", "->", "is_sortable", ")", "{", "return", "false", ";", "}", "return", "!", "in_array", "(", "$", "column", ",", "$", "this", "->", "column_nosort", ")", ";", "}" ]
Is the column sortable? @param string column name, null means table @return bool
[ "Is", "the", "column", "sortable?" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/tablelib.php#L277-L285
214,849
moodle/moodle
lib/tablelib.php
flexible_table.pagesize
function pagesize($perpage, $total) { $this->pagesize = $perpage; $this->totalrows = $total; $this->use_pages = true; }
php
function pagesize($perpage, $total) { $this->pagesize = $perpage; $this->totalrows = $total; $this->use_pages = true; }
[ "function", "pagesize", "(", "$", "perpage", ",", "$", "total", ")", "{", "$", "this", "->", "pagesize", "=", "$", "perpage", ";", "$", "this", "->", "totalrows", "=", "$", "total", ";", "$", "this", "->", "use_pages", "=", "true", ";", "}" ]
Sets the pagesize variable to the given integer, the totalrows variable to the given integer, and the use_pages variable to true. @param int $perpage @param int $total @return void
[ "Sets", "the", "pagesize", "variable", "to", "the", "given", "integer", "the", "totalrows", "variable", "to", "the", "given", "integer", "and", "the", "use_pages", "variable", "to", "true", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/tablelib.php#L321-L325
214,850
moodle/moodle
lib/tablelib.php
flexible_table.set_control_variables
function set_control_variables($variables) { foreach ($variables as $what => $variable) { if (isset($this->request[$what])) { $this->request[$what] = $variable; } } }
php
function set_control_variables($variables) { foreach ($variables as $what => $variable) { if (isset($this->request[$what])) { $this->request[$what] = $variable; } } }
[ "function", "set_control_variables", "(", "$", "variables", ")", "{", "foreach", "(", "$", "variables", "as", "$", "what", "=>", "$", "variable", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "request", "[", "$", "what", "]", ")", ")", "{", "$", "this", "->", "request", "[", "$", "what", "]", "=", "$", "variable", ";", "}", "}", "}" ]
Assigns each given variable in the array to the corresponding index in the request class variable. @param array $variables @return void
[ "Assigns", "each", "given", "variable", "in", "the", "array", "to", "the", "corresponding", "index", "in", "the", "request", "class", "variable", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/tablelib.php#L333-L339
214,851
moodle/moodle
lib/tablelib.php
flexible_table.column_suppress
function column_suppress($column) { if (isset($this->column_suppress[$column])) { $this->column_suppress[$column] = true; } }
php
function column_suppress($column) { if (isset($this->column_suppress[$column])) { $this->column_suppress[$column] = true; } }
[ "function", "column_suppress", "(", "$", "column", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "column_suppress", "[", "$", "column", "]", ")", ")", "{", "$", "this", "->", "column_suppress", "[", "$", "column", "]", "=", "true", ";", "}", "}" ]
What this method does is set the column so that if the same data appears in consecutive rows, then it is not repeated. For example, in the quiz overview report, the fullname column is set to be suppressed, so that when one student has made multiple attempts, their name is only printed in the row for their first attempt. @param int $column the index of a column.
[ "What", "this", "method", "does", "is", "set", "the", "column", "so", "that", "if", "the", "same", "data", "appears", "in", "consecutive", "rows", "then", "it", "is", "not", "repeated", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/tablelib.php#L360-L364
214,852
moodle/moodle
lib/tablelib.php
flexible_table.construct_order_by
public static function construct_order_by($cols, $textsortcols=array()) { global $DB; $bits = array(); foreach ($cols as $column => $order) { if (in_array($column, $textsortcols)) { $column = $DB->sql_order_by_text($column); } if ($order == SORT_ASC) { $bits[] = $column . ' ASC'; } else { $bits[] = $column . ' DESC'; } } return implode(', ', $bits); }
php
public static function construct_order_by($cols, $textsortcols=array()) { global $DB; $bits = array(); foreach ($cols as $column => $order) { if (in_array($column, $textsortcols)) { $column = $DB->sql_order_by_text($column); } if ($order == SORT_ASC) { $bits[] = $column . ' ASC'; } else { $bits[] = $column . ' DESC'; } } return implode(', ', $bits); }
[ "public", "static", "function", "construct_order_by", "(", "$", "cols", ",", "$", "textsortcols", "=", "array", "(", ")", ")", "{", "global", "$", "DB", ";", "$", "bits", "=", "array", "(", ")", ";", "foreach", "(", "$", "cols", "as", "$", "column", "=>", "$", "order", ")", "{", "if", "(", "in_array", "(", "$", "column", ",", "$", "textsortcols", ")", ")", "{", "$", "column", "=", "$", "DB", "->", "sql_order_by_text", "(", "$", "column", ")", ";", "}", "if", "(", "$", "order", "==", "SORT_ASC", ")", "{", "$", "bits", "[", "]", "=", "$", "column", ".", "' ASC'", ";", "}", "else", "{", "$", "bits", "[", "]", "=", "$", "column", ".", "' DESC'", ";", "}", "}", "return", "implode", "(", "', '", ",", "$", "bits", ")", ";", "}" ]
Prepare an an order by clause from the list of columns to be sorted. @param array $cols column name => SORT_ASC or SORT_DESC @return SQL fragment that can be used in an ORDER BY clause.
[ "Prepare", "an", "an", "order", "by", "clause", "from", "the", "list", "of", "columns", "to", "be", "sorted", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/tablelib.php#L609-L625
214,853
moodle/moodle
lib/tablelib.php
flexible_table.format_and_add_array_of_rows
public function format_and_add_array_of_rows($rowstoadd, $finish = true) { foreach ($rowstoadd as $row) { if (is_null($row)) { $this->add_separator(); } else { $this->add_data_keyed($this->format_row($row)); } } if ($finish) { $this->finish_output(!$this->is_downloading()); } }
php
public function format_and_add_array_of_rows($rowstoadd, $finish = true) { foreach ($rowstoadd as $row) { if (is_null($row)) { $this->add_separator(); } else { $this->add_data_keyed($this->format_row($row)); } } if ($finish) { $this->finish_output(!$this->is_downloading()); } }
[ "public", "function", "format_and_add_array_of_rows", "(", "$", "rowstoadd", ",", "$", "finish", "=", "true", ")", "{", "foreach", "(", "$", "rowstoadd", "as", "$", "row", ")", "{", "if", "(", "is_null", "(", "$", "row", ")", ")", "{", "$", "this", "->", "add_separator", "(", ")", ";", "}", "else", "{", "$", "this", "->", "add_data_keyed", "(", "$", "this", "->", "format_row", "(", "$", "row", ")", ")", ";", "}", "}", "if", "(", "$", "finish", ")", "{", "$", "this", "->", "finish_output", "(", "!", "$", "this", "->", "is_downloading", "(", ")", ")", ";", "}", "}" ]
Add a number of rows to the table at once. And optionally finish output after they have been added. @param (object|array|null)[] $rowstoadd Array of rows to add to table, a null value in array adds a separator row. Or a object or array is added to table. We expect properties for the row array as would be passed to add_data_keyed. @param bool $finish
[ "Add", "a", "number", "of", "rows", "to", "the", "table", "at", "once", ".", "And", "optionally", "finish", "output", "after", "they", "have", "been", "added", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/tablelib.php#L734-L745
214,854
moodle/moodle
lib/tablelib.php
flexible_table.add_data
function add_data($row, $classname = '') { if (!$this->setup) { return false; } if (!$this->started_output) { $this->start_output(); } if ($this->exportclass!==null) { if ($row === null) { $this->exportclass->add_seperator(); } else { $this->exportclass->add_data($row); } } else { $this->print_row($row, $classname); } return true; }
php
function add_data($row, $classname = '') { if (!$this->setup) { return false; } if (!$this->started_output) { $this->start_output(); } if ($this->exportclass!==null) { if ($row === null) { $this->exportclass->add_seperator(); } else { $this->exportclass->add_data($row); } } else { $this->print_row($row, $classname); } return true; }
[ "function", "add_data", "(", "$", "row", ",", "$", "classname", "=", "''", ")", "{", "if", "(", "!", "$", "this", "->", "setup", ")", "{", "return", "false", ";", "}", "if", "(", "!", "$", "this", "->", "started_output", ")", "{", "$", "this", "->", "start_output", "(", ")", ";", "}", "if", "(", "$", "this", "->", "exportclass", "!==", "null", ")", "{", "if", "(", "$", "row", "===", "null", ")", "{", "$", "this", "->", "exportclass", "->", "add_seperator", "(", ")", ";", "}", "else", "{", "$", "this", "->", "exportclass", "->", "add_data", "(", "$", "row", ")", ";", "}", "}", "else", "{", "$", "this", "->", "print_row", "(", "$", "row", ",", "$", "classname", ")", ";", "}", "return", "true", ";", "}" ]
This method actually directly echoes the row passed to it now or adds it to the download. If this is the first row and start_output has not already been called this method also calls start_output to open the table or send headers for the downloaded. Can be used as before. print_html now calls finish_html to close table. @param array $row a numerically keyed row of data to add to the table. @param string $classname CSS class name to add to this row's tr tag. @return bool success.
[ "This", "method", "actually", "directly", "echoes", "the", "row", "passed", "to", "it", "now", "or", "adds", "it", "to", "the", "download", ".", "If", "this", "is", "the", "first", "row", "and", "start_output", "has", "not", "already", "been", "called", "this", "method", "also", "calls", "start_output", "to", "open", "the", "table", "or", "send", "headers", "for", "the", "downloaded", ".", "Can", "be", "used", "as", "before", ".", "print_html", "now", "calls", "finish_html", "to", "close", "table", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/tablelib.php#L768-L785
214,855
moodle/moodle
lib/tablelib.php
flexible_table.finish_output
function finish_output($closeexportclassdoc = true) { if ($this->exportclass!==null) { $this->exportclass->finish_table(); if ($closeexportclassdoc) { $this->exportclass->finish_document(); } } else { $this->finish_html(); } }
php
function finish_output($closeexportclassdoc = true) { if ($this->exportclass!==null) { $this->exportclass->finish_table(); if ($closeexportclassdoc) { $this->exportclass->finish_document(); } } else { $this->finish_html(); } }
[ "function", "finish_output", "(", "$", "closeexportclassdoc", "=", "true", ")", "{", "if", "(", "$", "this", "->", "exportclass", "!==", "null", ")", "{", "$", "this", "->", "exportclass", "->", "finish_table", "(", ")", ";", "if", "(", "$", "closeexportclassdoc", ")", "{", "$", "this", "->", "exportclass", "->", "finish_document", "(", ")", ";", "}", "}", "else", "{", "$", "this", "->", "finish_html", "(", ")", ";", "}", "}" ]
You should call this to finish outputting the table data after adding data to the table with add_data or add_data_keyed.
[ "You", "should", "call", "this", "to", "finish", "outputting", "the", "table", "data", "after", "adding", "data", "to", "the", "table", "with", "add_data", "or", "add_data_keyed", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/tablelib.php#L792-L801
214,856
moodle/moodle
lib/tablelib.php
flexible_table.download_buttons
public function download_buttons() { global $OUTPUT; if ($this->is_downloadable() && !$this->is_downloading()) { return $OUTPUT->download_dataformat_selector(get_string('downloadas', 'table'), $this->baseurl->out_omit_querystring(), 'download', $this->baseurl->params()); } else { return ''; } }
php
public function download_buttons() { global $OUTPUT; if ($this->is_downloadable() && !$this->is_downloading()) { return $OUTPUT->download_dataformat_selector(get_string('downloadas', 'table'), $this->baseurl->out_omit_querystring(), 'download', $this->baseurl->params()); } else { return ''; } }
[ "public", "function", "download_buttons", "(", ")", "{", "global", "$", "OUTPUT", ";", "if", "(", "$", "this", "->", "is_downloadable", "(", ")", "&&", "!", "$", "this", "->", "is_downloading", "(", ")", ")", "{", "return", "$", "OUTPUT", "->", "download_dataformat_selector", "(", "get_string", "(", "'downloadas'", ",", "'table'", ")", ",", "$", "this", "->", "baseurl", "->", "out_omit_querystring", "(", ")", ",", "'download'", ",", "$", "this", "->", "baseurl", "->", "params", "(", ")", ")", ";", "}", "else", "{", "return", "''", ";", "}", "}" ]
Get the html for the download buttons Usually only use internally
[ "Get", "the", "html", "for", "the", "download", "buttons" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/tablelib.php#L1049-L1058
214,857
moodle/moodle
lib/tablelib.php
flexible_table.start_output
function start_output() { $this->started_output = true; if ($this->exportclass!==null) { $this->exportclass->start_table($this->sheettitle); $this->exportclass->output_headers($this->headers); } else { $this->start_html(); $this->print_headers(); echo html_writer::start_tag('tbody'); } }
php
function start_output() { $this->started_output = true; if ($this->exportclass!==null) { $this->exportclass->start_table($this->sheettitle); $this->exportclass->output_headers($this->headers); } else { $this->start_html(); $this->print_headers(); echo html_writer::start_tag('tbody'); } }
[ "function", "start_output", "(", ")", "{", "$", "this", "->", "started_output", "=", "true", ";", "if", "(", "$", "this", "->", "exportclass", "!==", "null", ")", "{", "$", "this", "->", "exportclass", "->", "start_table", "(", "$", "this", "->", "sheettitle", ")", ";", "$", "this", "->", "exportclass", "->", "output_headers", "(", "$", "this", "->", "headers", ")", ";", "}", "else", "{", "$", "this", "->", "start_html", "(", ")", ";", "$", "this", "->", "print_headers", "(", ")", ";", "echo", "html_writer", "::", "start_tag", "(", "'tbody'", ")", ";", "}", "}" ]
This function is not part of the public api. You don't normally need to call this. It is called automatically when needed when you start adding data to the table.
[ "This", "function", "is", "not", "part", "of", "the", "public", "api", ".", "You", "don", "t", "normally", "need", "to", "call", "this", ".", "It", "is", "called", "automatically", "when", "needed", "when", "you", "start", "adding", "data", "to", "the", "table", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/tablelib.php#L1066-L1076
214,858
moodle/moodle
lib/tablelib.php
flexible_table.get_row_html
public function get_row_html($row, $classname = '') { static $suppress_lastrow = NULL; $rowclasses = array(); if ($classname) { $rowclasses[] = $classname; } $rowid = $this->uniqueid . '_r' . $this->currentrow; $html = ''; $html .= html_writer::start_tag('tr', array('class' => implode(' ', $rowclasses), 'id' => $rowid)); // If we have a separator, print it if ($row === NULL) { $colcount = count($this->columns); $html .= html_writer::tag('td', html_writer::tag('div', '', array('class' => 'tabledivider')), array('colspan' => $colcount)); } else { $colbyindex = array_flip($this->columns); foreach ($row as $index => $data) { $column = $colbyindex[$index]; $attributes = [ 'class' => "cell c{$index}" . $this->column_class[$column], 'id' => "{$rowid}_c{$index}", 'style' => $this->make_styles_string($this->column_style[$column]), ]; $celltype = 'td'; if ($this->headercolumn && $column == $this->headercolumn) { $celltype = 'th'; $attributes['scope'] = 'row'; } if (empty($this->prefs['collapse'][$column])) { if ($this->column_suppress[$column] && $suppress_lastrow !== NULL && $suppress_lastrow[$index] === $data) { $content = '&nbsp;'; } else { $content = $data; } } else { $content = '&nbsp;'; } $html .= html_writer::tag($celltype, $content, $attributes); } } $html .= html_writer::end_tag('tr'); $suppress_enabled = array_sum($this->column_suppress); if ($suppress_enabled) { $suppress_lastrow = $row; } $this->currentrow++; return $html; }
php
public function get_row_html($row, $classname = '') { static $suppress_lastrow = NULL; $rowclasses = array(); if ($classname) { $rowclasses[] = $classname; } $rowid = $this->uniqueid . '_r' . $this->currentrow; $html = ''; $html .= html_writer::start_tag('tr', array('class' => implode(' ', $rowclasses), 'id' => $rowid)); // If we have a separator, print it if ($row === NULL) { $colcount = count($this->columns); $html .= html_writer::tag('td', html_writer::tag('div', '', array('class' => 'tabledivider')), array('colspan' => $colcount)); } else { $colbyindex = array_flip($this->columns); foreach ($row as $index => $data) { $column = $colbyindex[$index]; $attributes = [ 'class' => "cell c{$index}" . $this->column_class[$column], 'id' => "{$rowid}_c{$index}", 'style' => $this->make_styles_string($this->column_style[$column]), ]; $celltype = 'td'; if ($this->headercolumn && $column == $this->headercolumn) { $celltype = 'th'; $attributes['scope'] = 'row'; } if (empty($this->prefs['collapse'][$column])) { if ($this->column_suppress[$column] && $suppress_lastrow !== NULL && $suppress_lastrow[$index] === $data) { $content = '&nbsp;'; } else { $content = $data; } } else { $content = '&nbsp;'; } $html .= html_writer::tag($celltype, $content, $attributes); } } $html .= html_writer::end_tag('tr'); $suppress_enabled = array_sum($this->column_suppress); if ($suppress_enabled) { $suppress_lastrow = $row; } $this->currentrow++; return $html; }
[ "public", "function", "get_row_html", "(", "$", "row", ",", "$", "classname", "=", "''", ")", "{", "static", "$", "suppress_lastrow", "=", "NULL", ";", "$", "rowclasses", "=", "array", "(", ")", ";", "if", "(", "$", "classname", ")", "{", "$", "rowclasses", "[", "]", "=", "$", "classname", ";", "}", "$", "rowid", "=", "$", "this", "->", "uniqueid", ".", "'_r'", ".", "$", "this", "->", "currentrow", ";", "$", "html", "=", "''", ";", "$", "html", ".=", "html_writer", "::", "start_tag", "(", "'tr'", ",", "array", "(", "'class'", "=>", "implode", "(", "' '", ",", "$", "rowclasses", ")", ",", "'id'", "=>", "$", "rowid", ")", ")", ";", "// If we have a separator, print it", "if", "(", "$", "row", "===", "NULL", ")", "{", "$", "colcount", "=", "count", "(", "$", "this", "->", "columns", ")", ";", "$", "html", ".=", "html_writer", "::", "tag", "(", "'td'", ",", "html_writer", "::", "tag", "(", "'div'", ",", "''", ",", "array", "(", "'class'", "=>", "'tabledivider'", ")", ")", ",", "array", "(", "'colspan'", "=>", "$", "colcount", ")", ")", ";", "}", "else", "{", "$", "colbyindex", "=", "array_flip", "(", "$", "this", "->", "columns", ")", ";", "foreach", "(", "$", "row", "as", "$", "index", "=>", "$", "data", ")", "{", "$", "column", "=", "$", "colbyindex", "[", "$", "index", "]", ";", "$", "attributes", "=", "[", "'class'", "=>", "\"cell c{$index}\"", ".", "$", "this", "->", "column_class", "[", "$", "column", "]", ",", "'id'", "=>", "\"{$rowid}_c{$index}\"", ",", "'style'", "=>", "$", "this", "->", "make_styles_string", "(", "$", "this", "->", "column_style", "[", "$", "column", "]", ")", ",", "]", ";", "$", "celltype", "=", "'td'", ";", "if", "(", "$", "this", "->", "headercolumn", "&&", "$", "column", "==", "$", "this", "->", "headercolumn", ")", "{", "$", "celltype", "=", "'th'", ";", "$", "attributes", "[", "'scope'", "]", "=", "'row'", ";", "}", "if", "(", "empty", "(", "$", "this", "->", "prefs", "[", "'collapse'", "]", "[", "$", "column", "]", ")", ")", "{", "if", "(", "$", "this", "->", "column_suppress", "[", "$", "column", "]", "&&", "$", "suppress_lastrow", "!==", "NULL", "&&", "$", "suppress_lastrow", "[", "$", "index", "]", "===", "$", "data", ")", "{", "$", "content", "=", "'&nbsp;'", ";", "}", "else", "{", "$", "content", "=", "$", "data", ";", "}", "}", "else", "{", "$", "content", "=", "'&nbsp;'", ";", "}", "$", "html", ".=", "html_writer", "::", "tag", "(", "$", "celltype", ",", "$", "content", ",", "$", "attributes", ")", ";", "}", "}", "$", "html", ".=", "html_writer", "::", "end_tag", "(", "'tr'", ")", ";", "$", "suppress_enabled", "=", "array_sum", "(", "$", "this", "->", "column_suppress", ")", ";", "if", "(", "$", "suppress_enabled", ")", "{", "$", "suppress_lastrow", "=", "$", "row", ";", "}", "$", "this", "->", "currentrow", "++", ";", "return", "$", "html", ";", "}" ]
Generate html code for the passed row. @param array $row Row data. @param string $classname classes to add. @return string $html html code for the row passed.
[ "Generate", "html", "code", "for", "the", "passed", "row", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/tablelib.php#L1093-L1151
214,859
moodle/moodle
lib/tablelib.php
flexible_table.render_reset_button
protected function render_reset_button() { if (!$this->can_be_reset()) { return ''; } $url = $this->baseurl->out(false, array($this->request[TABLE_VAR_RESET] => 1)); $html = html_writer::start_div('resettable mdl-right'); $html .= html_writer::link($url, get_string('resettable')); $html .= html_writer::end_div(); return $html; }
php
protected function render_reset_button() { if (!$this->can_be_reset()) { return ''; } $url = $this->baseurl->out(false, array($this->request[TABLE_VAR_RESET] => 1)); $html = html_writer::start_div('resettable mdl-right'); $html .= html_writer::link($url, get_string('resettable')); $html .= html_writer::end_div(); return $html; }
[ "protected", "function", "render_reset_button", "(", ")", "{", "if", "(", "!", "$", "this", "->", "can_be_reset", "(", ")", ")", "{", "return", "''", ";", "}", "$", "url", "=", "$", "this", "->", "baseurl", "->", "out", "(", "false", ",", "array", "(", "$", "this", "->", "request", "[", "TABLE_VAR_RESET", "]", "=>", "1", ")", ")", ";", "$", "html", "=", "html_writer", "::", "start_div", "(", "'resettable mdl-right'", ")", ";", "$", "html", ".=", "html_writer", "::", "link", "(", "$", "url", ",", "get_string", "(", "'resettable'", ")", ")", ";", "$", "html", ".=", "html_writer", "::", "end_div", "(", ")", ";", "return", "$", "html", ";", "}" ]
Generate the HTML for the table preferences reset button. @return string HTML fragment, empty string if no need to reset
[ "Generate", "the", "HTML", "for", "the", "table", "preferences", "reset", "button", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/tablelib.php#L1425-L1438
214,860
moodle/moodle
lib/tablelib.php
flexible_table.can_be_reset
protected function can_be_reset() { // Loop through preferences and make sure they are empty or set to the default value. foreach ($this->prefs as $prefname => $prefval) { if ($prefname === 'sortby' and !empty($this->sort_default_column)) { // Check if the actual sorting differs from the default one. if (empty($prefval) or $prefval !== array($this->sort_default_column => $this->sort_default_order)) { return true; } } else if ($prefname === 'collapse' and !empty($prefval)) { // Check if there are some collapsed columns (all are expanded by default). foreach ($prefval as $columnname => $iscollapsed) { if ($iscollapsed) { return true; } } } else if (!empty($prefval)) { // For all other cases, we just check if some preference is set. return true; } } return false; }
php
protected function can_be_reset() { // Loop through preferences and make sure they are empty or set to the default value. foreach ($this->prefs as $prefname => $prefval) { if ($prefname === 'sortby' and !empty($this->sort_default_column)) { // Check if the actual sorting differs from the default one. if (empty($prefval) or $prefval !== array($this->sort_default_column => $this->sort_default_order)) { return true; } } else if ($prefname === 'collapse' and !empty($prefval)) { // Check if there are some collapsed columns (all are expanded by default). foreach ($prefval as $columnname => $iscollapsed) { if ($iscollapsed) { return true; } } } else if (!empty($prefval)) { // For all other cases, we just check if some preference is set. return true; } } return false; }
[ "protected", "function", "can_be_reset", "(", ")", "{", "// Loop through preferences and make sure they are empty or set to the default value.", "foreach", "(", "$", "this", "->", "prefs", "as", "$", "prefname", "=>", "$", "prefval", ")", "{", "if", "(", "$", "prefname", "===", "'sortby'", "and", "!", "empty", "(", "$", "this", "->", "sort_default_column", ")", ")", "{", "// Check if the actual sorting differs from the default one.", "if", "(", "empty", "(", "$", "prefval", ")", "or", "$", "prefval", "!==", "array", "(", "$", "this", "->", "sort_default_column", "=>", "$", "this", "->", "sort_default_order", ")", ")", "{", "return", "true", ";", "}", "}", "else", "if", "(", "$", "prefname", "===", "'collapse'", "and", "!", "empty", "(", "$", "prefval", ")", ")", "{", "// Check if there are some collapsed columns (all are expanded by default).", "foreach", "(", "$", "prefval", "as", "$", "columnname", "=>", "$", "iscollapsed", ")", "{", "if", "(", "$", "iscollapsed", ")", "{", "return", "true", ";", "}", "}", "}", "else", "if", "(", "!", "empty", "(", "$", "prefval", ")", ")", "{", "// For all other cases, we just check if some preference is set.", "return", "true", ";", "}", "}", "return", "false", ";", "}" ]
Are there some table preferences that can be reset? If true, then the "reset table preferences" widget should be displayed. @return bool
[ "Are", "there", "some", "table", "preferences", "that", "can", "be", "reset?" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/tablelib.php#L1447-L1473
214,861
moodle/moodle
lib/tablelib.php
table_sql.set_count_sql
function set_count_sql($sql, array $params = NULL) { $this->countsql = $sql; $this->countparams = $params; }
php
function set_count_sql($sql, array $params = NULL) { $this->countsql = $sql; $this->countparams = $params; }
[ "function", "set_count_sql", "(", "$", "sql", ",", "array", "$", "params", "=", "NULL", ")", "{", "$", "this", "->", "countsql", "=", "$", "sql", ";", "$", "this", "->", "countparams", "=", "$", "params", ";", "}" ]
This is only needed if you want to use different sql to count rows. Used for example when perhaps all db JOINS are not needed when counting records. You don't need to call this function the count_sql will be generated automatically. We need to count rows returned by the db seperately to the query itself as we need to know how many pages of data we have to display.
[ "This", "is", "only", "needed", "if", "you", "want", "to", "use", "different", "sql", "to", "count", "rows", ".", "Used", "for", "example", "when", "perhaps", "all", "db", "JOINS", "are", "not", "needed", "when", "counting", "records", ".", "You", "don", "t", "need", "to", "call", "this", "function", "the", "count_sql", "will", "be", "generated", "automatically", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/tablelib.php#L1568-L1571
214,862
moodle/moodle
lib/tablelib.php
table_default_export_format_parent.format_text
function format_text($text, $format=FORMAT_MOODLE, $options=NULL, $courseid=NULL) { //use some whitespace to indicate where there was some line spacing. $text = str_replace(array('</p>', "\n", "\r"), ' ', $text); return strip_tags($text); }
php
function format_text($text, $format=FORMAT_MOODLE, $options=NULL, $courseid=NULL) { //use some whitespace to indicate where there was some line spacing. $text = str_replace(array('</p>', "\n", "\r"), ' ', $text); return strip_tags($text); }
[ "function", "format_text", "(", "$", "text", ",", "$", "format", "=", "FORMAT_MOODLE", ",", "$", "options", "=", "NULL", ",", "$", "courseid", "=", "NULL", ")", "{", "//use some whitespace to indicate where there was some line spacing.", "$", "text", "=", "str_replace", "(", "array", "(", "'</p>'", ",", "\"\\n\"", ",", "\"\\r\"", ")", ",", "' '", ",", "$", "text", ")", ";", "return", "strip_tags", "(", "$", "text", ")", ";", "}" ]
Given text in a variety of format codings, this function returns the text as safe HTML or as plain text dependent on what is appropriate for the download format. The default removes all tags.
[ "Given", "text", "in", "a", "variety", "of", "format", "codings", "this", "function", "returns", "the", "text", "as", "safe", "HTML", "or", "as", "plain", "text", "dependent", "on", "what", "is", "appropriate", "for", "the", "download", "format", ".", "The", "default", "removes", "all", "tags", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/tablelib.php#L1720-L1724
214,863
moodle/moodle
lib/horde/framework/Horde/Imap/Client/Data/Thread.php
Horde_Imap_Client_Data_Thread.getThread
public function getThread($index) { foreach ($this->_thread as $v) { if (isset($v[$index])) { reset($v); $ob = new stdClass; $ob->base = (count($v) > 1) ? key($v) : null; $ob->last = false; $levels = $out = array(); $last = 0; while (($v2 = current($v)) !== false) { $k2 = key($v); $ob2 = clone $ob; $ob2->level = $v2; $out[$k2] = $ob2; if (($last < $v2) && isset($levels[$v2])) { $out[$levels[$v2]]->last = true; } $levels[$v2] = $k2; $last = $v2; next($v); } foreach ($levels as $v) { $out[$v]->last = true; } return $out; } } return array(); }
php
public function getThread($index) { foreach ($this->_thread as $v) { if (isset($v[$index])) { reset($v); $ob = new stdClass; $ob->base = (count($v) > 1) ? key($v) : null; $ob->last = false; $levels = $out = array(); $last = 0; while (($v2 = current($v)) !== false) { $k2 = key($v); $ob2 = clone $ob; $ob2->level = $v2; $out[$k2] = $ob2; if (($last < $v2) && isset($levels[$v2])) { $out[$levels[$v2]]->last = true; } $levels[$v2] = $k2; $last = $v2; next($v); } foreach ($levels as $v) { $out[$v]->last = true; } return $out; } } return array(); }
[ "public", "function", "getThread", "(", "$", "index", ")", "{", "foreach", "(", "$", "this", "->", "_thread", "as", "$", "v", ")", "{", "if", "(", "isset", "(", "$", "v", "[", "$", "index", "]", ")", ")", "{", "reset", "(", "$", "v", ")", ";", "$", "ob", "=", "new", "stdClass", ";", "$", "ob", "->", "base", "=", "(", "count", "(", "$", "v", ")", ">", "1", ")", "?", "key", "(", "$", "v", ")", ":", "null", ";", "$", "ob", "->", "last", "=", "false", ";", "$", "levels", "=", "$", "out", "=", "array", "(", ")", ";", "$", "last", "=", "0", ";", "while", "(", "(", "$", "v2", "=", "current", "(", "$", "v", ")", ")", "!==", "false", ")", "{", "$", "k2", "=", "key", "(", "$", "v", ")", ";", "$", "ob2", "=", "clone", "$", "ob", ";", "$", "ob2", "->", "level", "=", "$", "v2", ";", "$", "out", "[", "$", "k2", "]", "=", "$", "ob2", ";", "if", "(", "(", "$", "last", "<", "$", "v2", ")", "&&", "isset", "(", "$", "levels", "[", "$", "v2", "]", ")", ")", "{", "$", "out", "[", "$", "levels", "[", "$", "v2", "]", "]", "->", "last", "=", "true", ";", "}", "$", "levels", "[", "$", "v2", "]", "=", "$", "k2", ";", "$", "last", "=", "$", "v2", ";", "next", "(", "$", "v", ")", ";", "}", "foreach", "(", "$", "levels", "as", "$", "v", ")", "{", "$", "out", "[", "$", "v", "]", "->", "last", "=", "true", ";", "}", "return", "$", "out", ";", "}", "}", "return", "array", "(", ")", ";", "}" ]
Returns the list of messages in a thread. @param integer $index An index contained in the thread. @return array Keys are indices, values are objects with the following properties: - base: (integer) Base ID of the thread. If null, thread is a single message. - last: (boolean) If true, this is the last index in the sublevel. - level: (integer) The sublevel of the index.
[ "Returns", "the", "list", "of", "messages", "in", "a", "thread", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/horde/framework/Horde/Imap/Client/Data/Thread.php#L85-L121
214,864
moodle/moodle
lib/horde/framework/Horde/Imap/Client/Data/Thread.php
Horde_Imap_Client_Data_Thread._getAllIndices
protected function _getAllIndices() { $out = array(); foreach ($this->_thread as $val) { $out += $val; } return array_keys($out); }
php
protected function _getAllIndices() { $out = array(); foreach ($this->_thread as $val) { $out += $val; } return array_keys($out); }
[ "protected", "function", "_getAllIndices", "(", ")", "{", "$", "out", "=", "array", "(", ")", ";", "foreach", "(", "$", "this", "->", "_thread", "as", "$", "val", ")", "{", "$", "out", "+=", "$", "val", ";", "}", "return", "array_keys", "(", "$", "out", ")", ";", "}" ]
Return all indices. @return array An array of indices.
[ "Return", "all", "indices", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/horde/framework/Horde/Imap/Client/Data/Thread.php#L158-L167
214,865
moodle/moodle
question/type/calculatedmulti/question.php
qtype_calculatedmulti_calculate_helper.calculate_all_expressions
public static function calculate_all_expressions( qtype_calculated_question_with_expressions $question) { $question->questiontext = $question->vs->replace_expressions_in_text( $question->questiontext); $question->generalfeedback = $question->vs->replace_expressions_in_text( $question->generalfeedback); foreach ($question->answers as $ans) { if ($ans->answer && $ans->answer !== '*') { $ans->answer = $question->vs->replace_expressions_in_text($ans->answer, $ans->correctanswerlength, $ans->correctanswerformat); } $ans->feedback = $question->vs->replace_expressions_in_text($ans->feedback, $ans->correctanswerlength, $ans->correctanswerformat); } }
php
public static function calculate_all_expressions( qtype_calculated_question_with_expressions $question) { $question->questiontext = $question->vs->replace_expressions_in_text( $question->questiontext); $question->generalfeedback = $question->vs->replace_expressions_in_text( $question->generalfeedback); foreach ($question->answers as $ans) { if ($ans->answer && $ans->answer !== '*') { $ans->answer = $question->vs->replace_expressions_in_text($ans->answer, $ans->correctanswerlength, $ans->correctanswerformat); } $ans->feedback = $question->vs->replace_expressions_in_text($ans->feedback, $ans->correctanswerlength, $ans->correctanswerformat); } }
[ "public", "static", "function", "calculate_all_expressions", "(", "qtype_calculated_question_with_expressions", "$", "question", ")", "{", "$", "question", "->", "questiontext", "=", "$", "question", "->", "vs", "->", "replace_expressions_in_text", "(", "$", "question", "->", "questiontext", ")", ";", "$", "question", "->", "generalfeedback", "=", "$", "question", "->", "vs", "->", "replace_expressions_in_text", "(", "$", "question", "->", "generalfeedback", ")", ";", "foreach", "(", "$", "question", "->", "answers", "as", "$", "ans", ")", "{", "if", "(", "$", "ans", "->", "answer", "&&", "$", "ans", "->", "answer", "!==", "'*'", ")", "{", "$", "ans", "->", "answer", "=", "$", "question", "->", "vs", "->", "replace_expressions_in_text", "(", "$", "ans", "->", "answer", ",", "$", "ans", "->", "correctanswerlength", ",", "$", "ans", "->", "correctanswerformat", ")", ";", "}", "$", "ans", "->", "feedback", "=", "$", "question", "->", "vs", "->", "replace_expressions_in_text", "(", "$", "ans", "->", "feedback", ",", "$", "ans", "->", "correctanswerlength", ",", "$", "ans", "->", "correctanswerformat", ")", ";", "}", "}" ]
Calculate all the exressions in a qtype_calculatedmulti_single_question or qtype_calculatedmulti_multi_question. @param unknown_type $question
[ "Calculate", "all", "the", "exressions", "in", "a", "qtype_calculatedmulti_single_question", "or", "qtype_calculatedmulti_multi_question", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/type/calculatedmulti/question.php#L147-L162
214,866
moodle/moodle
user/classes/output/status_field.php
status_field.set_status
public function set_status($status = self::STATUS_ACTIVE) { $this->statusactive = $status == static::STATUS_ACTIVE; $this->statussuspended = $status == static::STATUS_SUSPENDED; $this->statusnotcurrent = $status == static::STATUS_NOT_CURRENT; return $this; }
php
public function set_status($status = self::STATUS_ACTIVE) { $this->statusactive = $status == static::STATUS_ACTIVE; $this->statussuspended = $status == static::STATUS_SUSPENDED; $this->statusnotcurrent = $status == static::STATUS_NOT_CURRENT; return $this; }
[ "public", "function", "set_status", "(", "$", "status", "=", "self", "::", "STATUS_ACTIVE", ")", "{", "$", "this", "->", "statusactive", "=", "$", "status", "==", "static", "::", "STATUS_ACTIVE", ";", "$", "this", "->", "statussuspended", "=", "$", "status", "==", "static", "::", "STATUS_SUSPENDED", ";", "$", "this", "->", "statusnotcurrent", "=", "$", "status", "==", "static", "::", "STATUS_NOT_CURRENT", ";", "return", "$", "this", ";", "}" ]
Status setter. @param int $status The user enrolment status representing one of this class' STATUS_* constants. @return status_field This class' instance. Useful for chaining.
[ "Status", "setter", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/user/classes/output/status_field.php#L164-L170
214,867
moodle/moodle
files/classes/conversion.php
conversion.define_properties
protected static function define_properties() { return array( 'sourcefileid' => [ 'type' => PARAM_INT, ], 'targetformat' => [ 'type' => PARAM_ALPHANUMEXT, ], 'status' => [ 'type' => PARAM_INT, 'choices' => [ self::STATUS_PENDING, self::STATUS_IN_PROGRESS, self::STATUS_COMPLETE, self::STATUS_FAILED, ], 'default' => self::STATUS_PENDING, ], 'statusmessage' => [ 'type' => PARAM_RAW, 'null' => NULL_ALLOWED, 'default' => null, ], 'converter' => [ 'type' => PARAM_RAW, 'null' => NULL_ALLOWED, 'default' => null, ], 'destfileid' => [ 'type' => PARAM_INT, 'null' => NULL_ALLOWED, 'default' => null, ], 'data' => [ 'type' => PARAM_RAW, 'null' => NULL_ALLOWED, 'default' => null, ], ); }
php
protected static function define_properties() { return array( 'sourcefileid' => [ 'type' => PARAM_INT, ], 'targetformat' => [ 'type' => PARAM_ALPHANUMEXT, ], 'status' => [ 'type' => PARAM_INT, 'choices' => [ self::STATUS_PENDING, self::STATUS_IN_PROGRESS, self::STATUS_COMPLETE, self::STATUS_FAILED, ], 'default' => self::STATUS_PENDING, ], 'statusmessage' => [ 'type' => PARAM_RAW, 'null' => NULL_ALLOWED, 'default' => null, ], 'converter' => [ 'type' => PARAM_RAW, 'null' => NULL_ALLOWED, 'default' => null, ], 'destfileid' => [ 'type' => PARAM_INT, 'null' => NULL_ALLOWED, 'default' => null, ], 'data' => [ 'type' => PARAM_RAW, 'null' => NULL_ALLOWED, 'default' => null, ], ); }
[ "protected", "static", "function", "define_properties", "(", ")", "{", "return", "array", "(", "'sourcefileid'", "=>", "[", "'type'", "=>", "PARAM_INT", ",", "]", ",", "'targetformat'", "=>", "[", "'type'", "=>", "PARAM_ALPHANUMEXT", ",", "]", ",", "'status'", "=>", "[", "'type'", "=>", "PARAM_INT", ",", "'choices'", "=>", "[", "self", "::", "STATUS_PENDING", ",", "self", "::", "STATUS_IN_PROGRESS", ",", "self", "::", "STATUS_COMPLETE", ",", "self", "::", "STATUS_FAILED", ",", "]", ",", "'default'", "=>", "self", "::", "STATUS_PENDING", ",", "]", ",", "'statusmessage'", "=>", "[", "'type'", "=>", "PARAM_RAW", ",", "'null'", "=>", "NULL_ALLOWED", ",", "'default'", "=>", "null", ",", "]", ",", "'converter'", "=>", "[", "'type'", "=>", "PARAM_RAW", ",", "'null'", "=>", "NULL_ALLOWED", ",", "'default'", "=>", "null", ",", "]", ",", "'destfileid'", "=>", "[", "'type'", "=>", "PARAM_INT", ",", "'null'", "=>", "NULL_ALLOWED", ",", "'default'", "=>", "null", ",", "]", ",", "'data'", "=>", "[", "'type'", "=>", "PARAM_RAW", ",", "'null'", "=>", "NULL_ALLOWED", ",", "'default'", "=>", "null", ",", "]", ",", ")", ";", "}" ]
Define properties. @return array
[ "Define", "properties", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/files/classes/conversion.php#L69-L108
214,868
moodle/moodle
files/classes/conversion.php
conversion.get_conversions_for_file
public static function get_conversions_for_file(stored_file $file, $format) { global $DB; $instances = []; // Conversion records are intended for tracking a conversion in progress or recently completed. // The record is removed periodically, but the destination file is not. // We need to fetch all conversion records which match the source file and target, and also all source and // destination files which do not have a conversion record. $sqlfields = self::get_sql_fields('c', 'conversion'); // Fetch actual conversions which relate to the specified source file, and have a matching conversion record, // and either have a valid destination file which still exists, or do not have a destination file at all. $sql = "SELECT {$sqlfields} FROM {" . self::TABLE . "} c INNER JOIN {files} conversionsourcefile ON conversionsourcefile.id = c.sourcefileid LEFT JOIN {files} conversiondestfile ON conversiondestfile.id = c.destfileid WHERE conversionsourcefile.contenthash = :ccontenthash AND c.targetformat = :cformat AND ( c.destfileid IS NULL OR conversiondestfile.id IS NOT NULL )"; // Fetch a empty conversion record for each source/destination combination that we find to match where the // destination file is in the correct filearea/filepath/filename combination to meet the requirements. // This ensures that existing conversions are used where possible, even if there is no 'conversion' record for // them. $sql .= " UNION ALL SELECT NULL AS conversionid, orphanedsourcefile.id AS conversionsourcefileid, :oformat AS conversiontargetformat, 2 AS conversionstatus, NULL AS conversionstatusmessage, NULL AS conversionconverter, orphaneddestfile.id AS conversiondestfileid, NULL AS conversiondata, 0 AS conversiontimecreated, 0 AS conversiontimemodified, 0 AS conversionusermodified FROM {files} orphanedsourcefile INNER JOIN {files} orphaneddestfile ON ( orphaneddestfile.filename = orphanedsourcefile.contenthash AND orphaneddestfile.component = 'core' AND orphaneddestfile.filearea = 'documentconversion' AND orphaneddestfile.filepath = :ofilepath ) LEFT JOIN {" . self::TABLE . "} orphanedconversion ON orphanedconversion.destfileid = orphaneddestfile.id WHERE orphanedconversion.id IS NULL AND orphanedsourcefile.id = :osourcefileid "; $records = $DB->get_records_sql($sql, [ 'ccontenthash' => $file->get_contenthash(), 'osourcefileid' => $file->get_id(), 'cfilepath' => "/{$format}/", 'ofilepath' => "/{$format}/", 'cformat' => $format, 'oformat' => $format, ]); foreach ($records as $record) { $data = self::extract_record($record, 'conversion'); $newrecord = new static(0, $data); $instances[] = $newrecord; } return $instances; }
php
public static function get_conversions_for_file(stored_file $file, $format) { global $DB; $instances = []; // Conversion records are intended for tracking a conversion in progress or recently completed. // The record is removed periodically, but the destination file is not. // We need to fetch all conversion records which match the source file and target, and also all source and // destination files which do not have a conversion record. $sqlfields = self::get_sql_fields('c', 'conversion'); // Fetch actual conversions which relate to the specified source file, and have a matching conversion record, // and either have a valid destination file which still exists, or do not have a destination file at all. $sql = "SELECT {$sqlfields} FROM {" . self::TABLE . "} c INNER JOIN {files} conversionsourcefile ON conversionsourcefile.id = c.sourcefileid LEFT JOIN {files} conversiondestfile ON conversiondestfile.id = c.destfileid WHERE conversionsourcefile.contenthash = :ccontenthash AND c.targetformat = :cformat AND ( c.destfileid IS NULL OR conversiondestfile.id IS NOT NULL )"; // Fetch a empty conversion record for each source/destination combination that we find to match where the // destination file is in the correct filearea/filepath/filename combination to meet the requirements. // This ensures that existing conversions are used where possible, even if there is no 'conversion' record for // them. $sql .= " UNION ALL SELECT NULL AS conversionid, orphanedsourcefile.id AS conversionsourcefileid, :oformat AS conversiontargetformat, 2 AS conversionstatus, NULL AS conversionstatusmessage, NULL AS conversionconverter, orphaneddestfile.id AS conversiondestfileid, NULL AS conversiondata, 0 AS conversiontimecreated, 0 AS conversiontimemodified, 0 AS conversionusermodified FROM {files} orphanedsourcefile INNER JOIN {files} orphaneddestfile ON ( orphaneddestfile.filename = orphanedsourcefile.contenthash AND orphaneddestfile.component = 'core' AND orphaneddestfile.filearea = 'documentconversion' AND orphaneddestfile.filepath = :ofilepath ) LEFT JOIN {" . self::TABLE . "} orphanedconversion ON orphanedconversion.destfileid = orphaneddestfile.id WHERE orphanedconversion.id IS NULL AND orphanedsourcefile.id = :osourcefileid "; $records = $DB->get_records_sql($sql, [ 'ccontenthash' => $file->get_contenthash(), 'osourcefileid' => $file->get_id(), 'cfilepath' => "/{$format}/", 'ofilepath' => "/{$format}/", 'cformat' => $format, 'oformat' => $format, ]); foreach ($records as $record) { $data = self::extract_record($record, 'conversion'); $newrecord = new static(0, $data); $instances[] = $newrecord; } return $instances; }
[ "public", "static", "function", "get_conversions_for_file", "(", "stored_file", "$", "file", ",", "$", "format", ")", "{", "global", "$", "DB", ";", "$", "instances", "=", "[", "]", ";", "// Conversion records are intended for tracking a conversion in progress or recently completed.", "// The record is removed periodically, but the destination file is not.", "// We need to fetch all conversion records which match the source file and target, and also all source and", "// destination files which do not have a conversion record.", "$", "sqlfields", "=", "self", "::", "get_sql_fields", "(", "'c'", ",", "'conversion'", ")", ";", "// Fetch actual conversions which relate to the specified source file, and have a matching conversion record,", "// and either have a valid destination file which still exists, or do not have a destination file at all.", "$", "sql", "=", "\"SELECT {$sqlfields}\n FROM {\"", ".", "self", "::", "TABLE", ".", "\"} c\n INNER JOIN {files} conversionsourcefile ON conversionsourcefile.id = c.sourcefileid\n LEFT JOIN {files} conversiondestfile ON conversiondestfile.id = c.destfileid\n WHERE\n conversionsourcefile.contenthash = :ccontenthash\n AND c.targetformat = :cformat\n AND (\n c.destfileid IS NULL OR conversiondestfile.id IS NOT NULL\n )\"", ";", "// Fetch a empty conversion record for each source/destination combination that we find to match where the", "// destination file is in the correct filearea/filepath/filename combination to meet the requirements.", "// This ensures that existing conversions are used where possible, even if there is no 'conversion' record for", "// them.", "$", "sql", ".=", "\"\n UNION ALL\n SELECT\n NULL AS conversionid,\n orphanedsourcefile.id AS conversionsourcefileid,\n :oformat AS conversiontargetformat,\n 2 AS conversionstatus,\n NULL AS conversionstatusmessage,\n NULL AS conversionconverter,\n orphaneddestfile.id AS conversiondestfileid,\n NULL AS conversiondata,\n 0 AS conversiontimecreated,\n 0 AS conversiontimemodified,\n 0 AS conversionusermodified\n FROM {files} orphanedsourcefile\n INNER JOIN {files} orphaneddestfile ON (\n orphaneddestfile.filename = orphanedsourcefile.contenthash\n AND orphaneddestfile.component = 'core'\n AND orphaneddestfile.filearea = 'documentconversion'\n AND orphaneddestfile.filepath = :ofilepath\n )\n LEFT JOIN {\"", ".", "self", "::", "TABLE", ".", "\"} orphanedconversion ON orphanedconversion.destfileid = orphaneddestfile.id\n WHERE\n orphanedconversion.id IS NULL\n AND\n orphanedsourcefile.id = :osourcefileid\n \"", ";", "$", "records", "=", "$", "DB", "->", "get_records_sql", "(", "$", "sql", ",", "[", "'ccontenthash'", "=>", "$", "file", "->", "get_contenthash", "(", ")", ",", "'osourcefileid'", "=>", "$", "file", "->", "get_id", "(", ")", ",", "'cfilepath'", "=>", "\"/{$format}/\"", ",", "'ofilepath'", "=>", "\"/{$format}/\"", ",", "'cformat'", "=>", "$", "format", ",", "'oformat'", "=>", "$", "format", ",", "]", ")", ";", "foreach", "(", "$", "records", "as", "$", "record", ")", "{", "$", "data", "=", "self", "::", "extract_record", "(", "$", "record", ",", "'conversion'", ")", ";", "$", "newrecord", "=", "new", "static", "(", "0", ",", "$", "data", ")", ";", "$", "instances", "[", "]", "=", "$", "newrecord", ";", "}", "return", "$", "instances", ";", "}" ]
Fetch all conversions relating to the specified file. Only conversions which have a valid file are returned. @param stored_file $file The source file being converted @param string $format The targetforamt to filter to @return conversion[]
[ "Fetch", "all", "conversions", "relating", "to", "the", "specified", "file", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/files/classes/conversion.php#L119-L189
214,869
moodle/moodle
files/classes/conversion.php
conversion.remove_orphan_records
public static function remove_orphan_records() { global $DB; $sql = " SELECT c.id FROM {" . self::TABLE . "} c LEFT JOIN {files} f ON f.id = c.sourcefileid WHERE f.id IS NULL"; $ids = $DB->get_fieldset_sql($sql, []); if (empty($ids)) { return; } list($insql, $inparams) = $DB->get_in_or_equal($ids, SQL_PARAMS_NAMED); $DB->delete_records_select(self::TABLE, "id $insql", $inparams); }
php
public static function remove_orphan_records() { global $DB; $sql = " SELECT c.id FROM {" . self::TABLE . "} c LEFT JOIN {files} f ON f.id = c.sourcefileid WHERE f.id IS NULL"; $ids = $DB->get_fieldset_sql($sql, []); if (empty($ids)) { return; } list($insql, $inparams) = $DB->get_in_or_equal($ids, SQL_PARAMS_NAMED); $DB->delete_records_select(self::TABLE, "id $insql", $inparams); }
[ "public", "static", "function", "remove_orphan_records", "(", ")", "{", "global", "$", "DB", ";", "$", "sql", "=", "\"\n SELECT c.id\n FROM {\"", ".", "self", "::", "TABLE", ".", "\"} c\n LEFT JOIN {files} f\n ON f.id = c.sourcefileid\n WHERE f.id IS NULL\"", ";", "$", "ids", "=", "$", "DB", "->", "get_fieldset_sql", "(", "$", "sql", ",", "[", "]", ")", ";", "if", "(", "empty", "(", "$", "ids", ")", ")", "{", "return", ";", "}", "list", "(", "$", "insql", ",", "$", "inparams", ")", "=", "$", "DB", "->", "get_in_or_equal", "(", "$", "ids", ",", "SQL_PARAMS_NAMED", ")", ";", "$", "DB", "->", "delete_records_select", "(", "self", "::", "TABLE", ",", "\"id $insql\"", ",", "$", "inparams", ")", ";", "}" ]
Remove orphan records. Records are considered orphans when their source file not longer exists. In this scenario we do not want to keep the converted file any longer, in particular to be compliant with privacy laws.
[ "Remove", "orphan", "records", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/files/classes/conversion.php#L209-L226
214,870
moodle/moodle
files/classes/conversion.php
conversion.get_file_record
protected function get_file_record() { $file = $this->get_sourcefile(); if (!$file) { // If the source file was removed before we completed, we must return early. return false; } return [ 'contextid' => \context_system::instance()->id, 'component' => 'core', 'filearea' => 'documentconversion', 'itemid' => 0, 'filepath' => "/" . $this->get('targetformat') . "/", 'filename' => $file->get_contenthash(), ]; }
php
protected function get_file_record() { $file = $this->get_sourcefile(); if (!$file) { // If the source file was removed before we completed, we must return early. return false; } return [ 'contextid' => \context_system::instance()->id, 'component' => 'core', 'filearea' => 'documentconversion', 'itemid' => 0, 'filepath' => "/" . $this->get('targetformat') . "/", 'filename' => $file->get_contenthash(), ]; }
[ "protected", "function", "get_file_record", "(", ")", "{", "$", "file", "=", "$", "this", "->", "get_sourcefile", "(", ")", ";", "if", "(", "!", "$", "file", ")", "{", "// If the source file was removed before we completed, we must return early.", "return", "false", ";", "}", "return", "[", "'contextid'", "=>", "\\", "context_system", "::", "instance", "(", ")", "->", "id", ",", "'component'", "=>", "'core'", ",", "'filearea'", "=>", "'documentconversion'", ",", "'itemid'", "=>", "0", ",", "'filepath'", "=>", "\"/\"", ".", "$", "this", "->", "get", "(", "'targetformat'", ")", ".", "\"/\"", ",", "'filename'", "=>", "$", "file", "->", "get_contenthash", "(", ")", ",", "]", ";", "}" ]
Return the file record base for use in the files table. @return array|bool
[ "Return", "the", "file", "record", "base", "for", "use", "in", "the", "files", "table", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/files/classes/conversion.php#L374-L390
214,871
moodle/moodle
mod/wiki/diff/difflib.php
ouwiki_line.get_as_strings
static function get_as_strings($lines) { $strings=array(); foreach($lines as $key=>$value) { $strings[$key]=$value->get_as_string(); } return $strings; }
php
static function get_as_strings($lines) { $strings=array(); foreach($lines as $key=>$value) { $strings[$key]=$value->get_as_string(); } return $strings; }
[ "static", "function", "get_as_strings", "(", "$", "lines", ")", "{", "$", "strings", "=", "array", "(", ")", ";", "foreach", "(", "$", "lines", "as", "$", "key", "=>", "$", "value", ")", "{", "$", "strings", "[", "$", "key", "]", "=", "$", "value", "->", "get_as_string", "(", ")", ";", "}", "return", "$", "strings", ";", "}" ]
Static function converts lines to strings. @param array $lines Array of ouwiki_line @return array Array of strings
[ "Static", "function", "converts", "lines", "to", "strings", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/wiki/diff/difflib.php#L353-L359
214,872
moodle/moodle
mod/assign/feedback/editpdf/classes/privacy/provider.php
provider.delete_feedback_for_grade
public static function delete_feedback_for_grade(assign_plugin_request_data $requestdata) { $requestdata->set_userids([$requestdata->get_user()->id]); $requestdata->populate_submissions_and_grades(); self::delete_feedback_for_grades($requestdata); }
php
public static function delete_feedback_for_grade(assign_plugin_request_data $requestdata) { $requestdata->set_userids([$requestdata->get_user()->id]); $requestdata->populate_submissions_and_grades(); self::delete_feedback_for_grades($requestdata); }
[ "public", "static", "function", "delete_feedback_for_grade", "(", "assign_plugin_request_data", "$", "requestdata", ")", "{", "$", "requestdata", "->", "set_userids", "(", "[", "$", "requestdata", "->", "get_user", "(", ")", "->", "id", "]", ")", ";", "$", "requestdata", "->", "populate_submissions_and_grades", "(", ")", ";", "self", "::", "delete_feedback_for_grades", "(", "$", "requestdata", ")", ";", "}" ]
Calling this function should delete all user data associated with this grade. @param assign_plugin_request_data $requestdata Data useful for deleting user data.
[ "Calling", "this", "function", "should", "delete", "all", "user", "data", "associated", "with", "this", "grade", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/assign/feedback/editpdf/classes/privacy/provider.php#L141-L145
214,873
moodle/moodle
lib/behat/classes/behat_selectors.php
behat_selectors.get_behat_selector
public static function get_behat_selector($selectortype, $element, Behat\Mink\Session $session) { // CSS and XPath selectors locator is one single argument. if ($selectortype == 'css_element' || $selectortype == 'xpath_element') { $selector = str_replace('_element', '', $selectortype); $locator = $element; } else { // Named selectors uses arrays as locators including the type of named selector. $allowedselectors = self::get_allowed_selectors(); if (!isset($allowedselectors[$selectortype])) { throw new ExpectationException('The "' . $selectortype . '" selector not registered.', $session); } $locator = array($allowedselectors[$selectortype], behat_context_helper::escape($element)); // Get the selector which should be used. $allowedpartialselectors = behat_partial_named_selector::get_allowed_selectors(); $allowedexactselectors = behat_exact_named_selector::get_allowed_selectors(); if (isset($allowedpartialselectors[$selectortype])) { $selector = 'named_partial'; } else if (isset($allowedexactselectors[$selectortype])) { $selector = 'named_exact'; } else { throw new ExpectationException('The "' . $selectortype . '" selector not registered.', $session); } } return array($selector, $locator); }
php
public static function get_behat_selector($selectortype, $element, Behat\Mink\Session $session) { // CSS and XPath selectors locator is one single argument. if ($selectortype == 'css_element' || $selectortype == 'xpath_element') { $selector = str_replace('_element', '', $selectortype); $locator = $element; } else { // Named selectors uses arrays as locators including the type of named selector. $allowedselectors = self::get_allowed_selectors(); if (!isset($allowedselectors[$selectortype])) { throw new ExpectationException('The "' . $selectortype . '" selector not registered.', $session); } $locator = array($allowedselectors[$selectortype], behat_context_helper::escape($element)); // Get the selector which should be used. $allowedpartialselectors = behat_partial_named_selector::get_allowed_selectors(); $allowedexactselectors = behat_exact_named_selector::get_allowed_selectors(); if (isset($allowedpartialselectors[$selectortype])) { $selector = 'named_partial'; } else if (isset($allowedexactselectors[$selectortype])) { $selector = 'named_exact'; } else { throw new ExpectationException('The "' . $selectortype . '" selector not registered.', $session); } } return array($selector, $locator); }
[ "public", "static", "function", "get_behat_selector", "(", "$", "selectortype", ",", "$", "element", ",", "Behat", "\\", "Mink", "\\", "Session", "$", "session", ")", "{", "// CSS and XPath selectors locator is one single argument.", "if", "(", "$", "selectortype", "==", "'css_element'", "||", "$", "selectortype", "==", "'xpath_element'", ")", "{", "$", "selector", "=", "str_replace", "(", "'_element'", ",", "''", ",", "$", "selectortype", ")", ";", "$", "locator", "=", "$", "element", ";", "}", "else", "{", "// Named selectors uses arrays as locators including the type of named selector.", "$", "allowedselectors", "=", "self", "::", "get_allowed_selectors", "(", ")", ";", "if", "(", "!", "isset", "(", "$", "allowedselectors", "[", "$", "selectortype", "]", ")", ")", "{", "throw", "new", "ExpectationException", "(", "'The \"'", ".", "$", "selectortype", ".", "'\" selector not registered.'", ",", "$", "session", ")", ";", "}", "$", "locator", "=", "array", "(", "$", "allowedselectors", "[", "$", "selectortype", "]", ",", "behat_context_helper", "::", "escape", "(", "$", "element", ")", ")", ";", "// Get the selector which should be used.", "$", "allowedpartialselectors", "=", "behat_partial_named_selector", "::", "get_allowed_selectors", "(", ")", ";", "$", "allowedexactselectors", "=", "behat_exact_named_selector", "::", "get_allowed_selectors", "(", ")", ";", "if", "(", "isset", "(", "$", "allowedpartialselectors", "[", "$", "selectortype", "]", ")", ")", "{", "$", "selector", "=", "'named_partial'", ";", "}", "else", "if", "(", "isset", "(", "$", "allowedexactselectors", "[", "$", "selectortype", "]", ")", ")", "{", "$", "selector", "=", "'named_exact'", ";", "}", "else", "{", "throw", "new", "ExpectationException", "(", "'The \"'", ".", "$", "selectortype", ".", "'\" selector not registered.'", ",", "$", "session", ")", ";", "}", "}", "return", "array", "(", "$", "selector", ",", "$", "locator", ")", ";", "}" ]
Returns the behat selector and locator for a given moodle selector and locator @param string $selectortype The moodle selector type, which includes moodle selectors @param string $element The locator we look for in that kind of selector @param Session $session The Mink opened session @return array Contains the selector and the locator expected by Mink.
[ "Returns", "the", "behat", "selector", "and", "locator", "for", "a", "given", "moodle", "selector", "and", "locator" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/behat/classes/behat_selectors.php#L49-L76
214,874
moodle/moodle
mod/workshop/allocation/random/lib.php
workshop_random_allocator.available_numofreviews_list
public static function available_numofreviews_list() { $options = array(); $options[30] = 30; $options[20] = 20; $options[15] = 15; for ($i = 10; $i >= 0; $i--) { $options[$i] = $i; } return $options; }
php
public static function available_numofreviews_list() { $options = array(); $options[30] = 30; $options[20] = 20; $options[15] = 15; for ($i = 10; $i >= 0; $i--) { $options[$i] = $i; } return $options; }
[ "public", "static", "function", "available_numofreviews_list", "(", ")", "{", "$", "options", "=", "array", "(", ")", ";", "$", "options", "[", "30", "]", "=", "30", ";", "$", "options", "[", "20", "]", "=", "20", ";", "$", "options", "[", "15", "]", "=", "15", ";", "for", "(", "$", "i", "=", "10", ";", "$", "i", ">=", "0", ";", "$", "i", "--", ")", "{", "$", "options", "[", "$", "i", "]", "=", "$", "i", ";", "}", "return", "$", "options", ";", "}" ]
Return an array of possible numbers of reviews to be done Should contain numbers 1, 2, 3, ... 10 and possibly others up to a reasonable value @return array of integers
[ "Return", "an", "array", "of", "possible", "numbers", "of", "reviews", "to", "be", "done" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/workshop/allocation/random/lib.php#L265-L274
214,875
moodle/moodle
mod/workshop/allocation/random/lib.php
workshop_random_allocator.self_allocation
protected function self_allocation($authors=array(), $reviewers=array(), $assessments=array()) { if (!isset($authors[0]) || !isset($reviewers[0])) { // no authors or no reviewers return array(); } $alreadyallocated = array(); foreach ($assessments as $assessment) { if ($assessment->authorid == $assessment->reviewerid) { $alreadyallocated[$assessment->authorid] = 1; } } $add = array(); // list of new allocations to be created foreach ($authors[0] as $authorid => $author) { // for all authors in all groups if (isset($reviewers[0][$authorid])) { // if the author can be reviewer if (!isset($alreadyallocated[$authorid])) { // and the allocation does not exist yet, then $add[] = array($authorid => $authorid); } } } return $add; }
php
protected function self_allocation($authors=array(), $reviewers=array(), $assessments=array()) { if (!isset($authors[0]) || !isset($reviewers[0])) { // no authors or no reviewers return array(); } $alreadyallocated = array(); foreach ($assessments as $assessment) { if ($assessment->authorid == $assessment->reviewerid) { $alreadyallocated[$assessment->authorid] = 1; } } $add = array(); // list of new allocations to be created foreach ($authors[0] as $authorid => $author) { // for all authors in all groups if (isset($reviewers[0][$authorid])) { // if the author can be reviewer if (!isset($alreadyallocated[$authorid])) { // and the allocation does not exist yet, then $add[] = array($authorid => $authorid); } } } return $add; }
[ "protected", "function", "self_allocation", "(", "$", "authors", "=", "array", "(", ")", ",", "$", "reviewers", "=", "array", "(", ")", ",", "$", "assessments", "=", "array", "(", ")", ")", "{", "if", "(", "!", "isset", "(", "$", "authors", "[", "0", "]", ")", "||", "!", "isset", "(", "$", "reviewers", "[", "0", "]", ")", ")", "{", "// no authors or no reviewers", "return", "array", "(", ")", ";", "}", "$", "alreadyallocated", "=", "array", "(", ")", ";", "foreach", "(", "$", "assessments", "as", "$", "assessment", ")", "{", "if", "(", "$", "assessment", "->", "authorid", "==", "$", "assessment", "->", "reviewerid", ")", "{", "$", "alreadyallocated", "[", "$", "assessment", "->", "authorid", "]", "=", "1", ";", "}", "}", "$", "add", "=", "array", "(", ")", ";", "// list of new allocations to be created", "foreach", "(", "$", "authors", "[", "0", "]", "as", "$", "authorid", "=>", "$", "author", ")", "{", "// for all authors in all groups", "if", "(", "isset", "(", "$", "reviewers", "[", "0", "]", "[", "$", "authorid", "]", ")", ")", "{", "// if the author can be reviewer", "if", "(", "!", "isset", "(", "$", "alreadyallocated", "[", "$", "authorid", "]", ")", ")", "{", "// and the allocation does not exist yet, then", "$", "add", "[", "]", "=", "array", "(", "$", "authorid", "=>", "$", "authorid", ")", ";", "}", "}", "}", "return", "$", "add", ";", "}" ]
Allocates submissions to their authors for review If the submission has already been allocated, it is skipped. If the author is not found among reviewers, the submission is not assigned. @param array $authors grouped of {@see workshop::get_potential_authors()} @param array $reviewers grouped by {@see workshop::get_potential_reviewers()} @param array $assessments as returned by {@see workshop::get_all_assessments()} @return array of new allocations to be created, array of array(reviewerid => authorid)
[ "Allocates", "submissions", "to", "their", "authors", "for", "review" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/workshop/allocation/random/lib.php#L287-L310
214,876
moodle/moodle
mod/workshop/allocation/random/lib.php
workshop_random_allocator.add_new_allocations
protected function add_new_allocations(array $newallocations, array $dataauthors, array $datareviewers) { global $DB; $newallocations = $this->get_unique_allocations($newallocations); $authorids = $this->get_author_ids($newallocations); $submissions = $this->workshop->get_submissions($authorids); $submissions = $this->index_submissions_by_authors($submissions); foreach ($newallocations as $newallocation) { $reviewerid = key($newallocation); $authorid = current($newallocation); if (!isset($submissions[$authorid])) { throw new moodle_exception('unabletoallocateauthorwithoutsubmission', 'workshop'); } $submission = $submissions[$authorid]; $status = $this->workshop->add_allocation($submission, $reviewerid, 1, true); // todo configurable weight? if (workshop::ALLOCATION_EXISTS == $status) { debugging('newallocations array contains existing allocation, this should not happen'); } } }
php
protected function add_new_allocations(array $newallocations, array $dataauthors, array $datareviewers) { global $DB; $newallocations = $this->get_unique_allocations($newallocations); $authorids = $this->get_author_ids($newallocations); $submissions = $this->workshop->get_submissions($authorids); $submissions = $this->index_submissions_by_authors($submissions); foreach ($newallocations as $newallocation) { $reviewerid = key($newallocation); $authorid = current($newallocation); if (!isset($submissions[$authorid])) { throw new moodle_exception('unabletoallocateauthorwithoutsubmission', 'workshop'); } $submission = $submissions[$authorid]; $status = $this->workshop->add_allocation($submission, $reviewerid, 1, true); // todo configurable weight? if (workshop::ALLOCATION_EXISTS == $status) { debugging('newallocations array contains existing allocation, this should not happen'); } } }
[ "protected", "function", "add_new_allocations", "(", "array", "$", "newallocations", ",", "array", "$", "dataauthors", ",", "array", "$", "datareviewers", ")", "{", "global", "$", "DB", ";", "$", "newallocations", "=", "$", "this", "->", "get_unique_allocations", "(", "$", "newallocations", ")", ";", "$", "authorids", "=", "$", "this", "->", "get_author_ids", "(", "$", "newallocations", ")", ";", "$", "submissions", "=", "$", "this", "->", "workshop", "->", "get_submissions", "(", "$", "authorids", ")", ";", "$", "submissions", "=", "$", "this", "->", "index_submissions_by_authors", "(", "$", "submissions", ")", ";", "foreach", "(", "$", "newallocations", "as", "$", "newallocation", ")", "{", "$", "reviewerid", "=", "key", "(", "$", "newallocation", ")", ";", "$", "authorid", "=", "current", "(", "$", "newallocation", ")", ";", "if", "(", "!", "isset", "(", "$", "submissions", "[", "$", "authorid", "]", ")", ")", "{", "throw", "new", "moodle_exception", "(", "'unabletoallocateauthorwithoutsubmission'", ",", "'workshop'", ")", ";", "}", "$", "submission", "=", "$", "submissions", "[", "$", "authorid", "]", ";", "$", "status", "=", "$", "this", "->", "workshop", "->", "add_allocation", "(", "$", "submission", ",", "$", "reviewerid", ",", "1", ",", "true", ")", ";", "// todo configurable weight?", "if", "(", "workshop", "::", "ALLOCATION_EXISTS", "==", "$", "status", ")", "{", "debugging", "(", "'newallocations array contains existing allocation, this should not happen'", ")", ";", "}", "}", "}" ]
Creates new assessment records @param array $newallocations pairs 'reviewerid' => 'authorid' @param array $dataauthors authors by group, group [0] contains all authors @param array $datareviewers reviewers by group, group [0] contains all reviewers @return bool
[ "Creates", "new", "assessment", "records" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/workshop/allocation/random/lib.php#L320-L339
214,877
moodle/moodle
mod/workshop/allocation/random/lib.php
workshop_random_allocator.index_submissions_by_authors
protected function index_submissions_by_authors($submissions) { $byauthor = array(); if (is_array($submissions)) { foreach ($submissions as $submissionid => $submission) { if (isset($byauthor[$submission->authorid])) { throw new moodle_exception('moresubmissionsbyauthor', 'workshop'); } $byauthor[$submission->authorid] = $submission; } } return $byauthor; }
php
protected function index_submissions_by_authors($submissions) { $byauthor = array(); if (is_array($submissions)) { foreach ($submissions as $submissionid => $submission) { if (isset($byauthor[$submission->authorid])) { throw new moodle_exception('moresubmissionsbyauthor', 'workshop'); } $byauthor[$submission->authorid] = $submission; } } return $byauthor; }
[ "protected", "function", "index_submissions_by_authors", "(", "$", "submissions", ")", "{", "$", "byauthor", "=", "array", "(", ")", ";", "if", "(", "is_array", "(", "$", "submissions", ")", ")", "{", "foreach", "(", "$", "submissions", "as", "$", "submissionid", "=>", "$", "submission", ")", "{", "if", "(", "isset", "(", "$", "byauthor", "[", "$", "submission", "->", "authorid", "]", ")", ")", "{", "throw", "new", "moodle_exception", "(", "'moresubmissionsbyauthor'", ",", "'workshop'", ")", ";", "}", "$", "byauthor", "[", "$", "submission", "->", "authorid", "]", "=", "$", "submission", ";", "}", "}", "return", "$", "byauthor", ";", "}" ]
Flips the structure of submission so it is indexed by authorid attribute It is the caller's responsibility to make sure the submissions are not teacher examples so no user is the author of more submissions. @param string $submissions array indexed by submission id @return array indexed by author id
[ "Flips", "the", "structure", "of", "submission", "so", "it", "is", "indexed", "by", "authorid", "attribute" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/workshop/allocation/random/lib.php#L350-L361
214,878
moodle/moodle
mod/workshop/allocation/random/lib.php
workshop_random_allocator.get_author_ids
protected function get_author_ids($newallocations) { $authors = array(); foreach ($newallocations as $newallocation) { $authorid = reset($newallocation); if (!in_array($authorid, $authors)) { $authors[] = $authorid; } } return $authors; }
php
protected function get_author_ids($newallocations) { $authors = array(); foreach ($newallocations as $newallocation) { $authorid = reset($newallocation); if (!in_array($authorid, $authors)) { $authors[] = $authorid; } } return $authors; }
[ "protected", "function", "get_author_ids", "(", "$", "newallocations", ")", "{", "$", "authors", "=", "array", "(", ")", ";", "foreach", "(", "$", "newallocations", "as", "$", "newallocation", ")", "{", "$", "authorid", "=", "reset", "(", "$", "newallocation", ")", ";", "if", "(", "!", "in_array", "(", "$", "authorid", ",", "$", "authors", ")", ")", "{", "$", "authors", "[", "]", "=", "$", "authorid", ";", "}", "}", "return", "$", "authors", ";", "}" ]
Extracts unique list of authors' IDs from the structure of new allocations @param array $newallocations of pairs 'reviewerid' => 'authorid' @return array of authorids
[ "Extracts", "unique", "list", "of", "authors", "IDs", "from", "the", "structure", "of", "new", "allocations" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/workshop/allocation/random/lib.php#L369-L378
214,879
moodle/moodle
mod/workshop/allocation/random/lib.php
workshop_random_allocator.get_unkept_assessments
protected function get_unkept_assessments($assessments, $newallocations, $keepselfassessments) { $keepids = array(); // keep these assessments foreach ($assessments as $assessmentid => $assessment) { $aaid = $assessment->authorid; $arid = $assessment->reviewerid; if (($keepselfassessments) && ($aaid == $arid)) { $keepids[$assessmentid] = null; continue; } foreach ($newallocations as $newallocation) { $nrid = key($newallocation); $naid = current($newallocation); if (array($arid, $aaid) == array($nrid, $naid)) { // re-allocation found - let us continue with the next assessment $keepids[$assessmentid] = null; continue 2; } } } return array_keys(array_diff_key($assessments, $keepids)); }
php
protected function get_unkept_assessments($assessments, $newallocations, $keepselfassessments) { $keepids = array(); // keep these assessments foreach ($assessments as $assessmentid => $assessment) { $aaid = $assessment->authorid; $arid = $assessment->reviewerid; if (($keepselfassessments) && ($aaid == $arid)) { $keepids[$assessmentid] = null; continue; } foreach ($newallocations as $newallocation) { $nrid = key($newallocation); $naid = current($newallocation); if (array($arid, $aaid) == array($nrid, $naid)) { // re-allocation found - let us continue with the next assessment $keepids[$assessmentid] = null; continue 2; } } } return array_keys(array_diff_key($assessments, $keepids)); }
[ "protected", "function", "get_unkept_assessments", "(", "$", "assessments", ",", "$", "newallocations", ",", "$", "keepselfassessments", ")", "{", "$", "keepids", "=", "array", "(", ")", ";", "// keep these assessments", "foreach", "(", "$", "assessments", "as", "$", "assessmentid", "=>", "$", "assessment", ")", "{", "$", "aaid", "=", "$", "assessment", "->", "authorid", ";", "$", "arid", "=", "$", "assessment", "->", "reviewerid", ";", "if", "(", "(", "$", "keepselfassessments", ")", "&&", "(", "$", "aaid", "==", "$", "arid", ")", ")", "{", "$", "keepids", "[", "$", "assessmentid", "]", "=", "null", ";", "continue", ";", "}", "foreach", "(", "$", "newallocations", "as", "$", "newallocation", ")", "{", "$", "nrid", "=", "key", "(", "$", "newallocation", ")", ";", "$", "naid", "=", "current", "(", "$", "newallocation", ")", ";", "if", "(", "array", "(", "$", "arid", ",", "$", "aaid", ")", "==", "array", "(", "$", "nrid", ",", "$", "naid", ")", ")", "{", "// re-allocation found - let us continue with the next assessment", "$", "keepids", "[", "$", "assessmentid", "]", "=", "null", ";", "continue", "2", ";", "}", "}", "}", "return", "array_keys", "(", "array_diff_key", "(", "$", "assessments", ",", "$", "keepids", ")", ")", ";", "}" ]
Returns the list of assessments to remove If user selects "removecurrentallocations", we should remove all current assessment records and insert new ones. But this would needlessly waste table ids. Instead, let us find only those assessments that have not been re-allocated in this run of allocation. So, the once-allocated submissions are kept with their original id. @param array $assessments list of current assessments @param mixed $newallocations array of 'reviewerid' => 'authorid' pairs @param bool $keepselfassessments do not remove already allocated self assessments @return array of assessments ids to be removed
[ "Returns", "the", "list", "of", "assessments", "to", "remove" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/workshop/allocation/random/lib.php#L403-L423
214,880
moodle/moodle
mod/workshop/allocation/random/lib.php
workshop_random_allocator.convert_assessments_to_links
protected function convert_assessments_to_links($assessments) { $authorlinks = array(); // [authorid] => array(reviewerid, reviewerid, ...) $reviewerlinks = array(); // [reviewerid] => array(authorid, authorid, ...) foreach ($assessments as $assessment) { if (!isset($authorlinks[$assessment->authorid])) { $authorlinks[$assessment->authorid] = array(); } if (!isset($reviewerlinks[$assessment->reviewerid])) { $reviewerlinks[$assessment->reviewerid] = array(); } $authorlinks[$assessment->authorid][] = $assessment->reviewerid; $reviewerlinks[$assessment->reviewerid][] = $assessment->authorid; } return array($authorlinks, $reviewerlinks); }
php
protected function convert_assessments_to_links($assessments) { $authorlinks = array(); // [authorid] => array(reviewerid, reviewerid, ...) $reviewerlinks = array(); // [reviewerid] => array(authorid, authorid, ...) foreach ($assessments as $assessment) { if (!isset($authorlinks[$assessment->authorid])) { $authorlinks[$assessment->authorid] = array(); } if (!isset($reviewerlinks[$assessment->reviewerid])) { $reviewerlinks[$assessment->reviewerid] = array(); } $authorlinks[$assessment->authorid][] = $assessment->reviewerid; $reviewerlinks[$assessment->reviewerid][] = $assessment->authorid; } return array($authorlinks, $reviewerlinks); }
[ "protected", "function", "convert_assessments_to_links", "(", "$", "assessments", ")", "{", "$", "authorlinks", "=", "array", "(", ")", ";", "// [authorid] => array(reviewerid, reviewerid, ...)", "$", "reviewerlinks", "=", "array", "(", ")", ";", "// [reviewerid] => array(authorid, authorid, ...)", "foreach", "(", "$", "assessments", "as", "$", "assessment", ")", "{", "if", "(", "!", "isset", "(", "$", "authorlinks", "[", "$", "assessment", "->", "authorid", "]", ")", ")", "{", "$", "authorlinks", "[", "$", "assessment", "->", "authorid", "]", "=", "array", "(", ")", ";", "}", "if", "(", "!", "isset", "(", "$", "reviewerlinks", "[", "$", "assessment", "->", "reviewerid", "]", ")", ")", "{", "$", "reviewerlinks", "[", "$", "assessment", "->", "reviewerid", "]", "=", "array", "(", ")", ";", "}", "$", "authorlinks", "[", "$", "assessment", "->", "authorid", "]", "[", "]", "=", "$", "assessment", "->", "reviewerid", ";", "$", "reviewerlinks", "[", "$", "assessment", "->", "reviewerid", "]", "[", "]", "=", "$", "assessment", "->", "authorid", ";", "}", "return", "array", "(", "$", "authorlinks", ",", "$", "reviewerlinks", ")", ";", "}" ]
Extracts the information about reviews from the authors' and reviewers' perspectives @param array $assessments array of assessments as returned by {@link workshop::get_all_assessments()} @return array of two arrays
[ "Extracts", "the", "information", "about", "reviews", "from", "the", "authors", "and", "reviewers", "perspectives" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/workshop/allocation/random/lib.php#L631-L645
214,881
moodle/moodle
mod/workshop/allocation/random/lib.php
workshop_random_allocator.get_element_with_lowest_workload
protected function get_element_with_lowest_workload($workload) { $precision = 10; if (empty($workload)) { return false; } $minload = round(min($workload), $precision); $minkeys = array(); foreach ($workload as $key => $val) { if (round($val, $precision) == $minload) { $minkeys[$key] = $val; } } return array_rand($minkeys); }
php
protected function get_element_with_lowest_workload($workload) { $precision = 10; if (empty($workload)) { return false; } $minload = round(min($workload), $precision); $minkeys = array(); foreach ($workload as $key => $val) { if (round($val, $precision) == $minload) { $minkeys[$key] = $val; } } return array_rand($minkeys); }
[ "protected", "function", "get_element_with_lowest_workload", "(", "$", "workload", ")", "{", "$", "precision", "=", "10", ";", "if", "(", "empty", "(", "$", "workload", ")", ")", "{", "return", "false", ";", "}", "$", "minload", "=", "round", "(", "min", "(", "$", "workload", ")", ",", "$", "precision", ")", ";", "$", "minkeys", "=", "array", "(", ")", ";", "foreach", "(", "$", "workload", "as", "$", "key", "=>", "$", "val", ")", "{", "if", "(", "round", "(", "$", "val", ",", "$", "precision", ")", "==", "$", "minload", ")", "{", "$", "minkeys", "[", "$", "key", "]", "=", "$", "val", ";", "}", "}", "return", "array_rand", "(", "$", "minkeys", ")", ";", "}" ]
Selects an element with the lowest workload If there are more elements with the same workload, choose one of them randomly. This may be used to select a group or user. @param array $workload [groupid] => (int)workload @return mixed int|bool id of the selected element or false if it is impossible to choose
[ "Selects", "an", "element", "with", "the", "lowest", "workload" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/workshop/allocation/random/lib.php#L656-L670
214,882
moodle/moodle
mod/workshop/allocation/random/lib.php
workshop_random_allocator.shuffle_assoc
protected function shuffle_assoc(&$array) { if (count($array) > 1) { // $keys needs to be an array, no need to shuffle 1 item or empty arrays, anyway $keys = array_keys($array); shuffle($keys); foreach($keys as $key) { $new[$key] = $array[$key]; } $array = $new; } return true; // because this behaves like in-built shuffle(), which returns true }
php
protected function shuffle_assoc(&$array) { if (count($array) > 1) { // $keys needs to be an array, no need to shuffle 1 item or empty arrays, anyway $keys = array_keys($array); shuffle($keys); foreach($keys as $key) { $new[$key] = $array[$key]; } $array = $new; } return true; // because this behaves like in-built shuffle(), which returns true }
[ "protected", "function", "shuffle_assoc", "(", "&", "$", "array", ")", "{", "if", "(", "count", "(", "$", "array", ")", ">", "1", ")", "{", "// $keys needs to be an array, no need to shuffle 1 item or empty arrays, anyway", "$", "keys", "=", "array_keys", "(", "$", "array", ")", ";", "shuffle", "(", "$", "keys", ")", ";", "foreach", "(", "$", "keys", "as", "$", "key", ")", "{", "$", "new", "[", "$", "key", "]", "=", "$", "array", "[", "$", "key", "]", ";", "}", "$", "array", "=", "$", "new", ";", "}", "return", "true", ";", "// because this behaves like in-built shuffle(), which returns true", "}" ]
Shuffle the order of array elements preserving the key=>values @param array $array to be shuffled @return true
[ "Shuffle", "the", "order", "of", "array", "elements", "preserving", "the", "key", "=", ">", "values" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/workshop/allocation/random/lib.php#L678-L689
214,883
moodle/moodle
mod/workshop/allocation/random/lib.php
workshop_random_allocator.filter_current_assessments
protected function filter_current_assessments(&$newallocations, $assessments) { foreach ($assessments as $assessment) { $allocation = array($assessment->reviewerid => $assessment->authorid); $foundat = array_keys($newallocations, $allocation); $newallocations = array_diff_key($newallocations, array_flip($foundat)); } }
php
protected function filter_current_assessments(&$newallocations, $assessments) { foreach ($assessments as $assessment) { $allocation = array($assessment->reviewerid => $assessment->authorid); $foundat = array_keys($newallocations, $allocation); $newallocations = array_diff_key($newallocations, array_flip($foundat)); } }
[ "protected", "function", "filter_current_assessments", "(", "&", "$", "newallocations", ",", "$", "assessments", ")", "{", "foreach", "(", "$", "assessments", "as", "$", "assessment", ")", "{", "$", "allocation", "=", "array", "(", "$", "assessment", "->", "reviewerid", "=>", "$", "assessment", "->", "authorid", ")", ";", "$", "foundat", "=", "array_keys", "(", "$", "newallocations", ",", "$", "allocation", ")", ";", "$", "newallocations", "=", "array_diff_key", "(", "$", "newallocations", ",", "array_flip", "(", "$", "foundat", ")", ")", ";", "}", "}" ]
Filter new allocations so that they do not contain an already existing assessment @param mixed $newallocations array of ('reviewerid' => 'authorid') tuples @param array $assessments array of assessment records @return void
[ "Filter", "new", "allocations", "so", "that", "they", "do", "not", "contain", "an", "already", "existing", "assessment" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/workshop/allocation/random/lib.php#L698-L704
214,884
moodle/moodle
mod/workshop/allocation/random/lib.php
workshop_random_allocator_setting.instance_from_object
public static function instance_from_object(stdClass $data) { $i = new self(); if (!isset($data->numofreviews)) { throw new coding_exception('Missing value of the numofreviews property'); } else { $i->numofreviews = (int)$data->numofreviews; } if (!isset($data->numper)) { throw new coding_exception('Missing value of the numper property'); } else { $i->numper = (int)$data->numper; if ($i->numper !== self::NUMPER_SUBMISSION and $i->numper !== self::NUMPER_REVIEWER) { throw new coding_exception('Invalid value of the numper property'); } } foreach (array('excludesamegroup', 'removecurrent', 'assesswosubmission', 'addselfassessment') as $k) { if (isset($data->$k)) { $i->$k = (bool)$data->$k; } else { $i->$k = false; } } return $i; }
php
public static function instance_from_object(stdClass $data) { $i = new self(); if (!isset($data->numofreviews)) { throw new coding_exception('Missing value of the numofreviews property'); } else { $i->numofreviews = (int)$data->numofreviews; } if (!isset($data->numper)) { throw new coding_exception('Missing value of the numper property'); } else { $i->numper = (int)$data->numper; if ($i->numper !== self::NUMPER_SUBMISSION and $i->numper !== self::NUMPER_REVIEWER) { throw new coding_exception('Invalid value of the numper property'); } } foreach (array('excludesamegroup', 'removecurrent', 'assesswosubmission', 'addselfassessment') as $k) { if (isset($data->$k)) { $i->$k = (bool)$data->$k; } else { $i->$k = false; } } return $i; }
[ "public", "static", "function", "instance_from_object", "(", "stdClass", "$", "data", ")", "{", "$", "i", "=", "new", "self", "(", ")", ";", "if", "(", "!", "isset", "(", "$", "data", "->", "numofreviews", ")", ")", "{", "throw", "new", "coding_exception", "(", "'Missing value of the numofreviews property'", ")", ";", "}", "else", "{", "$", "i", "->", "numofreviews", "=", "(", "int", ")", "$", "data", "->", "numofreviews", ";", "}", "if", "(", "!", "isset", "(", "$", "data", "->", "numper", ")", ")", "{", "throw", "new", "coding_exception", "(", "'Missing value of the numper property'", ")", ";", "}", "else", "{", "$", "i", "->", "numper", "=", "(", "int", ")", "$", "data", "->", "numper", ";", "if", "(", "$", "i", "->", "numper", "!==", "self", "::", "NUMPER_SUBMISSION", "and", "$", "i", "->", "numper", "!==", "self", "::", "NUMPER_REVIEWER", ")", "{", "throw", "new", "coding_exception", "(", "'Invalid value of the numper property'", ")", ";", "}", "}", "foreach", "(", "array", "(", "'excludesamegroup'", ",", "'removecurrent'", ",", "'assesswosubmission'", ",", "'addselfassessment'", ")", "as", "$", "k", ")", "{", "if", "(", "isset", "(", "$", "data", "->", "$", "k", ")", ")", "{", "$", "i", "->", "$", "k", "=", "(", "bool", ")", "$", "data", "->", "$", "k", ";", "}", "else", "{", "$", "i", "->", "$", "k", "=", "false", ";", "}", "}", "return", "$", "i", ";", "}" ]
Factory method making the instance from data in the passed object @param stdClass $data an object holding the values for our public properties @return workshop_random_allocator_setting
[ "Factory", "method", "making", "the", "instance", "from", "data", "in", "the", "passed", "object" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/workshop/allocation/random/lib.php#L743-L770
214,885
moodle/moodle
message/output/popup/classes/api.php
api.get_popup_notifications
public static function get_popup_notifications($useridto = 0, $sort = 'DESC', $limit = 0, $offset = 0) { global $DB, $USER; $sort = strtoupper($sort); if ($sort != 'DESC' && $sort != 'ASC') { throw new \moodle_exception('invalid parameter: sort: must be "DESC" or "ASC"'); } if (empty($useridto)) { $useridto = $USER->id; } // Is notification enabled ? if ($useridto == $USER->id) { $disabled = $USER->emailstop; } else { $user = \core_user::get_user($useridto, "emailstop", MUST_EXIST); $disabled = $user->emailstop; } if ($disabled) { // Notifications are disabled. return array(); } $sql = "SELECT n.id, n.useridfrom, n.useridto, n.subject, n.fullmessage, n.fullmessageformat, n.fullmessagehtml, n.smallmessage, n.contexturl, n.contexturlname, n.timecreated, n.component, n.eventtype, n.timeread, n.customdata FROM {notifications} n WHERE n.id IN (SELECT notificationid FROM {message_popup_notifications}) AND n.useridto = ? ORDER BY timecreated $sort, timeread $sort, id $sort"; $notifications = []; $records = $DB->get_recordset_sql($sql, [$useridto], $offset, $limit); foreach ($records as $record) { $notifications[] = (object) $record; } $records->close(); return $notifications; }
php
public static function get_popup_notifications($useridto = 0, $sort = 'DESC', $limit = 0, $offset = 0) { global $DB, $USER; $sort = strtoupper($sort); if ($sort != 'DESC' && $sort != 'ASC') { throw new \moodle_exception('invalid parameter: sort: must be "DESC" or "ASC"'); } if (empty($useridto)) { $useridto = $USER->id; } // Is notification enabled ? if ($useridto == $USER->id) { $disabled = $USER->emailstop; } else { $user = \core_user::get_user($useridto, "emailstop", MUST_EXIST); $disabled = $user->emailstop; } if ($disabled) { // Notifications are disabled. return array(); } $sql = "SELECT n.id, n.useridfrom, n.useridto, n.subject, n.fullmessage, n.fullmessageformat, n.fullmessagehtml, n.smallmessage, n.contexturl, n.contexturlname, n.timecreated, n.component, n.eventtype, n.timeread, n.customdata FROM {notifications} n WHERE n.id IN (SELECT notificationid FROM {message_popup_notifications}) AND n.useridto = ? ORDER BY timecreated $sort, timeread $sort, id $sort"; $notifications = []; $records = $DB->get_recordset_sql($sql, [$useridto], $offset, $limit); foreach ($records as $record) { $notifications[] = (object) $record; } $records->close(); return $notifications; }
[ "public", "static", "function", "get_popup_notifications", "(", "$", "useridto", "=", "0", ",", "$", "sort", "=", "'DESC'", ",", "$", "limit", "=", "0", ",", "$", "offset", "=", "0", ")", "{", "global", "$", "DB", ",", "$", "USER", ";", "$", "sort", "=", "strtoupper", "(", "$", "sort", ")", ";", "if", "(", "$", "sort", "!=", "'DESC'", "&&", "$", "sort", "!=", "'ASC'", ")", "{", "throw", "new", "\\", "moodle_exception", "(", "'invalid parameter: sort: must be \"DESC\" or \"ASC\"'", ")", ";", "}", "if", "(", "empty", "(", "$", "useridto", ")", ")", "{", "$", "useridto", "=", "$", "USER", "->", "id", ";", "}", "// Is notification enabled ?", "if", "(", "$", "useridto", "==", "$", "USER", "->", "id", ")", "{", "$", "disabled", "=", "$", "USER", "->", "emailstop", ";", "}", "else", "{", "$", "user", "=", "\\", "core_user", "::", "get_user", "(", "$", "useridto", ",", "\"emailstop\"", ",", "MUST_EXIST", ")", ";", "$", "disabled", "=", "$", "user", "->", "emailstop", ";", "}", "if", "(", "$", "disabled", ")", "{", "// Notifications are disabled.", "return", "array", "(", ")", ";", "}", "$", "sql", "=", "\"SELECT n.id, n.useridfrom, n.useridto,\n n.subject, n.fullmessage, n.fullmessageformat,\n n.fullmessagehtml, n.smallmessage, n.contexturl,\n n.contexturlname, n.timecreated, n.component,\n n.eventtype, n.timeread, n.customdata\n FROM {notifications} n\n WHERE n.id IN (SELECT notificationid FROM {message_popup_notifications})\n AND n.useridto = ?\n ORDER BY timecreated $sort, timeread $sort, id $sort\"", ";", "$", "notifications", "=", "[", "]", ";", "$", "records", "=", "$", "DB", "->", "get_recordset_sql", "(", "$", "sql", ",", "[", "$", "useridto", "]", ",", "$", "offset", ",", "$", "limit", ")", ";", "foreach", "(", "$", "records", "as", "$", "record", ")", "{", "$", "notifications", "[", "]", "=", "(", "object", ")", "$", "record", ";", "}", "$", "records", "->", "close", "(", ")", ";", "return", "$", "notifications", ";", "}" ]
Get popup notifications for the specified users. Nothing is returned if notifications are disabled. @param int $useridto the user id who received the notification @param string $sort the column name to order by including optionally direction @param int $limit limit the number of result returned @param int $offset offset the result set by this amount @return array notification records @throws \moodle_exception @since 3.2
[ "Get", "popup", "notifications", "for", "the", "specified", "users", ".", "Nothing", "is", "returned", "if", "notifications", "are", "disabled", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/message/output/popup/classes/api.php#L47-L89
214,886
moodle/moodle
message/output/popup/classes/api.php
api.count_unread_popup_notifications
public static function count_unread_popup_notifications($useridto = 0) { global $USER, $DB; if (empty($useridto)) { $useridto = $USER->id; } return $DB->count_records_sql( "SELECT count(id) FROM {notifications} WHERE id IN (SELECT notificationid FROM {message_popup_notifications}) AND useridto = ? AND timeread is NULL", [$useridto] ); }
php
public static function count_unread_popup_notifications($useridto = 0) { global $USER, $DB; if (empty($useridto)) { $useridto = $USER->id; } return $DB->count_records_sql( "SELECT count(id) FROM {notifications} WHERE id IN (SELECT notificationid FROM {message_popup_notifications}) AND useridto = ? AND timeread is NULL", [$useridto] ); }
[ "public", "static", "function", "count_unread_popup_notifications", "(", "$", "useridto", "=", "0", ")", "{", "global", "$", "USER", ",", "$", "DB", ";", "if", "(", "empty", "(", "$", "useridto", ")", ")", "{", "$", "useridto", "=", "$", "USER", "->", "id", ";", "}", "return", "$", "DB", "->", "count_records_sql", "(", "\"SELECT count(id)\n FROM {notifications}\n WHERE id IN (SELECT notificationid FROM {message_popup_notifications})\n AND useridto = ?\n AND timeread is NULL\"", ",", "[", "$", "useridto", "]", ")", ";", "}" ]
Count the unread notifications for a user. @param int $useridto the user id who received the notification @return int count of the unread notifications @since 3.2
[ "Count", "the", "unread", "notifications", "for", "a", "user", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/message/output/popup/classes/api.php#L98-L113
214,887
moodle/moodle
lib/mustache/src/Mustache/Parser.php
Mustache_Parser.parse
public function parse(array $tokens = array()) { $this->lineNum = -1; $this->lineTokens = 0; $this->pragmas = $this->defaultPragmas; $this->pragmaFilters = isset($this->pragmas[Mustache_Engine::PRAGMA_FILTERS]); $this->pragmaBlocks = isset($this->pragmas[Mustache_Engine::PRAGMA_BLOCKS]); return $this->buildTree($tokens); }
php
public function parse(array $tokens = array()) { $this->lineNum = -1; $this->lineTokens = 0; $this->pragmas = $this->defaultPragmas; $this->pragmaFilters = isset($this->pragmas[Mustache_Engine::PRAGMA_FILTERS]); $this->pragmaBlocks = isset($this->pragmas[Mustache_Engine::PRAGMA_BLOCKS]); return $this->buildTree($tokens); }
[ "public", "function", "parse", "(", "array", "$", "tokens", "=", "array", "(", ")", ")", "{", "$", "this", "->", "lineNum", "=", "-", "1", ";", "$", "this", "->", "lineTokens", "=", "0", ";", "$", "this", "->", "pragmas", "=", "$", "this", "->", "defaultPragmas", ";", "$", "this", "->", "pragmaFilters", "=", "isset", "(", "$", "this", "->", "pragmas", "[", "Mustache_Engine", "::", "PRAGMA_FILTERS", "]", ")", ";", "$", "this", "->", "pragmaBlocks", "=", "isset", "(", "$", "this", "->", "pragmas", "[", "Mustache_Engine", "::", "PRAGMA_BLOCKS", "]", ")", ";", "return", "$", "this", "->", "buildTree", "(", "$", "tokens", ")", ";", "}" ]
Process an array of Mustache tokens and convert them into a parse tree. @param array $tokens Set of Mustache tokens @return array Mustache token parse tree
[ "Process", "an", "array", "of", "Mustache", "tokens", "and", "convert", "them", "into", "a", "parse", "tree", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/mustache/src/Mustache/Parser.php#L34-L44
214,888
moodle/moodle
lib/mustache/src/Mustache/Parser.php
Mustache_Parser.clearStandaloneLines
private function clearStandaloneLines(array &$nodes, array &$tokens) { if ($this->lineTokens > 1) { // this is the third or later node on this line, so it can't be standalone return; } $prev = null; if ($this->lineTokens === 1) { // this is the second node on this line, so it can't be standalone // unless the previous node is whitespace. if ($prev = end($nodes)) { if (!$this->tokenIsWhitespace($prev)) { return; } } } if ($next = reset($tokens)) { // If we're on a new line, bail. if ($next[Mustache_Tokenizer::LINE] !== $this->lineNum) { return; } // If the next token isn't whitespace, bail. if (!$this->tokenIsWhitespace($next)) { return; } if (count($tokens) !== 1) { // Unless it's the last token in the template, the next token // must end in newline for this to be standalone. if (substr($next[Mustache_Tokenizer::VALUE], -1) !== "\n") { return; } } // Discard the whitespace suffix array_shift($tokens); } if ($prev) { // Return the whitespace prefix, if any return array_pop($nodes); } }
php
private function clearStandaloneLines(array &$nodes, array &$tokens) { if ($this->lineTokens > 1) { // this is the third or later node on this line, so it can't be standalone return; } $prev = null; if ($this->lineTokens === 1) { // this is the second node on this line, so it can't be standalone // unless the previous node is whitespace. if ($prev = end($nodes)) { if (!$this->tokenIsWhitespace($prev)) { return; } } } if ($next = reset($tokens)) { // If we're on a new line, bail. if ($next[Mustache_Tokenizer::LINE] !== $this->lineNum) { return; } // If the next token isn't whitespace, bail. if (!$this->tokenIsWhitespace($next)) { return; } if (count($tokens) !== 1) { // Unless it's the last token in the template, the next token // must end in newline for this to be standalone. if (substr($next[Mustache_Tokenizer::VALUE], -1) !== "\n") { return; } } // Discard the whitespace suffix array_shift($tokens); } if ($prev) { // Return the whitespace prefix, if any return array_pop($nodes); } }
[ "private", "function", "clearStandaloneLines", "(", "array", "&", "$", "nodes", ",", "array", "&", "$", "tokens", ")", "{", "if", "(", "$", "this", "->", "lineTokens", ">", "1", ")", "{", "// this is the third or later node on this line, so it can't be standalone", "return", ";", "}", "$", "prev", "=", "null", ";", "if", "(", "$", "this", "->", "lineTokens", "===", "1", ")", "{", "// this is the second node on this line, so it can't be standalone", "// unless the previous node is whitespace.", "if", "(", "$", "prev", "=", "end", "(", "$", "nodes", ")", ")", "{", "if", "(", "!", "$", "this", "->", "tokenIsWhitespace", "(", "$", "prev", ")", ")", "{", "return", ";", "}", "}", "}", "if", "(", "$", "next", "=", "reset", "(", "$", "tokens", ")", ")", "{", "// If we're on a new line, bail.", "if", "(", "$", "next", "[", "Mustache_Tokenizer", "::", "LINE", "]", "!==", "$", "this", "->", "lineNum", ")", "{", "return", ";", "}", "// If the next token isn't whitespace, bail.", "if", "(", "!", "$", "this", "->", "tokenIsWhitespace", "(", "$", "next", ")", ")", "{", "return", ";", "}", "if", "(", "count", "(", "$", "tokens", ")", "!==", "1", ")", "{", "// Unless it's the last token in the template, the next token", "// must end in newline for this to be standalone.", "if", "(", "substr", "(", "$", "next", "[", "Mustache_Tokenizer", "::", "VALUE", "]", ",", "-", "1", ")", "!==", "\"\\n\"", ")", "{", "return", ";", "}", "}", "// Discard the whitespace suffix", "array_shift", "(", "$", "tokens", ")", ";", "}", "if", "(", "$", "prev", ")", "{", "// Return the whitespace prefix, if any", "return", "array_pop", "(", "$", "nodes", ")", ";", "}", "}" ]
Clear standalone line tokens. Returns a whitespace token for indenting partials, if applicable. @param array $nodes Parsed nodes @param array $tokens Tokens to be parsed @return array|null Resulting indent token, if any
[ "Clear", "standalone", "line", "tokens", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/mustache/src/Mustache/Parser.php#L203-L248
214,889
moodle/moodle
lib/mustache/src/Mustache/Parser.php
Mustache_Parser.tokenIsWhitespace
private function tokenIsWhitespace(array $token) { if ($token[Mustache_Tokenizer::TYPE] === Mustache_Tokenizer::T_TEXT) { return preg_match('/^\s*$/', $token[Mustache_Tokenizer::VALUE]); } return false; }
php
private function tokenIsWhitespace(array $token) { if ($token[Mustache_Tokenizer::TYPE] === Mustache_Tokenizer::T_TEXT) { return preg_match('/^\s*$/', $token[Mustache_Tokenizer::VALUE]); } return false; }
[ "private", "function", "tokenIsWhitespace", "(", "array", "$", "token", ")", "{", "if", "(", "$", "token", "[", "Mustache_Tokenizer", "::", "TYPE", "]", "===", "Mustache_Tokenizer", "::", "T_TEXT", ")", "{", "return", "preg_match", "(", "'/^\\s*$/'", ",", "$", "token", "[", "Mustache_Tokenizer", "::", "VALUE", "]", ")", ";", "}", "return", "false", ";", "}" ]
Check whether token is a whitespace token. True if token type is T_TEXT and value is all whitespace characters. @param array $token @return bool True if token is a whitespace token
[ "Check", "whether", "token", "is", "a", "whitespace", "token", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/mustache/src/Mustache/Parser.php#L259-L266
214,890
moodle/moodle
lib/mustache/src/Mustache/Parser.php
Mustache_Parser.checkIfTokenIsAllowedInParent
private function checkIfTokenIsAllowedInParent($parent, array $token) { if ($parent[Mustache_Tokenizer::TYPE] === Mustache_Tokenizer::T_PARENT) { throw new Mustache_Exception_SyntaxException('Illegal content in < parent tag', $token); } }
php
private function checkIfTokenIsAllowedInParent($parent, array $token) { if ($parent[Mustache_Tokenizer::TYPE] === Mustache_Tokenizer::T_PARENT) { throw new Mustache_Exception_SyntaxException('Illegal content in < parent tag', $token); } }
[ "private", "function", "checkIfTokenIsAllowedInParent", "(", "$", "parent", ",", "array", "$", "token", ")", "{", "if", "(", "$", "parent", "[", "Mustache_Tokenizer", "::", "TYPE", "]", "===", "Mustache_Tokenizer", "::", "T_PARENT", ")", "{", "throw", "new", "Mustache_Exception_SyntaxException", "(", "'Illegal content in < parent tag'", ",", "$", "token", ")", ";", "}", "}" ]
Check whether a token is allowed inside a parent tag. @throws Mustache_Exception_SyntaxException if an invalid token is found inside a parent tag @param array|null $parent @param array $token
[ "Check", "whether", "a", "token", "is", "allowed", "inside", "a", "parent", "tag", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/mustache/src/Mustache/Parser.php#L276-L281
214,891
moodle/moodle
lib/mustache/src/Mustache/Parser.php
Mustache_Parser.getNameAndFilters
private function getNameAndFilters($name) { $filters = array_map('trim', explode('|', $name)); $name = array_shift($filters); return array($name, $filters); }
php
private function getNameAndFilters($name) { $filters = array_map('trim', explode('|', $name)); $name = array_shift($filters); return array($name, $filters); }
[ "private", "function", "getNameAndFilters", "(", "$", "name", ")", "{", "$", "filters", "=", "array_map", "(", "'trim'", ",", "explode", "(", "'|'", ",", "$", "name", ")", ")", ";", "$", "name", "=", "array_shift", "(", "$", "filters", ")", ";", "return", "array", "(", "$", "name", ",", "$", "filters", ")", ";", "}" ]
Split a tag name into name and filters. @param string $name @return array [Tag name, Array of filters]
[ "Split", "a", "tag", "name", "into", "name", "and", "filters", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/mustache/src/Mustache/Parser.php#L290-L296
214,892
moodle/moodle
lib/mustache/src/Mustache/Parser.php
Mustache_Parser.enablePragma
private function enablePragma($name) { $this->pragmas[$name] = true; switch ($name) { case Mustache_Engine::PRAGMA_BLOCKS: $this->pragmaBlocks = true; break; case Mustache_Engine::PRAGMA_FILTERS: $this->pragmaFilters = true; break; } }
php
private function enablePragma($name) { $this->pragmas[$name] = true; switch ($name) { case Mustache_Engine::PRAGMA_BLOCKS: $this->pragmaBlocks = true; break; case Mustache_Engine::PRAGMA_FILTERS: $this->pragmaFilters = true; break; } }
[ "private", "function", "enablePragma", "(", "$", "name", ")", "{", "$", "this", "->", "pragmas", "[", "$", "name", "]", "=", "true", ";", "switch", "(", "$", "name", ")", "{", "case", "Mustache_Engine", "::", "PRAGMA_BLOCKS", ":", "$", "this", "->", "pragmaBlocks", "=", "true", ";", "break", ";", "case", "Mustache_Engine", "::", "PRAGMA_FILTERS", ":", "$", "this", "->", "pragmaFilters", "=", "true", ";", "break", ";", "}", "}" ]
Enable a pragma. @param string $name
[ "Enable", "a", "pragma", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/mustache/src/Mustache/Parser.php#L303-L316
214,893
moodle/moodle
lib/ltiprovider/src/ToolProvider/Service/ToolSettings.php
ToolSettings.get
public function get($mode = self::MODE_CURRENT_LEVEL) { $parameter = array(); if ($mode === self::MODE_ALL_LEVELS) { $parameter['bubble'] = 'all'; } else if ($mode === self::MODE_DISTINCT_NAMES) { $parameter['bubble'] = 'distinct'; } $http = $this->send('GET', $parameter); if (!$http->ok) { $response = false; } else if ($this->simple) { $response = json_decode($http->response, true); } else if (isset($http->responseJson->{'@graph'})) { $response = array(); foreach ($http->responseJson->{'@graph'} as $level) { $settings = json_decode(json_encode($level->custom), true); unset($settings['@id']); $response[self::$LEVEL_NAMES[$level->{'@type'}]] = $settings; } } return $response; }
php
public function get($mode = self::MODE_CURRENT_LEVEL) { $parameter = array(); if ($mode === self::MODE_ALL_LEVELS) { $parameter['bubble'] = 'all'; } else if ($mode === self::MODE_DISTINCT_NAMES) { $parameter['bubble'] = 'distinct'; } $http = $this->send('GET', $parameter); if (!$http->ok) { $response = false; } else if ($this->simple) { $response = json_decode($http->response, true); } else if (isset($http->responseJson->{'@graph'})) { $response = array(); foreach ($http->responseJson->{'@graph'} as $level) { $settings = json_decode(json_encode($level->custom), true); unset($settings['@id']); $response[self::$LEVEL_NAMES[$level->{'@type'}]] = $settings; } } return $response; }
[ "public", "function", "get", "(", "$", "mode", "=", "self", "::", "MODE_CURRENT_LEVEL", ")", "{", "$", "parameter", "=", "array", "(", ")", ";", "if", "(", "$", "mode", "===", "self", "::", "MODE_ALL_LEVELS", ")", "{", "$", "parameter", "[", "'bubble'", "]", "=", "'all'", ";", "}", "else", "if", "(", "$", "mode", "===", "self", "::", "MODE_DISTINCT_NAMES", ")", "{", "$", "parameter", "[", "'bubble'", "]", "=", "'distinct'", ";", "}", "$", "http", "=", "$", "this", "->", "send", "(", "'GET'", ",", "$", "parameter", ")", ";", "if", "(", "!", "$", "http", "->", "ok", ")", "{", "$", "response", "=", "false", ";", "}", "else", "if", "(", "$", "this", "->", "simple", ")", "{", "$", "response", "=", "json_decode", "(", "$", "http", "->", "response", ",", "true", ")", ";", "}", "else", "if", "(", "isset", "(", "$", "http", "->", "responseJson", "->", "{", "'@graph'", "}", ")", ")", "{", "$", "response", "=", "array", "(", ")", ";", "foreach", "(", "$", "http", "->", "responseJson", "->", "{", "'@graph'", "}", "as", "$", "level", ")", "{", "$", "settings", "=", "json_decode", "(", "json_encode", "(", "$", "level", "->", "custom", ")", ",", "true", ")", ";", "unset", "(", "$", "settings", "[", "'@id'", "]", ")", ";", "$", "response", "[", "self", "::", "$", "LEVEL_NAMES", "[", "$", "level", "->", "{", "'@type'", "}", "]", "]", "=", "$", "settings", ";", "}", "}", "return", "$", "response", ";", "}" ]
Get the tool settings. @param int $mode Mode for request (optional, default is current level only) @return mixed The array of settings if successful, otherwise false
[ "Get", "the", "tool", "settings", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/ltiprovider/src/ToolProvider/Service/ToolSettings.php#L85-L109
214,894
moodle/moodle
lib/ltiprovider/src/ToolProvider/Service/ToolSettings.php
ToolSettings.set
public function set($settings) { if (!$this->simple) { if (is_a($this->source, 'ToolConsumer')) { $type = 'ToolProxy'; } else if (is_a($this->source, 'ToolConsumer')) { $type = 'ToolProxyBinding'; } else { $type = 'LtiLink'; } $obj = new \stdClass(); $obj->{'@context'} = 'http://purl.imsglobal.org/ctx/lti/v2/ToolSettings'; $obj->{'@graph'} = array(); $level = new \stdClass(); $level->{'@type'} = $type; $level->{'@id'} = $this->endpoint; $level->{'custom'} = $settings; $obj->{'@graph'}[] = $level; $body = json_encode($obj); } else { $body = json_encode($settings); } $response = parent::send('PUT', null, $body); return $response->ok; }
php
public function set($settings) { if (!$this->simple) { if (is_a($this->source, 'ToolConsumer')) { $type = 'ToolProxy'; } else if (is_a($this->source, 'ToolConsumer')) { $type = 'ToolProxyBinding'; } else { $type = 'LtiLink'; } $obj = new \stdClass(); $obj->{'@context'} = 'http://purl.imsglobal.org/ctx/lti/v2/ToolSettings'; $obj->{'@graph'} = array(); $level = new \stdClass(); $level->{'@type'} = $type; $level->{'@id'} = $this->endpoint; $level->{'custom'} = $settings; $obj->{'@graph'}[] = $level; $body = json_encode($obj); } else { $body = json_encode($settings); } $response = parent::send('PUT', null, $body); return $response->ok; }
[ "public", "function", "set", "(", "$", "settings", ")", "{", "if", "(", "!", "$", "this", "->", "simple", ")", "{", "if", "(", "is_a", "(", "$", "this", "->", "source", ",", "'ToolConsumer'", ")", ")", "{", "$", "type", "=", "'ToolProxy'", ";", "}", "else", "if", "(", "is_a", "(", "$", "this", "->", "source", ",", "'ToolConsumer'", ")", ")", "{", "$", "type", "=", "'ToolProxyBinding'", ";", "}", "else", "{", "$", "type", "=", "'LtiLink'", ";", "}", "$", "obj", "=", "new", "\\", "stdClass", "(", ")", ";", "$", "obj", "->", "{", "'@context'", "}", "=", "'http://purl.imsglobal.org/ctx/lti/v2/ToolSettings'", ";", "$", "obj", "->", "{", "'@graph'", "}", "=", "array", "(", ")", ";", "$", "level", "=", "new", "\\", "stdClass", "(", ")", ";", "$", "level", "->", "{", "'@type'", "}", "=", "$", "type", ";", "$", "level", "->", "{", "'@id'", "}", "=", "$", "this", "->", "endpoint", ";", "$", "level", "->", "{", "'custom'", "}", "=", "$", "settings", ";", "$", "obj", "->", "{", "'@graph'", "}", "[", "]", "=", "$", "level", ";", "$", "body", "=", "json_encode", "(", "$", "obj", ")", ";", "}", "else", "{", "$", "body", "=", "json_encode", "(", "$", "settings", ")", ";", "}", "$", "response", "=", "parent", "::", "send", "(", "'PUT'", ",", "null", ",", "$", "body", ")", ";", "return", "$", "response", "->", "ok", ";", "}" ]
Set the tool settings. @param array $settings An associative array of settings (optional, default is null) @return HTTPMessage HTTP object containing request and response details
[ "Set", "the", "tool", "settings", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/ltiprovider/src/ToolProvider/Service/ToolSettings.php#L118-L145
214,895
moodle/moodle
mod/forum/classes/local/factories/manager.php
manager.get_capability_manager
public function get_capability_manager(forum_entity $forum) { return new capability_manager( $forum, $this->legacydatamapperfactory->get_forum_data_mapper(), $this->legacydatamapperfactory->get_discussion_data_mapper(), $this->legacydatamapperfactory->get_post_data_mapper() ); }
php
public function get_capability_manager(forum_entity $forum) { return new capability_manager( $forum, $this->legacydatamapperfactory->get_forum_data_mapper(), $this->legacydatamapperfactory->get_discussion_data_mapper(), $this->legacydatamapperfactory->get_post_data_mapper() ); }
[ "public", "function", "get_capability_manager", "(", "forum_entity", "$", "forum", ")", "{", "return", "new", "capability_manager", "(", "$", "forum", ",", "$", "this", "->", "legacydatamapperfactory", "->", "get_forum_data_mapper", "(", ")", ",", "$", "this", "->", "legacydatamapperfactory", "->", "get_discussion_data_mapper", "(", ")", ",", "$", "this", "->", "legacydatamapperfactory", "->", "get_post_data_mapper", "(", ")", ")", ";", "}" ]
Create a capability manager for the given forum. @param forum_entity $forum The forum to manage capabilities for @return capability_manager
[ "Create", "a", "capability", "manager", "for", "the", "given", "forum", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/forum/classes/local/factories/manager.php#L64-L71
214,896
moodle/moodle
auth/ldap/classes/task/sync_roles.php
sync_roles.execute
public function execute() { global $DB; if (is_enabled_auth('ldap')) { $auth = get_auth_plugin('ldap'); $users = $DB->get_records('user', array('auth' => 'ldap')); foreach ($users as $user) { $auth->sync_roles($user); } } }
php
public function execute() { global $DB; if (is_enabled_auth('ldap')) { $auth = get_auth_plugin('ldap'); $users = $DB->get_records('user', array('auth' => 'ldap')); foreach ($users as $user) { $auth->sync_roles($user); } } }
[ "public", "function", "execute", "(", ")", "{", "global", "$", "DB", ";", "if", "(", "is_enabled_auth", "(", "'ldap'", ")", ")", "{", "$", "auth", "=", "get_auth_plugin", "(", "'ldap'", ")", ";", "$", "users", "=", "$", "DB", "->", "get_records", "(", "'user'", ",", "array", "(", "'auth'", "=>", "'ldap'", ")", ")", ";", "foreach", "(", "$", "users", "as", "$", "user", ")", "{", "$", "auth", "->", "sync_roles", "(", "$", "user", ")", ";", "}", "}", "}" ]
Synchronise role assignments from LDAP.
[ "Synchronise", "role", "assignments", "from", "LDAP", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/auth/ldap/classes/task/sync_roles.php#L50-L59
214,897
moodle/moodle
lib/horde/framework/Horde/Secret.php
Horde_Secret.write
public function write($key, $message) { $message = strval($message); return (strlen($key) && strlen($message)) ? $this->_getCipherOb($key)->encrypt($message) : ''; }
php
public function write($key, $message) { $message = strval($message); return (strlen($key) && strlen($message)) ? $this->_getCipherOb($key)->encrypt($message) : ''; }
[ "public", "function", "write", "(", "$", "key", ",", "$", "message", ")", "{", "$", "message", "=", "strval", "(", "$", "message", ")", ";", "return", "(", "strlen", "(", "$", "key", ")", "&&", "strlen", "(", "$", "message", ")", ")", "?", "$", "this", "->", "_getCipherOb", "(", "$", "key", ")", "->", "encrypt", "(", "$", "message", ")", ":", "''", ";", "}" ]
Take a small piece of data and encrypt it with a key. @param string $key The key to use for encryption. @param string $message The plaintext message. @return string The ciphertext message. @throws Horde_Secret_Exception
[ "Take", "a", "small", "piece", "of", "data", "and", "encrypt", "it", "with", "a", "key", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/horde/framework/Horde/Secret.php#L71-L77
214,898
moodle/moodle
lib/horde/framework/Horde/Secret.php
Horde_Secret._getCipherOb
protected function _getCipherOb($key) { if (!is_string($key)) { throw new Horde_Secret_Exception('Key must be a string', Horde_Secret_Exception::KEY_NOT_STRING); } if (!strlen($key)) { throw new Horde_Secret_Exception('Key must be non-zero.', Horde_Secret_Exception::KEY_ZERO_LENGTH); } $key = substr($key, 0, 56); $idx = hash('md5', $key); if (!isset($this->_cipherCache[$idx])) { $this->_cipherCache[$idx] = new Horde_Crypt_Blowfish($key); } return $this->_cipherCache[$idx]; }
php
protected function _getCipherOb($key) { if (!is_string($key)) { throw new Horde_Secret_Exception('Key must be a string', Horde_Secret_Exception::KEY_NOT_STRING); } if (!strlen($key)) { throw new Horde_Secret_Exception('Key must be non-zero.', Horde_Secret_Exception::KEY_ZERO_LENGTH); } $key = substr($key, 0, 56); $idx = hash('md5', $key); if (!isset($this->_cipherCache[$idx])) { $this->_cipherCache[$idx] = new Horde_Crypt_Blowfish($key); } return $this->_cipherCache[$idx]; }
[ "protected", "function", "_getCipherOb", "(", "$", "key", ")", "{", "if", "(", "!", "is_string", "(", "$", "key", ")", ")", "{", "throw", "new", "Horde_Secret_Exception", "(", "'Key must be a string'", ",", "Horde_Secret_Exception", "::", "KEY_NOT_STRING", ")", ";", "}", "if", "(", "!", "strlen", "(", "$", "key", ")", ")", "{", "throw", "new", "Horde_Secret_Exception", "(", "'Key must be non-zero.'", ",", "Horde_Secret_Exception", "::", "KEY_ZERO_LENGTH", ")", ";", "}", "$", "key", "=", "substr", "(", "$", "key", ",", "0", ",", "56", ")", ";", "$", "idx", "=", "hash", "(", "'md5'", ",", "$", "key", ")", ";", "if", "(", "!", "isset", "(", "$", "this", "->", "_cipherCache", "[", "$", "idx", "]", ")", ")", "{", "$", "this", "->", "_cipherCache", "[", "$", "idx", "]", "=", "new", "Horde_Crypt_Blowfish", "(", "$", "key", ")", ";", "}", "return", "$", "this", "->", "_cipherCache", "[", "$", "idx", "]", ";", "}" ]
Returns the cached crypt object. @param string $key The key to use for [de|en]cryption. Only the first 56 bytes of this string is used. @return Horde_Crypt_Blowfish The crypt object. @throws Horde_Secret_Exception
[ "Returns", "the", "cached", "crypt", "object", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/horde/framework/Horde/Secret.php#L105-L123
214,899
moodle/moodle
lib/horde/framework/Horde/Secret.php
Horde_Secret.getKey
public function getKey($keyname = self::DEFAULT_KEY) { if (!isset($this->_keyCache[$keyname])) { if (isset($_COOKIE[$keyname . '_key'])) { $key = $_COOKIE[$keyname . '_key']; } else { $key = session_id(); $this->_setCookie($keyname, $key); } $this->_keyCache[$keyname] = $key; } return $this->_keyCache[$keyname]; }
php
public function getKey($keyname = self::DEFAULT_KEY) { if (!isset($this->_keyCache[$keyname])) { if (isset($_COOKIE[$keyname . '_key'])) { $key = $_COOKIE[$keyname . '_key']; } else { $key = session_id(); $this->_setCookie($keyname, $key); } $this->_keyCache[$keyname] = $key; } return $this->_keyCache[$keyname]; }
[ "public", "function", "getKey", "(", "$", "keyname", "=", "self", "::", "DEFAULT_KEY", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "_keyCache", "[", "$", "keyname", "]", ")", ")", "{", "if", "(", "isset", "(", "$", "_COOKIE", "[", "$", "keyname", ".", "'_key'", "]", ")", ")", "{", "$", "key", "=", "$", "_COOKIE", "[", "$", "keyname", ".", "'_key'", "]", ";", "}", "else", "{", "$", "key", "=", "session_id", "(", ")", ";", "$", "this", "->", "_setCookie", "(", "$", "keyname", ",", "$", "key", ")", ";", "}", "$", "this", "->", "_keyCache", "[", "$", "keyname", "]", "=", "$", "key", ";", "}", "return", "$", "this", "->", "_keyCache", "[", "$", "keyname", "]", ";", "}" ]
Return a secret key, either from a cookie, or if the cookie isn't there, assume we are using a munged version of a known base value. @param string $keyname The name of the key to get. @return string The secret key.
[ "Return", "a", "secret", "key", "either", "from", "a", "cookie", "or", "if", "the", "cookie", "isn", "t", "there", "assume", "we", "are", "using", "a", "munged", "version", "of", "a", "known", "base", "value", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/horde/framework/Horde/Secret.php#L165-L179