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,500
moodle/moodle
mod/lesson/locallib.php
lesson.get_courserecord
public function get_courserecord() { global $DB; if ($this->courserecord == null) { $this->courserecord = $DB->get_record('course', array('id' => $this->properties->course)); } return $this->courserecord; }
php
public function get_courserecord() { global $DB; if ($this->courserecord == null) { $this->courserecord = $DB->get_record('course', array('id' => $this->properties->course)); } return $this->courserecord; }
[ "public", "function", "get_courserecord", "(", ")", "{", "global", "$", "DB", ";", "if", "(", "$", "this", "->", "courserecord", "==", "null", ")", "{", "$", "this", "->", "courserecord", "=", "$", "DB", "->", "get_record", "(", "'course'", ",", "array", "(", "'id'", "=>", "$", "this", "->", "properties", "->", "course", ")", ")", ";", "}", "return", "$", "this", "->", "courserecord", ";", "}" ]
Return the lesson course object. @return stdClass course @since Moodle 3.3
[ "Return", "the", "lesson", "course", "object", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/lesson/locallib.php#L2775-L2782
214,501
moodle/moodle
mod/lesson/locallib.php
lesson.get_time_restriction_status
public function get_time_restriction_status() { if ($this->can_manage()) { return false; } if (!$this->is_accessible()) { if ($this->properties->deadline != 0 && time() > $this->properties->deadline) { $status = ['reason' => 'lessonclosed', 'time' => $this->properties->deadline]; } else { $status = ['reason' => 'lessonopen', 'time' => $this->properties->available]; } return (object) $status; } return false; }
php
public function get_time_restriction_status() { if ($this->can_manage()) { return false; } if (!$this->is_accessible()) { if ($this->properties->deadline != 0 && time() > $this->properties->deadline) { $status = ['reason' => 'lessonclosed', 'time' => $this->properties->deadline]; } else { $status = ['reason' => 'lessonopen', 'time' => $this->properties->available]; } return (object) $status; } return false; }
[ "public", "function", "get_time_restriction_status", "(", ")", "{", "if", "(", "$", "this", "->", "can_manage", "(", ")", ")", "{", "return", "false", ";", "}", "if", "(", "!", "$", "this", "->", "is_accessible", "(", ")", ")", "{", "if", "(", "$", "this", "->", "properties", "->", "deadline", "!=", "0", "&&", "time", "(", ")", ">", "$", "this", "->", "properties", "->", "deadline", ")", "{", "$", "status", "=", "[", "'reason'", "=>", "'lessonclosed'", ",", "'time'", "=>", "$", "this", "->", "properties", "->", "deadline", "]", ";", "}", "else", "{", "$", "status", "=", "[", "'reason'", "=>", "'lessonopen'", ",", "'time'", "=>", "$", "this", "->", "properties", "->", "available", "]", ";", "}", "return", "(", "object", ")", "$", "status", ";", "}", "return", "false", ";", "}" ]
Check if time restriction is applied. @return mixed false if there aren't restrictions or an object with the restriction information @since Moodle 3.3
[ "Check", "if", "time", "restriction", "is", "applied", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/lesson/locallib.php#L2800-L2814
214,502
moodle/moodle
mod/lesson/locallib.php
lesson.get_password_restriction_status
public function get_password_restriction_status($userpassword) { global $USER; if ($this->can_manage()) { return false; } if ($this->properties->usepassword && empty($USER->lessonloggedin[$this->id])) { $correctpass = false; if (!empty($userpassword) && (($this->properties->password == md5(trim($userpassword))) || ($this->properties->password == trim($userpassword)))) { // With or without md5 for backward compatibility (MDL-11090). $correctpass = true; $USER->lessonloggedin[$this->id] = true; } else if (isset($this->properties->extrapasswords)) { // Group overrides may have additional passwords. foreach ($this->properties->extrapasswords as $password) { if (strcmp($password, md5(trim($userpassword))) === 0 || strcmp($password, trim($userpassword)) === 0) { $correctpass = true; $USER->lessonloggedin[$this->id] = true; } } } return !$correctpass; } return false; }
php
public function get_password_restriction_status($userpassword) { global $USER; if ($this->can_manage()) { return false; } if ($this->properties->usepassword && empty($USER->lessonloggedin[$this->id])) { $correctpass = false; if (!empty($userpassword) && (($this->properties->password == md5(trim($userpassword))) || ($this->properties->password == trim($userpassword)))) { // With or without md5 for backward compatibility (MDL-11090). $correctpass = true; $USER->lessonloggedin[$this->id] = true; } else if (isset($this->properties->extrapasswords)) { // Group overrides may have additional passwords. foreach ($this->properties->extrapasswords as $password) { if (strcmp($password, md5(trim($userpassword))) === 0 || strcmp($password, trim($userpassword)) === 0) { $correctpass = true; $USER->lessonloggedin[$this->id] = true; } } } return !$correctpass; } return false; }
[ "public", "function", "get_password_restriction_status", "(", "$", "userpassword", ")", "{", "global", "$", "USER", ";", "if", "(", "$", "this", "->", "can_manage", "(", ")", ")", "{", "return", "false", ";", "}", "if", "(", "$", "this", "->", "properties", "->", "usepassword", "&&", "empty", "(", "$", "USER", "->", "lessonloggedin", "[", "$", "this", "->", "id", "]", ")", ")", "{", "$", "correctpass", "=", "false", ";", "if", "(", "!", "empty", "(", "$", "userpassword", ")", "&&", "(", "(", "$", "this", "->", "properties", "->", "password", "==", "md5", "(", "trim", "(", "$", "userpassword", ")", ")", ")", "||", "(", "$", "this", "->", "properties", "->", "password", "==", "trim", "(", "$", "userpassword", ")", ")", ")", ")", "{", "// With or without md5 for backward compatibility (MDL-11090).", "$", "correctpass", "=", "true", ";", "$", "USER", "->", "lessonloggedin", "[", "$", "this", "->", "id", "]", "=", "true", ";", "}", "else", "if", "(", "isset", "(", "$", "this", "->", "properties", "->", "extrapasswords", ")", ")", "{", "// Group overrides may have additional passwords.", "foreach", "(", "$", "this", "->", "properties", "->", "extrapasswords", "as", "$", "password", ")", "{", "if", "(", "strcmp", "(", "$", "password", ",", "md5", "(", "trim", "(", "$", "userpassword", ")", ")", ")", "===", "0", "||", "strcmp", "(", "$", "password", ",", "trim", "(", "$", "userpassword", ")", ")", "===", "0", ")", "{", "$", "correctpass", "=", "true", ";", "$", "USER", "->", "lessonloggedin", "[", "$", "this", "->", "id", "]", "=", "true", ";", "}", "}", "}", "return", "!", "$", "correctpass", ";", "}", "return", "false", ";", "}" ]
Check if password restriction is applied. @param string $userpassword the user password to check (if the restriction is set) @return mixed false if there aren't restrictions or an object with the restriction information @since Moodle 3.3
[ "Check", "if", "password", "restriction", "is", "applied", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/lesson/locallib.php#L2823-L2848
214,503
moodle/moodle
mod/lesson/locallib.php
lesson.get_dependencies_restriction_status
public function get_dependencies_restriction_status() { global $DB, $USER; if ($this->can_manage()) { return false; } if ($dependentlesson = $DB->get_record('lesson', array('id' => $this->properties->dependency))) { // Lesson exists, so we can proceed. $conditions = unserialize($this->properties->conditions); // Assume false for all. $errors = array(); // Check for the timespent condition. if ($conditions->timespent) { $timespent = false; if ($attempttimes = $DB->get_records('lesson_timer', array("userid" => $USER->id, "lessonid" => $dependentlesson->id))) { // Go through all the times and test to see if any of them satisfy the condition. foreach ($attempttimes as $attempttime) { $duration = $attempttime->lessontime - $attempttime->starttime; if ($conditions->timespent < $duration / 60) { $timespent = true; } } } if (!$timespent) { $errors[] = get_string('timespenterror', 'lesson', $conditions->timespent); } } // Check for the gradebetterthan condition. if ($conditions->gradebetterthan) { $gradebetterthan = false; if ($studentgrades = $DB->get_records('lesson_grades', array("userid" => $USER->id, "lessonid" => $dependentlesson->id))) { // Go through all the grades and test to see if any of them satisfy the condition. foreach ($studentgrades as $studentgrade) { if ($studentgrade->grade >= $conditions->gradebetterthan) { $gradebetterthan = true; } } } if (!$gradebetterthan) { $errors[] = get_string('gradebetterthanerror', 'lesson', $conditions->gradebetterthan); } } // Check for the completed condition. if ($conditions->completed) { if (!$DB->count_records('lesson_grades', array('userid' => $USER->id, 'lessonid' => $dependentlesson->id))) { $errors[] = get_string('completederror', 'lesson'); } } if (!empty($errors)) { return (object) ['errors' => $errors, 'dependentlesson' => $dependentlesson]; } } return false; }
php
public function get_dependencies_restriction_status() { global $DB, $USER; if ($this->can_manage()) { return false; } if ($dependentlesson = $DB->get_record('lesson', array('id' => $this->properties->dependency))) { // Lesson exists, so we can proceed. $conditions = unserialize($this->properties->conditions); // Assume false for all. $errors = array(); // Check for the timespent condition. if ($conditions->timespent) { $timespent = false; if ($attempttimes = $DB->get_records('lesson_timer', array("userid" => $USER->id, "lessonid" => $dependentlesson->id))) { // Go through all the times and test to see if any of them satisfy the condition. foreach ($attempttimes as $attempttime) { $duration = $attempttime->lessontime - $attempttime->starttime; if ($conditions->timespent < $duration / 60) { $timespent = true; } } } if (!$timespent) { $errors[] = get_string('timespenterror', 'lesson', $conditions->timespent); } } // Check for the gradebetterthan condition. if ($conditions->gradebetterthan) { $gradebetterthan = false; if ($studentgrades = $DB->get_records('lesson_grades', array("userid" => $USER->id, "lessonid" => $dependentlesson->id))) { // Go through all the grades and test to see if any of them satisfy the condition. foreach ($studentgrades as $studentgrade) { if ($studentgrade->grade >= $conditions->gradebetterthan) { $gradebetterthan = true; } } } if (!$gradebetterthan) { $errors[] = get_string('gradebetterthanerror', 'lesson', $conditions->gradebetterthan); } } // Check for the completed condition. if ($conditions->completed) { if (!$DB->count_records('lesson_grades', array('userid' => $USER->id, 'lessonid' => $dependentlesson->id))) { $errors[] = get_string('completederror', 'lesson'); } } if (!empty($errors)) { return (object) ['errors' => $errors, 'dependentlesson' => $dependentlesson]; } } return false; }
[ "public", "function", "get_dependencies_restriction_status", "(", ")", "{", "global", "$", "DB", ",", "$", "USER", ";", "if", "(", "$", "this", "->", "can_manage", "(", ")", ")", "{", "return", "false", ";", "}", "if", "(", "$", "dependentlesson", "=", "$", "DB", "->", "get_record", "(", "'lesson'", ",", "array", "(", "'id'", "=>", "$", "this", "->", "properties", "->", "dependency", ")", ")", ")", "{", "// Lesson exists, so we can proceed.", "$", "conditions", "=", "unserialize", "(", "$", "this", "->", "properties", "->", "conditions", ")", ";", "// Assume false for all.", "$", "errors", "=", "array", "(", ")", ";", "// Check for the timespent condition.", "if", "(", "$", "conditions", "->", "timespent", ")", "{", "$", "timespent", "=", "false", ";", "if", "(", "$", "attempttimes", "=", "$", "DB", "->", "get_records", "(", "'lesson_timer'", ",", "array", "(", "\"userid\"", "=>", "$", "USER", "->", "id", ",", "\"lessonid\"", "=>", "$", "dependentlesson", "->", "id", ")", ")", ")", "{", "// Go through all the times and test to see if any of them satisfy the condition.", "foreach", "(", "$", "attempttimes", "as", "$", "attempttime", ")", "{", "$", "duration", "=", "$", "attempttime", "->", "lessontime", "-", "$", "attempttime", "->", "starttime", ";", "if", "(", "$", "conditions", "->", "timespent", "<", "$", "duration", "/", "60", ")", "{", "$", "timespent", "=", "true", ";", "}", "}", "}", "if", "(", "!", "$", "timespent", ")", "{", "$", "errors", "[", "]", "=", "get_string", "(", "'timespenterror'", ",", "'lesson'", ",", "$", "conditions", "->", "timespent", ")", ";", "}", "}", "// Check for the gradebetterthan condition.", "if", "(", "$", "conditions", "->", "gradebetterthan", ")", "{", "$", "gradebetterthan", "=", "false", ";", "if", "(", "$", "studentgrades", "=", "$", "DB", "->", "get_records", "(", "'lesson_grades'", ",", "array", "(", "\"userid\"", "=>", "$", "USER", "->", "id", ",", "\"lessonid\"", "=>", "$", "dependentlesson", "->", "id", ")", ")", ")", "{", "// Go through all the grades and test to see if any of them satisfy the condition.", "foreach", "(", "$", "studentgrades", "as", "$", "studentgrade", ")", "{", "if", "(", "$", "studentgrade", "->", "grade", ">=", "$", "conditions", "->", "gradebetterthan", ")", "{", "$", "gradebetterthan", "=", "true", ";", "}", "}", "}", "if", "(", "!", "$", "gradebetterthan", ")", "{", "$", "errors", "[", "]", "=", "get_string", "(", "'gradebetterthanerror'", ",", "'lesson'", ",", "$", "conditions", "->", "gradebetterthan", ")", ";", "}", "}", "// Check for the completed condition.", "if", "(", "$", "conditions", "->", "completed", ")", "{", "if", "(", "!", "$", "DB", "->", "count_records", "(", "'lesson_grades'", ",", "array", "(", "'userid'", "=>", "$", "USER", "->", "id", ",", "'lessonid'", "=>", "$", "dependentlesson", "->", "id", ")", ")", ")", "{", "$", "errors", "[", "]", "=", "get_string", "(", "'completederror'", ",", "'lesson'", ")", ";", "}", "}", "if", "(", "!", "empty", "(", "$", "errors", ")", ")", "{", "return", "(", "object", ")", "[", "'errors'", "=>", "$", "errors", ",", "'dependentlesson'", "=>", "$", "dependentlesson", "]", ";", "}", "}", "return", "false", ";", "}" ]
Check if dependencies restrictions are applied. @return mixed false if there aren't restrictions or an object with the restriction information @since Moodle 3.3
[ "Check", "if", "dependencies", "restrictions", "are", "applied", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/lesson/locallib.php#L2856-L2909
214,504
moodle/moodle
mod/lesson/locallib.php
lesson.get_last_page_seen
public function get_last_page_seen($retriescount) { global $DB, $USER; $lastpageseen = false; $allattempts = $this->get_attempts($retriescount); if (!empty($allattempts)) { $attempt = end($allattempts); $attemptpage = $this->load_page($attempt->pageid); $jumpto = $DB->get_field('lesson_answers', 'jumpto', array('id' => $attempt->answerid)); // Convert the jumpto to a proper page id. if ($jumpto == 0) { // Check if a question has been incorrectly answered AND no more attempts at it are left. $nattempts = $this->get_attempts($attempt->retry, false, $attempt->pageid, $USER->id); if (count($nattempts) >= $this->properties->maxattempts) { $lastpageseen = $this->get_next_page($attemptpage->nextpageid); } else { $lastpageseen = $attempt->pageid; } } else if ($jumpto == LESSON_NEXTPAGE) { $lastpageseen = $this->get_next_page($attemptpage->nextpageid); } else if ($jumpto == LESSON_CLUSTERJUMP) { $lastpageseen = $this->cluster_jump($attempt->pageid); } else { $lastpageseen = $jumpto; } } if ($branchtables = $this->get_content_pages_viewed($retriescount, $USER->id, 'timeseen DESC')) { // In here, user has viewed a branch table. $lastbranchtable = current($branchtables); if (count($allattempts) > 0) { if ($lastbranchtable->timeseen > $attempt->timeseen) { // This branch table was viewed more recently than the question page. if (!empty($lastbranchtable->nextpageid)) { $lastpageseen = $lastbranchtable->nextpageid; } else { // Next page ID did not exist prior to MDL-34006. $lastpageseen = $lastbranchtable->pageid; } } } else { // Has not answered any questions but has viewed a branch table. if (!empty($lastbranchtable->nextpageid)) { $lastpageseen = $lastbranchtable->nextpageid; } else { // Next page ID did not exist prior to MDL-34006. $lastpageseen = $lastbranchtable->pageid; } } } return $lastpageseen; }
php
public function get_last_page_seen($retriescount) { global $DB, $USER; $lastpageseen = false; $allattempts = $this->get_attempts($retriescount); if (!empty($allattempts)) { $attempt = end($allattempts); $attemptpage = $this->load_page($attempt->pageid); $jumpto = $DB->get_field('lesson_answers', 'jumpto', array('id' => $attempt->answerid)); // Convert the jumpto to a proper page id. if ($jumpto == 0) { // Check if a question has been incorrectly answered AND no more attempts at it are left. $nattempts = $this->get_attempts($attempt->retry, false, $attempt->pageid, $USER->id); if (count($nattempts) >= $this->properties->maxattempts) { $lastpageseen = $this->get_next_page($attemptpage->nextpageid); } else { $lastpageseen = $attempt->pageid; } } else if ($jumpto == LESSON_NEXTPAGE) { $lastpageseen = $this->get_next_page($attemptpage->nextpageid); } else if ($jumpto == LESSON_CLUSTERJUMP) { $lastpageseen = $this->cluster_jump($attempt->pageid); } else { $lastpageseen = $jumpto; } } if ($branchtables = $this->get_content_pages_viewed($retriescount, $USER->id, 'timeseen DESC')) { // In here, user has viewed a branch table. $lastbranchtable = current($branchtables); if (count($allattempts) > 0) { if ($lastbranchtable->timeseen > $attempt->timeseen) { // This branch table was viewed more recently than the question page. if (!empty($lastbranchtable->nextpageid)) { $lastpageseen = $lastbranchtable->nextpageid; } else { // Next page ID did not exist prior to MDL-34006. $lastpageseen = $lastbranchtable->pageid; } } } else { // Has not answered any questions but has viewed a branch table. if (!empty($lastbranchtable->nextpageid)) { $lastpageseen = $lastbranchtable->nextpageid; } else { // Next page ID did not exist prior to MDL-34006. $lastpageseen = $lastbranchtable->pageid; } } } return $lastpageseen; }
[ "public", "function", "get_last_page_seen", "(", "$", "retriescount", ")", "{", "global", "$", "DB", ",", "$", "USER", ";", "$", "lastpageseen", "=", "false", ";", "$", "allattempts", "=", "$", "this", "->", "get_attempts", "(", "$", "retriescount", ")", ";", "if", "(", "!", "empty", "(", "$", "allattempts", ")", ")", "{", "$", "attempt", "=", "end", "(", "$", "allattempts", ")", ";", "$", "attemptpage", "=", "$", "this", "->", "load_page", "(", "$", "attempt", "->", "pageid", ")", ";", "$", "jumpto", "=", "$", "DB", "->", "get_field", "(", "'lesson_answers'", ",", "'jumpto'", ",", "array", "(", "'id'", "=>", "$", "attempt", "->", "answerid", ")", ")", ";", "// Convert the jumpto to a proper page id.", "if", "(", "$", "jumpto", "==", "0", ")", "{", "// Check if a question has been incorrectly answered AND no more attempts at it are left.", "$", "nattempts", "=", "$", "this", "->", "get_attempts", "(", "$", "attempt", "->", "retry", ",", "false", ",", "$", "attempt", "->", "pageid", ",", "$", "USER", "->", "id", ")", ";", "if", "(", "count", "(", "$", "nattempts", ")", ">=", "$", "this", "->", "properties", "->", "maxattempts", ")", "{", "$", "lastpageseen", "=", "$", "this", "->", "get_next_page", "(", "$", "attemptpage", "->", "nextpageid", ")", ";", "}", "else", "{", "$", "lastpageseen", "=", "$", "attempt", "->", "pageid", ";", "}", "}", "else", "if", "(", "$", "jumpto", "==", "LESSON_NEXTPAGE", ")", "{", "$", "lastpageseen", "=", "$", "this", "->", "get_next_page", "(", "$", "attemptpage", "->", "nextpageid", ")", ";", "}", "else", "if", "(", "$", "jumpto", "==", "LESSON_CLUSTERJUMP", ")", "{", "$", "lastpageseen", "=", "$", "this", "->", "cluster_jump", "(", "$", "attempt", "->", "pageid", ")", ";", "}", "else", "{", "$", "lastpageseen", "=", "$", "jumpto", ";", "}", "}", "if", "(", "$", "branchtables", "=", "$", "this", "->", "get_content_pages_viewed", "(", "$", "retriescount", ",", "$", "USER", "->", "id", ",", "'timeseen DESC'", ")", ")", "{", "// In here, user has viewed a branch table.", "$", "lastbranchtable", "=", "current", "(", "$", "branchtables", ")", ";", "if", "(", "count", "(", "$", "allattempts", ")", ">", "0", ")", "{", "if", "(", "$", "lastbranchtable", "->", "timeseen", ">", "$", "attempt", "->", "timeseen", ")", "{", "// This branch table was viewed more recently than the question page.", "if", "(", "!", "empty", "(", "$", "lastbranchtable", "->", "nextpageid", ")", ")", "{", "$", "lastpageseen", "=", "$", "lastbranchtable", "->", "nextpageid", ";", "}", "else", "{", "// Next page ID did not exist prior to MDL-34006.", "$", "lastpageseen", "=", "$", "lastbranchtable", "->", "pageid", ";", "}", "}", "}", "else", "{", "// Has not answered any questions but has viewed a branch table.", "if", "(", "!", "empty", "(", "$", "lastbranchtable", "->", "nextpageid", ")", ")", "{", "$", "lastpageseen", "=", "$", "lastbranchtable", "->", "nextpageid", ";", "}", "else", "{", "// Next page ID did not exist prior to MDL-34006.", "$", "lastpageseen", "=", "$", "lastbranchtable", "->", "pageid", ";", "}", "}", "}", "return", "$", "lastpageseen", ";", "}" ]
Return the last page the current user saw. @param int $retriescount the number of retries for the lesson (the last retry number). @return mixed false if the user didn't see the lesson or the last page id
[ "Return", "the", "last", "page", "the", "current", "user", "saw", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/lesson/locallib.php#L2933-L2984
214,505
moodle/moodle
mod/lesson/locallib.php
lesson.left_during_timed_session
public function left_during_timed_session($retriescount) { global $DB, $USER; $conditions = array('lessonid' => $this->properties->id, 'userid' => $USER->id, 'retry' => $retriescount); return $DB->count_records('lesson_attempts', $conditions) > 0 || $DB->count_records('lesson_branch', $conditions) > 0; }
php
public function left_during_timed_session($retriescount) { global $DB, $USER; $conditions = array('lessonid' => $this->properties->id, 'userid' => $USER->id, 'retry' => $retriescount); return $DB->count_records('lesson_attempts', $conditions) > 0 || $DB->count_records('lesson_branch', $conditions) > 0; }
[ "public", "function", "left_during_timed_session", "(", "$", "retriescount", ")", "{", "global", "$", "DB", ",", "$", "USER", ";", "$", "conditions", "=", "array", "(", "'lessonid'", "=>", "$", "this", "->", "properties", "->", "id", ",", "'userid'", "=>", "$", "USER", "->", "id", ",", "'retry'", "=>", "$", "retriescount", ")", ";", "return", "$", "DB", "->", "count_records", "(", "'lesson_attempts'", ",", "$", "conditions", ")", ">", "0", "||", "$", "DB", "->", "count_records", "(", "'lesson_branch'", ",", "$", "conditions", ")", ">", "0", ";", "}" ]
Check if a user left a timed session. @param int $retriescount the number of retries for the lesson (the last retry number). @return true if the user left the timed session @since Moodle 3.3
[ "Check", "if", "a", "user", "left", "a", "timed", "session", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/lesson/locallib.php#L3006-L3011
214,506
moodle/moodle
mod/lesson/locallib.php
lesson.check_time
public function check_time($timer) { if ($this->properties->timelimit) { $timeleft = $timer->starttime + $this->properties->timelimit - time(); if ($timeleft <= 0) { // Out of time. $this->add_message(get_string('eolstudentoutoftime', 'lesson')); return false; } else if ($timeleft < 60) { // One minute warning. $this->add_message(get_string('studentoneminwarning', 'lesson')); } } return true; }
php
public function check_time($timer) { if ($this->properties->timelimit) { $timeleft = $timer->starttime + $this->properties->timelimit - time(); if ($timeleft <= 0) { // Out of time. $this->add_message(get_string('eolstudentoutoftime', 'lesson')); return false; } else if ($timeleft < 60) { // One minute warning. $this->add_message(get_string('studentoneminwarning', 'lesson')); } } return true; }
[ "public", "function", "check_time", "(", "$", "timer", ")", "{", "if", "(", "$", "this", "->", "properties", "->", "timelimit", ")", "{", "$", "timeleft", "=", "$", "timer", "->", "starttime", "+", "$", "this", "->", "properties", "->", "timelimit", "-", "time", "(", ")", ";", "if", "(", "$", "timeleft", "<=", "0", ")", "{", "// Out of time.", "$", "this", "->", "add_message", "(", "get_string", "(", "'eolstudentoutoftime'", ",", "'lesson'", ")", ")", ";", "return", "false", ";", "}", "else", "if", "(", "$", "timeleft", "<", "60", ")", "{", "// One minute warning.", "$", "this", "->", "add_message", "(", "get_string", "(", "'studentoneminwarning'", ",", "'lesson'", ")", ")", ";", "}", "}", "return", "true", ";", "}" ]
Check if the user is out of time in a timed lesson. @param stdClass $timer timer object @return bool True if the user is on time, false is the user ran out of time @since Moodle 3.3
[ "Check", "if", "the", "user", "is", "out", "of", "time", "in", "a", "timed", "lesson", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/lesson/locallib.php#L3065-L3078
214,507
moodle/moodle
mod/lesson/locallib.php
lesson.calculate_progress
public function calculate_progress() { global $USER, $DB; // Check if the user is reviewing the attempt. if (isset($USER->modattempts[$this->properties->id])) { return 100; } // All of the lesson pages. $pages = $this->load_all_pages(); foreach ($pages as $page) { if ($page->prevpageid == 0) { $pageid = $page->id; // Find the first page id. break; } } // Current attempt number. if (!$ntries = $DB->count_records("lesson_grades", array("lessonid" => $this->properties->id, "userid" => $USER->id))) { $ntries = 0; // May not be necessary. } $viewedpageids = array(); if ($attempts = $this->get_attempts($ntries, false)) { foreach ($attempts as $attempt) { $viewedpageids[$attempt->pageid] = $attempt; } } $viewedbranches = array(); // Collect all of the branch tables viewed. if ($branches = $this->get_content_pages_viewed($ntries, $USER->id, 'timeseen ASC', 'id, pageid')) { foreach ($branches as $branch) { $viewedbranches[$branch->pageid] = $branch; } $viewedpageids = array_merge($viewedpageids, $viewedbranches); } // Filter out the following pages: // - End of Cluster // - End of Branch // - Pages found inside of Clusters // Do not filter out Cluster Page(s) because we count a cluster as one. // By keeping the cluster page, we get our 1. $validpages = array(); while ($pageid != 0) { $pageid = $pages[$pageid]->valid_page_and_view($validpages, $viewedpageids); } // Progress calculation as a percent. $progress = round(count($viewedpageids) / count($validpages), 2) * 100; return (int) $progress; }
php
public function calculate_progress() { global $USER, $DB; // Check if the user is reviewing the attempt. if (isset($USER->modattempts[$this->properties->id])) { return 100; } // All of the lesson pages. $pages = $this->load_all_pages(); foreach ($pages as $page) { if ($page->prevpageid == 0) { $pageid = $page->id; // Find the first page id. break; } } // Current attempt number. if (!$ntries = $DB->count_records("lesson_grades", array("lessonid" => $this->properties->id, "userid" => $USER->id))) { $ntries = 0; // May not be necessary. } $viewedpageids = array(); if ($attempts = $this->get_attempts($ntries, false)) { foreach ($attempts as $attempt) { $viewedpageids[$attempt->pageid] = $attempt; } } $viewedbranches = array(); // Collect all of the branch tables viewed. if ($branches = $this->get_content_pages_viewed($ntries, $USER->id, 'timeseen ASC', 'id, pageid')) { foreach ($branches as $branch) { $viewedbranches[$branch->pageid] = $branch; } $viewedpageids = array_merge($viewedpageids, $viewedbranches); } // Filter out the following pages: // - End of Cluster // - End of Branch // - Pages found inside of Clusters // Do not filter out Cluster Page(s) because we count a cluster as one. // By keeping the cluster page, we get our 1. $validpages = array(); while ($pageid != 0) { $pageid = $pages[$pageid]->valid_page_and_view($validpages, $viewedpageids); } // Progress calculation as a percent. $progress = round(count($viewedpageids) / count($validpages), 2) * 100; return (int) $progress; }
[ "public", "function", "calculate_progress", "(", ")", "{", "global", "$", "USER", ",", "$", "DB", ";", "// Check if the user is reviewing the attempt.", "if", "(", "isset", "(", "$", "USER", "->", "modattempts", "[", "$", "this", "->", "properties", "->", "id", "]", ")", ")", "{", "return", "100", ";", "}", "// All of the lesson pages.", "$", "pages", "=", "$", "this", "->", "load_all_pages", "(", ")", ";", "foreach", "(", "$", "pages", "as", "$", "page", ")", "{", "if", "(", "$", "page", "->", "prevpageid", "==", "0", ")", "{", "$", "pageid", "=", "$", "page", "->", "id", ";", "// Find the first page id.", "break", ";", "}", "}", "// Current attempt number.", "if", "(", "!", "$", "ntries", "=", "$", "DB", "->", "count_records", "(", "\"lesson_grades\"", ",", "array", "(", "\"lessonid\"", "=>", "$", "this", "->", "properties", "->", "id", ",", "\"userid\"", "=>", "$", "USER", "->", "id", ")", ")", ")", "{", "$", "ntries", "=", "0", ";", "// May not be necessary.", "}", "$", "viewedpageids", "=", "array", "(", ")", ";", "if", "(", "$", "attempts", "=", "$", "this", "->", "get_attempts", "(", "$", "ntries", ",", "false", ")", ")", "{", "foreach", "(", "$", "attempts", "as", "$", "attempt", ")", "{", "$", "viewedpageids", "[", "$", "attempt", "->", "pageid", "]", "=", "$", "attempt", ";", "}", "}", "$", "viewedbranches", "=", "array", "(", ")", ";", "// Collect all of the branch tables viewed.", "if", "(", "$", "branches", "=", "$", "this", "->", "get_content_pages_viewed", "(", "$", "ntries", ",", "$", "USER", "->", "id", ",", "'timeseen ASC'", ",", "'id, pageid'", ")", ")", "{", "foreach", "(", "$", "branches", "as", "$", "branch", ")", "{", "$", "viewedbranches", "[", "$", "branch", "->", "pageid", "]", "=", "$", "branch", ";", "}", "$", "viewedpageids", "=", "array_merge", "(", "$", "viewedpageids", ",", "$", "viewedbranches", ")", ";", "}", "// Filter out the following pages:", "// - End of Cluster", "// - End of Branch", "// - Pages found inside of Clusters", "// Do not filter out Cluster Page(s) because we count a cluster as one.", "// By keeping the cluster page, we get our 1.", "$", "validpages", "=", "array", "(", ")", ";", "while", "(", "$", "pageid", "!=", "0", ")", "{", "$", "pageid", "=", "$", "pages", "[", "$", "pageid", "]", "->", "valid_page_and_view", "(", "$", "validpages", ",", "$", "viewedpageids", ")", ";", "}", "// Progress calculation as a percent.", "$", "progress", "=", "round", "(", "count", "(", "$", "viewedpageids", ")", "/", "count", "(", "$", "validpages", ")", ",", "2", ")", "*", "100", ";", "return", "(", "int", ")", "$", "progress", ";", "}" ]
Calculate the progress of the current user in the lesson. @return int the progress (scale 0-100) @since Moodle 3.3
[ "Calculate", "the", "progress", "of", "the", "current", "user", "in", "the", "lesson", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/lesson/locallib.php#L3167-L3219
214,508
moodle/moodle
mod/lesson/locallib.php
lesson.process_page_responses
public function process_page_responses(lesson_page $page) { $context = $this->get_context(); // Check the page has answers [MDL-25632]. if (count($page->answers) > 0) { $result = $page->record_attempt($context); } else { // The page has no answers so we will just progress to the next page in the // sequence (as set by newpageid). $result = new stdClass; $result->newpageid = optional_param('newpageid', $page->nextpageid, PARAM_INT); $result->nodefaultresponse = true; $result->inmediatejump = false; } if ($result->inmediatejump) { return $result; } $result->newpageid = $this->calculate_new_page_on_jump($page, $result->newpageid); return $result; }
php
public function process_page_responses(lesson_page $page) { $context = $this->get_context(); // Check the page has answers [MDL-25632]. if (count($page->answers) > 0) { $result = $page->record_attempt($context); } else { // The page has no answers so we will just progress to the next page in the // sequence (as set by newpageid). $result = new stdClass; $result->newpageid = optional_param('newpageid', $page->nextpageid, PARAM_INT); $result->nodefaultresponse = true; $result->inmediatejump = false; } if ($result->inmediatejump) { return $result; } $result->newpageid = $this->calculate_new_page_on_jump($page, $result->newpageid); return $result; }
[ "public", "function", "process_page_responses", "(", "lesson_page", "$", "page", ")", "{", "$", "context", "=", "$", "this", "->", "get_context", "(", ")", ";", "// Check the page has answers [MDL-25632].", "if", "(", "count", "(", "$", "page", "->", "answers", ")", ">", "0", ")", "{", "$", "result", "=", "$", "page", "->", "record_attempt", "(", "$", "context", ")", ";", "}", "else", "{", "// The page has no answers so we will just progress to the next page in the", "// sequence (as set by newpageid).", "$", "result", "=", "new", "stdClass", ";", "$", "result", "->", "newpageid", "=", "optional_param", "(", "'newpageid'", ",", "$", "page", "->", "nextpageid", ",", "PARAM_INT", ")", ";", "$", "result", "->", "nodefaultresponse", "=", "true", ";", "$", "result", "->", "inmediatejump", "=", "false", ";", "}", "if", "(", "$", "result", "->", "inmediatejump", ")", "{", "return", "$", "result", ";", "}", "$", "result", "->", "newpageid", "=", "$", "this", "->", "calculate_new_page_on_jump", "(", "$", "page", ",", "$", "result", "->", "newpageid", ")", ";", "return", "$", "result", ";", "}" ]
Process page responses. @param lesson_page $page page object @since Moodle 3.3
[ "Process", "page", "responses", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/lesson/locallib.php#L3372-L3394
214,509
moodle/moodle
mod/lesson/locallib.php
lesson_page.load
final public static function load($id, lesson $lesson) { global $DB; if (is_object($id) && !empty($id->qtype)) { $page = $id; } else { $page = $DB->get_record("lesson_pages", array("id" => $id)); if (!$page) { print_error('cannotfindpages', 'lesson'); } } $manager = lesson_page_type_manager::get($lesson); $class = 'lesson_page_type_'.$manager->get_page_type_idstring($page->qtype); if (!class_exists($class)) { $class = 'lesson_page'; } return new $class($page, $lesson); }
php
final public static function load($id, lesson $lesson) { global $DB; if (is_object($id) && !empty($id->qtype)) { $page = $id; } else { $page = $DB->get_record("lesson_pages", array("id" => $id)); if (!$page) { print_error('cannotfindpages', 'lesson'); } } $manager = lesson_page_type_manager::get($lesson); $class = 'lesson_page_type_'.$manager->get_page_type_idstring($page->qtype); if (!class_exists($class)) { $class = 'lesson_page'; } return new $class($page, $lesson); }
[ "final", "public", "static", "function", "load", "(", "$", "id", ",", "lesson", "$", "lesson", ")", "{", "global", "$", "DB", ";", "if", "(", "is_object", "(", "$", "id", ")", "&&", "!", "empty", "(", "$", "id", "->", "qtype", ")", ")", "{", "$", "page", "=", "$", "id", ";", "}", "else", "{", "$", "page", "=", "$", "DB", "->", "get_record", "(", "\"lesson_pages\"", ",", "array", "(", "\"id\"", "=>", "$", "id", ")", ")", ";", "if", "(", "!", "$", "page", ")", "{", "print_error", "(", "'cannotfindpages'", ",", "'lesson'", ")", ";", "}", "}", "$", "manager", "=", "lesson_page_type_manager", "::", "get", "(", "$", "lesson", ")", ";", "$", "class", "=", "'lesson_page_type_'", ".", "$", "manager", "->", "get_page_type_idstring", "(", "$", "page", "->", "qtype", ")", ";", "if", "(", "!", "class_exists", "(", "$", "class", ")", ")", "{", "$", "class", "=", "'lesson_page'", ";", "}", "return", "new", "$", "class", "(", "$", "page", ",", "$", "lesson", ")", ";", "}" ]
This method loads a page object from the database and returns it as a specialised object that extends lesson_page @final @static @param int $id @param lesson $lesson @return lesson_page Specialised lesson_page object
[ "This", "method", "loads", "a", "page", "object", "from", "the", "database", "and", "returns", "it", "as", "a", "specialised", "object", "that", "extends", "lesson_page" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/lesson/locallib.php#L3892-L3911
214,510
moodle/moodle
mod/lesson/locallib.php
lesson_page.move
final public function move($nextpageid=null, $prevpageid=null) { global $DB; if ($nextpageid === null) { $nextpageid = $this->properties->nextpageid; } if ($prevpageid === null) { $prevpageid = $this->properties->prevpageid; } $obj = new stdClass; $obj->id = $this->properties->id; $obj->prevpageid = $prevpageid; $obj->nextpageid = $nextpageid; $DB->update_record('lesson_pages', $obj); }
php
final public function move($nextpageid=null, $prevpageid=null) { global $DB; if ($nextpageid === null) { $nextpageid = $this->properties->nextpageid; } if ($prevpageid === null) { $prevpageid = $this->properties->prevpageid; } $obj = new stdClass; $obj->id = $this->properties->id; $obj->prevpageid = $prevpageid; $obj->nextpageid = $nextpageid; $DB->update_record('lesson_pages', $obj); }
[ "final", "public", "function", "move", "(", "$", "nextpageid", "=", "null", ",", "$", "prevpageid", "=", "null", ")", "{", "global", "$", "DB", ";", "if", "(", "$", "nextpageid", "===", "null", ")", "{", "$", "nextpageid", "=", "$", "this", "->", "properties", "->", "nextpageid", ";", "}", "if", "(", "$", "prevpageid", "===", "null", ")", "{", "$", "prevpageid", "=", "$", "this", "->", "properties", "->", "prevpageid", ";", "}", "$", "obj", "=", "new", "stdClass", ";", "$", "obj", "->", "id", "=", "$", "this", "->", "properties", "->", "id", ";", "$", "obj", "->", "prevpageid", "=", "$", "prevpageid", ";", "$", "obj", "->", "nextpageid", "=", "$", "nextpageid", ";", "$", "DB", "->", "update_record", "(", "'lesson_pages'", ",", "$", "obj", ")", ";", "}" ]
Moves a page by updating its nextpageid and prevpageid values within the database @final @param int $nextpageid @param int $prevpageid
[ "Moves", "a", "page", "by", "updating", "its", "nextpageid", "and", "prevpageid", "values", "within", "the", "database" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/lesson/locallib.php#L3996-L4009
214,511
moodle/moodle
mod/lesson/locallib.php
lesson_page.get_answers
final public function get_answers() { global $DB; if ($this->answers === null) { $this->answers = array(); $answers = $DB->get_records('lesson_answers', array('pageid'=>$this->properties->id, 'lessonid'=>$this->lesson->id), 'id'); if (!$answers) { // It is possible that a lesson upgraded from Moodle 1.9 still // contains questions without any answers [MDL-25632]. // debugging(get_string('cannotfindanswer', 'lesson')); return array(); } foreach ($answers as $answer) { $this->answers[count($this->answers)] = new lesson_page_answer($answer); } } return $this->answers; }
php
final public function get_answers() { global $DB; if ($this->answers === null) { $this->answers = array(); $answers = $DB->get_records('lesson_answers', array('pageid'=>$this->properties->id, 'lessonid'=>$this->lesson->id), 'id'); if (!$answers) { // It is possible that a lesson upgraded from Moodle 1.9 still // contains questions without any answers [MDL-25632]. // debugging(get_string('cannotfindanswer', 'lesson')); return array(); } foreach ($answers as $answer) { $this->answers[count($this->answers)] = new lesson_page_answer($answer); } } return $this->answers; }
[ "final", "public", "function", "get_answers", "(", ")", "{", "global", "$", "DB", ";", "if", "(", "$", "this", "->", "answers", "===", "null", ")", "{", "$", "this", "->", "answers", "=", "array", "(", ")", ";", "$", "answers", "=", "$", "DB", "->", "get_records", "(", "'lesson_answers'", ",", "array", "(", "'pageid'", "=>", "$", "this", "->", "properties", "->", "id", ",", "'lessonid'", "=>", "$", "this", "->", "lesson", "->", "id", ")", ",", "'id'", ")", ";", "if", "(", "!", "$", "answers", ")", "{", "// It is possible that a lesson upgraded from Moodle 1.9 still", "// contains questions without any answers [MDL-25632].", "// debugging(get_string('cannotfindanswer', 'lesson'));", "return", "array", "(", ")", ";", "}", "foreach", "(", "$", "answers", "as", "$", "answer", ")", "{", "$", "this", "->", "answers", "[", "count", "(", "$", "this", "->", "answers", ")", "]", "=", "new", "lesson_page_answer", "(", "$", "answer", ")", ";", "}", "}", "return", "$", "this", "->", "answers", ";", "}" ]
Returns the answers that are associated with this page in the database @final @return array
[ "Returns", "the", "answers", "that", "are", "associated", "with", "this", "page", "in", "the", "database" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/lesson/locallib.php#L4017-L4033
214,512
moodle/moodle
mod/lesson/locallib.php
lesson_page.format_answer
public function format_answer($answer, $context, $answerformat, $options = []) { if (is_object($options)) { $options = (array) $options; } if (empty($options['context'])) { $options['context'] = $context; } if (empty($options['para'])) { $options['para'] = true; } return format_text($answer, $answerformat, $options); }
php
public function format_answer($answer, $context, $answerformat, $options = []) { if (is_object($options)) { $options = (array) $options; } if (empty($options['context'])) { $options['context'] = $context; } if (empty($options['para'])) { $options['para'] = true; } return format_text($answer, $answerformat, $options); }
[ "public", "function", "format_answer", "(", "$", "answer", ",", "$", "context", ",", "$", "answerformat", ",", "$", "options", "=", "[", "]", ")", "{", "if", "(", "is_object", "(", "$", "options", ")", ")", "{", "$", "options", "=", "(", "array", ")", "$", "options", ";", "}", "if", "(", "empty", "(", "$", "options", "[", "'context'", "]", ")", ")", "{", "$", "options", "[", "'context'", "]", "=", "$", "context", ";", "}", "if", "(", "empty", "(", "$", "options", "[", "'para'", "]", ")", ")", "{", "$", "options", "[", "'para'", "]", "=", "true", ";", "}", "return", "format_text", "(", "$", "answer", ",", "$", "answerformat", ",", "$", "options", ")", ";", "}" ]
Formats the answer. Override for custom formatting. @param string $answer @param context $context @param int $answerformat @return string Returns formatted string
[ "Formats", "the", "answer", ".", "Override", "for", "custom", "formatting", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/lesson/locallib.php#L4277-L4292
214,513
moodle/moodle
mod/lesson/locallib.php
lesson_page.format_response
private function format_response($response, $context, $responseformat, $answerid, $options) { $convertstudentresponse = file_rewrite_pluginfile_urls($response, 'pluginfile.php', $context->id, 'mod_lesson', 'page_responses', $answerid); return format_text($convertstudentresponse, $responseformat, $options); }
php
private function format_response($response, $context, $responseformat, $answerid, $options) { $convertstudentresponse = file_rewrite_pluginfile_urls($response, 'pluginfile.php', $context->id, 'mod_lesson', 'page_responses', $answerid); return format_text($convertstudentresponse, $responseformat, $options); }
[ "private", "function", "format_response", "(", "$", "response", ",", "$", "context", ",", "$", "responseformat", ",", "$", "answerid", ",", "$", "options", ")", "{", "$", "convertstudentresponse", "=", "file_rewrite_pluginfile_urls", "(", "$", "response", ",", "'pluginfile.php'", ",", "$", "context", "->", "id", ",", "'mod_lesson'", ",", "'page_responses'", ",", "$", "answerid", ")", ";", "return", "format_text", "(", "$", "convertstudentresponse", ",", "$", "responseformat", ",", "$", "options", ")", ";", "}" ]
Formats the response @param string $response @param context $context @param int $responseformat @param int $answerid @param stdClass $options @return string Returns formatted string
[ "Formats", "the", "response" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/lesson/locallib.php#L4304-L4310
214,514
moodle/moodle
mod/lesson/locallib.php
lesson_page.get_jump_name
final protected function get_jump_name($jumpto) { global $DB; static $jumpnames = array(); if (!array_key_exists($jumpto, $jumpnames)) { if ($jumpto == LESSON_THISPAGE) { $jumptitle = get_string('thispage', 'lesson'); } elseif ($jumpto == LESSON_NEXTPAGE) { $jumptitle = get_string('nextpage', 'lesson'); } elseif ($jumpto == LESSON_EOL) { $jumptitle = get_string('endoflesson', 'lesson'); } elseif ($jumpto == LESSON_UNSEENBRANCHPAGE) { $jumptitle = get_string('unseenpageinbranch', 'lesson'); } elseif ($jumpto == LESSON_PREVIOUSPAGE) { $jumptitle = get_string('previouspage', 'lesson'); } elseif ($jumpto == LESSON_RANDOMPAGE) { $jumptitle = get_string('randompageinbranch', 'lesson'); } elseif ($jumpto == LESSON_RANDOMBRANCH) { $jumptitle = get_string('randombranch', 'lesson'); } elseif ($jumpto == LESSON_CLUSTERJUMP) { $jumptitle = get_string('clusterjump', 'lesson'); } else { if (!$jumptitle = $DB->get_field('lesson_pages', 'title', array('id' => $jumpto))) { $jumptitle = '<strong>'.get_string('notdefined', 'lesson').'</strong>'; } } $jumpnames[$jumpto] = format_string($jumptitle,true); } return $jumpnames[$jumpto]; }
php
final protected function get_jump_name($jumpto) { global $DB; static $jumpnames = array(); if (!array_key_exists($jumpto, $jumpnames)) { if ($jumpto == LESSON_THISPAGE) { $jumptitle = get_string('thispage', 'lesson'); } elseif ($jumpto == LESSON_NEXTPAGE) { $jumptitle = get_string('nextpage', 'lesson'); } elseif ($jumpto == LESSON_EOL) { $jumptitle = get_string('endoflesson', 'lesson'); } elseif ($jumpto == LESSON_UNSEENBRANCHPAGE) { $jumptitle = get_string('unseenpageinbranch', 'lesson'); } elseif ($jumpto == LESSON_PREVIOUSPAGE) { $jumptitle = get_string('previouspage', 'lesson'); } elseif ($jumpto == LESSON_RANDOMPAGE) { $jumptitle = get_string('randompageinbranch', 'lesson'); } elseif ($jumpto == LESSON_RANDOMBRANCH) { $jumptitle = get_string('randombranch', 'lesson'); } elseif ($jumpto == LESSON_CLUSTERJUMP) { $jumptitle = get_string('clusterjump', 'lesson'); } else { if (!$jumptitle = $DB->get_field('lesson_pages', 'title', array('id' => $jumpto))) { $jumptitle = '<strong>'.get_string('notdefined', 'lesson').'</strong>'; } } $jumpnames[$jumpto] = format_string($jumptitle,true); } return $jumpnames[$jumpto]; }
[ "final", "protected", "function", "get_jump_name", "(", "$", "jumpto", ")", "{", "global", "$", "DB", ";", "static", "$", "jumpnames", "=", "array", "(", ")", ";", "if", "(", "!", "array_key_exists", "(", "$", "jumpto", ",", "$", "jumpnames", ")", ")", "{", "if", "(", "$", "jumpto", "==", "LESSON_THISPAGE", ")", "{", "$", "jumptitle", "=", "get_string", "(", "'thispage'", ",", "'lesson'", ")", ";", "}", "elseif", "(", "$", "jumpto", "==", "LESSON_NEXTPAGE", ")", "{", "$", "jumptitle", "=", "get_string", "(", "'nextpage'", ",", "'lesson'", ")", ";", "}", "elseif", "(", "$", "jumpto", "==", "LESSON_EOL", ")", "{", "$", "jumptitle", "=", "get_string", "(", "'endoflesson'", ",", "'lesson'", ")", ";", "}", "elseif", "(", "$", "jumpto", "==", "LESSON_UNSEENBRANCHPAGE", ")", "{", "$", "jumptitle", "=", "get_string", "(", "'unseenpageinbranch'", ",", "'lesson'", ")", ";", "}", "elseif", "(", "$", "jumpto", "==", "LESSON_PREVIOUSPAGE", ")", "{", "$", "jumptitle", "=", "get_string", "(", "'previouspage'", ",", "'lesson'", ")", ";", "}", "elseif", "(", "$", "jumpto", "==", "LESSON_RANDOMPAGE", ")", "{", "$", "jumptitle", "=", "get_string", "(", "'randompageinbranch'", ",", "'lesson'", ")", ";", "}", "elseif", "(", "$", "jumpto", "==", "LESSON_RANDOMBRANCH", ")", "{", "$", "jumptitle", "=", "get_string", "(", "'randombranch'", ",", "'lesson'", ")", ";", "}", "elseif", "(", "$", "jumpto", "==", "LESSON_CLUSTERJUMP", ")", "{", "$", "jumptitle", "=", "get_string", "(", "'clusterjump'", ",", "'lesson'", ")", ";", "}", "else", "{", "if", "(", "!", "$", "jumptitle", "=", "$", "DB", "->", "get_field", "(", "'lesson_pages'", ",", "'title'", ",", "array", "(", "'id'", "=>", "$", "jumpto", ")", ")", ")", "{", "$", "jumptitle", "=", "'<strong>'", ".", "get_string", "(", "'notdefined'", ",", "'lesson'", ")", ".", "'</strong>'", ";", "}", "}", "$", "jumpnames", "[", "$", "jumpto", "]", "=", "format_string", "(", "$", "jumptitle", ",", "true", ")", ";", "}", "return", "$", "jumpnames", "[", "$", "jumpto", "]", ";", "}" ]
Returns the string for a jump name @final @param int $jumpto Jump code or page ID @return string
[ "Returns", "the", "string", "for", "a", "jump", "name" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/lesson/locallib.php#L4319-L4349
214,515
moodle/moodle
mod/lesson/locallib.php
lesson_page.save_answers_files
public function save_answers_files($context, $maxbytes, &$answer, $answereditor = '', $responseeditor = '') { global $DB; if (isset($answereditor['itemid'])) { $answer->answer = file_save_draft_area_files($answereditor['itemid'], $context->id, 'mod_lesson', 'page_answers', $answer->id, array('noclean' => true, 'maxfiles' => EDITOR_UNLIMITED_FILES, 'maxbytes' => $maxbytes), $answer->answer, null); $DB->set_field('lesson_answers', 'answer', $answer->answer, array('id' => $answer->id)); } if (isset($responseeditor['itemid'])) { $answer->response = file_save_draft_area_files($responseeditor['itemid'], $context->id, 'mod_lesson', 'page_responses', $answer->id, array('noclean' => true, 'maxfiles' => EDITOR_UNLIMITED_FILES, 'maxbytes' => $maxbytes), $answer->response, null); $DB->set_field('lesson_answers', 'response', $answer->response, array('id' => $answer->id)); } }
php
public function save_answers_files($context, $maxbytes, &$answer, $answereditor = '', $responseeditor = '') { global $DB; if (isset($answereditor['itemid'])) { $answer->answer = file_save_draft_area_files($answereditor['itemid'], $context->id, 'mod_lesson', 'page_answers', $answer->id, array('noclean' => true, 'maxfiles' => EDITOR_UNLIMITED_FILES, 'maxbytes' => $maxbytes), $answer->answer, null); $DB->set_field('lesson_answers', 'answer', $answer->answer, array('id' => $answer->id)); } if (isset($responseeditor['itemid'])) { $answer->response = file_save_draft_area_files($responseeditor['itemid'], $context->id, 'mod_lesson', 'page_responses', $answer->id, array('noclean' => true, 'maxfiles' => EDITOR_UNLIMITED_FILES, 'maxbytes' => $maxbytes), $answer->response, null); $DB->set_field('lesson_answers', 'response', $answer->response, array('id' => $answer->id)); } }
[ "public", "function", "save_answers_files", "(", "$", "context", ",", "$", "maxbytes", ",", "&", "$", "answer", ",", "$", "answereditor", "=", "''", ",", "$", "responseeditor", "=", "''", ")", "{", "global", "$", "DB", ";", "if", "(", "isset", "(", "$", "answereditor", "[", "'itemid'", "]", ")", ")", "{", "$", "answer", "->", "answer", "=", "file_save_draft_area_files", "(", "$", "answereditor", "[", "'itemid'", "]", ",", "$", "context", "->", "id", ",", "'mod_lesson'", ",", "'page_answers'", ",", "$", "answer", "->", "id", ",", "array", "(", "'noclean'", "=>", "true", ",", "'maxfiles'", "=>", "EDITOR_UNLIMITED_FILES", ",", "'maxbytes'", "=>", "$", "maxbytes", ")", ",", "$", "answer", "->", "answer", ",", "null", ")", ";", "$", "DB", "->", "set_field", "(", "'lesson_answers'", ",", "'answer'", ",", "$", "answer", "->", "answer", ",", "array", "(", "'id'", "=>", "$", "answer", "->", "id", ")", ")", ";", "}", "if", "(", "isset", "(", "$", "responseeditor", "[", "'itemid'", "]", ")", ")", "{", "$", "answer", "->", "response", "=", "file_save_draft_area_files", "(", "$", "responseeditor", "[", "'itemid'", "]", ",", "$", "context", "->", "id", ",", "'mod_lesson'", ",", "'page_responses'", ",", "$", "answer", "->", "id", ",", "array", "(", "'noclean'", "=>", "true", ",", "'maxfiles'", "=>", "EDITOR_UNLIMITED_FILES", ",", "'maxbytes'", "=>", "$", "maxbytes", ")", ",", "$", "answer", "->", "response", ",", "null", ")", ";", "$", "DB", "->", "set_field", "(", "'lesson_answers'", ",", "'response'", ",", "$", "answer", "->", "response", ",", "array", "(", "'id'", "=>", "$", "answer", "->", "id", ")", ")", ";", "}", "}" ]
save editor answers files and update answer record @param object $context @param int $maxbytes @param object $answer @param object $answereditor @param object $responseeditor
[ "save", "editor", "answers", "files", "and", "update", "answer", "record" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/lesson/locallib.php#L4393-L4409
214,516
moodle/moodle
mod/lesson/locallib.php
lesson_page.rewrite_answers_urls
public static function rewrite_answers_urls($answer, $rewriteanswer = true) { global $PAGE; $context = context_module::instance($PAGE->cm->id); if ($rewriteanswer) { $answer->answer = file_rewrite_pluginfile_urls($answer->answer, 'pluginfile.php', $context->id, 'mod_lesson', 'page_answers', $answer->id); } $answer->response = file_rewrite_pluginfile_urls($answer->response, 'pluginfile.php', $context->id, 'mod_lesson', 'page_responses', $answer->id); return $answer; }
php
public static function rewrite_answers_urls($answer, $rewriteanswer = true) { global $PAGE; $context = context_module::instance($PAGE->cm->id); if ($rewriteanswer) { $answer->answer = file_rewrite_pluginfile_urls($answer->answer, 'pluginfile.php', $context->id, 'mod_lesson', 'page_answers', $answer->id); } $answer->response = file_rewrite_pluginfile_urls($answer->response, 'pluginfile.php', $context->id, 'mod_lesson', 'page_responses', $answer->id); return $answer; }
[ "public", "static", "function", "rewrite_answers_urls", "(", "$", "answer", ",", "$", "rewriteanswer", "=", "true", ")", "{", "global", "$", "PAGE", ";", "$", "context", "=", "context_module", "::", "instance", "(", "$", "PAGE", "->", "cm", "->", "id", ")", ";", "if", "(", "$", "rewriteanswer", ")", "{", "$", "answer", "->", "answer", "=", "file_rewrite_pluginfile_urls", "(", "$", "answer", "->", "answer", ",", "'pluginfile.php'", ",", "$", "context", "->", "id", ",", "'mod_lesson'", ",", "'page_answers'", ",", "$", "answer", "->", "id", ")", ";", "}", "$", "answer", "->", "response", "=", "file_rewrite_pluginfile_urls", "(", "$", "answer", "->", "response", ",", "'pluginfile.php'", ",", "$", "context", "->", "id", ",", "'mod_lesson'", ",", "'page_responses'", ",", "$", "answer", "->", "id", ")", ";", "return", "$", "answer", ";", "}" ]
Rewrite urls in response and optionality answer of a question answer @param object $answer @param bool $rewriteanswer must rewrite answer @return object answer with rewritten urls
[ "Rewrite", "urls", "in", "response", "and", "optionality", "answer", "of", "a", "question", "answer" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/lesson/locallib.php#L4418-L4430
214,517
moodle/moodle
mod/lesson/locallib.php
lesson_page.is_unseen
public function is_unseen($param) { global $USER, $DB; if (is_array($param)) { $seenpages = $param; return (!array_key_exists($this->properties->id, $seenpages)); } else { $nretakes = $param; if (!$DB->count_records("lesson_attempts", array("pageid"=>$this->properties->id, "userid"=>$USER->id, "retry"=>$nretakes))) { return true; } } return false; }
php
public function is_unseen($param) { global $USER, $DB; if (is_array($param)) { $seenpages = $param; return (!array_key_exists($this->properties->id, $seenpages)); } else { $nretakes = $param; if (!$DB->count_records("lesson_attempts", array("pageid"=>$this->properties->id, "userid"=>$USER->id, "retry"=>$nretakes))) { return true; } } return false; }
[ "public", "function", "is_unseen", "(", "$", "param", ")", "{", "global", "$", "USER", ",", "$", "DB", ";", "if", "(", "is_array", "(", "$", "param", ")", ")", "{", "$", "seenpages", "=", "$", "param", ";", "return", "(", "!", "array_key_exists", "(", "$", "this", "->", "properties", "->", "id", ",", "$", "seenpages", ")", ")", ";", "}", "else", "{", "$", "nretakes", "=", "$", "param", ";", "if", "(", "!", "$", "DB", "->", "count_records", "(", "\"lesson_attempts\"", ",", "array", "(", "\"pageid\"", "=>", "$", "this", "->", "properties", "->", "id", ",", "\"userid\"", "=>", "$", "USER", "->", "id", ",", "\"retry\"", "=>", "$", "nretakes", ")", ")", ")", "{", "return", "true", ";", "}", "}", "return", "false", ";", "}" ]
Returns true if a page has been viewed before @param array|int $param Either an array of pages that have been seen or the number of retakes a user has had @return bool
[ "Returns", "true", "if", "a", "page", "has", "been", "viewed", "before" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/lesson/locallib.php#L4561-L4573
214,518
moodle/moodle
mod/lesson/locallib.php
lesson_page.is_unanswered
public function is_unanswered($nretakes) { global $DB, $USER; if (!$DB->count_records("lesson_attempts", array('pageid'=>$this->properties->id, 'userid'=>$USER->id, 'correct'=>1, 'retry'=>$nretakes))) { return true; } return false; }
php
public function is_unanswered($nretakes) { global $DB, $USER; if (!$DB->count_records("lesson_attempts", array('pageid'=>$this->properties->id, 'userid'=>$USER->id, 'correct'=>1, 'retry'=>$nretakes))) { return true; } return false; }
[ "public", "function", "is_unanswered", "(", "$", "nretakes", ")", "{", "global", "$", "DB", ",", "$", "USER", ";", "if", "(", "!", "$", "DB", "->", "count_records", "(", "\"lesson_attempts\"", ",", "array", "(", "'pageid'", "=>", "$", "this", "->", "properties", "->", "id", ",", "'userid'", "=>", "$", "USER", "->", "id", ",", "'correct'", "=>", "1", ",", "'retry'", "=>", "$", "nretakes", ")", ")", ")", "{", "return", "true", ";", "}", "return", "false", ";", "}" ]
Checks to see if a page has been answered previously @param int $nretakes @return bool
[ "Checks", "to", "see", "if", "a", "page", "has", "been", "answered", "previously" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/lesson/locallib.php#L4580-L4586
214,519
moodle/moodle
mod/lesson/locallib.php
lesson_page.check_answer
public function check_answer() { $result = new stdClass; $result->answerid = 0; $result->noanswer = false; $result->correctanswer = false; $result->isessayquestion = false; // use this to turn off review button on essay questions $result->response = ''; $result->newpageid = 0; // stay on the page $result->studentanswer = ''; // use this to store student's answer(s) in order to display it on feedback page $result->studentanswerformat = FORMAT_MOODLE; $result->userresponse = null; $result->feedback = ''; // Store data that was POSTd by a form. This is currently used to perform any logic after the 1st write to the db // of the attempt. $result->postdata = false; $result->nodefaultresponse = false; // Flag for redirecting when default feedback is turned off $result->inmediatejump = false; // Flag to detect when we should do a jump from the page without further processing. return $result; }
php
public function check_answer() { $result = new stdClass; $result->answerid = 0; $result->noanswer = false; $result->correctanswer = false; $result->isessayquestion = false; // use this to turn off review button on essay questions $result->response = ''; $result->newpageid = 0; // stay on the page $result->studentanswer = ''; // use this to store student's answer(s) in order to display it on feedback page $result->studentanswerformat = FORMAT_MOODLE; $result->userresponse = null; $result->feedback = ''; // Store data that was POSTd by a form. This is currently used to perform any logic after the 1st write to the db // of the attempt. $result->postdata = false; $result->nodefaultresponse = false; // Flag for redirecting when default feedback is turned off $result->inmediatejump = false; // Flag to detect when we should do a jump from the page without further processing. return $result; }
[ "public", "function", "check_answer", "(", ")", "{", "$", "result", "=", "new", "stdClass", ";", "$", "result", "->", "answerid", "=", "0", ";", "$", "result", "->", "noanswer", "=", "false", ";", "$", "result", "->", "correctanswer", "=", "false", ";", "$", "result", "->", "isessayquestion", "=", "false", ";", "// use this to turn off review button on essay questions", "$", "result", "->", "response", "=", "''", ";", "$", "result", "->", "newpageid", "=", "0", ";", "// stay on the page", "$", "result", "->", "studentanswer", "=", "''", ";", "// use this to store student's answer(s) in order to display it on feedback page", "$", "result", "->", "studentanswerformat", "=", "FORMAT_MOODLE", ";", "$", "result", "->", "userresponse", "=", "null", ";", "$", "result", "->", "feedback", "=", "''", ";", "// Store data that was POSTd by a form. This is currently used to perform any logic after the 1st write to the db", "// of the attempt.", "$", "result", "->", "postdata", "=", "false", ";", "$", "result", "->", "nodefaultresponse", "=", "false", ";", "// Flag for redirecting when default feedback is turned off", "$", "result", "->", "inmediatejump", "=", "false", ";", "// Flag to detect when we should do a jump from the page without further processing.", "return", "$", "result", ";", "}" ]
This method MUST be overridden by all question page types, or page types that wish to score a page. The structure of result should always be the same so it is a good idea when overriding this method on a page type to call <code> $result = parent::check_answer(); </code> before modifying it as required. @return stdClass
[ "This", "method", "MUST", "be", "overridden", "by", "all", "question", "page", "types", "or", "page", "types", "that", "wish", "to", "score", "a", "page", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/lesson/locallib.php#L4662-L4680
214,520
moodle/moodle
mod/lesson/locallib.php
lesson_page.properties
public function properties() { $properties = clone($this->properties); if ($this->answers === null) { $this->get_answers(); } if (count($this->answers)>0) { $count = 0; $qtype = $properties->qtype; foreach ($this->answers as $answer) { $properties->{'answer_editor['.$count.']'} = array('text' => $answer->answer, 'format' => $answer->answerformat); if ($qtype != LESSON_PAGE_MATCHING) { $properties->{'response_editor['.$count.']'} = array('text' => $answer->response, 'format' => $answer->responseformat); } else { $properties->{'response_editor['.$count.']'} = $answer->response; } $properties->{'jumpto['.$count.']'} = $answer->jumpto; $properties->{'score['.$count.']'} = $answer->score; $count++; } } return $properties; }
php
public function properties() { $properties = clone($this->properties); if ($this->answers === null) { $this->get_answers(); } if (count($this->answers)>0) { $count = 0; $qtype = $properties->qtype; foreach ($this->answers as $answer) { $properties->{'answer_editor['.$count.']'} = array('text' => $answer->answer, 'format' => $answer->answerformat); if ($qtype != LESSON_PAGE_MATCHING) { $properties->{'response_editor['.$count.']'} = array('text' => $answer->response, 'format' => $answer->responseformat); } else { $properties->{'response_editor['.$count.']'} = $answer->response; } $properties->{'jumpto['.$count.']'} = $answer->jumpto; $properties->{'score['.$count.']'} = $answer->score; $count++; } } return $properties; }
[ "public", "function", "properties", "(", ")", "{", "$", "properties", "=", "clone", "(", "$", "this", "->", "properties", ")", ";", "if", "(", "$", "this", "->", "answers", "===", "null", ")", "{", "$", "this", "->", "get_answers", "(", ")", ";", "}", "if", "(", "count", "(", "$", "this", "->", "answers", ")", ">", "0", ")", "{", "$", "count", "=", "0", ";", "$", "qtype", "=", "$", "properties", "->", "qtype", ";", "foreach", "(", "$", "this", "->", "answers", "as", "$", "answer", ")", "{", "$", "properties", "->", "{", "'answer_editor['", ".", "$", "count", ".", "']'", "}", "=", "array", "(", "'text'", "=>", "$", "answer", "->", "answer", ",", "'format'", "=>", "$", "answer", "->", "answerformat", ")", ";", "if", "(", "$", "qtype", "!=", "LESSON_PAGE_MATCHING", ")", "{", "$", "properties", "->", "{", "'response_editor['", ".", "$", "count", ".", "']'", "}", "=", "array", "(", "'text'", "=>", "$", "answer", "->", "response", ",", "'format'", "=>", "$", "answer", "->", "responseformat", ")", ";", "}", "else", "{", "$", "properties", "->", "{", "'response_editor['", ".", "$", "count", ".", "']'", "}", "=", "$", "answer", "->", "response", ";", "}", "$", "properties", "->", "{", "'jumpto['", ".", "$", "count", ".", "']'", "}", "=", "$", "answer", "->", "jumpto", ";", "$", "properties", "->", "{", "'score['", ".", "$", "count", ".", "']'", "}", "=", "$", "answer", "->", "score", ";", "$", "count", "++", ";", "}", "}", "return", "$", "properties", ";", "}" ]
Returns the properties of this lesson page as an object @return stdClass;
[ "Returns", "the", "properties", "of", "this", "lesson", "page", "as", "an", "object" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/lesson/locallib.php#L4721-L4742
214,521
moodle/moodle
mod/lesson/locallib.php
lesson_page.get_contents
public function get_contents() { global $PAGE; if (!empty($this->properties->contents)) { if (!isset($this->properties->contentsformat)) { $this->properties->contentsformat = FORMAT_HTML; } $context = context_module::instance($PAGE->cm->id); $contents = file_rewrite_pluginfile_urls($this->properties->contents, 'pluginfile.php', $context->id, 'mod_lesson', 'page_contents', $this->properties->id); // Must do this BEFORE format_text()! return format_text($contents, $this->properties->contentsformat, array('context' => $context, 'noclean' => true, 'overflowdiv' => true)); // Page edit is marked with XSS, we want all content here. } else { return ''; } }
php
public function get_contents() { global $PAGE; if (!empty($this->properties->contents)) { if (!isset($this->properties->contentsformat)) { $this->properties->contentsformat = FORMAT_HTML; } $context = context_module::instance($PAGE->cm->id); $contents = file_rewrite_pluginfile_urls($this->properties->contents, 'pluginfile.php', $context->id, 'mod_lesson', 'page_contents', $this->properties->id); // Must do this BEFORE format_text()! return format_text($contents, $this->properties->contentsformat, array('context' => $context, 'noclean' => true, 'overflowdiv' => true)); // Page edit is marked with XSS, we want all content here. } else { return ''; } }
[ "public", "function", "get_contents", "(", ")", "{", "global", "$", "PAGE", ";", "if", "(", "!", "empty", "(", "$", "this", "->", "properties", "->", "contents", ")", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "properties", "->", "contentsformat", ")", ")", "{", "$", "this", "->", "properties", "->", "contentsformat", "=", "FORMAT_HTML", ";", "}", "$", "context", "=", "context_module", "::", "instance", "(", "$", "PAGE", "->", "cm", "->", "id", ")", ";", "$", "contents", "=", "file_rewrite_pluginfile_urls", "(", "$", "this", "->", "properties", "->", "contents", ",", "'pluginfile.php'", ",", "$", "context", "->", "id", ",", "'mod_lesson'", ",", "'page_contents'", ",", "$", "this", "->", "properties", "->", "id", ")", ";", "// Must do this BEFORE format_text()!", "return", "format_text", "(", "$", "contents", ",", "$", "this", "->", "properties", "->", "contentsformat", ",", "array", "(", "'context'", "=>", "$", "context", ",", "'noclean'", "=>", "true", ",", "'overflowdiv'", "=>", "true", ")", ")", ";", "// Page edit is marked with XSS, we want all content here.", "}", "else", "{", "return", "''", ";", "}", "}" ]
Returns the contents field for the page properly formatted and with plugin file url's converted @return string
[ "Returns", "the", "contents", "field", "for", "the", "page", "properly", "formatted", "and", "with", "plugin", "file", "url", "s", "converted" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/lesson/locallib.php#L4791-L4806
214,522
moodle/moodle
mod/lesson/locallib.php
lesson_page.display_answers
public function display_answers(html_table $table) { $answers = $this->get_answers(); $i = 1; foreach ($answers as $answer) { $cells = array(); $cells[] = '<label>' . get_string('jump', 'lesson') . ' ' . $i . '</label>:'; $cells[] = $this->get_jump_name($answer->jumpto); $table->data[] = new html_table_row($cells); if ($i === 1){ $table->data[count($table->data)-1]->cells[0]->style = 'width:20%;'; } $i++; } return $table; }
php
public function display_answers(html_table $table) { $answers = $this->get_answers(); $i = 1; foreach ($answers as $answer) { $cells = array(); $cells[] = '<label>' . get_string('jump', 'lesson') . ' ' . $i . '</label>:'; $cells[] = $this->get_jump_name($answer->jumpto); $table->data[] = new html_table_row($cells); if ($i === 1){ $table->data[count($table->data)-1]->cells[0]->style = 'width:20%;'; } $i++; } return $table; }
[ "public", "function", "display_answers", "(", "html_table", "$", "table", ")", "{", "$", "answers", "=", "$", "this", "->", "get_answers", "(", ")", ";", "$", "i", "=", "1", ";", "foreach", "(", "$", "answers", "as", "$", "answer", ")", "{", "$", "cells", "=", "array", "(", ")", ";", "$", "cells", "[", "]", "=", "'<label>'", ".", "get_string", "(", "'jump'", ",", "'lesson'", ")", ".", "' '", ".", "$", "i", ".", "'</label>:'", ";", "$", "cells", "[", "]", "=", "$", "this", "->", "get_jump_name", "(", "$", "answer", "->", "jumpto", ")", ";", "$", "table", "->", "data", "[", "]", "=", "new", "html_table_row", "(", "$", "cells", ")", ";", "if", "(", "$", "i", "===", "1", ")", "{", "$", "table", "->", "data", "[", "count", "(", "$", "table", "->", "data", ")", "-", "1", "]", "->", "cells", "[", "0", "]", "->", "style", "=", "'width:20%;'", ";", "}", "$", "i", "++", ";", "}", "return", "$", "table", ";", "}" ]
Updates a table with the answers for this page @param html_table $table @return html_table
[ "Updates", "a", "table", "with", "the", "answers", "for", "this", "page" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/lesson/locallib.php#L4829-L4843
214,523
moodle/moodle
mod/lesson/locallib.php
lesson_page.report_answers
public function report_answers($answerpage, $answerdata, $useranswer, $pagestats, &$i, &$n) { $answers = $this->get_answers(); $formattextdefoptions = new stdClass; $formattextdefoptions->para = false; //I'll use it widely in this page foreach ($answers as $answer) { $data = get_string('jumpsto', 'lesson', $this->get_jump_name($answer->jumpto)); $answerdata->answers[] = array($data, ""); $answerpage->answerdata = $answerdata; } return $answerpage; }
php
public function report_answers($answerpage, $answerdata, $useranswer, $pagestats, &$i, &$n) { $answers = $this->get_answers(); $formattextdefoptions = new stdClass; $formattextdefoptions->para = false; //I'll use it widely in this page foreach ($answers as $answer) { $data = get_string('jumpsto', 'lesson', $this->get_jump_name($answer->jumpto)); $answerdata->answers[] = array($data, ""); $answerpage->answerdata = $answerdata; } return $answerpage; }
[ "public", "function", "report_answers", "(", "$", "answerpage", ",", "$", "answerdata", ",", "$", "useranswer", ",", "$", "pagestats", ",", "&", "$", "i", ",", "&", "$", "n", ")", "{", "$", "answers", "=", "$", "this", "->", "get_answers", "(", ")", ";", "$", "formattextdefoptions", "=", "new", "stdClass", ";", "$", "formattextdefoptions", "->", "para", "=", "false", ";", "//I'll use it widely in this page", "foreach", "(", "$", "answers", "as", "$", "answer", ")", "{", "$", "data", "=", "get_string", "(", "'jumpsto'", ",", "'lesson'", ",", "$", "this", "->", "get_jump_name", "(", "$", "answer", "->", "jumpto", ")", ")", ";", "$", "answerdata", "->", "answers", "[", "]", "=", "array", "(", "$", "data", ",", "\"\"", ")", ";", "$", "answerpage", "->", "answerdata", "=", "$", "answerdata", ";", "}", "return", "$", "answerpage", ";", "}" ]
Formats the answers of this page for a report @param object $answerpage @param object $answerdata @param object $useranswer @param array $pagestats @param int $i Count of first level answers @param int $n Count of second level answers @return object The answer page for this
[ "Formats", "the", "answers", "of", "this", "page", "for", "a", "report" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/lesson/locallib.php#L4875-L4885
214,524
moodle/moodle
mod/lesson/locallib.php
lesson_page.valid_page_and_view
public function valid_page_and_view(&$validpages, &$pageviews) { $validpages[$this->properties->id] = 1; return $this->properties->nextpageid; }
php
public function valid_page_and_view(&$validpages, &$pageviews) { $validpages[$this->properties->id] = 1; return $this->properties->nextpageid; }
[ "public", "function", "valid_page_and_view", "(", "&", "$", "validpages", ",", "&", "$", "pageviews", ")", "{", "$", "validpages", "[", "$", "this", "->", "properties", "->", "id", "]", "=", "1", ";", "return", "$", "this", "->", "properties", "->", "nextpageid", ";", "}" ]
This method is used to determine if this page is a valid page @param array $validpages @param array $pageviews @return int The next page id to check
[ "This", "method", "is", "used", "to", "determine", "if", "this", "page", "is", "a", "valid", "page" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/lesson/locallib.php#L4929-L4932
214,525
moodle/moodle
mod/lesson/locallib.php
lesson_page.get_files
public function get_files($includedirs = true, $updatedsince = 0) { $fs = get_file_storage(); return $fs->get_area_files($this->lesson->context->id, 'mod_lesson', 'page_contents', $this->properties->id, 'itemid, filepath, filename', $includedirs, $updatedsince); }
php
public function get_files($includedirs = true, $updatedsince = 0) { $fs = get_file_storage(); return $fs->get_area_files($this->lesson->context->id, 'mod_lesson', 'page_contents', $this->properties->id, 'itemid, filepath, filename', $includedirs, $updatedsince); }
[ "public", "function", "get_files", "(", "$", "includedirs", "=", "true", ",", "$", "updatedsince", "=", "0", ")", "{", "$", "fs", "=", "get_file_storage", "(", ")", ";", "return", "$", "fs", "->", "get_area_files", "(", "$", "this", "->", "lesson", "->", "context", "->", "id", ",", "'mod_lesson'", ",", "'page_contents'", ",", "$", "this", "->", "properties", "->", "id", ",", "'itemid, filepath, filename'", ",", "$", "includedirs", ",", "$", "updatedsince", ")", ";", "}" ]
Get files from the page area file. @param bool $includedirs whether or not include directories @param int $updatedsince return files updated since this time @return array list of stored_file objects @since Moodle 3.2
[ "Get", "files", "from", "the", "page", "area", "file", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/lesson/locallib.php#L4942-L4946
214,526
moodle/moodle
mod/lesson/locallib.php
lesson_page_answer.get_files
public function get_files($includedirs = true, $updatedsince = 0) { $lesson = lesson::load($this->properties->lessonid); $fs = get_file_storage(); $answerfiles = $fs->get_area_files($lesson->context->id, 'mod_lesson', 'page_answers', $this->properties->id, 'itemid, filepath, filename', $includedirs, $updatedsince); $responsefiles = $fs->get_area_files($lesson->context->id, 'mod_lesson', 'page_responses', $this->properties->id, 'itemid, filepath, filename', $includedirs, $updatedsince); return array_merge($answerfiles, $responsefiles); }
php
public function get_files($includedirs = true, $updatedsince = 0) { $lesson = lesson::load($this->properties->lessonid); $fs = get_file_storage(); $answerfiles = $fs->get_area_files($lesson->context->id, 'mod_lesson', 'page_answers', $this->properties->id, 'itemid, filepath, filename', $includedirs, $updatedsince); $responsefiles = $fs->get_area_files($lesson->context->id, 'mod_lesson', 'page_responses', $this->properties->id, 'itemid, filepath, filename', $includedirs, $updatedsince); return array_merge($answerfiles, $responsefiles); }
[ "public", "function", "get_files", "(", "$", "includedirs", "=", "true", ",", "$", "updatedsince", "=", "0", ")", "{", "$", "lesson", "=", "lesson", "::", "load", "(", "$", "this", "->", "properties", "->", "lessonid", ")", ";", "$", "fs", "=", "get_file_storage", "(", ")", ";", "$", "answerfiles", "=", "$", "fs", "->", "get_area_files", "(", "$", "lesson", "->", "context", "->", "id", ",", "'mod_lesson'", ",", "'page_answers'", ",", "$", "this", "->", "properties", "->", "id", ",", "'itemid, filepath, filename'", ",", "$", "includedirs", ",", "$", "updatedsince", ")", ";", "$", "responsefiles", "=", "$", "fs", "->", "get_area_files", "(", "$", "lesson", "->", "context", "->", "id", ",", "'mod_lesson'", ",", "'page_responses'", ",", "$", "this", "->", "properties", "->", "id", ",", "'itemid, filepath, filename'", ",", "$", "includedirs", ",", "$", "updatedsince", ")", ";", "return", "array_merge", "(", "$", "answerfiles", ",", "$", "responsefiles", ")", ";", "}" ]
Get files from the answer area file. @param bool $includedirs whether or not include directories @param int $updatedsince return files updated since this time @return array list of stored_file objects @since Moodle 3.2
[ "Get", "files", "from", "the", "answer", "area", "file", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/lesson/locallib.php#L5014-L5023
214,527
moodle/moodle
mod/lesson/locallib.php
lesson_page_type_manager.get
public static function get(lesson $lesson) { static $pagetypemanager; if (!($pagetypemanager instanceof lesson_page_type_manager)) { $pagetypemanager = new lesson_page_type_manager(); $pagetypemanager->load_lesson_types($lesson); } return $pagetypemanager; }
php
public static function get(lesson $lesson) { static $pagetypemanager; if (!($pagetypemanager instanceof lesson_page_type_manager)) { $pagetypemanager = new lesson_page_type_manager(); $pagetypemanager->load_lesson_types($lesson); } return $pagetypemanager; }
[ "public", "static", "function", "get", "(", "lesson", "$", "lesson", ")", "{", "static", "$", "pagetypemanager", ";", "if", "(", "!", "(", "$", "pagetypemanager", "instanceof", "lesson_page_type_manager", ")", ")", "{", "$", "pagetypemanager", "=", "new", "lesson_page_type_manager", "(", ")", ";", "$", "pagetypemanager", "->", "load_lesson_types", "(", "$", "lesson", ")", ";", "}", "return", "$", "pagetypemanager", ";", "}" ]
Retrieves the lesson page type manager object If the object hasn't yet been created it is created here. @staticvar lesson_page_type_manager $pagetypemanager @param lesson $lesson @return lesson_page_type_manager
[ "Retrieves", "the", "lesson", "page", "type", "manager", "object" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/lesson/locallib.php#L5058-L5065
214,528
moodle/moodle
mod/lesson/locallib.php
lesson_page_type_manager.get_page_type_strings
public function get_page_type_strings($type=null, $special=true) { $types = array(); foreach ($this->types as $pagetype) { if (($type===null || $pagetype->type===$type) && ($special===true || $pagetype->is_standard())) { $types[$pagetype->typeid] = $pagetype->typestring; } } return $types; }
php
public function get_page_type_strings($type=null, $special=true) { $types = array(); foreach ($this->types as $pagetype) { if (($type===null || $pagetype->type===$type) && ($special===true || $pagetype->is_standard())) { $types[$pagetype->typeid] = $pagetype->typestring; } } return $types; }
[ "public", "function", "get_page_type_strings", "(", "$", "type", "=", "null", ",", "$", "special", "=", "true", ")", "{", "$", "types", "=", "array", "(", ")", ";", "foreach", "(", "$", "this", "->", "types", "as", "$", "pagetype", ")", "{", "if", "(", "(", "$", "type", "===", "null", "||", "$", "pagetype", "->", "type", "===", "$", "type", ")", "&&", "(", "$", "special", "===", "true", "||", "$", "pagetype", "->", "is_standard", "(", ")", ")", ")", "{", "$", "types", "[", "$", "pagetype", "->", "typeid", "]", "=", "$", "pagetype", "->", "typestring", ";", "}", "}", "return", "$", "types", ";", "}" ]
Returns an array of strings to describe the loaded page types @param int $type Can be used to return JUST the string for the requested type @return array
[ "Returns", "an", "array", "of", "strings", "to", "describe", "the", "loaded", "page", "types" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/lesson/locallib.php#L5096-L5104
214,529
moodle/moodle
mod/lesson/locallib.php
lesson_page_type_manager.get_page_type_idstring
public function get_page_type_idstring($id) { foreach ($this->types as $pagetype) { if ((int)$pagetype->typeid === (int)$id) { return $pagetype->idstring; } } return 'unknown'; }
php
public function get_page_type_idstring($id) { foreach ($this->types as $pagetype) { if ((int)$pagetype->typeid === (int)$id) { return $pagetype->idstring; } } return 'unknown'; }
[ "public", "function", "get_page_type_idstring", "(", "$", "id", ")", "{", "foreach", "(", "$", "this", "->", "types", "as", "$", "pagetype", ")", "{", "if", "(", "(", "int", ")", "$", "pagetype", "->", "typeid", "===", "(", "int", ")", "$", "id", ")", "{", "return", "$", "pagetype", "->", "idstring", ";", "}", "}", "return", "'unknown'", ";", "}" ]
Returns the basic string used to identify a page type provided with an id This string can be used to instantiate or identify the page type class. If the page type id is unknown then 'unknown' is returned @param int $id @return string
[ "Returns", "the", "basic", "string", "used", "to", "identify", "a", "page", "type", "provided", "with", "an", "id" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/lesson/locallib.php#L5115-L5122
214,530
moodle/moodle
mod/lesson/locallib.php
lesson_page_type_manager.load_page
public function load_page($pageid, lesson $lesson) { global $DB; if (!($page =$DB->get_record('lesson_pages', array('id'=>$pageid, 'lessonid'=>$lesson->id)))) { print_error('cannotfindpages', 'lesson'); } $pagetype = get_class($this->types[$page->qtype]); $page = new $pagetype($page, $lesson); return $page; }
php
public function load_page($pageid, lesson $lesson) { global $DB; if (!($page =$DB->get_record('lesson_pages', array('id'=>$pageid, 'lessonid'=>$lesson->id)))) { print_error('cannotfindpages', 'lesson'); } $pagetype = get_class($this->types[$page->qtype]); $page = new $pagetype($page, $lesson); return $page; }
[ "public", "function", "load_page", "(", "$", "pageid", ",", "lesson", "$", "lesson", ")", "{", "global", "$", "DB", ";", "if", "(", "!", "(", "$", "page", "=", "$", "DB", "->", "get_record", "(", "'lesson_pages'", ",", "array", "(", "'id'", "=>", "$", "pageid", ",", "'lessonid'", "=>", "$", "lesson", "->", "id", ")", ")", ")", ")", "{", "print_error", "(", "'cannotfindpages'", ",", "'lesson'", ")", ";", "}", "$", "pagetype", "=", "get_class", "(", "$", "this", "->", "types", "[", "$", "page", "->", "qtype", "]", ")", ";", "$", "page", "=", "new", "$", "pagetype", "(", "$", "page", ",", "$", "lesson", ")", ";", "return", "$", "page", ";", "}" ]
Loads a page for the provided lesson given it's id This function loads a page from the lesson when given both the lesson it belongs to as well as the page's id. If the page doesn't exist an error is thrown @param int $pageid The id of the page to load @param lesson $lesson The lesson the page belongs to @return lesson_page A class that extends lesson_page
[ "Loads", "a", "page", "for", "the", "provided", "lesson", "given", "it", "s", "id" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/lesson/locallib.php#L5135-L5143
214,531
moodle/moodle
mod/lesson/locallib.php
lesson_page_type_manager.check_page_order
protected function check_page_order($page1, $page2) { global $DB; if (empty($page1)) { if ($page2->prevpageid != 0) { debugging("***prevpageid of page " . $page2->id . " set to 0***"); $page2->prevpageid = 0; $DB->set_field("lesson_pages", "prevpageid", 0, array("id" => $page2->id)); } } else if (empty($page2)) { if ($page1->nextpageid != 0) { debugging("***nextpageid of page " . $page1->id . " set to 0***"); $page1->nextpageid = 0; $DB->set_field("lesson_pages", "nextpageid", 0, array("id" => $page1->id)); } } else { if ($page1->nextpageid != $page2->id) { debugging("***nextpageid of page " . $page1->id . " set to " . $page2->id . "***"); $page1->nextpageid = $page2->id; $DB->set_field("lesson_pages", "nextpageid", $page2->id, array("id" => $page1->id)); } if ($page2->prevpageid != $page1->id) { debugging("***prevpageid of page " . $page2->id . " set to " . $page1->id . "***"); $page2->prevpageid = $page1->id; $DB->set_field("lesson_pages", "prevpageid", $page1->id, array("id" => $page2->id)); } } }
php
protected function check_page_order($page1, $page2) { global $DB; if (empty($page1)) { if ($page2->prevpageid != 0) { debugging("***prevpageid of page " . $page2->id . " set to 0***"); $page2->prevpageid = 0; $DB->set_field("lesson_pages", "prevpageid", 0, array("id" => $page2->id)); } } else if (empty($page2)) { if ($page1->nextpageid != 0) { debugging("***nextpageid of page " . $page1->id . " set to 0***"); $page1->nextpageid = 0; $DB->set_field("lesson_pages", "nextpageid", 0, array("id" => $page1->id)); } } else { if ($page1->nextpageid != $page2->id) { debugging("***nextpageid of page " . $page1->id . " set to " . $page2->id . "***"); $page1->nextpageid = $page2->id; $DB->set_field("lesson_pages", "nextpageid", $page2->id, array("id" => $page1->id)); } if ($page2->prevpageid != $page1->id) { debugging("***prevpageid of page " . $page2->id . " set to " . $page1->id . "***"); $page2->prevpageid = $page1->id; $DB->set_field("lesson_pages", "prevpageid", $page1->id, array("id" => $page2->id)); } } }
[ "protected", "function", "check_page_order", "(", "$", "page1", ",", "$", "page2", ")", "{", "global", "$", "DB", ";", "if", "(", "empty", "(", "$", "page1", ")", ")", "{", "if", "(", "$", "page2", "->", "prevpageid", "!=", "0", ")", "{", "debugging", "(", "\"***prevpageid of page \"", ".", "$", "page2", "->", "id", ".", "\" set to 0***\"", ")", ";", "$", "page2", "->", "prevpageid", "=", "0", ";", "$", "DB", "->", "set_field", "(", "\"lesson_pages\"", ",", "\"prevpageid\"", ",", "0", ",", "array", "(", "\"id\"", "=>", "$", "page2", "->", "id", ")", ")", ";", "}", "}", "else", "if", "(", "empty", "(", "$", "page2", ")", ")", "{", "if", "(", "$", "page1", "->", "nextpageid", "!=", "0", ")", "{", "debugging", "(", "\"***nextpageid of page \"", ".", "$", "page1", "->", "id", ".", "\" set to 0***\"", ")", ";", "$", "page1", "->", "nextpageid", "=", "0", ";", "$", "DB", "->", "set_field", "(", "\"lesson_pages\"", ",", "\"nextpageid\"", ",", "0", ",", "array", "(", "\"id\"", "=>", "$", "page1", "->", "id", ")", ")", ";", "}", "}", "else", "{", "if", "(", "$", "page1", "->", "nextpageid", "!=", "$", "page2", "->", "id", ")", "{", "debugging", "(", "\"***nextpageid of page \"", ".", "$", "page1", "->", "id", ".", "\" set to \"", ".", "$", "page2", "->", "id", ".", "\"***\"", ")", ";", "$", "page1", "->", "nextpageid", "=", "$", "page2", "->", "id", ";", "$", "DB", "->", "set_field", "(", "\"lesson_pages\"", ",", "\"nextpageid\"", ",", "$", "page2", "->", "id", ",", "array", "(", "\"id\"", "=>", "$", "page1", "->", "id", ")", ")", ";", "}", "if", "(", "$", "page2", "->", "prevpageid", "!=", "$", "page1", "->", "id", ")", "{", "debugging", "(", "\"***prevpageid of page \"", ".", "$", "page2", "->", "id", ".", "\" set to \"", ".", "$", "page1", "->", "id", ".", "\"***\"", ")", ";", "$", "page2", "->", "prevpageid", "=", "$", "page1", "->", "id", ";", "$", "DB", "->", "set_field", "(", "\"lesson_pages\"", ",", "\"prevpageid\"", ",", "$", "page1", "->", "id", ",", "array", "(", "\"id\"", "=>", "$", "page2", "->", "id", ")", ")", ";", "}", "}", "}" ]
This function detects errors in the ordering between 2 pages and updates the page records. @param stdClass $page1 Either the first of 2 pages or null if the $page2 param is the first in the list. @param stdClass $page1 Either the second of 2 pages or null if the $page1 param is the last in the list.
[ "This", "function", "detects", "errors", "in", "the", "ordering", "between", "2", "pages", "and", "updates", "the", "page", "records", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/lesson/locallib.php#L5151-L5177
214,532
moodle/moodle
mod/lesson/locallib.php
lesson_page_type_manager.load_all_pages
public function load_all_pages(lesson $lesson) { global $DB; if (!($pages =$DB->get_records('lesson_pages', array('lessonid'=>$lesson->id)))) { return array(); // Records returned empty. } foreach ($pages as $key=>$page) { $pagetype = get_class($this->types[$page->qtype]); $pages[$key] = new $pagetype($page, $lesson); } $orderedpages = array(); $lastpageid = 0; $morepages = true; while ($morepages) { $morepages = false; foreach ($pages as $page) { if ((int)$page->prevpageid === (int)$lastpageid) { // Check for errors in page ordering and fix them on the fly. $prevpage = null; if ($lastpageid !== 0) { $prevpage = $orderedpages[$lastpageid]; } $this->check_page_order($prevpage, $page); $morepages = true; $orderedpages[$page->id] = $page; unset($pages[$page->id]); $lastpageid = $page->id; if ((int)$page->nextpageid===0) { break 2; } else { break 1; } } } } // Add remaining pages and fix the nextpageid links for each page. foreach ($pages as $page) { // Check for errors in page ordering and fix them on the fly. $prevpage = null; if ($lastpageid !== 0) { $prevpage = $orderedpages[$lastpageid]; } $this->check_page_order($prevpage, $page); $orderedpages[$page->id] = $page; unset($pages[$page->id]); $lastpageid = $page->id; } if ($lastpageid !== 0) { $this->check_page_order($orderedpages[$lastpageid], null); } return $orderedpages; }
php
public function load_all_pages(lesson $lesson) { global $DB; if (!($pages =$DB->get_records('lesson_pages', array('lessonid'=>$lesson->id)))) { return array(); // Records returned empty. } foreach ($pages as $key=>$page) { $pagetype = get_class($this->types[$page->qtype]); $pages[$key] = new $pagetype($page, $lesson); } $orderedpages = array(); $lastpageid = 0; $morepages = true; while ($morepages) { $morepages = false; foreach ($pages as $page) { if ((int)$page->prevpageid === (int)$lastpageid) { // Check for errors in page ordering and fix them on the fly. $prevpage = null; if ($lastpageid !== 0) { $prevpage = $orderedpages[$lastpageid]; } $this->check_page_order($prevpage, $page); $morepages = true; $orderedpages[$page->id] = $page; unset($pages[$page->id]); $lastpageid = $page->id; if ((int)$page->nextpageid===0) { break 2; } else { break 1; } } } } // Add remaining pages and fix the nextpageid links for each page. foreach ($pages as $page) { // Check for errors in page ordering and fix them on the fly. $prevpage = null; if ($lastpageid !== 0) { $prevpage = $orderedpages[$lastpageid]; } $this->check_page_order($prevpage, $page); $orderedpages[$page->id] = $page; unset($pages[$page->id]); $lastpageid = $page->id; } if ($lastpageid !== 0) { $this->check_page_order($orderedpages[$lastpageid], null); } return $orderedpages; }
[ "public", "function", "load_all_pages", "(", "lesson", "$", "lesson", ")", "{", "global", "$", "DB", ";", "if", "(", "!", "(", "$", "pages", "=", "$", "DB", "->", "get_records", "(", "'lesson_pages'", ",", "array", "(", "'lessonid'", "=>", "$", "lesson", "->", "id", ")", ")", ")", ")", "{", "return", "array", "(", ")", ";", "// Records returned empty.", "}", "foreach", "(", "$", "pages", "as", "$", "key", "=>", "$", "page", ")", "{", "$", "pagetype", "=", "get_class", "(", "$", "this", "->", "types", "[", "$", "page", "->", "qtype", "]", ")", ";", "$", "pages", "[", "$", "key", "]", "=", "new", "$", "pagetype", "(", "$", "page", ",", "$", "lesson", ")", ";", "}", "$", "orderedpages", "=", "array", "(", ")", ";", "$", "lastpageid", "=", "0", ";", "$", "morepages", "=", "true", ";", "while", "(", "$", "morepages", ")", "{", "$", "morepages", "=", "false", ";", "foreach", "(", "$", "pages", "as", "$", "page", ")", "{", "if", "(", "(", "int", ")", "$", "page", "->", "prevpageid", "===", "(", "int", ")", "$", "lastpageid", ")", "{", "// Check for errors in page ordering and fix them on the fly.", "$", "prevpage", "=", "null", ";", "if", "(", "$", "lastpageid", "!==", "0", ")", "{", "$", "prevpage", "=", "$", "orderedpages", "[", "$", "lastpageid", "]", ";", "}", "$", "this", "->", "check_page_order", "(", "$", "prevpage", ",", "$", "page", ")", ";", "$", "morepages", "=", "true", ";", "$", "orderedpages", "[", "$", "page", "->", "id", "]", "=", "$", "page", ";", "unset", "(", "$", "pages", "[", "$", "page", "->", "id", "]", ")", ";", "$", "lastpageid", "=", "$", "page", "->", "id", ";", "if", "(", "(", "int", ")", "$", "page", "->", "nextpageid", "===", "0", ")", "{", "break", "2", ";", "}", "else", "{", "break", "1", ";", "}", "}", "}", "}", "// Add remaining pages and fix the nextpageid links for each page.", "foreach", "(", "$", "pages", "as", "$", "page", ")", "{", "// Check for errors in page ordering and fix them on the fly.", "$", "prevpage", "=", "null", ";", "if", "(", "$", "lastpageid", "!==", "0", ")", "{", "$", "prevpage", "=", "$", "orderedpages", "[", "$", "lastpageid", "]", ";", "}", "$", "this", "->", "check_page_order", "(", "$", "prevpage", ",", "$", "page", ")", ";", "$", "orderedpages", "[", "$", "page", "->", "id", "]", "=", "$", "page", ";", "unset", "(", "$", "pages", "[", "$", "page", "->", "id", "]", ")", ";", "$", "lastpageid", "=", "$", "page", "->", "id", ";", "}", "if", "(", "$", "lastpageid", "!==", "0", ")", "{", "$", "this", "->", "check_page_order", "(", "$", "orderedpages", "[", "$", "lastpageid", "]", ",", "null", ")", ";", "}", "return", "$", "orderedpages", ";", "}" ]
This function loads ALL pages that belong to the lesson. @param lesson $lesson @return array An array of lesson_page_type_*
[ "This", "function", "loads", "ALL", "pages", "that", "belong", "to", "the", "lesson", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/lesson/locallib.php#L5185-L5239
214,533
moodle/moodle
mod/lesson/locallib.php
lesson_page_type_manager.get_add_page_type_links
public function get_add_page_type_links($previd) { global $OUTPUT; $links = array(); foreach ($this->types as $key=>$type) { if ($link = $type->add_page_link($previd)) { $links[$key] = $link; } } return $links; }
php
public function get_add_page_type_links($previd) { global $OUTPUT; $links = array(); foreach ($this->types as $key=>$type) { if ($link = $type->add_page_link($previd)) { $links[$key] = $link; } } return $links; }
[ "public", "function", "get_add_page_type_links", "(", "$", "previd", ")", "{", "global", "$", "OUTPUT", ";", "$", "links", "=", "array", "(", ")", ";", "foreach", "(", "$", "this", "->", "types", "as", "$", "key", "=>", "$", "type", ")", "{", "if", "(", "$", "link", "=", "$", "type", "->", "add_page_link", "(", "$", "previd", ")", ")", "{", "$", "links", "[", "$", "key", "]", "=", "$", "link", ";", "}", "}", "return", "$", "links", ";", "}" ]
Returns an array of links to use as add page links @param int $previd The id of the previous page @return array
[ "Returns", "an", "array", "of", "links", "to", "use", "as", "add", "page", "links" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/lesson/locallib.php#L5264-L5276
214,534
moodle/moodle
lib/google/src/Google/Utils.php
Google_Utils.normalize
public static function normalize($arr) { if (!is_array($arr)) { return array(); } $normalized = array(); foreach ($arr as $key => $val) { $normalized[strtolower($key)] = $val; } return $normalized; }
php
public static function normalize($arr) { if (!is_array($arr)) { return array(); } $normalized = array(); foreach ($arr as $key => $val) { $normalized[strtolower($key)] = $val; } return $normalized; }
[ "public", "static", "function", "normalize", "(", "$", "arr", ")", "{", "if", "(", "!", "is_array", "(", "$", "arr", ")", ")", "{", "return", "array", "(", ")", ";", "}", "$", "normalized", "=", "array", "(", ")", ";", "foreach", "(", "$", "arr", "as", "$", "key", "=>", "$", "val", ")", "{", "$", "normalized", "[", "strtolower", "(", "$", "key", ")", "]", "=", "$", "val", ";", "}", "return", "$", "normalized", ";", "}" ]
Normalize all keys in an array to lower-case. @param array $arr @return array Normalized array.
[ "Normalize", "all", "keys", "in", "an", "array", "to", "lower", "-", "case", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/google/src/Google/Utils.php#L108-L119
214,535
moodle/moodle
customfield/classes/field_controller.php
field_controller.create
public static function create(int $id, \stdClass $record = null, category_controller $category = null) : field_controller { global $DB; if ($id && $record) { // This warning really should be in persistent as well. debugging('Too many parameters, either id need to be specified or a record, but not both.', DEBUG_DEVELOPER); } if ($id) { if (!$record = $DB->get_record(field::TABLE, array('id' => $id), '*', IGNORE_MISSING)) { throw new \moodle_exception('fieldnotfound', 'core_customfield'); } } if (empty($record->categoryid)) { if (!$category) { throw new \coding_exception('Not enough parameters to initialise field_controller - unknown category'); } else { $record->categoryid = $category->get('id'); } } if (empty($record->type)) { throw new \coding_exception('Not enough parameters to initialise field_controller - unknown field type'); } $type = $record->type; if (!$category) { $category = category_controller::create($record->categoryid); } if ($category->get('id') != $record->categoryid) { throw new \coding_exception('Category of the field does not match category from the parameter'); } $customfieldtype = "\\customfield_{$type}\\field_controller"; if (!class_exists($customfieldtype) || !is_subclass_of($customfieldtype, self::class)) { throw new \moodle_exception('errorfieldtypenotfound', 'core_customfield', '', s($type)); } $fieldcontroller = new $customfieldtype(0, $record); $fieldcontroller->category = $category; $category->add_field($fieldcontroller); return $fieldcontroller; }
php
public static function create(int $id, \stdClass $record = null, category_controller $category = null) : field_controller { global $DB; if ($id && $record) { // This warning really should be in persistent as well. debugging('Too many parameters, either id need to be specified or a record, but not both.', DEBUG_DEVELOPER); } if ($id) { if (!$record = $DB->get_record(field::TABLE, array('id' => $id), '*', IGNORE_MISSING)) { throw new \moodle_exception('fieldnotfound', 'core_customfield'); } } if (empty($record->categoryid)) { if (!$category) { throw new \coding_exception('Not enough parameters to initialise field_controller - unknown category'); } else { $record->categoryid = $category->get('id'); } } if (empty($record->type)) { throw new \coding_exception('Not enough parameters to initialise field_controller - unknown field type'); } $type = $record->type; if (!$category) { $category = category_controller::create($record->categoryid); } if ($category->get('id') != $record->categoryid) { throw new \coding_exception('Category of the field does not match category from the parameter'); } $customfieldtype = "\\customfield_{$type}\\field_controller"; if (!class_exists($customfieldtype) || !is_subclass_of($customfieldtype, self::class)) { throw new \moodle_exception('errorfieldtypenotfound', 'core_customfield', '', s($type)); } $fieldcontroller = new $customfieldtype(0, $record); $fieldcontroller->category = $category; $category->add_field($fieldcontroller); return $fieldcontroller; }
[ "public", "static", "function", "create", "(", "int", "$", "id", ",", "\\", "stdClass", "$", "record", "=", "null", ",", "category_controller", "$", "category", "=", "null", ")", ":", "field_controller", "{", "global", "$", "DB", ";", "if", "(", "$", "id", "&&", "$", "record", ")", "{", "// This warning really should be in persistent as well.", "debugging", "(", "'Too many parameters, either id need to be specified or a record, but not both.'", ",", "DEBUG_DEVELOPER", ")", ";", "}", "if", "(", "$", "id", ")", "{", "if", "(", "!", "$", "record", "=", "$", "DB", "->", "get_record", "(", "field", "::", "TABLE", ",", "array", "(", "'id'", "=>", "$", "id", ")", ",", "'*'", ",", "IGNORE_MISSING", ")", ")", "{", "throw", "new", "\\", "moodle_exception", "(", "'fieldnotfound'", ",", "'core_customfield'", ")", ";", "}", "}", "if", "(", "empty", "(", "$", "record", "->", "categoryid", ")", ")", "{", "if", "(", "!", "$", "category", ")", "{", "throw", "new", "\\", "coding_exception", "(", "'Not enough parameters to initialise field_controller - unknown category'", ")", ";", "}", "else", "{", "$", "record", "->", "categoryid", "=", "$", "category", "->", "get", "(", "'id'", ")", ";", "}", "}", "if", "(", "empty", "(", "$", "record", "->", "type", ")", ")", "{", "throw", "new", "\\", "coding_exception", "(", "'Not enough parameters to initialise field_controller - unknown field type'", ")", ";", "}", "$", "type", "=", "$", "record", "->", "type", ";", "if", "(", "!", "$", "category", ")", "{", "$", "category", "=", "category_controller", "::", "create", "(", "$", "record", "->", "categoryid", ")", ";", "}", "if", "(", "$", "category", "->", "get", "(", "'id'", ")", "!=", "$", "record", "->", "categoryid", ")", "{", "throw", "new", "\\", "coding_exception", "(", "'Category of the field does not match category from the parameter'", ")", ";", "}", "$", "customfieldtype", "=", "\"\\\\customfield_{$type}\\\\field_controller\"", ";", "if", "(", "!", "class_exists", "(", "$", "customfieldtype", ")", "||", "!", "is_subclass_of", "(", "$", "customfieldtype", ",", "self", "::", "class", ")", ")", "{", "throw", "new", "\\", "moodle_exception", "(", "'errorfieldtypenotfound'", ",", "'core_customfield'", ",", "''", ",", "s", "(", "$", "type", ")", ")", ";", "}", "$", "fieldcontroller", "=", "new", "$", "customfieldtype", "(", "0", ",", "$", "record", ")", ";", "$", "fieldcontroller", "->", "category", "=", "$", "category", ";", "$", "category", "->", "add_field", "(", "$", "fieldcontroller", ")", ";", "return", "$", "fieldcontroller", ";", "}" ]
Creates an instance of field_controller Parameters $id, $record and $category can complement each other but not conflict. If $id is not specified, categoryid must be present either in $record or in $category. If $id is not specified, type must be present in $record No DB queries are performed if both $record and $category are specified. @param int $id @param \stdClass|null $record @param category_controller|null $category @return field_controller will return the instance of the class from the customfield element plugin @throws \coding_exception @throws \moodle_exception
[ "Creates", "an", "instance", "of", "field_controller" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/customfield/classes/field_controller.php#L84-L124
214,536
moodle/moodle
customfield/classes/field_controller.php
field_controller.delete
public function delete() : bool { global $DB; $DB->delete_records('customfield_data', ['fieldid' => $this->get('id')]); return $this->field->delete(); }
php
public function delete() : bool { global $DB; $DB->delete_records('customfield_data', ['fieldid' => $this->get('id')]); return $this->field->delete(); }
[ "public", "function", "delete", "(", ")", ":", "bool", "{", "global", "$", "DB", ";", "$", "DB", "->", "delete_records", "(", "'customfield_data'", ",", "[", "'fieldid'", "=>", "$", "this", "->", "get", "(", "'id'", ")", "]", ")", ";", "return", "$", "this", "->", "field", "->", "delete", "(", ")", ";", "}" ]
Delete a field and all associated data Plugins may override it if it is necessary to delete related data (such as files) Not that the delete() method from data_controller is not called here. @return bool
[ "Delete", "a", "field", "and", "all", "associated", "data" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/customfield/classes/field_controller.php#L170-L174
214,537
moodle/moodle
customfield/classes/field_controller.php
field_controller.get_configdata_property
public function get_configdata_property(string $property) { $configdata = $this->field->get('configdata'); if (!isset($configdata[$property])) { return null; } return $configdata[$property]; }
php
public function get_configdata_property(string $property) { $configdata = $this->field->get('configdata'); if (!isset($configdata[$property])) { return null; } return $configdata[$property]; }
[ "public", "function", "get_configdata_property", "(", "string", "$", "property", ")", "{", "$", "configdata", "=", "$", "this", "->", "field", "->", "get", "(", "'configdata'", ")", ";", "if", "(", "!", "isset", "(", "$", "configdata", "[", "$", "property", "]", ")", ")", "{", "return", "null", ";", "}", "return", "$", "configdata", "[", "$", "property", "]", ";", "}" ]
Get configdata property. @param string $property name of the property @return mixed
[ "Get", "configdata", "property", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/customfield/classes/field_controller.php#L209-L215
214,538
moodle/moodle
customfield/classes/field_controller.php
field_controller.get_formatted_name
public function get_formatted_name() : string { $context = $this->get_handler()->get_configuration_context(); return format_string($this->get('name'), true, ['context' => $context]); }
php
public function get_formatted_name() : string { $context = $this->get_handler()->get_configuration_context(); return format_string($this->get('name'), true, ['context' => $context]); }
[ "public", "function", "get_formatted_name", "(", ")", ":", "string", "{", "$", "context", "=", "$", "this", "->", "get_handler", "(", ")", "->", "get_configuration_context", "(", ")", ";", "return", "format_string", "(", "$", "this", "->", "get", "(", "'name'", ")", ",", "true", ",", "[", "'context'", "=>", "$", "context", "]", ")", ";", "}" ]
Returns the field name formatted according to configuration context. @return string
[ "Returns", "the", "field", "name", "formatted", "according", "to", "configuration", "context", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/customfield/classes/field_controller.php#L248-L251
214,539
moodle/moodle
tag/classes/privacy/provider.php
provider.export_item_tags
public static function export_item_tags( int $userid, \context $context, array $subcontext, string $component, string $itemtype, int $itemid, bool $onlyuser = false ) { global $DB; // Ignore mdl_tag.userid here because it only reflects the user who originally created the tag. $sql = "SELECT t.rawname FROM {tag} t INNER JOIN {tag_instance} ti ON ti.tagid = t.id WHERE ti.component = :component AND ti.itemtype = :itemtype AND ti.itemid = :itemid "; if ($onlyuser) { $sql .= "AND ti.tiuserid = :userid"; } else { $sql .= "AND (ti.tiuserid = 0 OR ti.tiuserid = :userid)"; } $params = [ 'component' => $component, 'itemtype' => $itemtype, 'itemid' => $itemid, 'userid' => $userid, ]; if ($tags = $DB->get_fieldset_sql($sql, $params)) { $writer = \core_privacy\local\request\writer::with_context($context) ->export_related_data($subcontext, 'tags', $tags); } }
php
public static function export_item_tags( int $userid, \context $context, array $subcontext, string $component, string $itemtype, int $itemid, bool $onlyuser = false ) { global $DB; // Ignore mdl_tag.userid here because it only reflects the user who originally created the tag. $sql = "SELECT t.rawname FROM {tag} t INNER JOIN {tag_instance} ti ON ti.tagid = t.id WHERE ti.component = :component AND ti.itemtype = :itemtype AND ti.itemid = :itemid "; if ($onlyuser) { $sql .= "AND ti.tiuserid = :userid"; } else { $sql .= "AND (ti.tiuserid = 0 OR ti.tiuserid = :userid)"; } $params = [ 'component' => $component, 'itemtype' => $itemtype, 'itemid' => $itemid, 'userid' => $userid, ]; if ($tags = $DB->get_fieldset_sql($sql, $params)) { $writer = \core_privacy\local\request\writer::with_context($context) ->export_related_data($subcontext, 'tags', $tags); } }
[ "public", "static", "function", "export_item_tags", "(", "int", "$", "userid", ",", "\\", "context", "$", "context", ",", "array", "$", "subcontext", ",", "string", "$", "component", ",", "string", "$", "itemtype", ",", "int", "$", "itemid", ",", "bool", "$", "onlyuser", "=", "false", ")", "{", "global", "$", "DB", ";", "// Ignore mdl_tag.userid here because it only reflects the user who originally created the tag.", "$", "sql", "=", "\"SELECT\n t.rawname\n FROM {tag} t\n INNER JOIN {tag_instance} ti ON ti.tagid = t.id\n WHERE ti.component = :component\n AND ti.itemtype = :itemtype\n AND ti.itemid = :itemid\n \"", ";", "if", "(", "$", "onlyuser", ")", "{", "$", "sql", ".=", "\"AND ti.tiuserid = :userid\"", ";", "}", "else", "{", "$", "sql", ".=", "\"AND (ti.tiuserid = 0 OR ti.tiuserid = :userid)\"", ";", "}", "$", "params", "=", "[", "'component'", "=>", "$", "component", ",", "'itemtype'", "=>", "$", "itemtype", ",", "'itemid'", "=>", "$", "itemid", ",", "'userid'", "=>", "$", "userid", ",", "]", ";", "if", "(", "$", "tags", "=", "$", "DB", "->", "get_fieldset_sql", "(", "$", "sql", ",", "$", "params", ")", ")", "{", "$", "writer", "=", "\\", "core_privacy", "\\", "local", "\\", "request", "\\", "writer", "::", "with_context", "(", "$", "context", ")", "->", "export_related_data", "(", "$", "subcontext", ",", "'tags'", ",", "$", "tags", ")", ";", "}", "}" ]
Store all tags which match the specified component, itemtype, and itemid. In most situations you will want to specify $onlyuser as false. This will fetch only tags where the user themselves set the tag, or where tags are a shared resource. If you specify $onlyuser as true, only the tags created by that user will be included. @param int $userid The user whose information is to be exported @param \context $context The context to export for @param array $subcontext The subcontext within the context to export this information @param string $component The component to fetch data from @param string $itemtype The itemtype that the data was exported in within the component @param int $itemid The itemid within that tag @param bool $onlyuser Whether to only export ratings that the current user has made, or all tags
[ "Store", "all", "tags", "which", "match", "the", "specified", "component", "itemtype", "and", "itemid", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/tag/classes/privacy/provider.php#L117-L155
214,540
moodle/moodle
tag/classes/privacy/provider.php
provider.delete_item_tags
public static function delete_item_tags(\context $context, $component, $itemtype, $itemid = null, $userid = null) { global $DB; $params = ['contextid' => $context->id, 'component' => $component, 'itemtype' => $itemtype]; if ($itemid) { $params['itemid'] = $itemid; } if ($userid) { $params['tiuserid'] = $userid; } $DB->delete_records('tag_instance', $params); }
php
public static function delete_item_tags(\context $context, $component, $itemtype, $itemid = null, $userid = null) { global $DB; $params = ['contextid' => $context->id, 'component' => $component, 'itemtype' => $itemtype]; if ($itemid) { $params['itemid'] = $itemid; } if ($userid) { $params['tiuserid'] = $userid; } $DB->delete_records('tag_instance', $params); }
[ "public", "static", "function", "delete_item_tags", "(", "\\", "context", "$", "context", ",", "$", "component", ",", "$", "itemtype", ",", "$", "itemid", "=", "null", ",", "$", "userid", "=", "null", ")", "{", "global", "$", "DB", ";", "$", "params", "=", "[", "'contextid'", "=>", "$", "context", "->", "id", ",", "'component'", "=>", "$", "component", ",", "'itemtype'", "=>", "$", "itemtype", "]", ";", "if", "(", "$", "itemid", ")", "{", "$", "params", "[", "'itemid'", "]", "=", "$", "itemid", ";", "}", "if", "(", "$", "userid", ")", "{", "$", "params", "[", "'tiuserid'", "]", "=", "$", "userid", ";", "}", "$", "DB", "->", "delete_records", "(", "'tag_instance'", ",", "$", "params", ")", ";", "}" ]
Deletes all tag instances for given context, component, itemtype, itemid In most situations you will want to specify $userid as null. Per-user tag instances are possible in Tags API, however there are no components or standard plugins that actually use them. @param \context $context The context to export for @param string $component Tagarea component @param string $itemtype Tagarea item type @param int $itemid The itemid within that component and itemtype (optional) @param int $userid Only delete tag instances made by this user, per-user tags must be enabled for the tagarea
[ "Deletes", "all", "tag", "instances", "for", "given", "context", "component", "itemtype", "itemid" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/tag/classes/privacy/provider.php#L169-L180
214,541
moodle/moodle
question/type/gapselect/rendererbase.php
qtype_elements_embedded_in_question_text_renderer.get_fragments_glue_placeholders
protected function get_fragments_glue_placeholders($fragments) { $fragmentscount = count($fragments); if ($fragmentscount <= 1) { return []; } $prefix = '[[$'; $postfix = ']]'; $text = join('', $fragments); while (preg_match('/' . preg_quote($prefix, '/') . '\\d+' . preg_quote($postfix, '/') . '/', $text)) { $prefix .= '$'; } $glues = []; for ($i = 1; $i < $fragmentscount; $i++) { $glues[$i] = $prefix . $i . $postfix; } return $glues; }
php
protected function get_fragments_glue_placeholders($fragments) { $fragmentscount = count($fragments); if ($fragmentscount <= 1) { return []; } $prefix = '[[$'; $postfix = ']]'; $text = join('', $fragments); while (preg_match('/' . preg_quote($prefix, '/') . '\\d+' . preg_quote($postfix, '/') . '/', $text)) { $prefix .= '$'; } $glues = []; for ($i = 1; $i < $fragmentscount; $i++) { $glues[$i] = $prefix . $i . $postfix; } return $glues; }
[ "protected", "function", "get_fragments_glue_placeholders", "(", "$", "fragments", ")", "{", "$", "fragmentscount", "=", "count", "(", "$", "fragments", ")", ";", "if", "(", "$", "fragmentscount", "<=", "1", ")", "{", "return", "[", "]", ";", "}", "$", "prefix", "=", "'[[$'", ";", "$", "postfix", "=", "']]'", ";", "$", "text", "=", "join", "(", "''", ",", "$", "fragments", ")", ";", "while", "(", "preg_match", "(", "'/'", ".", "preg_quote", "(", "$", "prefix", ",", "'/'", ")", ".", "'\\\\d+'", ".", "preg_quote", "(", "$", "postfix", ",", "'/'", ")", ".", "'/'", ",", "$", "text", ")", ")", "{", "$", "prefix", ".=", "'$'", ";", "}", "$", "glues", "=", "[", "]", ";", "for", "(", "$", "i", "=", "1", ";", "$", "i", "<", "$", "fragmentscount", ";", "$", "i", "++", ")", "{", "$", "glues", "[", "$", "i", "]", "=", "$", "prefix", ".", "$", "i", ".", "$", "postfix", ";", "}", "return", "$", "glues", ";", "}" ]
Find strings that we can use to glue the fragments with These strings have to be all different and neither of them can be present in the text @param array $fragments @return array array with indexes from 1 to count($fragments)-1
[ "Find", "strings", "that", "we", "can", "use", "to", "glue", "the", "fragments", "with" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/type/gapselect/rendererbase.php#L87-L103
214,542
moodle/moodle
mod/choice/classes/event/answer_created.php
answer_created.create_from_object
public static function create_from_object($choiceanswer, $choice, $cm, $course) { global $USER; $eventdata = array(); $eventdata['objectid'] = $choiceanswer->id; $eventdata['context'] = \context_module::instance($cm->id); $eventdata['userid'] = $USER->id; $eventdata['courseid'] = $course->id; $eventdata['relateduserid'] = $choiceanswer->userid; $eventdata['other'] = array(); $eventdata['other']['choiceid'] = $choice->id; $eventdata['other']['optionid'] = $choiceanswer->optionid; $event = self::create($eventdata); $event->add_record_snapshot('course', $course); $event->add_record_snapshot('course_modules', $cm); $event->add_record_snapshot('choice', $choice); $event->add_record_snapshot('choice_answers', $choiceanswer); return $event; }
php
public static function create_from_object($choiceanswer, $choice, $cm, $course) { global $USER; $eventdata = array(); $eventdata['objectid'] = $choiceanswer->id; $eventdata['context'] = \context_module::instance($cm->id); $eventdata['userid'] = $USER->id; $eventdata['courseid'] = $course->id; $eventdata['relateduserid'] = $choiceanswer->userid; $eventdata['other'] = array(); $eventdata['other']['choiceid'] = $choice->id; $eventdata['other']['optionid'] = $choiceanswer->optionid; $event = self::create($eventdata); $event->add_record_snapshot('course', $course); $event->add_record_snapshot('course_modules', $cm); $event->add_record_snapshot('choice', $choice); $event->add_record_snapshot('choice_answers', $choiceanswer); return $event; }
[ "public", "static", "function", "create_from_object", "(", "$", "choiceanswer", ",", "$", "choice", ",", "$", "cm", ",", "$", "course", ")", "{", "global", "$", "USER", ";", "$", "eventdata", "=", "array", "(", ")", ";", "$", "eventdata", "[", "'objectid'", "]", "=", "$", "choiceanswer", "->", "id", ";", "$", "eventdata", "[", "'context'", "]", "=", "\\", "context_module", "::", "instance", "(", "$", "cm", "->", "id", ")", ";", "$", "eventdata", "[", "'userid'", "]", "=", "$", "USER", "->", "id", ";", "$", "eventdata", "[", "'courseid'", "]", "=", "$", "course", "->", "id", ";", "$", "eventdata", "[", "'relateduserid'", "]", "=", "$", "choiceanswer", "->", "userid", ";", "$", "eventdata", "[", "'other'", "]", "=", "array", "(", ")", ";", "$", "eventdata", "[", "'other'", "]", "[", "'choiceid'", "]", "=", "$", "choice", "->", "id", ";", "$", "eventdata", "[", "'other'", "]", "[", "'optionid'", "]", "=", "$", "choiceanswer", "->", "optionid", ";", "$", "event", "=", "self", "::", "create", "(", "$", "eventdata", ")", ";", "$", "event", "->", "add_record_snapshot", "(", "'course'", ",", "$", "course", ")", ";", "$", "event", "->", "add_record_snapshot", "(", "'course_modules'", ",", "$", "cm", ")", ";", "$", "event", "->", "add_record_snapshot", "(", "'choice'", ",", "$", "choice", ")", ";", "$", "event", "->", "add_record_snapshot", "(", "'choice_answers'", ",", "$", "choiceanswer", ")", ";", "return", "$", "event", ";", "}" ]
Creates an instance of the event from the records @param stdClass $choiceanswer record from 'choice_answers' table @param stdClass $choice record from 'choice' table @param stdClass $cm record from 'course_modules' table @param stdClass $course @return self
[ "Creates", "an", "instance", "of", "the", "event", "from", "the", "records" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/choice/classes/event/answer_created.php#L55-L72
214,543
moodle/moodle
grade/grading/form/guide/backup/moodle2/restore_gradingform_guide_plugin.class.php
restore_gradingform_guide_plugin.define_definition_plugin_structure
protected function define_definition_plugin_structure() { $paths = array(); $paths[] = new restore_path_element('gradingform_guide_criterion', $this->get_pathfor('/guidecriteria/guidecriterion')); $paths[] = new restore_path_element('gradingform_guide_comment', $this->get_pathfor('/guidecomments/guidecomment')); // MDL-37714: Correctly locate frequent used comments in both the // current and incorrect old format. $paths[] = new restore_path_element('gradingform_guide_comment_legacy', $this->get_pathfor('/guidecriteria/guidecomments/guidecomment')); return $paths; }
php
protected function define_definition_plugin_structure() { $paths = array(); $paths[] = new restore_path_element('gradingform_guide_criterion', $this->get_pathfor('/guidecriteria/guidecriterion')); $paths[] = new restore_path_element('gradingform_guide_comment', $this->get_pathfor('/guidecomments/guidecomment')); // MDL-37714: Correctly locate frequent used comments in both the // current and incorrect old format. $paths[] = new restore_path_element('gradingform_guide_comment_legacy', $this->get_pathfor('/guidecriteria/guidecomments/guidecomment')); return $paths; }
[ "protected", "function", "define_definition_plugin_structure", "(", ")", "{", "$", "paths", "=", "array", "(", ")", ";", "$", "paths", "[", "]", "=", "new", "restore_path_element", "(", "'gradingform_guide_criterion'", ",", "$", "this", "->", "get_pathfor", "(", "'/guidecriteria/guidecriterion'", ")", ")", ";", "$", "paths", "[", "]", "=", "new", "restore_path_element", "(", "'gradingform_guide_comment'", ",", "$", "this", "->", "get_pathfor", "(", "'/guidecomments/guidecomment'", ")", ")", ";", "// MDL-37714: Correctly locate frequent used comments in both the", "// current and incorrect old format.", "$", "paths", "[", "]", "=", "new", "restore_path_element", "(", "'gradingform_guide_comment_legacy'", ",", "$", "this", "->", "get_pathfor", "(", "'/guidecriteria/guidecomments/guidecomment'", ")", ")", ";", "return", "$", "paths", ";", "}" ]
Declares the marking guide XML paths attached to the form definition element @return array of {@link restore_path_element}
[ "Declares", "the", "marking", "guide", "XML", "paths", "attached", "to", "the", "form", "definition", "element" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/grade/grading/form/guide/backup/moodle2/restore_gradingform_guide_plugin.class.php#L41-L57
214,544
moodle/moodle
grade/grading/form/guide/backup/moodle2/restore_gradingform_guide_plugin.class.php
restore_gradingform_guide_plugin.process_gradingform_guide_criterion
public function process_gradingform_guide_criterion($data) { global $DB; $data = (object)$data; $oldid = $data->id; $data->definitionid = $this->get_new_parentid('grading_definition'); $newid = $DB->insert_record('gradingform_guide_criteria', $data); $this->set_mapping('gradingform_guide_criterion', $oldid, $newid); }
php
public function process_gradingform_guide_criterion($data) { global $DB; $data = (object)$data; $oldid = $data->id; $data->definitionid = $this->get_new_parentid('grading_definition'); $newid = $DB->insert_record('gradingform_guide_criteria', $data); $this->set_mapping('gradingform_guide_criterion', $oldid, $newid); }
[ "public", "function", "process_gradingform_guide_criterion", "(", "$", "data", ")", "{", "global", "$", "DB", ";", "$", "data", "=", "(", "object", ")", "$", "data", ";", "$", "oldid", "=", "$", "data", "->", "id", ";", "$", "data", "->", "definitionid", "=", "$", "this", "->", "get_new_parentid", "(", "'grading_definition'", ")", ";", "$", "newid", "=", "$", "DB", "->", "insert_record", "(", "'gradingform_guide_criteria'", ",", "$", "data", ")", ";", "$", "this", "->", "set_mapping", "(", "'gradingform_guide_criterion'", ",", "$", "oldid", ",", "$", "newid", ")", ";", "}" ]
Processes criterion element data Sets the mapping 'gradingform_guide_criterion' to be used later by {@link self::process_gradinform_guide_filling()} @param array|stdClass $data
[ "Processes", "criterion", "element", "data" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/grade/grading/form/guide/backup/moodle2/restore_gradingform_guide_plugin.class.php#L82-L91
214,545
moodle/moodle
question/engine/lib.php
question_engine.is_manual_grade_in_range
public static function is_manual_grade_in_range($qubaid, $slot) { $prefix = 'q' . $qubaid . ':' . $slot . '_'; $mark = question_utils::optional_param_mark($prefix . '-mark'); $maxmark = optional_param($prefix . '-maxmark', null, PARAM_FLOAT); $minfraction = optional_param($prefix . ':minfraction', null, PARAM_FLOAT); $maxfraction = optional_param($prefix . ':maxfraction', null, PARAM_FLOAT); return $mark === '' || ($mark !== null && $mark >= $minfraction * $maxmark && $mark <= $maxfraction * $maxmark) || ($mark === null && $maxmark === null); }
php
public static function is_manual_grade_in_range($qubaid, $slot) { $prefix = 'q' . $qubaid . ':' . $slot . '_'; $mark = question_utils::optional_param_mark($prefix . '-mark'); $maxmark = optional_param($prefix . '-maxmark', null, PARAM_FLOAT); $minfraction = optional_param($prefix . ':minfraction', null, PARAM_FLOAT); $maxfraction = optional_param($prefix . ':maxfraction', null, PARAM_FLOAT); return $mark === '' || ($mark !== null && $mark >= $minfraction * $maxmark && $mark <= $maxfraction * $maxmark) || ($mark === null && $maxmark === null); }
[ "public", "static", "function", "is_manual_grade_in_range", "(", "$", "qubaid", ",", "$", "slot", ")", "{", "$", "prefix", "=", "'q'", ".", "$", "qubaid", ".", "':'", ".", "$", "slot", ".", "'_'", ";", "$", "mark", "=", "question_utils", "::", "optional_param_mark", "(", "$", "prefix", ".", "'-mark'", ")", ";", "$", "maxmark", "=", "optional_param", "(", "$", "prefix", ".", "'-maxmark'", ",", "null", ",", "PARAM_FLOAT", ")", ";", "$", "minfraction", "=", "optional_param", "(", "$", "prefix", ".", "':minfraction'", ",", "null", ",", "PARAM_FLOAT", ")", ";", "$", "maxfraction", "=", "optional_param", "(", "$", "prefix", ".", "':maxfraction'", ",", "null", ",", "PARAM_FLOAT", ")", ";", "return", "$", "mark", "===", "''", "||", "(", "$", "mark", "!==", "null", "&&", "$", "mark", ">=", "$", "minfraction", "*", "$", "maxmark", "&&", "$", "mark", "<=", "$", "maxfraction", "*", "$", "maxmark", ")", "||", "(", "$", "mark", "===", "null", "&&", "$", "maxmark", "===", "null", ")", ";", "}" ]
Validate that the manual grade submitted for a particular question is in range. @param int $qubaid the question_usage id. @param int $slot the slot number within the usage. @return bool whether the submitted data is in range.
[ "Validate", "that", "the", "manual", "grade", "submitted", "for", "a", "particular", "question", "is", "in", "range", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/engine/lib.php#L140-L149
214,546
moodle/moodle
question/engine/lib.php
question_display_options.get_dp_options
public static function get_dp_options() { $options = array(); for ($i = 0; $i <= self::MAX_DP; $i += 1) { $options[$i] = $i; } return $options; }
php
public static function get_dp_options() { $options = array(); for ($i = 0; $i <= self::MAX_DP; $i += 1) { $options[$i] = $i; } return $options; }
[ "public", "static", "function", "get_dp_options", "(", ")", "{", "$", "options", "=", "array", "(", ")", ";", "for", "(", "$", "i", "=", "0", ";", "$", "i", "<=", "self", "::", "MAX_DP", ";", "$", "i", "+=", "1", ")", "{", "$", "options", "[", "$", "i", "]", "=", "$", "i", ";", "}", "return", "$", "options", ";", "}" ]
Returns the valid choices for the number of decimal places for showing question marks. For use in the user interface. Calling code should probably use {@link question_engine::get_dp_options()} rather than calling this method directly. @return array suitable for passing to {@link html_writer::select()} or similar.
[ "Returns", "the", "valid", "choices", "for", "the", "number", "of", "decimal", "places", "for", "showing", "question", "marks", ".", "For", "use", "in", "the", "user", "interface", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/engine/lib.php#L655-L661
214,547
moodle/moodle
question/engine/lib.php
question_flags.get_toggle_checksum
protected static function get_toggle_checksum($qubaid, $questionid, $qaid, $slot, $user = null) { if (is_null($user)) { global $USER; $user = $USER; } return md5($qubaid . "_" . $user->secret . "_" . $questionid . "_" . $qaid . "_" . $slot); }
php
protected static function get_toggle_checksum($qubaid, $questionid, $qaid, $slot, $user = null) { if (is_null($user)) { global $USER; $user = $USER; } return md5($qubaid . "_" . $user->secret . "_" . $questionid . "_" . $qaid . "_" . $slot); }
[ "protected", "static", "function", "get_toggle_checksum", "(", "$", "qubaid", ",", "$", "questionid", ",", "$", "qaid", ",", "$", "slot", ",", "$", "user", "=", "null", ")", "{", "if", "(", "is_null", "(", "$", "user", ")", ")", "{", "global", "$", "USER", ";", "$", "user", "=", "$", "USER", ";", "}", "return", "md5", "(", "$", "qubaid", ".", "\"_\"", ".", "$", "user", "->", "secret", ".", "\"_\"", ".", "$", "questionid", ".", "\"_\"", ".", "$", "qaid", ".", "\"_\"", ".", "$", "slot", ")", ";", "}" ]
Get the checksum that validates that a toggle request is valid. @param int $qubaid the question usage id. @param int $questionid the question id. @param int $sessionid the question_attempt id. @param object $user the user. If null, defaults to $USER. @return string that needs to be sent to question/toggleflag.php for it to work.
[ "Get", "the", "checksum", "that", "validates", "that", "a", "toggle", "request", "is", "valid", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/engine/lib.php#L680-L687
214,548
moodle/moodle
question/engine/lib.php
question_flags.update_flag
public static function update_flag($qubaid, $questionid, $qaid, $slot, $checksum, $newstate) { // Check the checksum - it is very hard to know who a question session belongs // to, so we require that checksum parameter is matches an md5 hash of the // three ids and the users username. Since we are only updating a flag, that // probably makes it sufficiently difficult for malicious users to toggle // other users flags. if ($checksum != self::get_toggle_checksum($qubaid, $questionid, $qaid, $slot)) { throw new moodle_exception('errorsavingflags', 'question'); } $dm = new question_engine_data_mapper(); $dm->update_question_attempt_flag($qubaid, $questionid, $qaid, $slot, $newstate); }
php
public static function update_flag($qubaid, $questionid, $qaid, $slot, $checksum, $newstate) { // Check the checksum - it is very hard to know who a question session belongs // to, so we require that checksum parameter is matches an md5 hash of the // three ids and the users username. Since we are only updating a flag, that // probably makes it sufficiently difficult for malicious users to toggle // other users flags. if ($checksum != self::get_toggle_checksum($qubaid, $questionid, $qaid, $slot)) { throw new moodle_exception('errorsavingflags', 'question'); } $dm = new question_engine_data_mapper(); $dm->update_question_attempt_flag($qubaid, $questionid, $qaid, $slot, $newstate); }
[ "public", "static", "function", "update_flag", "(", "$", "qubaid", ",", "$", "questionid", ",", "$", "qaid", ",", "$", "slot", ",", "$", "checksum", ",", "$", "newstate", ")", "{", "// Check the checksum - it is very hard to know who a question session belongs", "// to, so we require that checksum parameter is matches an md5 hash of the", "// three ids and the users username. Since we are only updating a flag, that", "// probably makes it sufficiently difficult for malicious users to toggle", "// other users flags.", "if", "(", "$", "checksum", "!=", "self", "::", "get_toggle_checksum", "(", "$", "qubaid", ",", "$", "questionid", ",", "$", "qaid", ",", "$", "slot", ")", ")", "{", "throw", "new", "moodle_exception", "(", "'errorsavingflags'", ",", "'question'", ")", ";", "}", "$", "dm", "=", "new", "question_engine_data_mapper", "(", ")", ";", "$", "dm", "->", "update_question_attempt_flag", "(", "$", "qubaid", ",", "$", "questionid", ",", "$", "qaid", ",", "$", "slot", ",", "$", "newstate", ")", ";", "}" ]
If the request seems valid, update the flag state of a question attempt. Throws exceptions if this is not a valid update request. @param int $qubaid the question usage id. @param int $questionid the question id. @param int $sessionid the question_attempt id. @param string $checksum checksum, as computed by {@link get_toggle_checksum()} corresponding to the last three arguments. @param bool $newstate the new state of the flag. true = flagged.
[ "If", "the", "request", "seems", "valid", "update", "the", "flag", "state", "of", "a", "question", "attempt", ".", "Throws", "exceptions", "if", "this", "is", "not", "a", "valid", "update", "request", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/engine/lib.php#L714-L726
214,549
moodle/moodle
question/engine/lib.php
question_utils.int_to_roman
public static function int_to_roman($number) { if (!is_integer($number) || $number < 1 || $number > 3999) { throw new coding_exception('Only integers between 0 and 3999 can be ' . 'converted to roman numerals.', $number); } return self::$thousands[$number / 1000 % 10] . self::$hundreds[$number / 100 % 10] . self::$tens[$number / 10 % 10] . self::$units[$number % 10]; }
php
public static function int_to_roman($number) { if (!is_integer($number) || $number < 1 || $number > 3999) { throw new coding_exception('Only integers between 0 and 3999 can be ' . 'converted to roman numerals.', $number); } return self::$thousands[$number / 1000 % 10] . self::$hundreds[$number / 100 % 10] . self::$tens[$number / 10 % 10] . self::$units[$number % 10]; }
[ "public", "static", "function", "int_to_roman", "(", "$", "number", ")", "{", "if", "(", "!", "is_integer", "(", "$", "number", ")", "||", "$", "number", "<", "1", "||", "$", "number", ">", "3999", ")", "{", "throw", "new", "coding_exception", "(", "'Only integers between 0 and 3999 can be '", ".", "'converted to roman numerals.'", ",", "$", "number", ")", ";", "}", "return", "self", "::", "$", "thousands", "[", "$", "number", "/", "1000", "%", "10", "]", ".", "self", "::", "$", "hundreds", "[", "$", "number", "/", "100", "%", "10", "]", ".", "self", "::", "$", "tens", "[", "$", "number", "/", "10", "%", "10", "]", ".", "self", "::", "$", "units", "[", "$", "number", "%", "10", "]", ";", "}" ]
Convert an integer to roman numerals. @param int $number an integer between 1 and 3999 inclusive. Anything else will throw an exception. @return string the number converted to lower case roman numerals.
[ "Convert", "an", "integer", "to", "roman", "numerals", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/engine/lib.php#L898-L906
214,550
moodle/moodle
question/engine/lib.php
question_utils.int_to_letter
public static function int_to_letter($number) { $alphabet = [ '1' => 'A', '2' => 'B', '3' => 'C', '4' => 'D', '5' => 'E', '6' => 'F', '7' => 'G', '8' => 'H', '9' => 'I', '10' => 'J', '11' => 'K', '12' => 'L', '13' => 'M', '14' => 'N', '15' => 'O', '16' => 'P', '17' => 'Q', '18' => 'R', '19' => 'S', '20' => 'T', '21' => 'U', '22' => 'V', '23' => 'W', '24' => 'X', '25' => 'Y', '26' => 'Z' ]; if (!is_integer($number) || $number < 1 || $number > count($alphabet)) { throw new coding_exception('Only integers between 1 and 26 can be converted to letters.', $number); } return $alphabet[$number]; }
php
public static function int_to_letter($number) { $alphabet = [ '1' => 'A', '2' => 'B', '3' => 'C', '4' => 'D', '5' => 'E', '6' => 'F', '7' => 'G', '8' => 'H', '9' => 'I', '10' => 'J', '11' => 'K', '12' => 'L', '13' => 'M', '14' => 'N', '15' => 'O', '16' => 'P', '17' => 'Q', '18' => 'R', '19' => 'S', '20' => 'T', '21' => 'U', '22' => 'V', '23' => 'W', '24' => 'X', '25' => 'Y', '26' => 'Z' ]; if (!is_integer($number) || $number < 1 || $number > count($alphabet)) { throw new coding_exception('Only integers between 1 and 26 can be converted to letters.', $number); } return $alphabet[$number]; }
[ "public", "static", "function", "int_to_letter", "(", "$", "number", ")", "{", "$", "alphabet", "=", "[", "'1'", "=>", "'A'", ",", "'2'", "=>", "'B'", ",", "'3'", "=>", "'C'", ",", "'4'", "=>", "'D'", ",", "'5'", "=>", "'E'", ",", "'6'", "=>", "'F'", ",", "'7'", "=>", "'G'", ",", "'8'", "=>", "'H'", ",", "'9'", "=>", "'I'", ",", "'10'", "=>", "'J'", ",", "'11'", "=>", "'K'", ",", "'12'", "=>", "'L'", ",", "'13'", "=>", "'M'", ",", "'14'", "=>", "'N'", ",", "'15'", "=>", "'O'", ",", "'16'", "=>", "'P'", ",", "'17'", "=>", "'Q'", ",", "'18'", "=>", "'R'", ",", "'19'", "=>", "'S'", ",", "'20'", "=>", "'T'", ",", "'21'", "=>", "'U'", ",", "'22'", "=>", "'V'", ",", "'23'", "=>", "'W'", ",", "'24'", "=>", "'X'", ",", "'25'", "=>", "'Y'", ",", "'26'", "=>", "'Z'", "]", ";", "if", "(", "!", "is_integer", "(", "$", "number", ")", "||", "$", "number", "<", "1", "||", "$", "number", ">", "count", "(", "$", "alphabet", ")", ")", "{", "throw", "new", "coding_exception", "(", "'Only integers between 1 and 26 can be converted to letters.'", ",", "$", "number", ")", ";", "}", "return", "$", "alphabet", "[", "$", "number", "]", ";", "}" ]
Convert an integer to a letter of alphabet. @param int $number an integer between 1 and 26 inclusive. Anything else will throw an exception. @return string the number converted to upper case letter of alphabet.
[ "Convert", "an", "integer", "to", "a", "letter", "of", "alphabet", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/engine/lib.php#L914-L947
214,551
moodle/moodle
question/engine/lib.php
question_utils.to_plain_text
public static function to_plain_text($text, $format, $options = array('noclean' => 'true')) { // The following call to html_to_text uses the option that strips out // all URLs, but format_text complains if it finds @@PLUGINFILE@@ tokens. // So, we need to replace @@PLUGINFILE@@ with a real URL, but it doesn't // matter what. We use http://example.com/. $text = str_replace('@@PLUGINFILE@@/', 'http://example.com/', $text); return html_to_text(format_text($text, $format, $options), 0, false); }
php
public static function to_plain_text($text, $format, $options = array('noclean' => 'true')) { // The following call to html_to_text uses the option that strips out // all URLs, but format_text complains if it finds @@PLUGINFILE@@ tokens. // So, we need to replace @@PLUGINFILE@@ with a real URL, but it doesn't // matter what. We use http://example.com/. $text = str_replace('@@PLUGINFILE@@/', 'http://example.com/', $text); return html_to_text(format_text($text, $format, $options), 0, false); }
[ "public", "static", "function", "to_plain_text", "(", "$", "text", ",", "$", "format", ",", "$", "options", "=", "array", "(", "'noclean'", "=>", "'true'", ")", ")", "{", "// The following call to html_to_text uses the option that strips out", "// all URLs, but format_text complains if it finds @@PLUGINFILE@@ tokens.", "// So, we need to replace @@PLUGINFILE@@ with a real URL, but it doesn't", "// matter what. We use http://example.com/.", "$", "text", "=", "str_replace", "(", "'@@PLUGINFILE@@/'", ",", "'http://example.com/'", ",", "$", "text", ")", ";", "return", "html_to_text", "(", "format_text", "(", "$", "text", ",", "$", "format", ",", "$", "options", ")", ",", "0", ",", "false", ")", ";", "}" ]
Convert part of some question content to plain text. @param string $text the text. @param int $format the text format. @param array $options formatting options. Passed to {@link format_text}. @return float|string|null cleaned mark as a float if possible. Otherwise '' or null.
[ "Convert", "part", "of", "some", "question", "content", "to", "plain", "text", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/engine/lib.php#L990-L997
214,552
moodle/moodle
question/engine/lib.php
question_utils.get_filepicker_options
public static function get_filepicker_options($context, $draftitemid) { return [ 'image' => self::specific_filepicker_options(['image'], $draftitemid, $context), 'media' => self::specific_filepicker_options(['video', 'audio'], $draftitemid, $context), 'link' => self::specific_filepicker_options('*', $draftitemid, $context), ]; }
php
public static function get_filepicker_options($context, $draftitemid) { return [ 'image' => self::specific_filepicker_options(['image'], $draftitemid, $context), 'media' => self::specific_filepicker_options(['video', 'audio'], $draftitemid, $context), 'link' => self::specific_filepicker_options('*', $draftitemid, $context), ]; }
[ "public", "static", "function", "get_filepicker_options", "(", "$", "context", ",", "$", "draftitemid", ")", "{", "return", "[", "'image'", "=>", "self", "::", "specific_filepicker_options", "(", "[", "'image'", "]", ",", "$", "draftitemid", ",", "$", "context", ")", ",", "'media'", "=>", "self", "::", "specific_filepicker_options", "(", "[", "'video'", ",", "'audio'", "]", ",", "$", "draftitemid", ",", "$", "context", ")", ",", "'link'", "=>", "self", "::", "specific_filepicker_options", "(", "'*'", ",", "$", "draftitemid", ",", "$", "context", ")", ",", "]", ";", "}" ]
Get filepicker options for question related text areas. @param object $context the context. @param int $draftitemid the draft area item id. @return array An array of options
[ "Get", "filepicker", "options", "for", "question", "related", "text", "areas", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/engine/lib.php#L1029-L1035
214,553
moodle/moodle
question/engine/lib.php
question_utils.get_editor_options
public static function get_editor_options($context) { global $CFG; $editoroptions = [ 'subdirs' => 0, 'context' => $context, 'maxfiles' => EDITOR_UNLIMITED_FILES, 'maxbytes' => $CFG->maxbytes, 'noclean' => 0, 'trusttext' => 0, 'autosave' => false ]; return $editoroptions; }
php
public static function get_editor_options($context) { global $CFG; $editoroptions = [ 'subdirs' => 0, 'context' => $context, 'maxfiles' => EDITOR_UNLIMITED_FILES, 'maxbytes' => $CFG->maxbytes, 'noclean' => 0, 'trusttext' => 0, 'autosave' => false ]; return $editoroptions; }
[ "public", "static", "function", "get_editor_options", "(", "$", "context", ")", "{", "global", "$", "CFG", ";", "$", "editoroptions", "=", "[", "'subdirs'", "=>", "0", ",", "'context'", "=>", "$", "context", ",", "'maxfiles'", "=>", "EDITOR_UNLIMITED_FILES", ",", "'maxbytes'", "=>", "$", "CFG", "->", "maxbytes", ",", "'noclean'", "=>", "0", ",", "'trusttext'", "=>", "0", ",", "'autosave'", "=>", "false", "]", ";", "return", "$", "editoroptions", ";", "}" ]
Get editor options for question related text areas. @param object $context the context. @return array An array of options
[ "Get", "editor", "options", "for", "question", "related", "text", "areas", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/engine/lib.php#L1042-L1056
214,554
moodle/moodle
mod/scorm/datamodels/scormlib.php
xml2Array.parse
public function parse($strinputxml) { $this->resparser = xml_parser_create ('UTF-8'); xml_set_object($this->resparser, $this); xml_set_element_handler($this->resparser, "tagopen", "tagclosed"); xml_set_character_data_handler($this->resparser, "tagdata"); $this->strxmldata = xml_parse($this->resparser, $strinputxml ); if (!$this->strxmldata) { die(sprintf("XML error: %s at line %d", xml_error_string(xml_get_error_code($this->resparser)), xml_get_current_line_number($this->resparser))); } xml_parser_free($this->resparser); return $this->arroutput; }
php
public function parse($strinputxml) { $this->resparser = xml_parser_create ('UTF-8'); xml_set_object($this->resparser, $this); xml_set_element_handler($this->resparser, "tagopen", "tagclosed"); xml_set_character_data_handler($this->resparser, "tagdata"); $this->strxmldata = xml_parse($this->resparser, $strinputxml ); if (!$this->strxmldata) { die(sprintf("XML error: %s at line %d", xml_error_string(xml_get_error_code($this->resparser)), xml_get_current_line_number($this->resparser))); } xml_parser_free($this->resparser); return $this->arroutput; }
[ "public", "function", "parse", "(", "$", "strinputxml", ")", "{", "$", "this", "->", "resparser", "=", "xml_parser_create", "(", "'UTF-8'", ")", ";", "xml_set_object", "(", "$", "this", "->", "resparser", ",", "$", "this", ")", ";", "xml_set_element_handler", "(", "$", "this", "->", "resparser", ",", "\"tagopen\"", ",", "\"tagclosed\"", ")", ";", "xml_set_character_data_handler", "(", "$", "this", "->", "resparser", ",", "\"tagdata\"", ")", ";", "$", "this", "->", "strxmldata", "=", "xml_parse", "(", "$", "this", "->", "resparser", ",", "$", "strinputxml", ")", ";", "if", "(", "!", "$", "this", "->", "strxmldata", ")", "{", "die", "(", "sprintf", "(", "\"XML error: %s at line %d\"", ",", "xml_error_string", "(", "xml_get_error_code", "(", "$", "this", "->", "resparser", ")", ")", ",", "xml_get_current_line_number", "(", "$", "this", "->", "resparser", ")", ")", ")", ";", "}", "xml_parser_free", "(", "$", "this", "->", "resparser", ")", ";", "return", "$", "this", "->", "arroutput", ";", "}" ]
Parse an XML text string and create an array tree that rapresent the XML structure @param string $strinputxml The XML string @return array
[ "Parse", "an", "XML", "text", "string", "and", "create", "an", "array", "tree", "that", "rapresent", "the", "XML", "structure" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/scorm/datamodels/scormlib.php#L917-L934
214,555
moodle/moodle
lib/filebrowser/file_info_context_user.php
file_info_context_user.get_area_user_private
protected function get_area_user_private($itemid, $filepath, $filename) { global $USER, $CFG; // access control: only my files, nobody else if ($this->user->id != $USER->id) { return null; } if (is_null($itemid)) { // go to parent, we do not use itemids here in private area return $this; } $fs = get_file_storage(); $filepath = is_null($filepath) ? '/' : $filepath; $filename = is_null($filename) ? '.' : $filename; if (!$storedfile = $fs->get_file($this->context->id, 'user', 'private', 0, $filepath, $filename)) { if ($filepath === '/' and $filename === '.') { // root dir does not exist yet $storedfile = new virtual_root_file($this->context->id, 'user', 'private', 0); } else { // not found return null; } } $urlbase = $CFG->wwwroot.'/pluginfile.php'; //TODO: user quota from $CFG->userquota return new file_info_stored($this->browser, $this->context, $storedfile, $urlbase, get_string('areauserpersonal', 'repository'), false, true, true, false); }
php
protected function get_area_user_private($itemid, $filepath, $filename) { global $USER, $CFG; // access control: only my files, nobody else if ($this->user->id != $USER->id) { return null; } if (is_null($itemid)) { // go to parent, we do not use itemids here in private area return $this; } $fs = get_file_storage(); $filepath = is_null($filepath) ? '/' : $filepath; $filename = is_null($filename) ? '.' : $filename; if (!$storedfile = $fs->get_file($this->context->id, 'user', 'private', 0, $filepath, $filename)) { if ($filepath === '/' and $filename === '.') { // root dir does not exist yet $storedfile = new virtual_root_file($this->context->id, 'user', 'private', 0); } else { // not found return null; } } $urlbase = $CFG->wwwroot.'/pluginfile.php'; //TODO: user quota from $CFG->userquota return new file_info_stored($this->browser, $this->context, $storedfile, $urlbase, get_string('areauserpersonal', 'repository'), false, true, true, false); }
[ "protected", "function", "get_area_user_private", "(", "$", "itemid", ",", "$", "filepath", ",", "$", "filename", ")", "{", "global", "$", "USER", ",", "$", "CFG", ";", "// access control: only my files, nobody else", "if", "(", "$", "this", "->", "user", "->", "id", "!=", "$", "USER", "->", "id", ")", "{", "return", "null", ";", "}", "if", "(", "is_null", "(", "$", "itemid", ")", ")", "{", "// go to parent, we do not use itemids here in private area", "return", "$", "this", ";", "}", "$", "fs", "=", "get_file_storage", "(", ")", ";", "$", "filepath", "=", "is_null", "(", "$", "filepath", ")", "?", "'/'", ":", "$", "filepath", ";", "$", "filename", "=", "is_null", "(", "$", "filename", ")", "?", "'.'", ":", "$", "filename", ";", "if", "(", "!", "$", "storedfile", "=", "$", "fs", "->", "get_file", "(", "$", "this", "->", "context", "->", "id", ",", "'user'", ",", "'private'", ",", "0", ",", "$", "filepath", ",", "$", "filename", ")", ")", "{", "if", "(", "$", "filepath", "===", "'/'", "and", "$", "filename", "===", "'.'", ")", "{", "// root dir does not exist yet", "$", "storedfile", "=", "new", "virtual_root_file", "(", "$", "this", "->", "context", "->", "id", ",", "'user'", ",", "'private'", ",", "0", ")", ";", "}", "else", "{", "// not found", "return", "null", ";", "}", "}", "$", "urlbase", "=", "$", "CFG", "->", "wwwroot", ".", "'/pluginfile.php'", ";", "//TODO: user quota from $CFG->userquota", "return", "new", "file_info_stored", "(", "$", "this", "->", "browser", ",", "$", "this", "->", "context", ",", "$", "storedfile", ",", "$", "urlbase", ",", "get_string", "(", "'areauserpersonal'", ",", "'repository'", ")", ",", "false", ",", "true", ",", "true", ",", "false", ")", ";", "}" ]
Get a file from user private area @todo MDL-31070 this method should respect $CFG->userquota @param int $itemid item ID @param string $filepath file path @param string $filename file name @return file_info|null
[ "Get", "a", "file", "from", "user", "private", "area" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/filebrowser/file_info_context_user.php#L94-L126
214,556
moodle/moodle
backup/moodle2/restore_plan_builder.class.php
restore_plan_builder.build_activity_plan
static protected function build_activity_plan($controller, $activityid) { $plan = $controller->get_plan(); $info = $controller->get_info(); $infoactivity = $info->activities[$activityid]; // Add the activity task, responsible for restoring // all the module related information. So it conditionally // as far as the module can be missing on restore if ($task = restore_factory::get_restore_activity_task($infoactivity)) { // can be missing $plan->add_task($task); $controller->get_progress()->progress(); // For the given activity path, add as many block tasks as necessary // TODO: Add blocks, we need to introspect xml here $blocks = backup_general_helper::get_blocks_from_path($task->get_taskbasepath()); foreach ($blocks as $basepath => $name) { if ($task = restore_factory::get_restore_block_task($name, $basepath)) { $plan->add_task($task); $controller->get_progress()->progress(); } else { // TODO: Debug information about block not supported } } } else { // Activity is missing in target site, inform plan about that $plan->set_missing_modules(); } }
php
static protected function build_activity_plan($controller, $activityid) { $plan = $controller->get_plan(); $info = $controller->get_info(); $infoactivity = $info->activities[$activityid]; // Add the activity task, responsible for restoring // all the module related information. So it conditionally // as far as the module can be missing on restore if ($task = restore_factory::get_restore_activity_task($infoactivity)) { // can be missing $plan->add_task($task); $controller->get_progress()->progress(); // For the given activity path, add as many block tasks as necessary // TODO: Add blocks, we need to introspect xml here $blocks = backup_general_helper::get_blocks_from_path($task->get_taskbasepath()); foreach ($blocks as $basepath => $name) { if ($task = restore_factory::get_restore_block_task($name, $basepath)) { $plan->add_task($task); $controller->get_progress()->progress(); } else { // TODO: Debug information about block not supported } } } else { // Activity is missing in target site, inform plan about that $plan->set_missing_modules(); } }
[ "static", "protected", "function", "build_activity_plan", "(", "$", "controller", ",", "$", "activityid", ")", "{", "$", "plan", "=", "$", "controller", "->", "get_plan", "(", ")", ";", "$", "info", "=", "$", "controller", "->", "get_info", "(", ")", ";", "$", "infoactivity", "=", "$", "info", "->", "activities", "[", "$", "activityid", "]", ";", "// Add the activity task, responsible for restoring", "// all the module related information. So it conditionally", "// as far as the module can be missing on restore", "if", "(", "$", "task", "=", "restore_factory", "::", "get_restore_activity_task", "(", "$", "infoactivity", ")", ")", "{", "// can be missing", "$", "plan", "->", "add_task", "(", "$", "task", ")", ";", "$", "controller", "->", "get_progress", "(", ")", "->", "progress", "(", ")", ";", "// For the given activity path, add as many block tasks as necessary", "// TODO: Add blocks, we need to introspect xml here", "$", "blocks", "=", "backup_general_helper", "::", "get_blocks_from_path", "(", "$", "task", "->", "get_taskbasepath", "(", ")", ")", ";", "foreach", "(", "$", "blocks", "as", "$", "basepath", "=>", "$", "name", ")", "{", "if", "(", "$", "task", "=", "restore_factory", "::", "get_restore_block_task", "(", "$", "name", ",", "$", "basepath", ")", ")", "{", "$", "plan", "->", "add_task", "(", "$", "task", ")", ";", "$", "controller", "->", "get_progress", "(", ")", "->", "progress", "(", ")", ";", "}", "else", "{", "// TODO: Debug information about block not supported", "}", "}", "}", "else", "{", "// Activity is missing in target site, inform plan about that", "$", "plan", "->", "set_missing_modules", "(", ")", ";", "}", "}" ]
Restore one 1-activity backup
[ "Restore", "one", "1", "-", "activity", "backup" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/moodle2/restore_plan_builder.class.php#L132-L160
214,557
moodle/moodle
backup/moodle2/restore_plan_builder.class.php
restore_plan_builder.build_section_plan
static protected function build_section_plan($controller, $sectionid) { $plan = $controller->get_plan(); $info = $controller->get_info(); $infosection = $info->sections[$sectionid]; // Add the section task, responsible for restoring // all the section related information $plan->add_task(restore_factory::get_restore_section_task($infosection)); $controller->get_progress()->progress(); // For the given section, add as many activity tasks as necessary foreach ($info->activities as $activityid => $activity) { if ($activity->sectionid != $infosection->sectionid) { continue; } if (plugin_supports('mod', $activity->modulename, FEATURE_BACKUP_MOODLE2)) { // Check we support the format self::build_activity_plan($controller, $activityid); } else { // TODO: Debug information about module not supported } } }
php
static protected function build_section_plan($controller, $sectionid) { $plan = $controller->get_plan(); $info = $controller->get_info(); $infosection = $info->sections[$sectionid]; // Add the section task, responsible for restoring // all the section related information $plan->add_task(restore_factory::get_restore_section_task($infosection)); $controller->get_progress()->progress(); // For the given section, add as many activity tasks as necessary foreach ($info->activities as $activityid => $activity) { if ($activity->sectionid != $infosection->sectionid) { continue; } if (plugin_supports('mod', $activity->modulename, FEATURE_BACKUP_MOODLE2)) { // Check we support the format self::build_activity_plan($controller, $activityid); } else { // TODO: Debug information about module not supported } } }
[ "static", "protected", "function", "build_section_plan", "(", "$", "controller", ",", "$", "sectionid", ")", "{", "$", "plan", "=", "$", "controller", "->", "get_plan", "(", ")", ";", "$", "info", "=", "$", "controller", "->", "get_info", "(", ")", ";", "$", "infosection", "=", "$", "info", "->", "sections", "[", "$", "sectionid", "]", ";", "// Add the section task, responsible for restoring", "// all the section related information", "$", "plan", "->", "add_task", "(", "restore_factory", "::", "get_restore_section_task", "(", "$", "infosection", ")", ")", ";", "$", "controller", "->", "get_progress", "(", ")", "->", "progress", "(", ")", ";", "// For the given section, add as many activity tasks as necessary", "foreach", "(", "$", "info", "->", "activities", "as", "$", "activityid", "=>", "$", "activity", ")", "{", "if", "(", "$", "activity", "->", "sectionid", "!=", "$", "infosection", "->", "sectionid", ")", "{", "continue", ";", "}", "if", "(", "plugin_supports", "(", "'mod'", ",", "$", "activity", "->", "modulename", ",", "FEATURE_BACKUP_MOODLE2", ")", ")", "{", "// Check we support the format", "self", "::", "build_activity_plan", "(", "$", "controller", ",", "$", "activityid", ")", ";", "}", "else", "{", "// TODO: Debug information about module not supported", "}", "}", "}" ]
Restore one 1-section backup
[ "Restore", "one", "1", "-", "section", "backup" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/moodle2/restore_plan_builder.class.php#L165-L186
214,558
moodle/moodle
backup/moodle2/restore_plan_builder.class.php
restore_plan_builder.build_course_plan
static protected function build_course_plan($controller, $courseid) { $plan = $controller->get_plan(); $info = $controller->get_info(); // Add the course task, responsible for restoring // all the course related information $task = restore_factory::get_restore_course_task($info->course, $courseid); $plan->add_task($task); $controller->get_progress()->progress(); // For the given course path, add as many block tasks as necessary // TODO: Add blocks, we need to introspect xml here $blocks = backup_general_helper::get_blocks_from_path($task->get_taskbasepath()); foreach ($blocks as $basepath => $name) { if ($task = restore_factory::get_restore_block_task($name, $basepath)) { $plan->add_task($task); $controller->get_progress()->progress(); } else { // TODO: Debug information about block not supported } } // For the given course, add as many section tasks as necessary foreach ($info->sections as $sectionid => $section) { self::build_section_plan($controller, $sectionid); } }
php
static protected function build_course_plan($controller, $courseid) { $plan = $controller->get_plan(); $info = $controller->get_info(); // Add the course task, responsible for restoring // all the course related information $task = restore_factory::get_restore_course_task($info->course, $courseid); $plan->add_task($task); $controller->get_progress()->progress(); // For the given course path, add as many block tasks as necessary // TODO: Add blocks, we need to introspect xml here $blocks = backup_general_helper::get_blocks_from_path($task->get_taskbasepath()); foreach ($blocks as $basepath => $name) { if ($task = restore_factory::get_restore_block_task($name, $basepath)) { $plan->add_task($task); $controller->get_progress()->progress(); } else { // TODO: Debug information about block not supported } } // For the given course, add as many section tasks as necessary foreach ($info->sections as $sectionid => $section) { self::build_section_plan($controller, $sectionid); } }
[ "static", "protected", "function", "build_course_plan", "(", "$", "controller", ",", "$", "courseid", ")", "{", "$", "plan", "=", "$", "controller", "->", "get_plan", "(", ")", ";", "$", "info", "=", "$", "controller", "->", "get_info", "(", ")", ";", "// Add the course task, responsible for restoring", "// all the course related information", "$", "task", "=", "restore_factory", "::", "get_restore_course_task", "(", "$", "info", "->", "course", ",", "$", "courseid", ")", ";", "$", "plan", "->", "add_task", "(", "$", "task", ")", ";", "$", "controller", "->", "get_progress", "(", ")", "->", "progress", "(", ")", ";", "// For the given course path, add as many block tasks as necessary", "// TODO: Add blocks, we need to introspect xml here", "$", "blocks", "=", "backup_general_helper", "::", "get_blocks_from_path", "(", "$", "task", "->", "get_taskbasepath", "(", ")", ")", ";", "foreach", "(", "$", "blocks", "as", "$", "basepath", "=>", "$", "name", ")", "{", "if", "(", "$", "task", "=", "restore_factory", "::", "get_restore_block_task", "(", "$", "name", ",", "$", "basepath", ")", ")", "{", "$", "plan", "->", "add_task", "(", "$", "task", ")", ";", "$", "controller", "->", "get_progress", "(", ")", "->", "progress", "(", ")", ";", "}", "else", "{", "// TODO: Debug information about block not supported", "}", "}", "// For the given course, add as many section tasks as necessary", "foreach", "(", "$", "info", "->", "sections", "as", "$", "sectionid", "=>", "$", "section", ")", "{", "self", "::", "build_section_plan", "(", "$", "controller", ",", "$", "sectionid", ")", ";", "}", "}" ]
Restore one 1-course backup
[ "Restore", "one", "1", "-", "course", "backup" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/moodle2/restore_plan_builder.class.php#L191-L218
214,559
moodle/moodle
analytics/classes/dataset_manager.php
dataset_manager.store
public function store($data) { // Delete previous file if it exists. $fs = get_file_storage(); $filerecord = [ 'component' => 'analytics', 'filearea' => $this->filearea, 'itemid' => $this->modelid, 'contextid' => \context_system::instance()->id, 'filepath' => '/analysable/' . $this->analysableid . '/' . \core_analytics\analysis::clean_time_splitting_id($this->timesplittingid) . '/', 'filename' => self::get_filename($this->evaluation) ]; // Delete previous and old (we already checked that previous copies are not recent) evaluation files for this analysable. if ($this->evaluation) { $select = " = {$filerecord['itemid']} AND filepath = :filepath"; $fs->delete_area_files_select($filerecord['contextid'], $filerecord['component'], $filerecord['filearea'], $select, array('filepath' => $filerecord['filepath'])); } // Write all this stuff to a tmp file. $filepath = make_request_directory() . DIRECTORY_SEPARATOR . $filerecord['filename']; $fh = fopen($filepath, 'w+'); if (!$fh) { return false; } foreach ($data as $line) { fputcsv($fh, $line); } fclose($fh); return $fs->create_file_from_pathname($filerecord, $filepath); }
php
public function store($data) { // Delete previous file if it exists. $fs = get_file_storage(); $filerecord = [ 'component' => 'analytics', 'filearea' => $this->filearea, 'itemid' => $this->modelid, 'contextid' => \context_system::instance()->id, 'filepath' => '/analysable/' . $this->analysableid . '/' . \core_analytics\analysis::clean_time_splitting_id($this->timesplittingid) . '/', 'filename' => self::get_filename($this->evaluation) ]; // Delete previous and old (we already checked that previous copies are not recent) evaluation files for this analysable. if ($this->evaluation) { $select = " = {$filerecord['itemid']} AND filepath = :filepath"; $fs->delete_area_files_select($filerecord['contextid'], $filerecord['component'], $filerecord['filearea'], $select, array('filepath' => $filerecord['filepath'])); } // Write all this stuff to a tmp file. $filepath = make_request_directory() . DIRECTORY_SEPARATOR . $filerecord['filename']; $fh = fopen($filepath, 'w+'); if (!$fh) { return false; } foreach ($data as $line) { fputcsv($fh, $line); } fclose($fh); return $fs->create_file_from_pathname($filerecord, $filepath); }
[ "public", "function", "store", "(", "$", "data", ")", "{", "// Delete previous file if it exists.", "$", "fs", "=", "get_file_storage", "(", ")", ";", "$", "filerecord", "=", "[", "'component'", "=>", "'analytics'", ",", "'filearea'", "=>", "$", "this", "->", "filearea", ",", "'itemid'", "=>", "$", "this", "->", "modelid", ",", "'contextid'", "=>", "\\", "context_system", "::", "instance", "(", ")", "->", "id", ",", "'filepath'", "=>", "'/analysable/'", ".", "$", "this", "->", "analysableid", ".", "'/'", ".", "\\", "core_analytics", "\\", "analysis", "::", "clean_time_splitting_id", "(", "$", "this", "->", "timesplittingid", ")", ".", "'/'", ",", "'filename'", "=>", "self", "::", "get_filename", "(", "$", "this", "->", "evaluation", ")", "]", ";", "// Delete previous and old (we already checked that previous copies are not recent) evaluation files for this analysable.", "if", "(", "$", "this", "->", "evaluation", ")", "{", "$", "select", "=", "\" = {$filerecord['itemid']} AND filepath = :filepath\"", ";", "$", "fs", "->", "delete_area_files_select", "(", "$", "filerecord", "[", "'contextid'", "]", ",", "$", "filerecord", "[", "'component'", "]", ",", "$", "filerecord", "[", "'filearea'", "]", ",", "$", "select", ",", "array", "(", "'filepath'", "=>", "$", "filerecord", "[", "'filepath'", "]", ")", ")", ";", "}", "// Write all this stuff to a tmp file.", "$", "filepath", "=", "make_request_directory", "(", ")", ".", "DIRECTORY_SEPARATOR", ".", "$", "filerecord", "[", "'filename'", "]", ";", "$", "fh", "=", "fopen", "(", "$", "filepath", ",", "'w+'", ")", ";", "if", "(", "!", "$", "fh", ")", "{", "return", "false", ";", "}", "foreach", "(", "$", "data", "as", "$", "line", ")", "{", "fputcsv", "(", "$", "fh", ",", "$", "line", ")", ";", "}", "fclose", "(", "$", "fh", ")", ";", "return", "$", "fs", "->", "create_file_from_pathname", "(", "$", "filerecord", ",", "$", "filepath", ")", ";", "}" ]
Store the dataset in the internal file system. @param array $data @return \stored_file
[ "Store", "the", "dataset", "in", "the", "internal", "file", "system", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/analytics/classes/dataset_manager.php#L122-L156
214,560
moodle/moodle
analytics/classes/dataset_manager.php
dataset_manager.get_previous_evaluation_file
public static function get_previous_evaluation_file($modelid, $timesplittingid) { $fs = get_file_storage(); // Evaluation data is always labelled. $filepath = '/timesplitting/' . \core_analytics\analysis::clean_time_splitting_id($timesplittingid) . '/'; return $fs->get_file(\context_system::instance()->id, 'analytics', self::LABELLED_FILEAREA, $modelid, $filepath, self::EVALUATION_FILENAME); }
php
public static function get_previous_evaluation_file($modelid, $timesplittingid) { $fs = get_file_storage(); // Evaluation data is always labelled. $filepath = '/timesplitting/' . \core_analytics\analysis::clean_time_splitting_id($timesplittingid) . '/'; return $fs->get_file(\context_system::instance()->id, 'analytics', self::LABELLED_FILEAREA, $modelid, $filepath, self::EVALUATION_FILENAME); }
[ "public", "static", "function", "get_previous_evaluation_file", "(", "$", "modelid", ",", "$", "timesplittingid", ")", "{", "$", "fs", "=", "get_file_storage", "(", ")", ";", "// Evaluation data is always labelled.", "$", "filepath", "=", "'/timesplitting/'", ".", "\\", "core_analytics", "\\", "analysis", "::", "clean_time_splitting_id", "(", "$", "timesplittingid", ")", ".", "'/'", ";", "return", "$", "fs", "->", "get_file", "(", "\\", "context_system", "::", "instance", "(", ")", "->", "id", ",", "'analytics'", ",", "self", "::", "LABELLED_FILEAREA", ",", "$", "modelid", ",", "$", "filepath", ",", "self", "::", "EVALUATION_FILENAME", ")", ";", "}" ]
Returns the previous evaluation file. Important to note that this is per modelid + timesplittingid, when dealing with multiple analysables this is the merged file. Do not confuse with self::get_evaluation_analysable_file @param int $modelid @param string $timesplittingid @return \stored_file
[ "Returns", "the", "previous", "evaluation", "file", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/analytics/classes/dataset_manager.php#L168-L174
214,561
moodle/moodle
analytics/classes/dataset_manager.php
dataset_manager.get_pending_files
public static function get_pending_files($modelid, $includetarget, $timesplittingids) { global $DB; $fs = get_file_storage(); if ($includetarget) { $filearea = self::LABELLED_FILEAREA; $usedfileaction = 'trained'; } else { $filearea = self::UNLABELLED_FILEAREA; $usedfileaction = 'predicted'; } $select = 'modelid = :modelid AND action = :action'; $params = array('modelid' => $modelid, 'action' => $usedfileaction); $usedfileids = $DB->get_fieldset_select('analytics_used_files', 'fileid', $select, $params); // Very likely that we will only have 1 time splitting method here. $filesbytimesplitting = array(); foreach ($timesplittingids as $timesplittingid) { $filepath = '/timesplitting/' . \core_analytics\analysis::clean_time_splitting_id($timesplittingid) . '/'; $files = $fs->get_directory_files(\context_system::instance()->id, 'analytics', $filearea, $modelid, $filepath); foreach ($files as $file) { // Discard evaluation files. if ($file->get_filename() === self::EVALUATION_FILENAME) { continue; } // No dirs. if ($file->is_directory()) { continue; } // Already used for training. if (in_array($file->get_id(), $usedfileids)) { continue; } $filesbytimesplitting[$timesplittingid][] = $file; } } return $filesbytimesplitting; }
php
public static function get_pending_files($modelid, $includetarget, $timesplittingids) { global $DB; $fs = get_file_storage(); if ($includetarget) { $filearea = self::LABELLED_FILEAREA; $usedfileaction = 'trained'; } else { $filearea = self::UNLABELLED_FILEAREA; $usedfileaction = 'predicted'; } $select = 'modelid = :modelid AND action = :action'; $params = array('modelid' => $modelid, 'action' => $usedfileaction); $usedfileids = $DB->get_fieldset_select('analytics_used_files', 'fileid', $select, $params); // Very likely that we will only have 1 time splitting method here. $filesbytimesplitting = array(); foreach ($timesplittingids as $timesplittingid) { $filepath = '/timesplitting/' . \core_analytics\analysis::clean_time_splitting_id($timesplittingid) . '/'; $files = $fs->get_directory_files(\context_system::instance()->id, 'analytics', $filearea, $modelid, $filepath); foreach ($files as $file) { // Discard evaluation files. if ($file->get_filename() === self::EVALUATION_FILENAME) { continue; } // No dirs. if ($file->is_directory()) { continue; } // Already used for training. if (in_array($file->get_id(), $usedfileids)) { continue; } $filesbytimesplitting[$timesplittingid][] = $file; } } return $filesbytimesplitting; }
[ "public", "static", "function", "get_pending_files", "(", "$", "modelid", ",", "$", "includetarget", ",", "$", "timesplittingids", ")", "{", "global", "$", "DB", ";", "$", "fs", "=", "get_file_storage", "(", ")", ";", "if", "(", "$", "includetarget", ")", "{", "$", "filearea", "=", "self", "::", "LABELLED_FILEAREA", ";", "$", "usedfileaction", "=", "'trained'", ";", "}", "else", "{", "$", "filearea", "=", "self", "::", "UNLABELLED_FILEAREA", ";", "$", "usedfileaction", "=", "'predicted'", ";", "}", "$", "select", "=", "'modelid = :modelid AND action = :action'", ";", "$", "params", "=", "array", "(", "'modelid'", "=>", "$", "modelid", ",", "'action'", "=>", "$", "usedfileaction", ")", ";", "$", "usedfileids", "=", "$", "DB", "->", "get_fieldset_select", "(", "'analytics_used_files'", ",", "'fileid'", ",", "$", "select", ",", "$", "params", ")", ";", "// Very likely that we will only have 1 time splitting method here.", "$", "filesbytimesplitting", "=", "array", "(", ")", ";", "foreach", "(", "$", "timesplittingids", "as", "$", "timesplittingid", ")", "{", "$", "filepath", "=", "'/timesplitting/'", ".", "\\", "core_analytics", "\\", "analysis", "::", "clean_time_splitting_id", "(", "$", "timesplittingid", ")", ".", "'/'", ";", "$", "files", "=", "$", "fs", "->", "get_directory_files", "(", "\\", "context_system", "::", "instance", "(", ")", "->", "id", ",", "'analytics'", ",", "$", "filearea", ",", "$", "modelid", ",", "$", "filepath", ")", ";", "foreach", "(", "$", "files", "as", "$", "file", ")", "{", "// Discard evaluation files.", "if", "(", "$", "file", "->", "get_filename", "(", ")", "===", "self", "::", "EVALUATION_FILENAME", ")", "{", "continue", ";", "}", "// No dirs.", "if", "(", "$", "file", "->", "is_directory", "(", ")", ")", "{", "continue", ";", "}", "// Already used for training.", "if", "(", "in_array", "(", "$", "file", "->", "get_id", "(", ")", ",", "$", "usedfileids", ")", ")", "{", "continue", ";", "}", "$", "filesbytimesplitting", "[", "$", "timesplittingid", "]", "[", "]", "=", "$", "file", ";", "}", "}", "return", "$", "filesbytimesplitting", ";", "}" ]
Gets the list of files that couldn't be previously used for training and prediction. @param int $modelid @param bool $includetarget @param string[] $timesplittingids @return null
[ "Gets", "the", "list", "of", "files", "that", "couldn", "t", "be", "previously", "used", "for", "training", "and", "prediction", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/analytics/classes/dataset_manager.php#L184-L229
214,562
moodle/moodle
analytics/classes/dataset_manager.php
dataset_manager.delete_previous_evaluation_file
public static function delete_previous_evaluation_file($modelid, $timesplittingid) { if ($file = self::get_previous_evaluation_file($modelid, $timesplittingid)) { $file->delete(); return true; } return false; }
php
public static function delete_previous_evaluation_file($modelid, $timesplittingid) { if ($file = self::get_previous_evaluation_file($modelid, $timesplittingid)) { $file->delete(); return true; } return false; }
[ "public", "static", "function", "delete_previous_evaluation_file", "(", "$", "modelid", ",", "$", "timesplittingid", ")", "{", "if", "(", "$", "file", "=", "self", "::", "get_previous_evaluation_file", "(", "$", "modelid", ",", "$", "timesplittingid", ")", ")", "{", "$", "file", "->", "delete", "(", ")", ";", "return", "true", ";", "}", "return", "false", ";", "}" ]
Deletes previous evaluation files of this model. @param int $modelid @param string $timesplittingid @return bool
[ "Deletes", "previous", "evaluation", "files", "of", "this", "model", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/analytics/classes/dataset_manager.php#L238-L245
214,563
moodle/moodle
analytics/classes/dataset_manager.php
dataset_manager.merge_datasets
public static function merge_datasets(array $files, $modelid, $timesplittingid, $filearea, $evaluation = false) { $tmpfilepath = make_request_directory() . DIRECTORY_SEPARATOR . 'tmpfile.csv'; // Add headers. // We could also do this with a single iteration gathering all files headers and appending them to the beginning of the file // once all file contents are merged. $varnames = ''; $analysablesvalues = array(); foreach ($files as $file) { $rh = $file->get_content_file_handle(); // Copy the var names as they are, all files should have the same var names. $varnames = fgetcsv($rh); $analysablesvalues[] = fgetcsv($rh); // Copy the columns as they are, all files should have the same columns. $columns = fgetcsv($rh); } // Merge analysable values skipping the ones that are the same in all analysables. $values = array(); foreach ($analysablesvalues as $analysablevalues) { foreach ($analysablevalues as $varkey => $value) { // Sha1 to make it unique. $values[$varkey][sha1($value)] = $value; } } foreach ($values as $varkey => $varvalues) { $values[$varkey] = implode('|', $varvalues); } // Start writing to the merge file. $wh = fopen($tmpfilepath, 'w'); if (!$wh) { throw new \moodle_exception('errorcannotwritedataset', 'analytics', '', $tmpfilepath); } fputcsv($wh, $varnames); fputcsv($wh, $values); fputcsv($wh, $columns); // Iterate through all files and add them to the tmp one. We don't want file contents in memory. foreach ($files as $file) { $rh = $file->get_content_file_handle(); // Skip headers. fgets($rh); fgets($rh); fgets($rh); // Copy all the following lines. while ($line = fgets($rh)) { fwrite($wh, $line); } fclose($rh); } fclose($wh); $filerecord = [ 'component' => 'analytics', 'filearea' => $filearea, 'itemid' => $modelid, 'contextid' => \context_system::instance()->id, 'filepath' => '/timesplitting/' . \core_analytics\analysis::clean_time_splitting_id($timesplittingid) . '/', 'filename' => self::get_filename($evaluation) ]; $fs = get_file_storage(); return $fs->create_file_from_pathname($filerecord, $tmpfilepath); }
php
public static function merge_datasets(array $files, $modelid, $timesplittingid, $filearea, $evaluation = false) { $tmpfilepath = make_request_directory() . DIRECTORY_SEPARATOR . 'tmpfile.csv'; // Add headers. // We could also do this with a single iteration gathering all files headers and appending them to the beginning of the file // once all file contents are merged. $varnames = ''; $analysablesvalues = array(); foreach ($files as $file) { $rh = $file->get_content_file_handle(); // Copy the var names as they are, all files should have the same var names. $varnames = fgetcsv($rh); $analysablesvalues[] = fgetcsv($rh); // Copy the columns as they are, all files should have the same columns. $columns = fgetcsv($rh); } // Merge analysable values skipping the ones that are the same in all analysables. $values = array(); foreach ($analysablesvalues as $analysablevalues) { foreach ($analysablevalues as $varkey => $value) { // Sha1 to make it unique. $values[$varkey][sha1($value)] = $value; } } foreach ($values as $varkey => $varvalues) { $values[$varkey] = implode('|', $varvalues); } // Start writing to the merge file. $wh = fopen($tmpfilepath, 'w'); if (!$wh) { throw new \moodle_exception('errorcannotwritedataset', 'analytics', '', $tmpfilepath); } fputcsv($wh, $varnames); fputcsv($wh, $values); fputcsv($wh, $columns); // Iterate through all files and add them to the tmp one. We don't want file contents in memory. foreach ($files as $file) { $rh = $file->get_content_file_handle(); // Skip headers. fgets($rh); fgets($rh); fgets($rh); // Copy all the following lines. while ($line = fgets($rh)) { fwrite($wh, $line); } fclose($rh); } fclose($wh); $filerecord = [ 'component' => 'analytics', 'filearea' => $filearea, 'itemid' => $modelid, 'contextid' => \context_system::instance()->id, 'filepath' => '/timesplitting/' . \core_analytics\analysis::clean_time_splitting_id($timesplittingid) . '/', 'filename' => self::get_filename($evaluation) ]; $fs = get_file_storage(); return $fs->create_file_from_pathname($filerecord, $tmpfilepath); }
[ "public", "static", "function", "merge_datasets", "(", "array", "$", "files", ",", "$", "modelid", ",", "$", "timesplittingid", ",", "$", "filearea", ",", "$", "evaluation", "=", "false", ")", "{", "$", "tmpfilepath", "=", "make_request_directory", "(", ")", ".", "DIRECTORY_SEPARATOR", ".", "'tmpfile.csv'", ";", "// Add headers.", "// We could also do this with a single iteration gathering all files headers and appending them to the beginning of the file", "// once all file contents are merged.", "$", "varnames", "=", "''", ";", "$", "analysablesvalues", "=", "array", "(", ")", ";", "foreach", "(", "$", "files", "as", "$", "file", ")", "{", "$", "rh", "=", "$", "file", "->", "get_content_file_handle", "(", ")", ";", "// Copy the var names as they are, all files should have the same var names.", "$", "varnames", "=", "fgetcsv", "(", "$", "rh", ")", ";", "$", "analysablesvalues", "[", "]", "=", "fgetcsv", "(", "$", "rh", ")", ";", "// Copy the columns as they are, all files should have the same columns.", "$", "columns", "=", "fgetcsv", "(", "$", "rh", ")", ";", "}", "// Merge analysable values skipping the ones that are the same in all analysables.", "$", "values", "=", "array", "(", ")", ";", "foreach", "(", "$", "analysablesvalues", "as", "$", "analysablevalues", ")", "{", "foreach", "(", "$", "analysablevalues", "as", "$", "varkey", "=>", "$", "value", ")", "{", "// Sha1 to make it unique.", "$", "values", "[", "$", "varkey", "]", "[", "sha1", "(", "$", "value", ")", "]", "=", "$", "value", ";", "}", "}", "foreach", "(", "$", "values", "as", "$", "varkey", "=>", "$", "varvalues", ")", "{", "$", "values", "[", "$", "varkey", "]", "=", "implode", "(", "'|'", ",", "$", "varvalues", ")", ";", "}", "// Start writing to the merge file.", "$", "wh", "=", "fopen", "(", "$", "tmpfilepath", ",", "'w'", ")", ";", "if", "(", "!", "$", "wh", ")", "{", "throw", "new", "\\", "moodle_exception", "(", "'errorcannotwritedataset'", ",", "'analytics'", ",", "''", ",", "$", "tmpfilepath", ")", ";", "}", "fputcsv", "(", "$", "wh", ",", "$", "varnames", ")", ";", "fputcsv", "(", "$", "wh", ",", "$", "values", ")", ";", "fputcsv", "(", "$", "wh", ",", "$", "columns", ")", ";", "// Iterate through all files and add them to the tmp one. We don't want file contents in memory.", "foreach", "(", "$", "files", "as", "$", "file", ")", "{", "$", "rh", "=", "$", "file", "->", "get_content_file_handle", "(", ")", ";", "// Skip headers.", "fgets", "(", "$", "rh", ")", ";", "fgets", "(", "$", "rh", ")", ";", "fgets", "(", "$", "rh", ")", ";", "// Copy all the following lines.", "while", "(", "$", "line", "=", "fgets", "(", "$", "rh", ")", ")", "{", "fwrite", "(", "$", "wh", ",", "$", "line", ")", ";", "}", "fclose", "(", "$", "rh", ")", ";", "}", "fclose", "(", "$", "wh", ")", ";", "$", "filerecord", "=", "[", "'component'", "=>", "'analytics'", ",", "'filearea'", "=>", "$", "filearea", ",", "'itemid'", "=>", "$", "modelid", ",", "'contextid'", "=>", "\\", "context_system", "::", "instance", "(", ")", "->", "id", ",", "'filepath'", "=>", "'/timesplitting/'", ".", "\\", "core_analytics", "\\", "analysis", "::", "clean_time_splitting_id", "(", "$", "timesplittingid", ")", ".", "'/'", ",", "'filename'", "=>", "self", "::", "get_filename", "(", "$", "evaluation", ")", "]", ";", "$", "fs", "=", "get_file_storage", "(", ")", ";", "return", "$", "fs", "->", "create_file_from_pathname", "(", "$", "filerecord", ",", "$", "tmpfilepath", ")", ";", "}" ]
Merge multiple files into one. Important! It is the caller responsability to ensure that the datasets are compatible. @param array $files @param int $modelid @param string $timesplittingid @param string $filearea @param bool $evaluation @return \stored_file
[ "Merge", "multiple", "files", "into", "one", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/analytics/classes/dataset_manager.php#L280-L352
214,564
moodle/moodle
analytics/classes/dataset_manager.php
dataset_manager.export_training_data
public static function export_training_data($modelid, $timesplittingid) { $fs = get_file_storage(); $contextid = \context_system::instance()->id; $filepath = '/timesplitting/' . \core_analytics\analysis::clean_time_splitting_id($timesplittingid) . '/'; $files = $fs->get_directory_files($contextid, 'analytics', self::LABELLED_FILEAREA, $modelid, $filepath, true, false); // Discard evaluation files. foreach ($files as $key => $file) { if ($file->get_filename() === self::EVALUATION_FILENAME) { unset($files[$key]); } } if (empty($files)) { return false; } return self::merge_datasets($files, $modelid, $timesplittingid, self::EXPORT_FILEAREA); }
php
public static function export_training_data($modelid, $timesplittingid) { $fs = get_file_storage(); $contextid = \context_system::instance()->id; $filepath = '/timesplitting/' . \core_analytics\analysis::clean_time_splitting_id($timesplittingid) . '/'; $files = $fs->get_directory_files($contextid, 'analytics', self::LABELLED_FILEAREA, $modelid, $filepath, true, false); // Discard evaluation files. foreach ($files as $key => $file) { if ($file->get_filename() === self::EVALUATION_FILENAME) { unset($files[$key]); } } if (empty($files)) { return false; } return self::merge_datasets($files, $modelid, $timesplittingid, self::EXPORT_FILEAREA); }
[ "public", "static", "function", "export_training_data", "(", "$", "modelid", ",", "$", "timesplittingid", ")", "{", "$", "fs", "=", "get_file_storage", "(", ")", ";", "$", "contextid", "=", "\\", "context_system", "::", "instance", "(", ")", "->", "id", ";", "$", "filepath", "=", "'/timesplitting/'", ".", "\\", "core_analytics", "\\", "analysis", "::", "clean_time_splitting_id", "(", "$", "timesplittingid", ")", ".", "'/'", ";", "$", "files", "=", "$", "fs", "->", "get_directory_files", "(", "$", "contextid", ",", "'analytics'", ",", "self", "::", "LABELLED_FILEAREA", ",", "$", "modelid", ",", "$", "filepath", ",", "true", ",", "false", ")", ";", "// Discard evaluation files.", "foreach", "(", "$", "files", "as", "$", "key", "=>", "$", "file", ")", "{", "if", "(", "$", "file", "->", "get_filename", "(", ")", "===", "self", "::", "EVALUATION_FILENAME", ")", "{", "unset", "(", "$", "files", "[", "$", "key", "]", ")", ";", "}", "}", "if", "(", "empty", "(", "$", "files", ")", ")", "{", "return", "false", ";", "}", "return", "self", "::", "merge_datasets", "(", "$", "files", ",", "$", "modelid", ",", "$", "timesplittingid", ",", "self", "::", "EXPORT_FILEAREA", ")", ";", "}" ]
Exports the model training data. @param int $modelid @param string $timesplittingid @return \stored_file|false
[ "Exports", "the", "model", "training", "data", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/analytics/classes/dataset_manager.php#L361-L383
214,565
moodle/moodle
analytics/classes/dataset_manager.php
dataset_manager.get_structured_data
public static function get_structured_data(\stored_file $dataset) { if ($dataset->get_filearea() !== 'unlabelled') { throw new \coding_exception('Sorry, only support for unlabelled data'); } $rh = $dataset->get_content_file_handle(); // Skip dataset info. fgets($rh); fgets($rh); $calculations = array(); $headers = fgetcsv($rh); // Get rid of the sampleid column name. array_shift($headers); while ($columns = fgetcsv($rh)) { $uniquesampleid = array_shift($columns); // Unfortunately fgetcsv does not respect line's var types. $calculations[$uniquesampleid] = array_map(function($value) { if ($value === '') { // We really want them as null because converted to float become 0 // and we need to treat the values separately. return null; } else if (is_numeric($value)) { return floatval($value); } return $value; }, array_combine($headers, $columns)); } return $calculations; }
php
public static function get_structured_data(\stored_file $dataset) { if ($dataset->get_filearea() !== 'unlabelled') { throw new \coding_exception('Sorry, only support for unlabelled data'); } $rh = $dataset->get_content_file_handle(); // Skip dataset info. fgets($rh); fgets($rh); $calculations = array(); $headers = fgetcsv($rh); // Get rid of the sampleid column name. array_shift($headers); while ($columns = fgetcsv($rh)) { $uniquesampleid = array_shift($columns); // Unfortunately fgetcsv does not respect line's var types. $calculations[$uniquesampleid] = array_map(function($value) { if ($value === '') { // We really want them as null because converted to float become 0 // and we need to treat the values separately. return null; } else if (is_numeric($value)) { return floatval($value); } return $value; }, array_combine($headers, $columns)); } return $calculations; }
[ "public", "static", "function", "get_structured_data", "(", "\\", "stored_file", "$", "dataset", ")", "{", "if", "(", "$", "dataset", "->", "get_filearea", "(", ")", "!==", "'unlabelled'", ")", "{", "throw", "new", "\\", "coding_exception", "(", "'Sorry, only support for unlabelled data'", ")", ";", "}", "$", "rh", "=", "$", "dataset", "->", "get_content_file_handle", "(", ")", ";", "// Skip dataset info.", "fgets", "(", "$", "rh", ")", ";", "fgets", "(", "$", "rh", ")", ";", "$", "calculations", "=", "array", "(", ")", ";", "$", "headers", "=", "fgetcsv", "(", "$", "rh", ")", ";", "// Get rid of the sampleid column name.", "array_shift", "(", "$", "headers", ")", ";", "while", "(", "$", "columns", "=", "fgetcsv", "(", "$", "rh", ")", ")", "{", "$", "uniquesampleid", "=", "array_shift", "(", "$", "columns", ")", ";", "// Unfortunately fgetcsv does not respect line's var types.", "$", "calculations", "[", "$", "uniquesampleid", "]", "=", "array_map", "(", "function", "(", "$", "value", ")", "{", "if", "(", "$", "value", "===", "''", ")", "{", "// We really want them as null because converted to float become 0", "// and we need to treat the values separately.", "return", "null", ";", "}", "else", "if", "(", "is_numeric", "(", "$", "value", ")", ")", "{", "return", "floatval", "(", "$", "value", ")", ";", "}", "return", "$", "value", ";", "}", ",", "array_combine", "(", "$", "headers", ",", "$", "columns", ")", ")", ";", "}", "return", "$", "calculations", ";", "}" ]
Returns the dataset file data structured by sampleids using the indicators and target column names. @param \stored_file $dataset @return array
[ "Returns", "the", "dataset", "file", "data", "structured", "by", "sampleids", "using", "the", "indicators", "and", "target", "column", "names", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/analytics/classes/dataset_manager.php#L391-L427
214,566
moodle/moodle
analytics/classes/dataset_manager.php
dataset_manager.clear_model_files
public static function clear_model_files($modelid) { $fs = get_file_storage(); return $fs->delete_area_files(\context_system::instance()->id, 'analytics', false, $modelid); }
php
public static function clear_model_files($modelid) { $fs = get_file_storage(); return $fs->delete_area_files(\context_system::instance()->id, 'analytics', false, $modelid); }
[ "public", "static", "function", "clear_model_files", "(", "$", "modelid", ")", "{", "$", "fs", "=", "get_file_storage", "(", ")", ";", "return", "$", "fs", "->", "delete_area_files", "(", "\\", "context_system", "::", "instance", "(", ")", "->", "id", ",", "'analytics'", ",", "false", ",", "$", "modelid", ")", ";", "}" ]
Delete all files of a model. @param int $modelid @return bool
[ "Delete", "all", "files", "of", "a", "model", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/analytics/classes/dataset_manager.php#L435-L438
214,567
moodle/moodle
analytics/classes/dataset_manager.php
dataset_manager.get_filename
protected static function get_filename($evaluation) { if ($evaluation === true) { $filename = self::EVALUATION_FILENAME; } else { // Incremental time, the lock will make sure we don't have concurrency problems. $filename = microtime(true) . '.csv'; } return $filename; }
php
protected static function get_filename($evaluation) { if ($evaluation === true) { $filename = self::EVALUATION_FILENAME; } else { // Incremental time, the lock will make sure we don't have concurrency problems. $filename = microtime(true) . '.csv'; } return $filename; }
[ "protected", "static", "function", "get_filename", "(", "$", "evaluation", ")", "{", "if", "(", "$", "evaluation", "===", "true", ")", "{", "$", "filename", "=", "self", "::", "EVALUATION_FILENAME", ";", "}", "else", "{", "// Incremental time, the lock will make sure we don't have concurrency problems.", "$", "filename", "=", "microtime", "(", "true", ")", ".", "'.csv'", ";", "}", "return", "$", "filename", ";", "}" ]
Returns the file name to be used. @param strinbool $evaluation @return string
[ "Returns", "the", "file", "name", "to", "be", "used", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/analytics/classes/dataset_manager.php#L446-L456
214,568
moodle/moodle
blocks/myoverview/classes/output/main.php
main.get_preferences_as_booleans
public function get_preferences_as_booleans() { $preferences = []; $preferences[$this->view] = true; $preferences[$this->sort] = true; $preferences[$this->grouping] = true; return $preferences; }
php
public function get_preferences_as_booleans() { $preferences = []; $preferences[$this->view] = true; $preferences[$this->sort] = true; $preferences[$this->grouping] = true; return $preferences; }
[ "public", "function", "get_preferences_as_booleans", "(", ")", "{", "$", "preferences", "=", "[", "]", ";", "$", "preferences", "[", "$", "this", "->", "view", "]", "=", "true", ";", "$", "preferences", "[", "$", "this", "->", "sort", "]", "=", "true", ";", "$", "preferences", "[", "$", "this", "->", "grouping", "]", "=", "true", ";", "return", "$", "preferences", ";", "}" ]
Get the user preferences as an array to figure out what has been selected @return array $preferences Array with the pref as key and value set to true
[ "Get", "the", "user", "preferences", "as", "an", "array", "to", "figure", "out", "what", "has", "been", "selected" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/blocks/myoverview/classes/output/main.php#L102-L109
214,569
moodle/moodle
question/type/numerical/question.php
qtype_numerical_question.get_matching_answer
public function get_matching_answer($value, $multiplier) { if (is_null($value) || $value === '') { return null; } if (!is_null($multiplier)) { $scaledvalue = $value * $multiplier; } else { $scaledvalue = $value; } foreach ($this->answers as $answer) { if ($answer->within_tolerance($scaledvalue)) { $answer->unitisright = !is_null($multiplier); return $answer; } else if ($answer->within_tolerance($value)) { $answer->unitisright = false; return $answer; } } return null; }
php
public function get_matching_answer($value, $multiplier) { if (is_null($value) || $value === '') { return null; } if (!is_null($multiplier)) { $scaledvalue = $value * $multiplier; } else { $scaledvalue = $value; } foreach ($this->answers as $answer) { if ($answer->within_tolerance($scaledvalue)) { $answer->unitisright = !is_null($multiplier); return $answer; } else if ($answer->within_tolerance($value)) { $answer->unitisright = false; return $answer; } } return null; }
[ "public", "function", "get_matching_answer", "(", "$", "value", ",", "$", "multiplier", ")", "{", "if", "(", "is_null", "(", "$", "value", ")", "||", "$", "value", "===", "''", ")", "{", "return", "null", ";", "}", "if", "(", "!", "is_null", "(", "$", "multiplier", ")", ")", "{", "$", "scaledvalue", "=", "$", "value", "*", "$", "multiplier", ";", "}", "else", "{", "$", "scaledvalue", "=", "$", "value", ";", "}", "foreach", "(", "$", "this", "->", "answers", "as", "$", "answer", ")", "{", "if", "(", "$", "answer", "->", "within_tolerance", "(", "$", "scaledvalue", ")", ")", "{", "$", "answer", "->", "unitisright", "=", "!", "is_null", "(", "$", "multiplier", ")", ";", "return", "$", "answer", ";", "}", "else", "if", "(", "$", "answer", "->", "within_tolerance", "(", "$", "value", ")", ")", "{", "$", "answer", "->", "unitisright", "=", "false", ";", "return", "$", "answer", ";", "}", "}", "return", "null", ";", "}" ]
Get an answer that contains the feedback and fraction that should be awarded for this response. @param number $value the numerical value of a response. @param number $multiplier for the unit the student gave, if any. When no unit was given, or an unrecognised unit was given, $multiplier will be null. @return question_answer the matching answer.
[ "Get", "an", "answer", "that", "contains", "the", "feedback", "and", "fraction", "that", "should", "be", "awarded", "for", "this", "response", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/type/numerical/question.php#L197-L218
214,570
moodle/moodle
question/type/numerical/question.php
qtype_numerical_question.apply_unit_penalty
public function apply_unit_penalty($fraction, $unitisright) { if ($unitisright) { return $fraction; } if ($this->unitgradingtype == qtype_numerical::UNITGRADEDOUTOFMARK) { $fraction -= $this->unitpenalty * $fraction; } else if ($this->unitgradingtype == qtype_numerical::UNITGRADEDOUTOFMAX) { $fraction -= $this->unitpenalty; } return max($fraction, 0); }
php
public function apply_unit_penalty($fraction, $unitisright) { if ($unitisright) { return $fraction; } if ($this->unitgradingtype == qtype_numerical::UNITGRADEDOUTOFMARK) { $fraction -= $this->unitpenalty * $fraction; } else if ($this->unitgradingtype == qtype_numerical::UNITGRADEDOUTOFMAX) { $fraction -= $this->unitpenalty; } return max($fraction, 0); }
[ "public", "function", "apply_unit_penalty", "(", "$", "fraction", ",", "$", "unitisright", ")", "{", "if", "(", "$", "unitisright", ")", "{", "return", "$", "fraction", ";", "}", "if", "(", "$", "this", "->", "unitgradingtype", "==", "qtype_numerical", "::", "UNITGRADEDOUTOFMARK", ")", "{", "$", "fraction", "-=", "$", "this", "->", "unitpenalty", "*", "$", "fraction", ";", "}", "else", "if", "(", "$", "this", "->", "unitgradingtype", "==", "qtype_numerical", "::", "UNITGRADEDOUTOFMAX", ")", "{", "$", "fraction", "-=", "$", "this", "->", "unitpenalty", ";", "}", "return", "max", "(", "$", "fraction", ",", "0", ")", ";", "}" ]
Adjust the fraction based on whether the unit was correct. @param number $fraction @param bool $unitisright @return number
[ "Adjust", "the", "fraction", "based", "on", "whether", "the", "unit", "was", "correct", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/type/numerical/question.php#L236-L247
214,571
moodle/moodle
lib/htmlpurifier/HTMLPurifier/Length.php
HTMLPurifier_Length.validate
protected function validate() { // Special case: if ($this->n === '+0' || $this->n === '-0') { $this->n = '0'; } if ($this->n === '0' && $this->unit === false) { return true; } if (!ctype_lower($this->unit)) { $this->unit = strtolower($this->unit); } if (!isset(HTMLPurifier_Length::$allowedUnits[$this->unit])) { return false; } // Hack: $def = new HTMLPurifier_AttrDef_CSS_Number(); $result = $def->validate($this->n, false, false); if ($result === false) { return false; } $this->n = $result; return true; }
php
protected function validate() { // Special case: if ($this->n === '+0' || $this->n === '-0') { $this->n = '0'; } if ($this->n === '0' && $this->unit === false) { return true; } if (!ctype_lower($this->unit)) { $this->unit = strtolower($this->unit); } if (!isset(HTMLPurifier_Length::$allowedUnits[$this->unit])) { return false; } // Hack: $def = new HTMLPurifier_AttrDef_CSS_Number(); $result = $def->validate($this->n, false, false); if ($result === false) { return false; } $this->n = $result; return true; }
[ "protected", "function", "validate", "(", ")", "{", "// Special case:", "if", "(", "$", "this", "->", "n", "===", "'+0'", "||", "$", "this", "->", "n", "===", "'-0'", ")", "{", "$", "this", "->", "n", "=", "'0'", ";", "}", "if", "(", "$", "this", "->", "n", "===", "'0'", "&&", "$", "this", "->", "unit", "===", "false", ")", "{", "return", "true", ";", "}", "if", "(", "!", "ctype_lower", "(", "$", "this", "->", "unit", ")", ")", "{", "$", "this", "->", "unit", "=", "strtolower", "(", "$", "this", "->", "unit", ")", ";", "}", "if", "(", "!", "isset", "(", "HTMLPurifier_Length", "::", "$", "allowedUnits", "[", "$", "this", "->", "unit", "]", ")", ")", "{", "return", "false", ";", "}", "// Hack:", "$", "def", "=", "new", "HTMLPurifier_AttrDef_CSS_Number", "(", ")", ";", "$", "result", "=", "$", "def", "->", "validate", "(", "$", "this", "->", "n", ",", "false", ",", "false", ")", ";", "if", "(", "$", "result", "===", "false", ")", "{", "return", "false", ";", "}", "$", "this", "->", "n", "=", "$", "result", ";", "return", "true", ";", "}" ]
Validates the number and unit. @return bool
[ "Validates", "the", "number", "and", "unit", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/htmlpurifier/HTMLPurifier/Length.php#L70-L93
214,572
moodle/moodle
lib/simplepie/library/SimplePie/Net/IPv6.php
SimplePie_Net_IPv6.uncompress
public static function uncompress($ip) { $c1 = -1; $c2 = -1; if (substr_count($ip, '::') === 1) { list($ip1, $ip2) = explode('::', $ip); if ($ip1 === '') { $c1 = -1; } else { $c1 = substr_count($ip1, ':'); } if ($ip2 === '') { $c2 = -1; } else { $c2 = substr_count($ip2, ':'); } if (strpos($ip2, '.') !== false) { $c2++; } // :: if ($c1 === -1 && $c2 === -1) { $ip = '0:0:0:0:0:0:0:0'; } // ::xxx else if ($c1 === -1) { $fill = str_repeat('0:', 7 - $c2); $ip = str_replace('::', $fill, $ip); } // xxx:: else if ($c2 === -1) { $fill = str_repeat(':0', 7 - $c1); $ip = str_replace('::', $fill, $ip); } // xxx::xxx else { $fill = ':' . str_repeat('0:', 6 - $c2 - $c1); $ip = str_replace('::', $fill, $ip); } } return $ip; }
php
public static function uncompress($ip) { $c1 = -1; $c2 = -1; if (substr_count($ip, '::') === 1) { list($ip1, $ip2) = explode('::', $ip); if ($ip1 === '') { $c1 = -1; } else { $c1 = substr_count($ip1, ':'); } if ($ip2 === '') { $c2 = -1; } else { $c2 = substr_count($ip2, ':'); } if (strpos($ip2, '.') !== false) { $c2++; } // :: if ($c1 === -1 && $c2 === -1) { $ip = '0:0:0:0:0:0:0:0'; } // ::xxx else if ($c1 === -1) { $fill = str_repeat('0:', 7 - $c2); $ip = str_replace('::', $fill, $ip); } // xxx:: else if ($c2 === -1) { $fill = str_repeat(':0', 7 - $c1); $ip = str_replace('::', $fill, $ip); } // xxx::xxx else { $fill = ':' . str_repeat('0:', 6 - $c2 - $c1); $ip = str_replace('::', $fill, $ip); } } return $ip; }
[ "public", "static", "function", "uncompress", "(", "$", "ip", ")", "{", "$", "c1", "=", "-", "1", ";", "$", "c2", "=", "-", "1", ";", "if", "(", "substr_count", "(", "$", "ip", ",", "'::'", ")", "===", "1", ")", "{", "list", "(", "$", "ip1", ",", "$", "ip2", ")", "=", "explode", "(", "'::'", ",", "$", "ip", ")", ";", "if", "(", "$", "ip1", "===", "''", ")", "{", "$", "c1", "=", "-", "1", ";", "}", "else", "{", "$", "c1", "=", "substr_count", "(", "$", "ip1", ",", "':'", ")", ";", "}", "if", "(", "$", "ip2", "===", "''", ")", "{", "$", "c2", "=", "-", "1", ";", "}", "else", "{", "$", "c2", "=", "substr_count", "(", "$", "ip2", ",", "':'", ")", ";", "}", "if", "(", "strpos", "(", "$", "ip2", ",", "'.'", ")", "!==", "false", ")", "{", "$", "c2", "++", ";", "}", "// ::", "if", "(", "$", "c1", "===", "-", "1", "&&", "$", "c2", "===", "-", "1", ")", "{", "$", "ip", "=", "'0:0:0:0:0:0:0:0'", ";", "}", "// ::xxx", "else", "if", "(", "$", "c1", "===", "-", "1", ")", "{", "$", "fill", "=", "str_repeat", "(", "'0:'", ",", "7", "-", "$", "c2", ")", ";", "$", "ip", "=", "str_replace", "(", "'::'", ",", "$", "fill", ",", "$", "ip", ")", ";", "}", "// xxx::", "else", "if", "(", "$", "c2", "===", "-", "1", ")", "{", "$", "fill", "=", "str_repeat", "(", "':0'", ",", "7", "-", "$", "c1", ")", ";", "$", "ip", "=", "str_replace", "(", "'::'", ",", "$", "fill", ",", "$", "ip", ")", ";", "}", "// xxx::xxx", "else", "{", "$", "fill", "=", "':'", ".", "str_repeat", "(", "'0:'", ",", "6", "-", "$", "c2", "-", "$", "c1", ")", ";", "$", "ip", "=", "str_replace", "(", "'::'", ",", "$", "fill", ",", "$", "ip", ")", ";", "}", "}", "return", "$", "ip", ";", "}" ]
Uncompresses an IPv6 address RFC 4291 allows you to compress concecutive zero pieces in an address to '::'. This method expects a valid IPv6 address and expands the '::' to the required number of zero pieces. Example: FF01::101 -> FF01:0:0:0:0:0:0:101 ::1 -> 0:0:0:0:0:0:0:1 @author Alexander Merz <alexander.merz@web.de> @author elfrink at introweb dot nl @author Josh Peck <jmp at joshpeck dot org> @copyright 2003-2005 The PHP Group @license http://www.opensource.org/licenses/bsd-license.php @param string $ip An IPv6 address @return string The uncompressed IPv6 address
[ "Uncompresses", "an", "IPv6", "address" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/simplepie/library/SimplePie/Net/IPv6.php#L78-L130
214,573
moodle/moodle
lib/simplepie/library/SimplePie/Net/IPv6.php
SimplePie_Net_IPv6.split_v6_v4
private static function split_v6_v4($ip) { if (strpos($ip, '.') !== false) { $pos = strrpos($ip, ':'); $ipv6_part = substr($ip, 0, $pos); $ipv4_part = substr($ip, $pos + 1); return array($ipv6_part, $ipv4_part); } else { return array($ip, ''); } }
php
private static function split_v6_v4($ip) { if (strpos($ip, '.') !== false) { $pos = strrpos($ip, ':'); $ipv6_part = substr($ip, 0, $pos); $ipv4_part = substr($ip, $pos + 1); return array($ipv6_part, $ipv4_part); } else { return array($ip, ''); } }
[ "private", "static", "function", "split_v6_v4", "(", "$", "ip", ")", "{", "if", "(", "strpos", "(", "$", "ip", ",", "'.'", ")", "!==", "false", ")", "{", "$", "pos", "=", "strrpos", "(", "$", "ip", ",", "':'", ")", ";", "$", "ipv6_part", "=", "substr", "(", "$", "ip", ",", "0", ",", "$", "pos", ")", ";", "$", "ipv4_part", "=", "substr", "(", "$", "ip", ",", "$", "pos", "+", "1", ")", ";", "return", "array", "(", "$", "ipv6_part", ",", "$", "ipv4_part", ")", ";", "}", "else", "{", "return", "array", "(", "$", "ip", ",", "''", ")", ";", "}", "}" ]
Splits an IPv6 address into the IPv6 and IPv4 representation parts RFC 4291 allows you to represent the last two parts of an IPv6 address using the standard IPv4 representation Example: 0:0:0:0:0:0:13.1.68.3 0:0:0:0:0:FFFF:129.144.52.38 @param string $ip An IPv6 address @return array [0] contains the IPv6 represented part, and [1] the IPv4 represented part
[ "Splits", "an", "IPv6", "address", "into", "the", "IPv6", "and", "IPv4", "representation", "parts" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/simplepie/library/SimplePie/Net/IPv6.php#L194-L207
214,574
moodle/moodle
lib/simplepie/library/SimplePie/Net/IPv6.php
SimplePie_Net_IPv6.check_ipv6
public static function check_ipv6($ip) { $ip = self::uncompress($ip); list($ipv6, $ipv4) = self::split_v6_v4($ip); $ipv6 = explode(':', $ipv6); $ipv4 = explode('.', $ipv4); if (count($ipv6) === 8 && count($ipv4) === 1 || count($ipv6) === 6 && count($ipv4) === 4) { foreach ($ipv6 as $ipv6_part) { // The section can't be empty if ($ipv6_part === '') return false; // Nor can it be over four characters if (strlen($ipv6_part) > 4) return false; // Remove leading zeros (this is safe because of the above) $ipv6_part = ltrim($ipv6_part, '0'); if ($ipv6_part === '') $ipv6_part = '0'; // Check the value is valid $value = hexdec($ipv6_part); if (dechex($value) !== strtolower($ipv6_part) || $value < 0 || $value > 0xFFFF) return false; } if (count($ipv4) === 4) { foreach ($ipv4 as $ipv4_part) { $value = (int) $ipv4_part; if ((string) $value !== $ipv4_part || $value < 0 || $value > 0xFF) return false; } } return true; } else { return false; } }
php
public static function check_ipv6($ip) { $ip = self::uncompress($ip); list($ipv6, $ipv4) = self::split_v6_v4($ip); $ipv6 = explode(':', $ipv6); $ipv4 = explode('.', $ipv4); if (count($ipv6) === 8 && count($ipv4) === 1 || count($ipv6) === 6 && count($ipv4) === 4) { foreach ($ipv6 as $ipv6_part) { // The section can't be empty if ($ipv6_part === '') return false; // Nor can it be over four characters if (strlen($ipv6_part) > 4) return false; // Remove leading zeros (this is safe because of the above) $ipv6_part = ltrim($ipv6_part, '0'); if ($ipv6_part === '') $ipv6_part = '0'; // Check the value is valid $value = hexdec($ipv6_part); if (dechex($value) !== strtolower($ipv6_part) || $value < 0 || $value > 0xFFFF) return false; } if (count($ipv4) === 4) { foreach ($ipv4 as $ipv4_part) { $value = (int) $ipv4_part; if ((string) $value !== $ipv4_part || $value < 0 || $value > 0xFF) return false; } } return true; } else { return false; } }
[ "public", "static", "function", "check_ipv6", "(", "$", "ip", ")", "{", "$", "ip", "=", "self", "::", "uncompress", "(", "$", "ip", ")", ";", "list", "(", "$", "ipv6", ",", "$", "ipv4", ")", "=", "self", "::", "split_v6_v4", "(", "$", "ip", ")", ";", "$", "ipv6", "=", "explode", "(", "':'", ",", "$", "ipv6", ")", ";", "$", "ipv4", "=", "explode", "(", "'.'", ",", "$", "ipv4", ")", ";", "if", "(", "count", "(", "$", "ipv6", ")", "===", "8", "&&", "count", "(", "$", "ipv4", ")", "===", "1", "||", "count", "(", "$", "ipv6", ")", "===", "6", "&&", "count", "(", "$", "ipv4", ")", "===", "4", ")", "{", "foreach", "(", "$", "ipv6", "as", "$", "ipv6_part", ")", "{", "// The section can't be empty", "if", "(", "$", "ipv6_part", "===", "''", ")", "return", "false", ";", "// Nor can it be over four characters", "if", "(", "strlen", "(", "$", "ipv6_part", ")", ">", "4", ")", "return", "false", ";", "// Remove leading zeros (this is safe because of the above)", "$", "ipv6_part", "=", "ltrim", "(", "$", "ipv6_part", ",", "'0'", ")", ";", "if", "(", "$", "ipv6_part", "===", "''", ")", "$", "ipv6_part", "=", "'0'", ";", "// Check the value is valid", "$", "value", "=", "hexdec", "(", "$", "ipv6_part", ")", ";", "if", "(", "dechex", "(", "$", "value", ")", "!==", "strtolower", "(", "$", "ipv6_part", ")", "||", "$", "value", "<", "0", "||", "$", "value", ">", "0xFFFF", ")", "return", "false", ";", "}", "if", "(", "count", "(", "$", "ipv4", ")", "===", "4", ")", "{", "foreach", "(", "$", "ipv4", "as", "$", "ipv4_part", ")", "{", "$", "value", "=", "(", "int", ")", "$", "ipv4_part", ";", "if", "(", "(", "string", ")", "$", "value", "!==", "$", "ipv4_part", "||", "$", "value", "<", "0", "||", "$", "value", ">", "0xFF", ")", "return", "false", ";", "}", "}", "return", "true", ";", "}", "else", "{", "return", "false", ";", "}", "}" ]
Checks an IPv6 address Checks if the given IP is a valid IPv6 address @param string $ip An IPv6 address @return bool true if $ip is a valid IPv6 address
[ "Checks", "an", "IPv6", "address" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/simplepie/library/SimplePie/Net/IPv6.php#L217-L260
214,575
moodle/moodle
enrol/lti/backup/moodle2/restore_enrol_lti_plugin.class.php
restore_enrol_lti_plugin.define_enrol_plugin_structure
protected function define_enrol_plugin_structure() { $paths = array(); $paths[] = new restore_path_element('enrol_lti_tool', $this->connectionpoint->get_path() . '/tool'); $paths[] = new restore_path_element('enrol_lti_users', $this->connectionpoint->get_path() . '/tool/users/user'); return $paths; }
php
protected function define_enrol_plugin_structure() { $paths = array(); $paths[] = new restore_path_element('enrol_lti_tool', $this->connectionpoint->get_path() . '/tool'); $paths[] = new restore_path_element('enrol_lti_users', $this->connectionpoint->get_path() . '/tool/users/user'); return $paths; }
[ "protected", "function", "define_enrol_plugin_structure", "(", ")", "{", "$", "paths", "=", "array", "(", ")", ";", "$", "paths", "[", "]", "=", "new", "restore_path_element", "(", "'enrol_lti_tool'", ",", "$", "this", "->", "connectionpoint", "->", "get_path", "(", ")", ".", "'/tool'", ")", ";", "$", "paths", "[", "]", "=", "new", "restore_path_element", "(", "'enrol_lti_users'", ",", "$", "this", "->", "connectionpoint", "->", "get_path", "(", ")", ".", "'/tool/users/user'", ")", ";", "return", "$", "paths", ";", "}" ]
Declares the enrol LTI XML paths attached to the enrol element @return array of {@link restore_path_element}
[ "Declares", "the", "enrol", "LTI", "XML", "paths", "attached", "to", "the", "enrol", "element" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/enrol/lti/backup/moodle2/restore_enrol_lti_plugin.class.php#L46-L53
214,576
moodle/moodle
enrol/lti/backup/moodle2/restore_enrol_lti_plugin.class.php
restore_enrol_lti_plugin.process_enrol_lti_tool
public function process_enrol_lti_tool($data) { global $DB; $data = (object) $data; // Store the old id. $oldid = $data->id; // Change the values before we insert it. $data->timecreated = time(); $data->timemodified = $data->timecreated; // Now we can insert the new record. $data->id = $DB->insert_record('enrol_lti_tools', $data); // Add the array of tools we need to process later. $this->tools[$data->id] = $data; // Set up the mapping. $this->set_mapping('enrol_lti_tool', $oldid, $data->id); }
php
public function process_enrol_lti_tool($data) { global $DB; $data = (object) $data; // Store the old id. $oldid = $data->id; // Change the values before we insert it. $data->timecreated = time(); $data->timemodified = $data->timecreated; // Now we can insert the new record. $data->id = $DB->insert_record('enrol_lti_tools', $data); // Add the array of tools we need to process later. $this->tools[$data->id] = $data; // Set up the mapping. $this->set_mapping('enrol_lti_tool', $oldid, $data->id); }
[ "public", "function", "process_enrol_lti_tool", "(", "$", "data", ")", "{", "global", "$", "DB", ";", "$", "data", "=", "(", "object", ")", "$", "data", ";", "// Store the old id.", "$", "oldid", "=", "$", "data", "->", "id", ";", "// Change the values before we insert it.", "$", "data", "->", "timecreated", "=", "time", "(", ")", ";", "$", "data", "->", "timemodified", "=", "$", "data", "->", "timecreated", ";", "// Now we can insert the new record.", "$", "data", "->", "id", "=", "$", "DB", "->", "insert_record", "(", "'enrol_lti_tools'", ",", "$", "data", ")", ";", "// Add the array of tools we need to process later.", "$", "this", "->", "tools", "[", "$", "data", "->", "id", "]", "=", "$", "data", ";", "// Set up the mapping.", "$", "this", "->", "set_mapping", "(", "'enrol_lti_tool'", ",", "$", "oldid", ",", "$", "data", "->", "id", ")", ";", "}" ]
Processes LTI tools element data @param array|stdClass $data
[ "Processes", "LTI", "tools", "element", "data" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/enrol/lti/backup/moodle2/restore_enrol_lti_plugin.class.php#L60-L80
214,577
moodle/moodle
enrol/lti/backup/moodle2/restore_enrol_lti_plugin.class.php
restore_enrol_lti_plugin.process_enrol_lti_users
public function process_enrol_lti_users($data) { global $DB; $data = (object) $data; $data->userid = $this->get_mappingid('user', $data->userid); $data->toolid = $this->get_mappingid('enrol_lti_tool', $data->toolid); $data->timecreated = time(); $DB->insert_record('enrol_lti_users', $data); }
php
public function process_enrol_lti_users($data) { global $DB; $data = (object) $data; $data->userid = $this->get_mappingid('user', $data->userid); $data->toolid = $this->get_mappingid('enrol_lti_tool', $data->toolid); $data->timecreated = time(); $DB->insert_record('enrol_lti_users', $data); }
[ "public", "function", "process_enrol_lti_users", "(", "$", "data", ")", "{", "global", "$", "DB", ";", "$", "data", "=", "(", "object", ")", "$", "data", ";", "$", "data", "->", "userid", "=", "$", "this", "->", "get_mappingid", "(", "'user'", ",", "$", "data", "->", "userid", ")", ";", "$", "data", "->", "toolid", "=", "$", "this", "->", "get_mappingid", "(", "'enrol_lti_tool'", ",", "$", "data", "->", "toolid", ")", ";", "$", "data", "->", "timecreated", "=", "time", "(", ")", ";", "$", "DB", "->", "insert_record", "(", "'enrol_lti_users'", ",", "$", "data", ")", ";", "}" ]
Processes LTI users element data @param array|stdClass $data The data to insert as a comment
[ "Processes", "LTI", "users", "element", "data" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/enrol/lti/backup/moodle2/restore_enrol_lti_plugin.class.php#L87-L97
214,578
moodle/moodle
enrol/lti/backup/moodle2/restore_enrol_lti_plugin.class.php
restore_enrol_lti_plugin.after_restore_enrol
public function after_restore_enrol() { global $DB; // Need to go through and change the values. foreach ($this->tools as $tool) { $updatetool = new stdClass(); $updatetool->id = $tool->id; $updatetool->enrolid = $this->get_mappingid('enrol', $tool->enrolid); $updatetool->contextid = $this->get_mappingid('context', $tool->contextid); $DB->update_record('enrol_lti_tools', $updatetool); } }
php
public function after_restore_enrol() { global $DB; // Need to go through and change the values. foreach ($this->tools as $tool) { $updatetool = new stdClass(); $updatetool->id = $tool->id; $updatetool->enrolid = $this->get_mappingid('enrol', $tool->enrolid); $updatetool->contextid = $this->get_mappingid('context', $tool->contextid); $DB->update_record('enrol_lti_tools', $updatetool); } }
[ "public", "function", "after_restore_enrol", "(", ")", "{", "global", "$", "DB", ";", "// Need to go through and change the values.", "foreach", "(", "$", "this", "->", "tools", "as", "$", "tool", ")", "{", "$", "updatetool", "=", "new", "stdClass", "(", ")", ";", "$", "updatetool", "->", "id", "=", "$", "tool", "->", "id", ";", "$", "updatetool", "->", "enrolid", "=", "$", "this", "->", "get_mappingid", "(", "'enrol'", ",", "$", "tool", "->", "enrolid", ")", ";", "$", "updatetool", "->", "contextid", "=", "$", "this", "->", "get_mappingid", "(", "'context'", ",", "$", "tool", "->", "contextid", ")", ";", "$", "DB", "->", "update_record", "(", "'enrol_lti_tools'", ",", "$", "updatetool", ")", ";", "}", "}" ]
This function is executed after all the tasks in the plan have been finished. This must be done here because the activities have not been restored yet.
[ "This", "function", "is", "executed", "after", "all", "the", "tasks", "in", "the", "plan", "have", "been", "finished", ".", "This", "must", "be", "done", "here", "because", "the", "activities", "have", "not", "been", "restored", "yet", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/enrol/lti/backup/moodle2/restore_enrol_lti_plugin.class.php#L103-L114
214,579
moodle/moodle
lib/phpexcel/PHPExcel/Writer/HTML.php
PHPExcel_Writer_HTML.mapBorderStyle
private function mapBorderStyle($borderStyle) { switch ($borderStyle) { case PHPExcel_Style_Border::BORDER_NONE: return 'none'; case PHPExcel_Style_Border::BORDER_DASHDOT: return '1px dashed'; case PHPExcel_Style_Border::BORDER_DASHDOTDOT: return '1px dotted'; case PHPExcel_Style_Border::BORDER_DASHED: return '1px dashed'; case PHPExcel_Style_Border::BORDER_DOTTED: return '1px dotted'; case PHPExcel_Style_Border::BORDER_DOUBLE: return '3px double'; case PHPExcel_Style_Border::BORDER_HAIR: return '1px solid'; case PHPExcel_Style_Border::BORDER_MEDIUM: return '2px solid'; case PHPExcel_Style_Border::BORDER_MEDIUMDASHDOT: return '2px dashed'; case PHPExcel_Style_Border::BORDER_MEDIUMDASHDOTDOT: return '2px dotted'; case PHPExcel_Style_Border::BORDER_MEDIUMDASHED: return '2px dashed'; case PHPExcel_Style_Border::BORDER_SLANTDASHDOT: return '2px dashed'; case PHPExcel_Style_Border::BORDER_THICK: return '3px solid'; case PHPExcel_Style_Border::BORDER_THIN: return '1px solid'; default: // map others to thin return '1px solid'; } }
php
private function mapBorderStyle($borderStyle) { switch ($borderStyle) { case PHPExcel_Style_Border::BORDER_NONE: return 'none'; case PHPExcel_Style_Border::BORDER_DASHDOT: return '1px dashed'; case PHPExcel_Style_Border::BORDER_DASHDOTDOT: return '1px dotted'; case PHPExcel_Style_Border::BORDER_DASHED: return '1px dashed'; case PHPExcel_Style_Border::BORDER_DOTTED: return '1px dotted'; case PHPExcel_Style_Border::BORDER_DOUBLE: return '3px double'; case PHPExcel_Style_Border::BORDER_HAIR: return '1px solid'; case PHPExcel_Style_Border::BORDER_MEDIUM: return '2px solid'; case PHPExcel_Style_Border::BORDER_MEDIUMDASHDOT: return '2px dashed'; case PHPExcel_Style_Border::BORDER_MEDIUMDASHDOTDOT: return '2px dotted'; case PHPExcel_Style_Border::BORDER_MEDIUMDASHED: return '2px dashed'; case PHPExcel_Style_Border::BORDER_SLANTDASHDOT: return '2px dashed'; case PHPExcel_Style_Border::BORDER_THICK: return '3px solid'; case PHPExcel_Style_Border::BORDER_THIN: return '1px solid'; default: // map others to thin return '1px solid'; } }
[ "private", "function", "mapBorderStyle", "(", "$", "borderStyle", ")", "{", "switch", "(", "$", "borderStyle", ")", "{", "case", "PHPExcel_Style_Border", "::", "BORDER_NONE", ":", "return", "'none'", ";", "case", "PHPExcel_Style_Border", "::", "BORDER_DASHDOT", ":", "return", "'1px dashed'", ";", "case", "PHPExcel_Style_Border", "::", "BORDER_DASHDOTDOT", ":", "return", "'1px dotted'", ";", "case", "PHPExcel_Style_Border", "::", "BORDER_DASHED", ":", "return", "'1px dashed'", ";", "case", "PHPExcel_Style_Border", "::", "BORDER_DOTTED", ":", "return", "'1px dotted'", ";", "case", "PHPExcel_Style_Border", "::", "BORDER_DOUBLE", ":", "return", "'3px double'", ";", "case", "PHPExcel_Style_Border", "::", "BORDER_HAIR", ":", "return", "'1px solid'", ";", "case", "PHPExcel_Style_Border", "::", "BORDER_MEDIUM", ":", "return", "'2px solid'", ";", "case", "PHPExcel_Style_Border", "::", "BORDER_MEDIUMDASHDOT", ":", "return", "'2px dashed'", ";", "case", "PHPExcel_Style_Border", "::", "BORDER_MEDIUMDASHDOTDOT", ":", "return", "'2px dotted'", ";", "case", "PHPExcel_Style_Border", "::", "BORDER_MEDIUMDASHED", ":", "return", "'2px dashed'", ";", "case", "PHPExcel_Style_Border", "::", "BORDER_SLANTDASHDOT", ":", "return", "'2px dashed'", ";", "case", "PHPExcel_Style_Border", "::", "BORDER_THICK", ":", "return", "'3px solid'", ";", "case", "PHPExcel_Style_Border", "::", "BORDER_THIN", ":", "return", "'1px solid'", ";", "default", ":", "// map others to thin", "return", "'1px solid'", ";", "}", "}" ]
Map border style @param int $borderStyle Sheet index @return string
[ "Map", "border", "style" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/phpexcel/PHPExcel/Writer/HTML.php#L237-L272
214,580
moodle/moodle
lib/phpexcel/PHPExcel/Writer/HTML.php
PHPExcel_Writer_HTML.generateHTMLHeader
public function generateHTMLHeader($pIncludeStyles = false) { // PHPExcel object known? if (is_null($this->phpExcel)) { throw new PHPExcel_Writer_Exception('Internal PHPExcel object not set to an instance of an object.'); } // Construct HTML $properties = $this->phpExcel->getProperties(); $html = '<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">' . PHP_EOL; $html .= '<!-- Generated by PHPExcel - http://www.phpexcel.net -->' . PHP_EOL; $html .= '<html>' . PHP_EOL; $html .= ' <head>' . PHP_EOL; $html .= ' <meta http-equiv="Content-Type" content="text/html; charset=utf-8">' . PHP_EOL; if ($properties->getTitle() > '') { $html .= ' <title>' . htmlspecialchars($properties->getTitle()) . '</title>' . PHP_EOL; } if ($properties->getCreator() > '') { $html .= ' <meta name="author" content="' . htmlspecialchars($properties->getCreator()) . '" />' . PHP_EOL; } if ($properties->getTitle() > '') { $html .= ' <meta name="title" content="' . htmlspecialchars($properties->getTitle()) . '" />' . PHP_EOL; } if ($properties->getDescription() > '') { $html .= ' <meta name="description" content="' . htmlspecialchars($properties->getDescription()) . '" />' . PHP_EOL; } if ($properties->getSubject() > '') { $html .= ' <meta name="subject" content="' . htmlspecialchars($properties->getSubject()) . '" />' . PHP_EOL; } if ($properties->getKeywords() > '') { $html .= ' <meta name="keywords" content="' . htmlspecialchars($properties->getKeywords()) . '" />' . PHP_EOL; } if ($properties->getCategory() > '') { $html .= ' <meta name="category" content="' . htmlspecialchars($properties->getCategory()) . '" />' . PHP_EOL; } if ($properties->getCompany() > '') { $html .= ' <meta name="company" content="' . htmlspecialchars($properties->getCompany()) . '" />' . PHP_EOL; } if ($properties->getManager() > '') { $html .= ' <meta name="manager" content="' . htmlspecialchars($properties->getManager()) . '" />' . PHP_EOL; } if ($pIncludeStyles) { $html .= $this->generateStyles(true); } $html .= ' </head>' . PHP_EOL; $html .= '' . PHP_EOL; $html .= ' <body>' . PHP_EOL; return $html; }
php
public function generateHTMLHeader($pIncludeStyles = false) { // PHPExcel object known? if (is_null($this->phpExcel)) { throw new PHPExcel_Writer_Exception('Internal PHPExcel object not set to an instance of an object.'); } // Construct HTML $properties = $this->phpExcel->getProperties(); $html = '<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">' . PHP_EOL; $html .= '<!-- Generated by PHPExcel - http://www.phpexcel.net -->' . PHP_EOL; $html .= '<html>' . PHP_EOL; $html .= ' <head>' . PHP_EOL; $html .= ' <meta http-equiv="Content-Type" content="text/html; charset=utf-8">' . PHP_EOL; if ($properties->getTitle() > '') { $html .= ' <title>' . htmlspecialchars($properties->getTitle()) . '</title>' . PHP_EOL; } if ($properties->getCreator() > '') { $html .= ' <meta name="author" content="' . htmlspecialchars($properties->getCreator()) . '" />' . PHP_EOL; } if ($properties->getTitle() > '') { $html .= ' <meta name="title" content="' . htmlspecialchars($properties->getTitle()) . '" />' . PHP_EOL; } if ($properties->getDescription() > '') { $html .= ' <meta name="description" content="' . htmlspecialchars($properties->getDescription()) . '" />' . PHP_EOL; } if ($properties->getSubject() > '') { $html .= ' <meta name="subject" content="' . htmlspecialchars($properties->getSubject()) . '" />' . PHP_EOL; } if ($properties->getKeywords() > '') { $html .= ' <meta name="keywords" content="' . htmlspecialchars($properties->getKeywords()) . '" />' . PHP_EOL; } if ($properties->getCategory() > '') { $html .= ' <meta name="category" content="' . htmlspecialchars($properties->getCategory()) . '" />' . PHP_EOL; } if ($properties->getCompany() > '') { $html .= ' <meta name="company" content="' . htmlspecialchars($properties->getCompany()) . '" />' . PHP_EOL; } if ($properties->getManager() > '') { $html .= ' <meta name="manager" content="' . htmlspecialchars($properties->getManager()) . '" />' . PHP_EOL; } if ($pIncludeStyles) { $html .= $this->generateStyles(true); } $html .= ' </head>' . PHP_EOL; $html .= '' . PHP_EOL; $html .= ' <body>' . PHP_EOL; return $html; }
[ "public", "function", "generateHTMLHeader", "(", "$", "pIncludeStyles", "=", "false", ")", "{", "// PHPExcel object known?", "if", "(", "is_null", "(", "$", "this", "->", "phpExcel", ")", ")", "{", "throw", "new", "PHPExcel_Writer_Exception", "(", "'Internal PHPExcel object not set to an instance of an object.'", ")", ";", "}", "// Construct HTML", "$", "properties", "=", "$", "this", "->", "phpExcel", "->", "getProperties", "(", ")", ";", "$", "html", "=", "'<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01//EN\" \"http://www.w3.org/TR/html4/strict.dtd\">'", ".", "PHP_EOL", ";", "$", "html", ".=", "'<!-- Generated by PHPExcel - http://www.phpexcel.net -->'", ".", "PHP_EOL", ";", "$", "html", ".=", "'<html>'", ".", "PHP_EOL", ";", "$", "html", ".=", "' <head>'", ".", "PHP_EOL", ";", "$", "html", ".=", "' <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">'", ".", "PHP_EOL", ";", "if", "(", "$", "properties", "->", "getTitle", "(", ")", ">", "''", ")", "{", "$", "html", ".=", "' <title>'", ".", "htmlspecialchars", "(", "$", "properties", "->", "getTitle", "(", ")", ")", ".", "'</title>'", ".", "PHP_EOL", ";", "}", "if", "(", "$", "properties", "->", "getCreator", "(", ")", ">", "''", ")", "{", "$", "html", ".=", "' <meta name=\"author\" content=\"'", ".", "htmlspecialchars", "(", "$", "properties", "->", "getCreator", "(", ")", ")", ".", "'\" />'", ".", "PHP_EOL", ";", "}", "if", "(", "$", "properties", "->", "getTitle", "(", ")", ">", "''", ")", "{", "$", "html", ".=", "' <meta name=\"title\" content=\"'", ".", "htmlspecialchars", "(", "$", "properties", "->", "getTitle", "(", ")", ")", ".", "'\" />'", ".", "PHP_EOL", ";", "}", "if", "(", "$", "properties", "->", "getDescription", "(", ")", ">", "''", ")", "{", "$", "html", ".=", "' <meta name=\"description\" content=\"'", ".", "htmlspecialchars", "(", "$", "properties", "->", "getDescription", "(", ")", ")", ".", "'\" />'", ".", "PHP_EOL", ";", "}", "if", "(", "$", "properties", "->", "getSubject", "(", ")", ">", "''", ")", "{", "$", "html", ".=", "' <meta name=\"subject\" content=\"'", ".", "htmlspecialchars", "(", "$", "properties", "->", "getSubject", "(", ")", ")", ".", "'\" />'", ".", "PHP_EOL", ";", "}", "if", "(", "$", "properties", "->", "getKeywords", "(", ")", ">", "''", ")", "{", "$", "html", ".=", "' <meta name=\"keywords\" content=\"'", ".", "htmlspecialchars", "(", "$", "properties", "->", "getKeywords", "(", ")", ")", ".", "'\" />'", ".", "PHP_EOL", ";", "}", "if", "(", "$", "properties", "->", "getCategory", "(", ")", ">", "''", ")", "{", "$", "html", ".=", "' <meta name=\"category\" content=\"'", ".", "htmlspecialchars", "(", "$", "properties", "->", "getCategory", "(", ")", ")", ".", "'\" />'", ".", "PHP_EOL", ";", "}", "if", "(", "$", "properties", "->", "getCompany", "(", ")", ">", "''", ")", "{", "$", "html", ".=", "' <meta name=\"company\" content=\"'", ".", "htmlspecialchars", "(", "$", "properties", "->", "getCompany", "(", ")", ")", ".", "'\" />'", ".", "PHP_EOL", ";", "}", "if", "(", "$", "properties", "->", "getManager", "(", ")", ">", "''", ")", "{", "$", "html", ".=", "' <meta name=\"manager\" content=\"'", ".", "htmlspecialchars", "(", "$", "properties", "->", "getManager", "(", ")", ")", ".", "'\" />'", ".", "PHP_EOL", ";", "}", "if", "(", "$", "pIncludeStyles", ")", "{", "$", "html", ".=", "$", "this", "->", "generateStyles", "(", "true", ")", ";", "}", "$", "html", ".=", "' </head>'", ".", "PHP_EOL", ";", "$", "html", ".=", "''", ".", "PHP_EOL", ";", "$", "html", ".=", "' <body>'", ".", "PHP_EOL", ";", "return", "$", "html", ";", "}" ]
Generate HTML header @param boolean $pIncludeStyles Include styles? @return string @throws PHPExcel_Writer_Exception
[ "Generate", "HTML", "header" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/phpexcel/PHPExcel/Writer/HTML.php#L334-L385
214,581
moodle/moodle
lib/phpexcel/PHPExcel/Writer/HTML.php
PHPExcel_Writer_HTML.writeChartInCell
private function writeChartInCell(PHPExcel_Worksheet $pSheet, $coordinates) { // Construct HTML $html = ''; // Write charts foreach ($pSheet->getChartCollection() as $chart) { if ($chart instanceof PHPExcel_Chart) { $chartCoordinates = $chart->getTopLeftPosition(); if ($chartCoordinates['cell'] == $coordinates) { $chartFileName = PHPExcel_Shared_File::sys_get_temp_dir().'/'.uniqid().'.png'; if (!$chart->render($chartFileName)) { return; } $html .= PHP_EOL; $imageDetails = getimagesize($chartFileName); if ($fp = fopen($chartFileName, "rb", 0)) { $picture = fread($fp, filesize($chartFileName)); fclose($fp); // base64 encode the binary data, then break it // into chunks according to RFC 2045 semantics $base64 = chunk_split(base64_encode($picture)); $imageData = 'data:'.$imageDetails['mime'].';base64,' . $base64; $html .= '<div style="position: relative;">'; $html .= '<img style="position: absolute; z-index: 1; left: ' . $chartCoordinates['xOffset'] . 'px; top: ' . $chartCoordinates['yOffset'] . 'px; width: ' . $imageDetails[0] . 'px; height: ' . $imageDetails[1] . 'px;" src="' . $imageData . '" border="0" />' . PHP_EOL; $html .= '</div>'; unlink($chartFileName); } } } } // Return return $html; }
php
private function writeChartInCell(PHPExcel_Worksheet $pSheet, $coordinates) { // Construct HTML $html = ''; // Write charts foreach ($pSheet->getChartCollection() as $chart) { if ($chart instanceof PHPExcel_Chart) { $chartCoordinates = $chart->getTopLeftPosition(); if ($chartCoordinates['cell'] == $coordinates) { $chartFileName = PHPExcel_Shared_File::sys_get_temp_dir().'/'.uniqid().'.png'; if (!$chart->render($chartFileName)) { return; } $html .= PHP_EOL; $imageDetails = getimagesize($chartFileName); if ($fp = fopen($chartFileName, "rb", 0)) { $picture = fread($fp, filesize($chartFileName)); fclose($fp); // base64 encode the binary data, then break it // into chunks according to RFC 2045 semantics $base64 = chunk_split(base64_encode($picture)); $imageData = 'data:'.$imageDetails['mime'].';base64,' . $base64; $html .= '<div style="position: relative;">'; $html .= '<img style="position: absolute; z-index: 1; left: ' . $chartCoordinates['xOffset'] . 'px; top: ' . $chartCoordinates['yOffset'] . 'px; width: ' . $imageDetails[0] . 'px; height: ' . $imageDetails[1] . 'px;" src="' . $imageData . '" border="0" />' . PHP_EOL; $html .= '</div>'; unlink($chartFileName); } } } } // Return return $html; }
[ "private", "function", "writeChartInCell", "(", "PHPExcel_Worksheet", "$", "pSheet", ",", "$", "coordinates", ")", "{", "// Construct HTML", "$", "html", "=", "''", ";", "// Write charts", "foreach", "(", "$", "pSheet", "->", "getChartCollection", "(", ")", "as", "$", "chart", ")", "{", "if", "(", "$", "chart", "instanceof", "PHPExcel_Chart", ")", "{", "$", "chartCoordinates", "=", "$", "chart", "->", "getTopLeftPosition", "(", ")", ";", "if", "(", "$", "chartCoordinates", "[", "'cell'", "]", "==", "$", "coordinates", ")", "{", "$", "chartFileName", "=", "PHPExcel_Shared_File", "::", "sys_get_temp_dir", "(", ")", ".", "'/'", ".", "uniqid", "(", ")", ".", "'.png'", ";", "if", "(", "!", "$", "chart", "->", "render", "(", "$", "chartFileName", ")", ")", "{", "return", ";", "}", "$", "html", ".=", "PHP_EOL", ";", "$", "imageDetails", "=", "getimagesize", "(", "$", "chartFileName", ")", ";", "if", "(", "$", "fp", "=", "fopen", "(", "$", "chartFileName", ",", "\"rb\"", ",", "0", ")", ")", "{", "$", "picture", "=", "fread", "(", "$", "fp", ",", "filesize", "(", "$", "chartFileName", ")", ")", ";", "fclose", "(", "$", "fp", ")", ";", "// base64 encode the binary data, then break it", "// into chunks according to RFC 2045 semantics", "$", "base64", "=", "chunk_split", "(", "base64_encode", "(", "$", "picture", ")", ")", ";", "$", "imageData", "=", "'data:'", ".", "$", "imageDetails", "[", "'mime'", "]", ".", "';base64,'", ".", "$", "base64", ";", "$", "html", ".=", "'<div style=\"position: relative;\">'", ";", "$", "html", ".=", "'<img style=\"position: absolute; z-index: 1; left: '", ".", "$", "chartCoordinates", "[", "'xOffset'", "]", ".", "'px; top: '", ".", "$", "chartCoordinates", "[", "'yOffset'", "]", ".", "'px; width: '", ".", "$", "imageDetails", "[", "0", "]", ".", "'px; height: '", ".", "$", "imageDetails", "[", "1", "]", ".", "'px;\" src=\"'", ".", "$", "imageData", ".", "'\" border=\"0\" />'", ".", "PHP_EOL", ";", "$", "html", ".=", "'</div>'", ";", "unlink", "(", "$", "chartFileName", ")", ";", "}", "}", "}", "}", "// Return", "return", "$", "html", ";", "}" ]
Generate chart tag in cell @param PHPExcel_Worksheet $pSheet PHPExcel_Worksheet @param string $coordinates Cell coordinates @return string @throws PHPExcel_Writer_Exception
[ "Generate", "chart", "tag", "in", "cell" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/phpexcel/PHPExcel/Writer/HTML.php#L673-L710
214,582
moodle/moodle
calendar/classes/type_factory.php
type_factory.get_list_of_calendar_types
public static function get_list_of_calendar_types() { $calendars = array(); $calendardirs = \core_component::get_plugin_list('calendartype'); foreach ($calendardirs as $name => $location) { $calendars[$name] = get_string('name', "calendartype_{$name}"); } return $calendars; }
php
public static function get_list_of_calendar_types() { $calendars = array(); $calendardirs = \core_component::get_plugin_list('calendartype'); foreach ($calendardirs as $name => $location) { $calendars[$name] = get_string('name', "calendartype_{$name}"); } return $calendars; }
[ "public", "static", "function", "get_list_of_calendar_types", "(", ")", "{", "$", "calendars", "=", "array", "(", ")", ";", "$", "calendardirs", "=", "\\", "core_component", "::", "get_plugin_list", "(", "'calendartype'", ")", ";", "foreach", "(", "$", "calendardirs", "as", "$", "name", "=>", "$", "location", ")", "{", "$", "calendars", "[", "$", "name", "]", "=", "get_string", "(", "'name'", ",", "\"calendartype_{$name}\"", ")", ";", "}", "return", "$", "calendars", ";", "}" ]
Returns a list of calendar typess available for use. @return array the list of calendar types
[ "Returns", "a", "list", "of", "calendar", "typess", "available", "for", "use", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/calendar/classes/type_factory.php#L58-L67
214,583
moodle/moodle
calendar/classes/type_factory.php
type_factory.get_calendar_type
public static function get_calendar_type() { global $CFG, $USER, $SESSION, $COURSE; // Course calendartype can override all other settings for this page. if (!empty($COURSE->id) and $COURSE->id != SITEID and !empty($COURSE->calendartype)) { $return = $COURSE->calendartype; } else if (!empty($SESSION->calendartype)) { // Session calendartype can override other settings. $return = $SESSION->calendartype; } else if (!empty($USER->calendartype)) { $return = $USER->calendartype; } else if (!empty($CFG->calendartype)) { $return = $CFG->calendartype; } else { $return = 'gregorian'; } return $return; }
php
public static function get_calendar_type() { global $CFG, $USER, $SESSION, $COURSE; // Course calendartype can override all other settings for this page. if (!empty($COURSE->id) and $COURSE->id != SITEID and !empty($COURSE->calendartype)) { $return = $COURSE->calendartype; } else if (!empty($SESSION->calendartype)) { // Session calendartype can override other settings. $return = $SESSION->calendartype; } else if (!empty($USER->calendartype)) { $return = $USER->calendartype; } else if (!empty($CFG->calendartype)) { $return = $CFG->calendartype; } else { $return = 'gregorian'; } return $return; }
[ "public", "static", "function", "get_calendar_type", "(", ")", "{", "global", "$", "CFG", ",", "$", "USER", ",", "$", "SESSION", ",", "$", "COURSE", ";", "// Course calendartype can override all other settings for this page.", "if", "(", "!", "empty", "(", "$", "COURSE", "->", "id", ")", "and", "$", "COURSE", "->", "id", "!=", "SITEID", "and", "!", "empty", "(", "$", "COURSE", "->", "calendartype", ")", ")", "{", "$", "return", "=", "$", "COURSE", "->", "calendartype", ";", "}", "else", "if", "(", "!", "empty", "(", "$", "SESSION", "->", "calendartype", ")", ")", "{", "// Session calendartype can override other settings.", "$", "return", "=", "$", "SESSION", "->", "calendartype", ";", "}", "else", "if", "(", "!", "empty", "(", "$", "USER", "->", "calendartype", ")", ")", "{", "$", "return", "=", "$", "USER", "->", "calendartype", ";", "}", "else", "if", "(", "!", "empty", "(", "$", "CFG", "->", "calendartype", ")", ")", "{", "$", "return", "=", "$", "CFG", "->", "calendartype", ";", "}", "else", "{", "$", "return", "=", "'gregorian'", ";", "}", "return", "$", "return", ";", "}" ]
Returns the current calendar type in use. @return string the current calendar type being used
[ "Returns", "the", "current", "calendar", "type", "in", "use", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/calendar/classes/type_factory.php#L74-L91
214,584
moodle/moodle
grade/grading/form/rubric/rubriceditor.php
MoodleQuickForm_rubriceditor.toHtml
public function toHtml() { global $PAGE; $html = $this->_getTabs(); $renderer = $PAGE->get_renderer('gradingform_rubric'); $data = $this->prepare_data(null, $this->wasvalidated); if (!$this->_flagFrozen) { $mode = gradingform_rubric_controller::DISPLAY_EDIT_FULL; $module = array('name'=>'gradingform_rubriceditor', 'fullpath'=>'/grade/grading/form/rubric/js/rubriceditor.js', 'requires' => array('base', 'dom', 'event', 'event-touch', 'escape'), 'strings' => array(array('confirmdeletecriterion', 'gradingform_rubric'), array('confirmdeletelevel', 'gradingform_rubric'), array('criterionempty', 'gradingform_rubric'), array('levelempty', 'gradingform_rubric') )); $PAGE->requires->js_init_call('M.gradingform_rubriceditor.init', array( array('name' => $this->getName(), 'criteriontemplate' => $renderer->criterion_template($mode, $data['options'], $this->getName()), 'leveltemplate' => $renderer->level_template($mode, $data['options'], $this->getName()) )), true, $module); } else { // Rubric is frozen, no javascript needed if ($this->_persistantFreeze) { $mode = gradingform_rubric_controller::DISPLAY_EDIT_FROZEN; } else { $mode = gradingform_rubric_controller::DISPLAY_PREVIEW; } } if ($this->regradeconfirmation) { if (!isset($data['regrade'])) { $data['regrade'] = 1; } $html .= $renderer->display_regrade_confirmation($this->getName(), $this->regradeconfirmation, $data['regrade']); } if ($this->validationerrors) { $html .= html_writer::div($renderer->notification($this->validationerrors)); } $html .= $renderer->display_rubric($data['criteria'], $data['options'], $mode, $this->getName()); return $html; }
php
public function toHtml() { global $PAGE; $html = $this->_getTabs(); $renderer = $PAGE->get_renderer('gradingform_rubric'); $data = $this->prepare_data(null, $this->wasvalidated); if (!$this->_flagFrozen) { $mode = gradingform_rubric_controller::DISPLAY_EDIT_FULL; $module = array('name'=>'gradingform_rubriceditor', 'fullpath'=>'/grade/grading/form/rubric/js/rubriceditor.js', 'requires' => array('base', 'dom', 'event', 'event-touch', 'escape'), 'strings' => array(array('confirmdeletecriterion', 'gradingform_rubric'), array('confirmdeletelevel', 'gradingform_rubric'), array('criterionempty', 'gradingform_rubric'), array('levelempty', 'gradingform_rubric') )); $PAGE->requires->js_init_call('M.gradingform_rubriceditor.init', array( array('name' => $this->getName(), 'criteriontemplate' => $renderer->criterion_template($mode, $data['options'], $this->getName()), 'leveltemplate' => $renderer->level_template($mode, $data['options'], $this->getName()) )), true, $module); } else { // Rubric is frozen, no javascript needed if ($this->_persistantFreeze) { $mode = gradingform_rubric_controller::DISPLAY_EDIT_FROZEN; } else { $mode = gradingform_rubric_controller::DISPLAY_PREVIEW; } } if ($this->regradeconfirmation) { if (!isset($data['regrade'])) { $data['regrade'] = 1; } $html .= $renderer->display_regrade_confirmation($this->getName(), $this->regradeconfirmation, $data['regrade']); } if ($this->validationerrors) { $html .= html_writer::div($renderer->notification($this->validationerrors)); } $html .= $renderer->display_rubric($data['criteria'], $data['options'], $mode, $this->getName()); return $html; }
[ "public", "function", "toHtml", "(", ")", "{", "global", "$", "PAGE", ";", "$", "html", "=", "$", "this", "->", "_getTabs", "(", ")", ";", "$", "renderer", "=", "$", "PAGE", "->", "get_renderer", "(", "'gradingform_rubric'", ")", ";", "$", "data", "=", "$", "this", "->", "prepare_data", "(", "null", ",", "$", "this", "->", "wasvalidated", ")", ";", "if", "(", "!", "$", "this", "->", "_flagFrozen", ")", "{", "$", "mode", "=", "gradingform_rubric_controller", "::", "DISPLAY_EDIT_FULL", ";", "$", "module", "=", "array", "(", "'name'", "=>", "'gradingform_rubriceditor'", ",", "'fullpath'", "=>", "'/grade/grading/form/rubric/js/rubriceditor.js'", ",", "'requires'", "=>", "array", "(", "'base'", ",", "'dom'", ",", "'event'", ",", "'event-touch'", ",", "'escape'", ")", ",", "'strings'", "=>", "array", "(", "array", "(", "'confirmdeletecriterion'", ",", "'gradingform_rubric'", ")", ",", "array", "(", "'confirmdeletelevel'", ",", "'gradingform_rubric'", ")", ",", "array", "(", "'criterionempty'", ",", "'gradingform_rubric'", ")", ",", "array", "(", "'levelempty'", ",", "'gradingform_rubric'", ")", ")", ")", ";", "$", "PAGE", "->", "requires", "->", "js_init_call", "(", "'M.gradingform_rubriceditor.init'", ",", "array", "(", "array", "(", "'name'", "=>", "$", "this", "->", "getName", "(", ")", ",", "'criteriontemplate'", "=>", "$", "renderer", "->", "criterion_template", "(", "$", "mode", ",", "$", "data", "[", "'options'", "]", ",", "$", "this", "->", "getName", "(", ")", ")", ",", "'leveltemplate'", "=>", "$", "renderer", "->", "level_template", "(", "$", "mode", ",", "$", "data", "[", "'options'", "]", ",", "$", "this", "->", "getName", "(", ")", ")", ")", ")", ",", "true", ",", "$", "module", ")", ";", "}", "else", "{", "// Rubric is frozen, no javascript needed", "if", "(", "$", "this", "->", "_persistantFreeze", ")", "{", "$", "mode", "=", "gradingform_rubric_controller", "::", "DISPLAY_EDIT_FROZEN", ";", "}", "else", "{", "$", "mode", "=", "gradingform_rubric_controller", "::", "DISPLAY_PREVIEW", ";", "}", "}", "if", "(", "$", "this", "->", "regradeconfirmation", ")", "{", "if", "(", "!", "isset", "(", "$", "data", "[", "'regrade'", "]", ")", ")", "{", "$", "data", "[", "'regrade'", "]", "=", "1", ";", "}", "$", "html", ".=", "$", "renderer", "->", "display_regrade_confirmation", "(", "$", "this", "->", "getName", "(", ")", ",", "$", "this", "->", "regradeconfirmation", ",", "$", "data", "[", "'regrade'", "]", ")", ";", "}", "if", "(", "$", "this", "->", "validationerrors", ")", "{", "$", "html", ".=", "html_writer", "::", "div", "(", "$", "renderer", "->", "notification", "(", "$", "this", "->", "validationerrors", ")", ")", ";", "}", "$", "html", ".=", "$", "renderer", "->", "display_rubric", "(", "$", "data", "[", "'criteria'", "]", ",", "$", "data", "[", "'options'", "]", ",", "$", "mode", ",", "$", "this", "->", "getName", "(", ")", ")", ";", "return", "$", "html", ";", "}" ]
Returns html string to display this element @return string
[ "Returns", "html", "string", "to", "display", "this", "element" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/grade/grading/form/rubric/rubriceditor.php#L111-L148
214,585
moodle/moodle
grade/grading/form/rubric/rubriceditor.php
MoodleQuickForm_rubriceditor.validate
public function validate($value) { if (!$this->wasvalidated) { $this->prepare_data($value, true); } return $this->validationerrors; }
php
public function validate($value) { if (!$this->wasvalidated) { $this->prepare_data($value, true); } return $this->validationerrors; }
[ "public", "function", "validate", "(", "$", "value", ")", "{", "if", "(", "!", "$", "this", "->", "wasvalidated", ")", "{", "$", "this", "->", "prepare_data", "(", "$", "value", ",", "true", ")", ";", "}", "return", "$", "this", "->", "validationerrors", ";", "}" ]
Validates that rubric has at least one criterion, at least two levels within one criterion, each level has a valid score, all levels have filled definitions and all criteria have filled descriptions @param array $value @return string|false error text or false if no errors found
[ "Validates", "that", "rubric", "has", "at", "least", "one", "criterion", "at", "least", "two", "levels", "within", "one", "criterion", "each", "level", "has", "a", "valid", "score", "all", "levels", "have", "filled", "definitions", "and", "all", "criteria", "have", "filled", "descriptions" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/grade/grading/form/rubric/rubriceditor.php#L376-L381
214,586
moodle/moodle
lib/badgeslib.php
badge.get_context
public function get_context() { if ($this->type == BADGE_TYPE_SITE) { return context_system::instance(); } else if ($this->type == BADGE_TYPE_COURSE) { return context_course::instance($this->courseid); } else { debugging('Something is wrong...'); } }
php
public function get_context() { if ($this->type == BADGE_TYPE_SITE) { return context_system::instance(); } else if ($this->type == BADGE_TYPE_COURSE) { return context_course::instance($this->courseid); } else { debugging('Something is wrong...'); } }
[ "public", "function", "get_context", "(", ")", "{", "if", "(", "$", "this", "->", "type", "==", "BADGE_TYPE_SITE", ")", "{", "return", "context_system", "::", "instance", "(", ")", ";", "}", "else", "if", "(", "$", "this", "->", "type", "==", "BADGE_TYPE_COURSE", ")", "{", "return", "context_course", "::", "instance", "(", "$", "this", "->", "courseid", ")", ";", "}", "else", "{", "debugging", "(", "'Something is wrong...'", ")", ";", "}", "}" ]
Use to get context instance of a badge. @return context instance.
[ "Use", "to", "get", "context", "instance", "of", "a", "badge", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/badgeslib.php#L195-L203
214,587
moodle/moodle
lib/badgeslib.php
badge.get_accepted_criteria
public function get_accepted_criteria() { global $CFG; $criteriatypes = array(); if ($this->type == BADGE_TYPE_COURSE) { $criteriatypes = array( BADGE_CRITERIA_TYPE_OVERALL, BADGE_CRITERIA_TYPE_MANUAL, BADGE_CRITERIA_TYPE_COURSE, BADGE_CRITERIA_TYPE_BADGE, BADGE_CRITERIA_TYPE_ACTIVITY, BADGE_CRITERIA_TYPE_COMPETENCY ); } else if ($this->type == BADGE_TYPE_SITE) { $criteriatypes = array( BADGE_CRITERIA_TYPE_OVERALL, BADGE_CRITERIA_TYPE_MANUAL, BADGE_CRITERIA_TYPE_COURSESET, BADGE_CRITERIA_TYPE_BADGE, BADGE_CRITERIA_TYPE_PROFILE, BADGE_CRITERIA_TYPE_COHORT, BADGE_CRITERIA_TYPE_COMPETENCY ); } $alltypes = badges_list_criteria(); foreach ($criteriatypes as $index => $type) { if (!isset($alltypes[$type])) { unset($criteriatypes[$index]); } } return $criteriatypes; }
php
public function get_accepted_criteria() { global $CFG; $criteriatypes = array(); if ($this->type == BADGE_TYPE_COURSE) { $criteriatypes = array( BADGE_CRITERIA_TYPE_OVERALL, BADGE_CRITERIA_TYPE_MANUAL, BADGE_CRITERIA_TYPE_COURSE, BADGE_CRITERIA_TYPE_BADGE, BADGE_CRITERIA_TYPE_ACTIVITY, BADGE_CRITERIA_TYPE_COMPETENCY ); } else if ($this->type == BADGE_TYPE_SITE) { $criteriatypes = array( BADGE_CRITERIA_TYPE_OVERALL, BADGE_CRITERIA_TYPE_MANUAL, BADGE_CRITERIA_TYPE_COURSESET, BADGE_CRITERIA_TYPE_BADGE, BADGE_CRITERIA_TYPE_PROFILE, BADGE_CRITERIA_TYPE_COHORT, BADGE_CRITERIA_TYPE_COMPETENCY ); } $alltypes = badges_list_criteria(); foreach ($criteriatypes as $index => $type) { if (!isset($alltypes[$type])) { unset($criteriatypes[$index]); } } return $criteriatypes; }
[ "public", "function", "get_accepted_criteria", "(", ")", "{", "global", "$", "CFG", ";", "$", "criteriatypes", "=", "array", "(", ")", ";", "if", "(", "$", "this", "->", "type", "==", "BADGE_TYPE_COURSE", ")", "{", "$", "criteriatypes", "=", "array", "(", "BADGE_CRITERIA_TYPE_OVERALL", ",", "BADGE_CRITERIA_TYPE_MANUAL", ",", "BADGE_CRITERIA_TYPE_COURSE", ",", "BADGE_CRITERIA_TYPE_BADGE", ",", "BADGE_CRITERIA_TYPE_ACTIVITY", ",", "BADGE_CRITERIA_TYPE_COMPETENCY", ")", ";", "}", "else", "if", "(", "$", "this", "->", "type", "==", "BADGE_TYPE_SITE", ")", "{", "$", "criteriatypes", "=", "array", "(", "BADGE_CRITERIA_TYPE_OVERALL", ",", "BADGE_CRITERIA_TYPE_MANUAL", ",", "BADGE_CRITERIA_TYPE_COURSESET", ",", "BADGE_CRITERIA_TYPE_BADGE", ",", "BADGE_CRITERIA_TYPE_PROFILE", ",", "BADGE_CRITERIA_TYPE_COHORT", ",", "BADGE_CRITERIA_TYPE_COMPETENCY", ")", ";", "}", "$", "alltypes", "=", "badges_list_criteria", "(", ")", ";", "foreach", "(", "$", "criteriatypes", "as", "$", "index", "=>", "$", "type", ")", "{", "if", "(", "!", "isset", "(", "$", "alltypes", "[", "$", "type", "]", ")", ")", "{", "unset", "(", "$", "criteriatypes", "[", "$", "index", "]", ")", ";", "}", "}", "return", "$", "criteriatypes", ";", "}" ]
Return array of accepted criteria types for this badge @return array
[ "Return", "array", "of", "accepted", "criteria", "types", "for", "this", "badge" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/badgeslib.php#L220-L252
214,588
moodle/moodle
lib/badgeslib.php
badge.make_clone
public function make_clone() { global $DB, $USER, $PAGE; $fordb = new stdClass(); foreach (get_object_vars($this) as $k => $v) { $fordb->{$k} = $v; } $fordb->name = get_string('copyof', 'badges', $this->name); $fordb->status = BADGE_STATUS_INACTIVE; $fordb->usercreated = $USER->id; $fordb->usermodified = $USER->id; $fordb->timecreated = time(); $fordb->timemodified = time(); unset($fordb->id); if ($fordb->notification > 1) { $fordb->nextcron = badges_calculate_message_schedule($fordb->notification); } $criteria = $fordb->criteria; unset($fordb->criteria); if ($new = $DB->insert_record('badge', $fordb, true)) { $newbadge = new badge($new); // Copy badge image. $fs = get_file_storage(); if ($file = $fs->get_file($this->get_context()->id, 'badges', 'badgeimage', $this->id, '/', 'f1.png')) { if ($imagefile = $file->copy_content_to_temp()) { badges_process_badge_image($newbadge, $imagefile); } } // Copy badge criteria. foreach ($this->criteria as $crit) { $crit->make_clone($new); } // Copy endorsement. $endorsement = $this->get_endorsement(); if ($endorsement) { unset($endorsement->id); $endorsement->badgeid = $new; $newbadge->save_endorsement($endorsement); } // Copy alignments. $alignments = $this->get_alignments(); foreach ($alignments as $alignment) { unset($alignment->id); $alignment->badgeid = $new; $newbadge->save_alignment($alignment); } // Copy related badges. $related = $this->get_related_badges(true); if (!empty($related)) { $newbadge->add_related_badges(array_keys($related)); } // Trigger event, badge duplicated. $eventparams = array('objectid' => $new, 'context' => $PAGE->context); $event = \core\event\badge_duplicated::create($eventparams); $event->trigger(); return $new; } else { throw new moodle_exception('error:clone', 'badges'); return false; } }
php
public function make_clone() { global $DB, $USER, $PAGE; $fordb = new stdClass(); foreach (get_object_vars($this) as $k => $v) { $fordb->{$k} = $v; } $fordb->name = get_string('copyof', 'badges', $this->name); $fordb->status = BADGE_STATUS_INACTIVE; $fordb->usercreated = $USER->id; $fordb->usermodified = $USER->id; $fordb->timecreated = time(); $fordb->timemodified = time(); unset($fordb->id); if ($fordb->notification > 1) { $fordb->nextcron = badges_calculate_message_schedule($fordb->notification); } $criteria = $fordb->criteria; unset($fordb->criteria); if ($new = $DB->insert_record('badge', $fordb, true)) { $newbadge = new badge($new); // Copy badge image. $fs = get_file_storage(); if ($file = $fs->get_file($this->get_context()->id, 'badges', 'badgeimage', $this->id, '/', 'f1.png')) { if ($imagefile = $file->copy_content_to_temp()) { badges_process_badge_image($newbadge, $imagefile); } } // Copy badge criteria. foreach ($this->criteria as $crit) { $crit->make_clone($new); } // Copy endorsement. $endorsement = $this->get_endorsement(); if ($endorsement) { unset($endorsement->id); $endorsement->badgeid = $new; $newbadge->save_endorsement($endorsement); } // Copy alignments. $alignments = $this->get_alignments(); foreach ($alignments as $alignment) { unset($alignment->id); $alignment->badgeid = $new; $newbadge->save_alignment($alignment); } // Copy related badges. $related = $this->get_related_badges(true); if (!empty($related)) { $newbadge->add_related_badges(array_keys($related)); } // Trigger event, badge duplicated. $eventparams = array('objectid' => $new, 'context' => $PAGE->context); $event = \core\event\badge_duplicated::create($eventparams); $event->trigger(); return $new; } else { throw new moodle_exception('error:clone', 'badges'); return false; } }
[ "public", "function", "make_clone", "(", ")", "{", "global", "$", "DB", ",", "$", "USER", ",", "$", "PAGE", ";", "$", "fordb", "=", "new", "stdClass", "(", ")", ";", "foreach", "(", "get_object_vars", "(", "$", "this", ")", "as", "$", "k", "=>", "$", "v", ")", "{", "$", "fordb", "->", "{", "$", "k", "}", "=", "$", "v", ";", "}", "$", "fordb", "->", "name", "=", "get_string", "(", "'copyof'", ",", "'badges'", ",", "$", "this", "->", "name", ")", ";", "$", "fordb", "->", "status", "=", "BADGE_STATUS_INACTIVE", ";", "$", "fordb", "->", "usercreated", "=", "$", "USER", "->", "id", ";", "$", "fordb", "->", "usermodified", "=", "$", "USER", "->", "id", ";", "$", "fordb", "->", "timecreated", "=", "time", "(", ")", ";", "$", "fordb", "->", "timemodified", "=", "time", "(", ")", ";", "unset", "(", "$", "fordb", "->", "id", ")", ";", "if", "(", "$", "fordb", "->", "notification", ">", "1", ")", "{", "$", "fordb", "->", "nextcron", "=", "badges_calculate_message_schedule", "(", "$", "fordb", "->", "notification", ")", ";", "}", "$", "criteria", "=", "$", "fordb", "->", "criteria", ";", "unset", "(", "$", "fordb", "->", "criteria", ")", ";", "if", "(", "$", "new", "=", "$", "DB", "->", "insert_record", "(", "'badge'", ",", "$", "fordb", ",", "true", ")", ")", "{", "$", "newbadge", "=", "new", "badge", "(", "$", "new", ")", ";", "// Copy badge image.", "$", "fs", "=", "get_file_storage", "(", ")", ";", "if", "(", "$", "file", "=", "$", "fs", "->", "get_file", "(", "$", "this", "->", "get_context", "(", ")", "->", "id", ",", "'badges'", ",", "'badgeimage'", ",", "$", "this", "->", "id", ",", "'/'", ",", "'f1.png'", ")", ")", "{", "if", "(", "$", "imagefile", "=", "$", "file", "->", "copy_content_to_temp", "(", ")", ")", "{", "badges_process_badge_image", "(", "$", "newbadge", ",", "$", "imagefile", ")", ";", "}", "}", "// Copy badge criteria.", "foreach", "(", "$", "this", "->", "criteria", "as", "$", "crit", ")", "{", "$", "crit", "->", "make_clone", "(", "$", "new", ")", ";", "}", "// Copy endorsement.", "$", "endorsement", "=", "$", "this", "->", "get_endorsement", "(", ")", ";", "if", "(", "$", "endorsement", ")", "{", "unset", "(", "$", "endorsement", "->", "id", ")", ";", "$", "endorsement", "->", "badgeid", "=", "$", "new", ";", "$", "newbadge", "->", "save_endorsement", "(", "$", "endorsement", ")", ";", "}", "// Copy alignments.", "$", "alignments", "=", "$", "this", "->", "get_alignments", "(", ")", ";", "foreach", "(", "$", "alignments", "as", "$", "alignment", ")", "{", "unset", "(", "$", "alignment", "->", "id", ")", ";", "$", "alignment", "->", "badgeid", "=", "$", "new", ";", "$", "newbadge", "->", "save_alignment", "(", "$", "alignment", ")", ";", "}", "// Copy related badges.", "$", "related", "=", "$", "this", "->", "get_related_badges", "(", "true", ")", ";", "if", "(", "!", "empty", "(", "$", "related", ")", ")", "{", "$", "newbadge", "->", "add_related_badges", "(", "array_keys", "(", "$", "related", ")", ")", ";", "}", "// Trigger event, badge duplicated.", "$", "eventparams", "=", "array", "(", "'objectid'", "=>", "$", "new", ",", "'context'", "=>", "$", "PAGE", "->", "context", ")", ";", "$", "event", "=", "\\", "core", "\\", "event", "\\", "badge_duplicated", "::", "create", "(", "$", "eventparams", ")", ";", "$", "event", "->", "trigger", "(", ")", ";", "return", "$", "new", ";", "}", "else", "{", "throw", "new", "moodle_exception", "(", "'error:clone'", ",", "'badges'", ")", ";", "return", "false", ";", "}", "}" ]
Creates and saves a clone of badge with all its properties. Clone is not active by default and has 'Copy of' attached to its name. @return int ID of new badge.
[ "Creates", "and", "saves", "a", "clone", "of", "badge", "with", "all", "its", "properties", ".", "Clone", "is", "not", "active", "by", "default", "and", "has", "Copy", "of", "attached", "to", "its", "name", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/badgeslib.php#L288-L359
214,589
moodle/moodle
lib/badgeslib.php
badge.issue
public function issue($userid, $nobake = false) { global $DB, $CFG; $now = time(); $issued = new stdClass(); $issued->badgeid = $this->id; $issued->userid = $userid; $issued->uniquehash = sha1(rand() . $userid . $this->id . $now); $issued->dateissued = $now; if ($this->can_expire()) { $issued->dateexpire = $this->calculate_expiry($now); } else { $issued->dateexpire = null; } // Take into account user badges privacy settings. // If none set, badges default visibility is set to public. $issued->visible = get_user_preferences('badgeprivacysetting', 1, $userid); $result = $DB->insert_record('badge_issued', $issued, true); if ($result) { // Trigger badge awarded event. $eventdata = array ( 'context' => $this->get_context(), 'objectid' => $this->id, 'relateduserid' => $userid, 'other' => array('dateexpire' => $issued->dateexpire, 'badgeissuedid' => $result) ); \core\event\badge_awarded::create($eventdata)->trigger(); // Lock the badge, so that its criteria could not be changed any more. if ($this->status == BADGE_STATUS_ACTIVE) { $this->set_status(BADGE_STATUS_ACTIVE_LOCKED); } // Update details in criteria_met table. $compl = $this->get_criteria_completions($userid); foreach ($compl as $c) { $obj = new stdClass(); $obj->id = $c->id; $obj->issuedid = $result; $DB->update_record('badge_criteria_met', $obj, true); } if (!$nobake) { // Bake a badge image. $pathhash = badges_bake($issued->uniquehash, $this->id, $userid, true); // Notify recipients and badge creators. badges_notify_badge_award($this, $userid, $issued->uniquehash, $pathhash); } } }
php
public function issue($userid, $nobake = false) { global $DB, $CFG; $now = time(); $issued = new stdClass(); $issued->badgeid = $this->id; $issued->userid = $userid; $issued->uniquehash = sha1(rand() . $userid . $this->id . $now); $issued->dateissued = $now; if ($this->can_expire()) { $issued->dateexpire = $this->calculate_expiry($now); } else { $issued->dateexpire = null; } // Take into account user badges privacy settings. // If none set, badges default visibility is set to public. $issued->visible = get_user_preferences('badgeprivacysetting', 1, $userid); $result = $DB->insert_record('badge_issued', $issued, true); if ($result) { // Trigger badge awarded event. $eventdata = array ( 'context' => $this->get_context(), 'objectid' => $this->id, 'relateduserid' => $userid, 'other' => array('dateexpire' => $issued->dateexpire, 'badgeissuedid' => $result) ); \core\event\badge_awarded::create($eventdata)->trigger(); // Lock the badge, so that its criteria could not be changed any more. if ($this->status == BADGE_STATUS_ACTIVE) { $this->set_status(BADGE_STATUS_ACTIVE_LOCKED); } // Update details in criteria_met table. $compl = $this->get_criteria_completions($userid); foreach ($compl as $c) { $obj = new stdClass(); $obj->id = $c->id; $obj->issuedid = $result; $DB->update_record('badge_criteria_met', $obj, true); } if (!$nobake) { // Bake a badge image. $pathhash = badges_bake($issued->uniquehash, $this->id, $userid, true); // Notify recipients and badge creators. badges_notify_badge_award($this, $userid, $issued->uniquehash, $pathhash); } } }
[ "public", "function", "issue", "(", "$", "userid", ",", "$", "nobake", "=", "false", ")", "{", "global", "$", "DB", ",", "$", "CFG", ";", "$", "now", "=", "time", "(", ")", ";", "$", "issued", "=", "new", "stdClass", "(", ")", ";", "$", "issued", "->", "badgeid", "=", "$", "this", "->", "id", ";", "$", "issued", "->", "userid", "=", "$", "userid", ";", "$", "issued", "->", "uniquehash", "=", "sha1", "(", "rand", "(", ")", ".", "$", "userid", ".", "$", "this", "->", "id", ".", "$", "now", ")", ";", "$", "issued", "->", "dateissued", "=", "$", "now", ";", "if", "(", "$", "this", "->", "can_expire", "(", ")", ")", "{", "$", "issued", "->", "dateexpire", "=", "$", "this", "->", "calculate_expiry", "(", "$", "now", ")", ";", "}", "else", "{", "$", "issued", "->", "dateexpire", "=", "null", ";", "}", "// Take into account user badges privacy settings.", "// If none set, badges default visibility is set to public.", "$", "issued", "->", "visible", "=", "get_user_preferences", "(", "'badgeprivacysetting'", ",", "1", ",", "$", "userid", ")", ";", "$", "result", "=", "$", "DB", "->", "insert_record", "(", "'badge_issued'", ",", "$", "issued", ",", "true", ")", ";", "if", "(", "$", "result", ")", "{", "// Trigger badge awarded event.", "$", "eventdata", "=", "array", "(", "'context'", "=>", "$", "this", "->", "get_context", "(", ")", ",", "'objectid'", "=>", "$", "this", "->", "id", ",", "'relateduserid'", "=>", "$", "userid", ",", "'other'", "=>", "array", "(", "'dateexpire'", "=>", "$", "issued", "->", "dateexpire", ",", "'badgeissuedid'", "=>", "$", "result", ")", ")", ";", "\\", "core", "\\", "event", "\\", "badge_awarded", "::", "create", "(", "$", "eventdata", ")", "->", "trigger", "(", ")", ";", "// Lock the badge, so that its criteria could not be changed any more.", "if", "(", "$", "this", "->", "status", "==", "BADGE_STATUS_ACTIVE", ")", "{", "$", "this", "->", "set_status", "(", "BADGE_STATUS_ACTIVE_LOCKED", ")", ";", "}", "// Update details in criteria_met table.", "$", "compl", "=", "$", "this", "->", "get_criteria_completions", "(", "$", "userid", ")", ";", "foreach", "(", "$", "compl", "as", "$", "c", ")", "{", "$", "obj", "=", "new", "stdClass", "(", ")", ";", "$", "obj", "->", "id", "=", "$", "c", "->", "id", ";", "$", "obj", "->", "issuedid", "=", "$", "result", ";", "$", "DB", "->", "update_record", "(", "'badge_criteria_met'", ",", "$", "obj", ",", "true", ")", ";", "}", "if", "(", "!", "$", "nobake", ")", "{", "// Bake a badge image.", "$", "pathhash", "=", "badges_bake", "(", "$", "issued", "->", "uniquehash", ",", "$", "this", "->", "id", ",", "$", "userid", ",", "true", ")", ";", "// Notify recipients and badge creators.", "badges_notify_badge_award", "(", "$", "this", ",", "$", "userid", ",", "$", "issued", "->", "uniquehash", ",", "$", "pathhash", ")", ";", "}", "}", "}" ]
Issue a badge to user. @param int $userid User who earned the badge @param bool $nobake Not baking actual badges (for testing purposes)
[ "Issue", "a", "badge", "to", "user", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/badgeslib.php#L466-L520
214,590
moodle/moodle
lib/badgeslib.php
badge.review_all_criteria
public function review_all_criteria() { global $DB, $CFG; $awards = 0; // Raise timelimit as this could take a while for big web sites. core_php_time_limit::raise(); raise_memory_limit(MEMORY_HUGE); foreach ($this->criteria as $crit) { // Overall criterion is decided when other criteria are reviewed. if ($crit->criteriatype == BADGE_CRITERIA_TYPE_OVERALL) { continue; } list($extrajoin, $extrawhere, $extraparams) = $crit->get_completed_criteria_sql(); // For site level badges, get all active site users who can earn this badge and haven't got it yet. if ($this->type == BADGE_TYPE_SITE) { $sql = "SELECT DISTINCT u.id, bi.badgeid FROM {user} u {$extrajoin} LEFT JOIN {badge_issued} bi ON u.id = bi.userid AND bi.badgeid = :badgeid WHERE bi.badgeid IS NULL AND u.id != :guestid AND u.deleted = 0 " . $extrawhere; $params = array_merge(array('badgeid' => $this->id, 'guestid' => $CFG->siteguest), $extraparams); $toearn = $DB->get_fieldset_sql($sql, $params); } else { // For course level badges, get all users who already earned the badge in this course. // Then find the ones who are enrolled in the course and don't have a badge yet. $earned = $DB->get_fieldset_select('badge_issued', 'userid AS id', 'badgeid = :badgeid', array('badgeid' => $this->id)); $wheresql = ''; $earnedparams = array(); if (!empty($earned)) { list($earnedsql, $earnedparams) = $DB->get_in_or_equal($earned, SQL_PARAMS_NAMED, 'u', false); $wheresql = ' WHERE u.id ' . $earnedsql; } list($enrolledsql, $enrolledparams) = get_enrolled_sql($this->get_context(), 'moodle/badges:earnbadge', 0, true); $sql = "SELECT DISTINCT u.id FROM {user} u {$extrajoin} JOIN ({$enrolledsql}) je ON je.id = u.id " . $wheresql . $extrawhere; $params = array_merge($enrolledparams, $earnedparams, $extraparams); $toearn = $DB->get_fieldset_sql($sql, $params); } foreach ($toearn as $uid) { $reviewoverall = false; if ($crit->review($uid, true)) { $crit->mark_complete($uid); if ($this->criteria[BADGE_CRITERIA_TYPE_OVERALL]->method == BADGE_CRITERIA_AGGREGATION_ANY) { $this->criteria[BADGE_CRITERIA_TYPE_OVERALL]->mark_complete($uid); $this->issue($uid); $awards++; } else { $reviewoverall = true; } } else { // Will be reviewed some other time. $reviewoverall = false; } // Review overall if it is required. if ($reviewoverall && $this->criteria[BADGE_CRITERIA_TYPE_OVERALL]->review($uid)) { $this->criteria[BADGE_CRITERIA_TYPE_OVERALL]->mark_complete($uid); $this->issue($uid); $awards++; } } } return $awards; }
php
public function review_all_criteria() { global $DB, $CFG; $awards = 0; // Raise timelimit as this could take a while for big web sites. core_php_time_limit::raise(); raise_memory_limit(MEMORY_HUGE); foreach ($this->criteria as $crit) { // Overall criterion is decided when other criteria are reviewed. if ($crit->criteriatype == BADGE_CRITERIA_TYPE_OVERALL) { continue; } list($extrajoin, $extrawhere, $extraparams) = $crit->get_completed_criteria_sql(); // For site level badges, get all active site users who can earn this badge and haven't got it yet. if ($this->type == BADGE_TYPE_SITE) { $sql = "SELECT DISTINCT u.id, bi.badgeid FROM {user} u {$extrajoin} LEFT JOIN {badge_issued} bi ON u.id = bi.userid AND bi.badgeid = :badgeid WHERE bi.badgeid IS NULL AND u.id != :guestid AND u.deleted = 0 " . $extrawhere; $params = array_merge(array('badgeid' => $this->id, 'guestid' => $CFG->siteguest), $extraparams); $toearn = $DB->get_fieldset_sql($sql, $params); } else { // For course level badges, get all users who already earned the badge in this course. // Then find the ones who are enrolled in the course and don't have a badge yet. $earned = $DB->get_fieldset_select('badge_issued', 'userid AS id', 'badgeid = :badgeid', array('badgeid' => $this->id)); $wheresql = ''; $earnedparams = array(); if (!empty($earned)) { list($earnedsql, $earnedparams) = $DB->get_in_or_equal($earned, SQL_PARAMS_NAMED, 'u', false); $wheresql = ' WHERE u.id ' . $earnedsql; } list($enrolledsql, $enrolledparams) = get_enrolled_sql($this->get_context(), 'moodle/badges:earnbadge', 0, true); $sql = "SELECT DISTINCT u.id FROM {user} u {$extrajoin} JOIN ({$enrolledsql}) je ON je.id = u.id " . $wheresql . $extrawhere; $params = array_merge($enrolledparams, $earnedparams, $extraparams); $toearn = $DB->get_fieldset_sql($sql, $params); } foreach ($toearn as $uid) { $reviewoverall = false; if ($crit->review($uid, true)) { $crit->mark_complete($uid); if ($this->criteria[BADGE_CRITERIA_TYPE_OVERALL]->method == BADGE_CRITERIA_AGGREGATION_ANY) { $this->criteria[BADGE_CRITERIA_TYPE_OVERALL]->mark_complete($uid); $this->issue($uid); $awards++; } else { $reviewoverall = true; } } else { // Will be reviewed some other time. $reviewoverall = false; } // Review overall if it is required. if ($reviewoverall && $this->criteria[BADGE_CRITERIA_TYPE_OVERALL]->review($uid)) { $this->criteria[BADGE_CRITERIA_TYPE_OVERALL]->mark_complete($uid); $this->issue($uid); $awards++; } } } return $awards; }
[ "public", "function", "review_all_criteria", "(", ")", "{", "global", "$", "DB", ",", "$", "CFG", ";", "$", "awards", "=", "0", ";", "// Raise timelimit as this could take a while for big web sites.", "core_php_time_limit", "::", "raise", "(", ")", ";", "raise_memory_limit", "(", "MEMORY_HUGE", ")", ";", "foreach", "(", "$", "this", "->", "criteria", "as", "$", "crit", ")", "{", "// Overall criterion is decided when other criteria are reviewed.", "if", "(", "$", "crit", "->", "criteriatype", "==", "BADGE_CRITERIA_TYPE_OVERALL", ")", "{", "continue", ";", "}", "list", "(", "$", "extrajoin", ",", "$", "extrawhere", ",", "$", "extraparams", ")", "=", "$", "crit", "->", "get_completed_criteria_sql", "(", ")", ";", "// For site level badges, get all active site users who can earn this badge and haven't got it yet.", "if", "(", "$", "this", "->", "type", "==", "BADGE_TYPE_SITE", ")", "{", "$", "sql", "=", "\"SELECT DISTINCT u.id, bi.badgeid\n FROM {user} u\n {$extrajoin}\n LEFT JOIN {badge_issued} bi\n ON u.id = bi.userid AND bi.badgeid = :badgeid\n WHERE bi.badgeid IS NULL AND u.id != :guestid AND u.deleted = 0 \"", ".", "$", "extrawhere", ";", "$", "params", "=", "array_merge", "(", "array", "(", "'badgeid'", "=>", "$", "this", "->", "id", ",", "'guestid'", "=>", "$", "CFG", "->", "siteguest", ")", ",", "$", "extraparams", ")", ";", "$", "toearn", "=", "$", "DB", "->", "get_fieldset_sql", "(", "$", "sql", ",", "$", "params", ")", ";", "}", "else", "{", "// For course level badges, get all users who already earned the badge in this course.", "// Then find the ones who are enrolled in the course and don't have a badge yet.", "$", "earned", "=", "$", "DB", "->", "get_fieldset_select", "(", "'badge_issued'", ",", "'userid AS id'", ",", "'badgeid = :badgeid'", ",", "array", "(", "'badgeid'", "=>", "$", "this", "->", "id", ")", ")", ";", "$", "wheresql", "=", "''", ";", "$", "earnedparams", "=", "array", "(", ")", ";", "if", "(", "!", "empty", "(", "$", "earned", ")", ")", "{", "list", "(", "$", "earnedsql", ",", "$", "earnedparams", ")", "=", "$", "DB", "->", "get_in_or_equal", "(", "$", "earned", ",", "SQL_PARAMS_NAMED", ",", "'u'", ",", "false", ")", ";", "$", "wheresql", "=", "' WHERE u.id '", ".", "$", "earnedsql", ";", "}", "list", "(", "$", "enrolledsql", ",", "$", "enrolledparams", ")", "=", "get_enrolled_sql", "(", "$", "this", "->", "get_context", "(", ")", ",", "'moodle/badges:earnbadge'", ",", "0", ",", "true", ")", ";", "$", "sql", "=", "\"SELECT DISTINCT u.id\n FROM {user} u\n {$extrajoin}\n JOIN ({$enrolledsql}) je ON je.id = u.id \"", ".", "$", "wheresql", ".", "$", "extrawhere", ";", "$", "params", "=", "array_merge", "(", "$", "enrolledparams", ",", "$", "earnedparams", ",", "$", "extraparams", ")", ";", "$", "toearn", "=", "$", "DB", "->", "get_fieldset_sql", "(", "$", "sql", ",", "$", "params", ")", ";", "}", "foreach", "(", "$", "toearn", "as", "$", "uid", ")", "{", "$", "reviewoverall", "=", "false", ";", "if", "(", "$", "crit", "->", "review", "(", "$", "uid", ",", "true", ")", ")", "{", "$", "crit", "->", "mark_complete", "(", "$", "uid", ")", ";", "if", "(", "$", "this", "->", "criteria", "[", "BADGE_CRITERIA_TYPE_OVERALL", "]", "->", "method", "==", "BADGE_CRITERIA_AGGREGATION_ANY", ")", "{", "$", "this", "->", "criteria", "[", "BADGE_CRITERIA_TYPE_OVERALL", "]", "->", "mark_complete", "(", "$", "uid", ")", ";", "$", "this", "->", "issue", "(", "$", "uid", ")", ";", "$", "awards", "++", ";", "}", "else", "{", "$", "reviewoverall", "=", "true", ";", "}", "}", "else", "{", "// Will be reviewed some other time.", "$", "reviewoverall", "=", "false", ";", "}", "// Review overall if it is required.", "if", "(", "$", "reviewoverall", "&&", "$", "this", "->", "criteria", "[", "BADGE_CRITERIA_TYPE_OVERALL", "]", "->", "review", "(", "$", "uid", ")", ")", "{", "$", "this", "->", "criteria", "[", "BADGE_CRITERIA_TYPE_OVERALL", "]", "->", "mark_complete", "(", "$", "uid", ")", ";", "$", "this", "->", "issue", "(", "$", "uid", ")", ";", "$", "awards", "++", ";", "}", "}", "}", "return", "$", "awards", ";", "}" ]
Reviews all badge criteria and checks if badge can be instantly awarded. @return int Number of awards
[ "Reviews", "all", "badge", "criteria", "and", "checks", "if", "badge", "can", "be", "instantly", "awarded", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/badgeslib.php#L527-L597
214,591
moodle/moodle
lib/badgeslib.php
badge.get_criteria_completions
public function get_criteria_completions($userid) { global $DB; $completions = array(); $sql = "SELECT bcm.id, bcm.critid FROM {badge_criteria_met} bcm INNER JOIN {badge_criteria} bc ON bcm.critid = bc.id WHERE bc.badgeid = :badgeid AND bcm.userid = :userid "; $completions = $DB->get_records_sql($sql, array('badgeid' => $this->id, 'userid' => $userid)); return $completions; }
php
public function get_criteria_completions($userid) { global $DB; $completions = array(); $sql = "SELECT bcm.id, bcm.critid FROM {badge_criteria_met} bcm INNER JOIN {badge_criteria} bc ON bcm.critid = bc.id WHERE bc.badgeid = :badgeid AND bcm.userid = :userid "; $completions = $DB->get_records_sql($sql, array('badgeid' => $this->id, 'userid' => $userid)); return $completions; }
[ "public", "function", "get_criteria_completions", "(", "$", "userid", ")", "{", "global", "$", "DB", ";", "$", "completions", "=", "array", "(", ")", ";", "$", "sql", "=", "\"SELECT bcm.id, bcm.critid\n FROM {badge_criteria_met} bcm\n INNER JOIN {badge_criteria} bc ON bcm.critid = bc.id\n WHERE bc.badgeid = :badgeid AND bcm.userid = :userid \"", ";", "$", "completions", "=", "$", "DB", "->", "get_records_sql", "(", "$", "sql", ",", "array", "(", "'badgeid'", "=>", "$", "this", "->", "id", ",", "'userid'", "=>", "$", "userid", ")", ")", ";", "return", "$", "completions", ";", "}" ]
Gets an array of completed criteria from 'badge_criteria_met' table. @param int $userid Completions for a user @return array Records of criteria completions
[ "Gets", "an", "array", "of", "completed", "criteria", "from", "badge_criteria_met", "table", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/badgeslib.php#L605-L615
214,592
moodle/moodle
lib/badgeslib.php
badge.get_criteria
public function get_criteria() { global $DB; $criteria = array(); if ($records = (array)$DB->get_records('badge_criteria', array('badgeid' => $this->id))) { foreach ($records as $record) { $criteria[$record->criteriatype] = award_criteria::build((array)$record); } } return $criteria; }
php
public function get_criteria() { global $DB; $criteria = array(); if ($records = (array)$DB->get_records('badge_criteria', array('badgeid' => $this->id))) { foreach ($records as $record) { $criteria[$record->criteriatype] = award_criteria::build((array)$record); } } return $criteria; }
[ "public", "function", "get_criteria", "(", ")", "{", "global", "$", "DB", ";", "$", "criteria", "=", "array", "(", ")", ";", "if", "(", "$", "records", "=", "(", "array", ")", "$", "DB", "->", "get_records", "(", "'badge_criteria'", ",", "array", "(", "'badgeid'", "=>", "$", "this", "->", "id", ")", ")", ")", "{", "foreach", "(", "$", "records", "as", "$", "record", ")", "{", "$", "criteria", "[", "$", "record", "->", "criteriatype", "]", "=", "award_criteria", "::", "build", "(", "(", "array", ")", "$", "record", ")", ";", "}", "}", "return", "$", "criteria", ";", "}" ]
Returns badge award criteria @return array An array of badge criteria
[ "Returns", "badge", "award", "criteria" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/badgeslib.php#L634-L645
214,593
moodle/moodle
lib/badgeslib.php
badge.get_aggregation_method
public function get_aggregation_method($criteriatype = 0) { global $DB; $params = array('badgeid' => $this->id, 'criteriatype' => $criteriatype); $aggregation = $DB->get_field('badge_criteria', 'method', $params, IGNORE_MULTIPLE); if (!$aggregation) { return BADGE_CRITERIA_AGGREGATION_ALL; } return $aggregation; }
php
public function get_aggregation_method($criteriatype = 0) { global $DB; $params = array('badgeid' => $this->id, 'criteriatype' => $criteriatype); $aggregation = $DB->get_field('badge_criteria', 'method', $params, IGNORE_MULTIPLE); if (!$aggregation) { return BADGE_CRITERIA_AGGREGATION_ALL; } return $aggregation; }
[ "public", "function", "get_aggregation_method", "(", "$", "criteriatype", "=", "0", ")", "{", "global", "$", "DB", ";", "$", "params", "=", "array", "(", "'badgeid'", "=>", "$", "this", "->", "id", ",", "'criteriatype'", "=>", "$", "criteriatype", ")", ";", "$", "aggregation", "=", "$", "DB", "->", "get_field", "(", "'badge_criteria'", ",", "'method'", ",", "$", "params", ",", "IGNORE_MULTIPLE", ")", ";", "if", "(", "!", "$", "aggregation", ")", "{", "return", "BADGE_CRITERIA_AGGREGATION_ALL", ";", "}", "return", "$", "aggregation", ";", "}" ]
Get aggregation method for badge criteria @param int $criteriatype If none supplied, get overall aggregation method (optional) @return int One of BADGE_CRITERIA_AGGREGATION_ALL or BADGE_CRITERIA_AGGREGATION_ANY
[ "Get", "aggregation", "method", "for", "badge", "criteria" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/badgeslib.php#L653-L663
214,594
moodle/moodle
lib/badgeslib.php
badge.calculate_expiry
public function calculate_expiry($timestamp) { $expiry = null; if (isset($this->expiredate)) { $expiry = $this->expiredate; } else if (isset($this->expireperiod)) { $expiry = $timestamp + $this->expireperiod; } return $expiry; }
php
public function calculate_expiry($timestamp) { $expiry = null; if (isset($this->expiredate)) { $expiry = $this->expiredate; } else if (isset($this->expireperiod)) { $expiry = $timestamp + $this->expireperiod; } return $expiry; }
[ "public", "function", "calculate_expiry", "(", "$", "timestamp", ")", "{", "$", "expiry", "=", "null", ";", "if", "(", "isset", "(", "$", "this", "->", "expiredate", ")", ")", "{", "$", "expiry", "=", "$", "this", "->", "expiredate", ";", "}", "else", "if", "(", "isset", "(", "$", "this", "->", "expireperiod", ")", ")", "{", "$", "expiry", "=", "$", "timestamp", "+", "$", "this", "->", "expireperiod", ";", "}", "return", "$", "expiry", ";", "}" ]
Calculates badge expiry date based on either expirydate or expiryperiod. @param int $timestamp Time of badge issue @return int A timestamp
[ "Calculates", "badge", "expiry", "date", "based", "on", "either", "expirydate", "or", "expiryperiod", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/badgeslib.php#L683-L693
214,595
moodle/moodle
lib/badgeslib.php
badge.has_manual_award_criteria
public function has_manual_award_criteria() { foreach ($this->criteria as $criterion) { if ($criterion->criteriatype == BADGE_CRITERIA_TYPE_MANUAL) { return true; } } return false; }
php
public function has_manual_award_criteria() { foreach ($this->criteria as $criterion) { if ($criterion->criteriatype == BADGE_CRITERIA_TYPE_MANUAL) { return true; } } return false; }
[ "public", "function", "has_manual_award_criteria", "(", ")", "{", "foreach", "(", "$", "this", "->", "criteria", "as", "$", "criterion", ")", "{", "if", "(", "$", "criterion", "->", "criteriatype", "==", "BADGE_CRITERIA_TYPE_MANUAL", ")", "{", "return", "true", ";", "}", "}", "return", "false", ";", "}" ]
Checks if badge has manual award criteria set. @return bool A status indicating badge can be awarded manually
[ "Checks", "if", "badge", "has", "manual", "award", "criteria", "set", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/badgeslib.php#L700-L707
214,596
moodle/moodle
lib/badgeslib.php
badge.delete
public function delete($archive = true) { global $DB; if ($archive) { $this->status = BADGE_STATUS_ARCHIVED; $this->save(); // Trigger event, badge archived. $eventparams = array('objectid' => $this->id, 'context' => $this->get_context()); $event = \core\event\badge_archived::create($eventparams); $event->trigger(); return; } $fs = get_file_storage(); // Remove all issued badge image files and badge awards. // Cannot bulk remove area files here because they are issued in user context. $awards = $this->get_awards(); foreach ($awards as $award) { $usercontext = context_user::instance($award->userid); $fs->delete_area_files($usercontext->id, 'badges', 'userbadge', $this->id); } $DB->delete_records('badge_issued', array('badgeid' => $this->id)); // Remove all badge criteria. $criteria = $this->get_criteria(); foreach ($criteria as $criterion) { $criterion->delete(); } // Delete badge images. $badgecontext = $this->get_context(); $fs->delete_area_files($badgecontext->id, 'badges', 'badgeimage', $this->id); // Delete endorsements, alignments and related badges. $DB->delete_records('badge_endorsement', array('badgeid' => $this->id)); $relatedsql = 'badgeid = :badgeid OR relatedbadgeid = :relatedbadgeid'; $relatedparams = array( 'badgeid' => $this->id, 'relatedbadgeid' => $this->id ); $DB->delete_records_select('badge_related', $relatedsql, $relatedparams); $DB->delete_records('badge_alignment', array('badgeid' => $this->id)); // Finally, remove badge itself. $DB->delete_records('badge', array('id' => $this->id)); // Trigger event, badge deleted. $eventparams = array('objectid' => $this->id, 'context' => $this->get_context(), 'other' => array('badgetype' => $this->type, 'courseid' => $this->courseid) ); $event = \core\event\badge_deleted::create($eventparams); $event->trigger(); }
php
public function delete($archive = true) { global $DB; if ($archive) { $this->status = BADGE_STATUS_ARCHIVED; $this->save(); // Trigger event, badge archived. $eventparams = array('objectid' => $this->id, 'context' => $this->get_context()); $event = \core\event\badge_archived::create($eventparams); $event->trigger(); return; } $fs = get_file_storage(); // Remove all issued badge image files and badge awards. // Cannot bulk remove area files here because they are issued in user context. $awards = $this->get_awards(); foreach ($awards as $award) { $usercontext = context_user::instance($award->userid); $fs->delete_area_files($usercontext->id, 'badges', 'userbadge', $this->id); } $DB->delete_records('badge_issued', array('badgeid' => $this->id)); // Remove all badge criteria. $criteria = $this->get_criteria(); foreach ($criteria as $criterion) { $criterion->delete(); } // Delete badge images. $badgecontext = $this->get_context(); $fs->delete_area_files($badgecontext->id, 'badges', 'badgeimage', $this->id); // Delete endorsements, alignments and related badges. $DB->delete_records('badge_endorsement', array('badgeid' => $this->id)); $relatedsql = 'badgeid = :badgeid OR relatedbadgeid = :relatedbadgeid'; $relatedparams = array( 'badgeid' => $this->id, 'relatedbadgeid' => $this->id ); $DB->delete_records_select('badge_related', $relatedsql, $relatedparams); $DB->delete_records('badge_alignment', array('badgeid' => $this->id)); // Finally, remove badge itself. $DB->delete_records('badge', array('id' => $this->id)); // Trigger event, badge deleted. $eventparams = array('objectid' => $this->id, 'context' => $this->get_context(), 'other' => array('badgetype' => $this->type, 'courseid' => $this->courseid) ); $event = \core\event\badge_deleted::create($eventparams); $event->trigger(); }
[ "public", "function", "delete", "(", "$", "archive", "=", "true", ")", "{", "global", "$", "DB", ";", "if", "(", "$", "archive", ")", "{", "$", "this", "->", "status", "=", "BADGE_STATUS_ARCHIVED", ";", "$", "this", "->", "save", "(", ")", ";", "// Trigger event, badge archived.", "$", "eventparams", "=", "array", "(", "'objectid'", "=>", "$", "this", "->", "id", ",", "'context'", "=>", "$", "this", "->", "get_context", "(", ")", ")", ";", "$", "event", "=", "\\", "core", "\\", "event", "\\", "badge_archived", "::", "create", "(", "$", "eventparams", ")", ";", "$", "event", "->", "trigger", "(", ")", ";", "return", ";", "}", "$", "fs", "=", "get_file_storage", "(", ")", ";", "// Remove all issued badge image files and badge awards.", "// Cannot bulk remove area files here because they are issued in user context.", "$", "awards", "=", "$", "this", "->", "get_awards", "(", ")", ";", "foreach", "(", "$", "awards", "as", "$", "award", ")", "{", "$", "usercontext", "=", "context_user", "::", "instance", "(", "$", "award", "->", "userid", ")", ";", "$", "fs", "->", "delete_area_files", "(", "$", "usercontext", "->", "id", ",", "'badges'", ",", "'userbadge'", ",", "$", "this", "->", "id", ")", ";", "}", "$", "DB", "->", "delete_records", "(", "'badge_issued'", ",", "array", "(", "'badgeid'", "=>", "$", "this", "->", "id", ")", ")", ";", "// Remove all badge criteria.", "$", "criteria", "=", "$", "this", "->", "get_criteria", "(", ")", ";", "foreach", "(", "$", "criteria", "as", "$", "criterion", ")", "{", "$", "criterion", "->", "delete", "(", ")", ";", "}", "// Delete badge images.", "$", "badgecontext", "=", "$", "this", "->", "get_context", "(", ")", ";", "$", "fs", "->", "delete_area_files", "(", "$", "badgecontext", "->", "id", ",", "'badges'", ",", "'badgeimage'", ",", "$", "this", "->", "id", ")", ";", "// Delete endorsements, alignments and related badges.", "$", "DB", "->", "delete_records", "(", "'badge_endorsement'", ",", "array", "(", "'badgeid'", "=>", "$", "this", "->", "id", ")", ")", ";", "$", "relatedsql", "=", "'badgeid = :badgeid OR relatedbadgeid = :relatedbadgeid'", ";", "$", "relatedparams", "=", "array", "(", "'badgeid'", "=>", "$", "this", "->", "id", ",", "'relatedbadgeid'", "=>", "$", "this", "->", "id", ")", ";", "$", "DB", "->", "delete_records_select", "(", "'badge_related'", ",", "$", "relatedsql", ",", "$", "relatedparams", ")", ";", "$", "DB", "->", "delete_records", "(", "'badge_alignment'", ",", "array", "(", "'badgeid'", "=>", "$", "this", "->", "id", ")", ")", ";", "// Finally, remove badge itself.", "$", "DB", "->", "delete_records", "(", "'badge'", ",", "array", "(", "'id'", "=>", "$", "this", "->", "id", ")", ")", ";", "// Trigger event, badge deleted.", "$", "eventparams", "=", "array", "(", "'objectid'", "=>", "$", "this", "->", "id", ",", "'context'", "=>", "$", "this", "->", "get_context", "(", ")", ",", "'other'", "=>", "array", "(", "'badgetype'", "=>", "$", "this", "->", "type", ",", "'courseid'", "=>", "$", "this", "->", "courseid", ")", ")", ";", "$", "event", "=", "\\", "core", "\\", "event", "\\", "badge_deleted", "::", "create", "(", "$", "eventparams", ")", ";", "$", "event", "->", "trigger", "(", ")", ";", "}" ]
Fully deletes the badge or marks it as archived. @param $archive bool Achive a badge without actual deleting of any data.
[ "Fully", "deletes", "the", "badge", "or", "marks", "it", "as", "archived", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/badgeslib.php#L714-L769
214,597
moodle/moodle
lib/badgeslib.php
badge.add_related_badges
public function add_related_badges($relatedids) { global $DB; $relatedbadges = array(); foreach ($relatedids as $relatedid) { $relatedbadge = new stdClass(); $relatedbadge->badgeid = $this->id; $relatedbadge->relatedbadgeid = $relatedid; $relatedbadges[] = $relatedbadge; } $DB->insert_records('badge_related', $relatedbadges); }
php
public function add_related_badges($relatedids) { global $DB; $relatedbadges = array(); foreach ($relatedids as $relatedid) { $relatedbadge = new stdClass(); $relatedbadge->badgeid = $this->id; $relatedbadge->relatedbadgeid = $relatedid; $relatedbadges[] = $relatedbadge; } $DB->insert_records('badge_related', $relatedbadges); }
[ "public", "function", "add_related_badges", "(", "$", "relatedids", ")", "{", "global", "$", "DB", ";", "$", "relatedbadges", "=", "array", "(", ")", ";", "foreach", "(", "$", "relatedids", "as", "$", "relatedid", ")", "{", "$", "relatedbadge", "=", "new", "stdClass", "(", ")", ";", "$", "relatedbadge", "->", "badgeid", "=", "$", "this", "->", "id", ";", "$", "relatedbadge", "->", "relatedbadgeid", "=", "$", "relatedid", ";", "$", "relatedbadges", "[", "]", "=", "$", "relatedbadge", ";", "}", "$", "DB", "->", "insert_records", "(", "'badge_related'", ",", "$", "relatedbadges", ")", ";", "}" ]
Add multiple related badges. @param array $relatedids Id of badges.
[ "Add", "multiple", "related", "badges", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/badgeslib.php#L776-L786
214,598
moodle/moodle
lib/badgeslib.php
badge.delete_related_badge
public function delete_related_badge($relatedid) { global $DB; $sql = "(badgeid = :badgeid AND relatedbadgeid = :relatedid) OR " . "(badgeid = :relatedid2 AND relatedbadgeid = :badgeid2)"; $params = ['badgeid' => $this->id, 'badgeid2' => $this->id, 'relatedid' => $relatedid, 'relatedid2' => $relatedid]; return $DB->delete_records_select('badge_related', $sql, $params); }
php
public function delete_related_badge($relatedid) { global $DB; $sql = "(badgeid = :badgeid AND relatedbadgeid = :relatedid) OR " . "(badgeid = :relatedid2 AND relatedbadgeid = :badgeid2)"; $params = ['badgeid' => $this->id, 'badgeid2' => $this->id, 'relatedid' => $relatedid, 'relatedid2' => $relatedid]; return $DB->delete_records_select('badge_related', $sql, $params); }
[ "public", "function", "delete_related_badge", "(", "$", "relatedid", ")", "{", "global", "$", "DB", ";", "$", "sql", "=", "\"(badgeid = :badgeid AND relatedbadgeid = :relatedid) OR \"", ".", "\"(badgeid = :relatedid2 AND relatedbadgeid = :badgeid2)\"", ";", "$", "params", "=", "[", "'badgeid'", "=>", "$", "this", "->", "id", ",", "'badgeid2'", "=>", "$", "this", "->", "id", ",", "'relatedid'", "=>", "$", "relatedid", ",", "'relatedid2'", "=>", "$", "relatedid", "]", ";", "return", "$", "DB", "->", "delete_records_select", "(", "'badge_related'", ",", "$", "sql", ",", "$", "params", ")", ";", "}" ]
Delete an related badge. @param int $relatedid Id related badge. @return bool A status for delete an related badge.
[ "Delete", "an", "related", "badge", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/badgeslib.php#L794-L800
214,599
moodle/moodle
lib/badgeslib.php
badge.has_related
public function has_related() { global $DB; $sql = "SELECT DISTINCT b.id FROM {badge_related} br JOIN {badge} b ON (br.relatedbadgeid = b.id OR br.badgeid = b.id) WHERE (br.badgeid = :badgeid OR br.relatedbadgeid = :badgeid2) AND b.id != :badgeid3"; return $DB->record_exists_sql($sql, ['badgeid' => $this->id, 'badgeid2' => $this->id, 'badgeid3' => $this->id]); }
php
public function has_related() { global $DB; $sql = "SELECT DISTINCT b.id FROM {badge_related} br JOIN {badge} b ON (br.relatedbadgeid = b.id OR br.badgeid = b.id) WHERE (br.badgeid = :badgeid OR br.relatedbadgeid = :badgeid2) AND b.id != :badgeid3"; return $DB->record_exists_sql($sql, ['badgeid' => $this->id, 'badgeid2' => $this->id, 'badgeid3' => $this->id]); }
[ "public", "function", "has_related", "(", ")", "{", "global", "$", "DB", ";", "$", "sql", "=", "\"SELECT DISTINCT b.id\n FROM {badge_related} br\n JOIN {badge} b ON (br.relatedbadgeid = b.id OR br.badgeid = b.id)\n WHERE (br.badgeid = :badgeid OR br.relatedbadgeid = :badgeid2) AND b.id != :badgeid3\"", ";", "return", "$", "DB", "->", "record_exists_sql", "(", "$", "sql", ",", "[", "'badgeid'", "=>", "$", "this", "->", "id", ",", "'badgeid2'", "=>", "$", "this", "->", "id", ",", "'badgeid3'", "=>", "$", "this", "->", "id", "]", ")", ";", "}" ]
Checks if badge has related badges. @return bool A status related badge.
[ "Checks", "if", "badge", "has", "related", "badges", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/badgeslib.php#L807-L814