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
218,100
moodle/moodle
mod/assign/externallib.php
mod_assign_external.generate_warning
private static function generate_warning($assignmentid, $warningcode, $detail) { $warningmessages = array( 'couldnotlock'=>'Could not lock the submission for this user.', 'couldnotunlock'=>'Could not unlock the submission for this user.', 'couldnotsubmitforgrading'=>'Could not submit assignment for grading.', 'couldnotrevealidentities'=>'Could not reveal identities.', 'couldnotgrantextensions'=>'Could not grant submission date extensions.', 'couldnotrevert'=>'Could not revert submission to draft.', 'invalidparameters'=>'Invalid parameters.', 'couldnotsavesubmission'=>'Could not save submission.', 'couldnotsavegrade'=>'Could not save grade.' ); $message = $warningmessages[$warningcode]; if (empty($message)) { $message = 'Unknown warning type.'; } return array('item' => s($detail), 'itemid'=>$assignmentid, 'warningcode'=>$warningcode, 'message'=>$message); }
php
private static function generate_warning($assignmentid, $warningcode, $detail) { $warningmessages = array( 'couldnotlock'=>'Could not lock the submission for this user.', 'couldnotunlock'=>'Could not unlock the submission for this user.', 'couldnotsubmitforgrading'=>'Could not submit assignment for grading.', 'couldnotrevealidentities'=>'Could not reveal identities.', 'couldnotgrantextensions'=>'Could not grant submission date extensions.', 'couldnotrevert'=>'Could not revert submission to draft.', 'invalidparameters'=>'Invalid parameters.', 'couldnotsavesubmission'=>'Could not save submission.', 'couldnotsavegrade'=>'Could not save grade.' ); $message = $warningmessages[$warningcode]; if (empty($message)) { $message = 'Unknown warning type.'; } return array('item' => s($detail), 'itemid'=>$assignmentid, 'warningcode'=>$warningcode, 'message'=>$message); }
[ "private", "static", "function", "generate_warning", "(", "$", "assignmentid", ",", "$", "warningcode", ",", "$", "detail", ")", "{", "$", "warningmessages", "=", "array", "(", "'couldnotlock'", "=>", "'Could not lock the submission for this user.'", ",", "'couldnotunlock'", "=>", "'Could not unlock the submission for this user.'", ",", "'couldnotsubmitforgrading'", "=>", "'Could not submit assignment for grading.'", ",", "'couldnotrevealidentities'", "=>", "'Could not reveal identities.'", ",", "'couldnotgrantextensions'", "=>", "'Could not grant submission date extensions.'", ",", "'couldnotrevert'", "=>", "'Could not revert submission to draft.'", ",", "'invalidparameters'", "=>", "'Invalid parameters.'", ",", "'couldnotsavesubmission'", "=>", "'Could not save submission.'", ",", "'couldnotsavegrade'", "=>", "'Could not save grade.'", ")", ";", "$", "message", "=", "$", "warningmessages", "[", "$", "warningcode", "]", ";", "if", "(", "empty", "(", "$", "message", ")", ")", "{", "$", "message", "=", "'Unknown warning type.'", ";", "}", "return", "array", "(", "'item'", "=>", "s", "(", "$", "detail", ")", ",", "'itemid'", "=>", "$", "assignmentid", ",", "'warningcode'", "=>", "$", "warningcode", ",", "'message'", "=>", "$", "message", ")", ";", "}" ]
Generate a warning in a standard structure for a known failure. @param int $assignmentid - The assignment @param string $warningcode - The key for the warning message @param string $detail - A description of the error @return array - Warning structure containing item, itemid, warningcode, message
[ "Generate", "a", "warning", "in", "a", "standard", "structure", "for", "a", "known", "failure", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/assign/externallib.php#L47-L69
218,101
moodle/moodle
mod/assign/externallib.php
mod_assign_external.get_grade_structure
private static function get_grade_structure($required = VALUE_REQUIRED) { return new external_single_structure( array( 'id' => new external_value(PARAM_INT, 'grade id'), 'assignment' => new external_value(PARAM_INT, 'assignment id', VALUE_OPTIONAL), 'userid' => new external_value(PARAM_INT, 'student id'), 'attemptnumber' => new external_value(PARAM_INT, 'attempt number'), 'timecreated' => new external_value(PARAM_INT, 'grade creation time'), 'timemodified' => new external_value(PARAM_INT, 'grade last modified time'), 'grader' => new external_value(PARAM_INT, 'grader, -1 if grader is hidden'), 'grade' => new external_value(PARAM_TEXT, 'grade'), 'gradefordisplay' => new external_value(PARAM_RAW, 'grade rendered into a format suitable for display', VALUE_OPTIONAL), ), 'grade information', $required ); }
php
private static function get_grade_structure($required = VALUE_REQUIRED) { return new external_single_structure( array( 'id' => new external_value(PARAM_INT, 'grade id'), 'assignment' => new external_value(PARAM_INT, 'assignment id', VALUE_OPTIONAL), 'userid' => new external_value(PARAM_INT, 'student id'), 'attemptnumber' => new external_value(PARAM_INT, 'attempt number'), 'timecreated' => new external_value(PARAM_INT, 'grade creation time'), 'timemodified' => new external_value(PARAM_INT, 'grade last modified time'), 'grader' => new external_value(PARAM_INT, 'grader, -1 if grader is hidden'), 'grade' => new external_value(PARAM_TEXT, 'grade'), 'gradefordisplay' => new external_value(PARAM_RAW, 'grade rendered into a format suitable for display', VALUE_OPTIONAL), ), 'grade information', $required ); }
[ "private", "static", "function", "get_grade_structure", "(", "$", "required", "=", "VALUE_REQUIRED", ")", "{", "return", "new", "external_single_structure", "(", "array", "(", "'id'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'grade id'", ")", ",", "'assignment'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'assignment id'", ",", "VALUE_OPTIONAL", ")", ",", "'userid'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'student id'", ")", ",", "'attemptnumber'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'attempt number'", ")", ",", "'timecreated'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'grade creation time'", ")", ",", "'timemodified'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'grade last modified time'", ")", ",", "'grader'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'grader, -1 if grader is hidden'", ")", ",", "'grade'", "=>", "new", "external_value", "(", "PARAM_TEXT", ",", "'grade'", ")", ",", "'gradefordisplay'", "=>", "new", "external_value", "(", "PARAM_RAW", ",", "'grade rendered into a format suitable for display'", ",", "VALUE_OPTIONAL", ")", ",", ")", ",", "'grade information'", ",", "$", "required", ")", ";", "}" ]
Creates a grade single structure. @return external_single_structure a grade single structure. @since Moodle 3.1
[ "Creates", "a", "grade", "single", "structure", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/assign/externallib.php#L206-L221
218,102
moodle/moodle
mod/assign/externallib.php
mod_assign_external.get_assignments_assignment_structure
private static function get_assignments_assignment_structure() { return new external_single_structure( array( 'id' => new external_value(PARAM_INT, 'assignment id'), 'cmid' => new external_value(PARAM_INT, 'course module id'), 'course' => new external_value(PARAM_INT, 'course id'), 'name' => new external_value(PARAM_TEXT, 'assignment name'), 'nosubmissions' => new external_value(PARAM_INT, 'no submissions'), 'submissiondrafts' => new external_value(PARAM_INT, 'submissions drafts'), 'sendnotifications' => new external_value(PARAM_INT, 'send notifications'), 'sendlatenotifications' => new external_value(PARAM_INT, 'send notifications'), 'sendstudentnotifications' => new external_value(PARAM_INT, 'send student notifications (default)'), 'duedate' => new external_value(PARAM_INT, 'assignment due date'), 'allowsubmissionsfromdate' => new external_value(PARAM_INT, 'allow submissions from date'), 'grade' => new external_value(PARAM_INT, 'grade type'), 'timemodified' => new external_value(PARAM_INT, 'last time assignment was modified'), 'completionsubmit' => new external_value(PARAM_INT, 'if enabled, set activity as complete following submission'), 'cutoffdate' => new external_value(PARAM_INT, 'date after which submission is not accepted without an extension'), 'gradingduedate' => new external_value(PARAM_INT, 'the expected date for marking the submissions'), 'teamsubmission' => new external_value(PARAM_INT, 'if enabled, students submit as a team'), 'requireallteammemberssubmit' => new external_value(PARAM_INT, 'if enabled, all team members must submit'), 'teamsubmissiongroupingid' => new external_value(PARAM_INT, 'the grouping id for the team submission groups'), 'blindmarking' => new external_value(PARAM_INT, 'if enabled, hide identities until reveal identities actioned'), 'hidegrader' => new external_value(PARAM_INT, 'If enabled, hide grader to student'), 'revealidentities' => new external_value(PARAM_INT, 'show identities for a blind marking assignment'), 'attemptreopenmethod' => new external_value(PARAM_TEXT, 'method used to control opening new attempts'), 'maxattempts' => new external_value(PARAM_INT, 'maximum number of attempts allowed'), 'markingworkflow' => new external_value(PARAM_INT, 'enable marking workflow'), 'markingallocation' => new external_value(PARAM_INT, 'enable marking allocation'), 'requiresubmissionstatement' => new external_value(PARAM_INT, 'student must accept submission statement'), 'preventsubmissionnotingroup' => new external_value(PARAM_INT, 'Prevent submission not in group', VALUE_OPTIONAL), 'submissionstatement' => new external_value(PARAM_RAW, 'Submission statement formatted.', VALUE_OPTIONAL), 'submissionstatementformat' => new external_format_value('submissionstatement', VALUE_OPTIONAL), 'configs' => new external_multiple_structure(self::get_assignments_config_structure(), 'configuration settings'), 'intro' => new external_value(PARAM_RAW, 'assignment intro, not allways returned because it deppends on the activity configuration', VALUE_OPTIONAL), 'introformat' => new external_format_value('intro', VALUE_OPTIONAL), 'introfiles' => new external_files('Files in the introduction text', VALUE_OPTIONAL), 'introattachments' => new external_files('intro attachments files', VALUE_OPTIONAL), ), 'assignment information object'); }
php
private static function get_assignments_assignment_structure() { return new external_single_structure( array( 'id' => new external_value(PARAM_INT, 'assignment id'), 'cmid' => new external_value(PARAM_INT, 'course module id'), 'course' => new external_value(PARAM_INT, 'course id'), 'name' => new external_value(PARAM_TEXT, 'assignment name'), 'nosubmissions' => new external_value(PARAM_INT, 'no submissions'), 'submissiondrafts' => new external_value(PARAM_INT, 'submissions drafts'), 'sendnotifications' => new external_value(PARAM_INT, 'send notifications'), 'sendlatenotifications' => new external_value(PARAM_INT, 'send notifications'), 'sendstudentnotifications' => new external_value(PARAM_INT, 'send student notifications (default)'), 'duedate' => new external_value(PARAM_INT, 'assignment due date'), 'allowsubmissionsfromdate' => new external_value(PARAM_INT, 'allow submissions from date'), 'grade' => new external_value(PARAM_INT, 'grade type'), 'timemodified' => new external_value(PARAM_INT, 'last time assignment was modified'), 'completionsubmit' => new external_value(PARAM_INT, 'if enabled, set activity as complete following submission'), 'cutoffdate' => new external_value(PARAM_INT, 'date after which submission is not accepted without an extension'), 'gradingduedate' => new external_value(PARAM_INT, 'the expected date for marking the submissions'), 'teamsubmission' => new external_value(PARAM_INT, 'if enabled, students submit as a team'), 'requireallteammemberssubmit' => new external_value(PARAM_INT, 'if enabled, all team members must submit'), 'teamsubmissiongroupingid' => new external_value(PARAM_INT, 'the grouping id for the team submission groups'), 'blindmarking' => new external_value(PARAM_INT, 'if enabled, hide identities until reveal identities actioned'), 'hidegrader' => new external_value(PARAM_INT, 'If enabled, hide grader to student'), 'revealidentities' => new external_value(PARAM_INT, 'show identities for a blind marking assignment'), 'attemptreopenmethod' => new external_value(PARAM_TEXT, 'method used to control opening new attempts'), 'maxattempts' => new external_value(PARAM_INT, 'maximum number of attempts allowed'), 'markingworkflow' => new external_value(PARAM_INT, 'enable marking workflow'), 'markingallocation' => new external_value(PARAM_INT, 'enable marking allocation'), 'requiresubmissionstatement' => new external_value(PARAM_INT, 'student must accept submission statement'), 'preventsubmissionnotingroup' => new external_value(PARAM_INT, 'Prevent submission not in group', VALUE_OPTIONAL), 'submissionstatement' => new external_value(PARAM_RAW, 'Submission statement formatted.', VALUE_OPTIONAL), 'submissionstatementformat' => new external_format_value('submissionstatement', VALUE_OPTIONAL), 'configs' => new external_multiple_structure(self::get_assignments_config_structure(), 'configuration settings'), 'intro' => new external_value(PARAM_RAW, 'assignment intro, not allways returned because it deppends on the activity configuration', VALUE_OPTIONAL), 'introformat' => new external_format_value('intro', VALUE_OPTIONAL), 'introfiles' => new external_files('Files in the introduction text', VALUE_OPTIONAL), 'introattachments' => new external_files('intro attachments files', VALUE_OPTIONAL), ), 'assignment information object'); }
[ "private", "static", "function", "get_assignments_assignment_structure", "(", ")", "{", "return", "new", "external_single_structure", "(", "array", "(", "'id'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'assignment id'", ")", ",", "'cmid'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'course module id'", ")", ",", "'course'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'course id'", ")", ",", "'name'", "=>", "new", "external_value", "(", "PARAM_TEXT", ",", "'assignment name'", ")", ",", "'nosubmissions'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'no submissions'", ")", ",", "'submissiondrafts'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'submissions drafts'", ")", ",", "'sendnotifications'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'send notifications'", ")", ",", "'sendlatenotifications'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'send notifications'", ")", ",", "'sendstudentnotifications'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'send student notifications (default)'", ")", ",", "'duedate'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'assignment due date'", ")", ",", "'allowsubmissionsfromdate'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'allow submissions from date'", ")", ",", "'grade'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'grade type'", ")", ",", "'timemodified'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'last time assignment was modified'", ")", ",", "'completionsubmit'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'if enabled, set activity as complete following submission'", ")", ",", "'cutoffdate'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'date after which submission is not accepted without an extension'", ")", ",", "'gradingduedate'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'the expected date for marking the submissions'", ")", ",", "'teamsubmission'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'if enabled, students submit as a team'", ")", ",", "'requireallteammemberssubmit'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'if enabled, all team members must submit'", ")", ",", "'teamsubmissiongroupingid'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'the grouping id for the team submission groups'", ")", ",", "'blindmarking'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'if enabled, hide identities until reveal identities actioned'", ")", ",", "'hidegrader'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'If enabled, hide grader to student'", ")", ",", "'revealidentities'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'show identities for a blind marking assignment'", ")", ",", "'attemptreopenmethod'", "=>", "new", "external_value", "(", "PARAM_TEXT", ",", "'method used to control opening new attempts'", ")", ",", "'maxattempts'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'maximum number of attempts allowed'", ")", ",", "'markingworkflow'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'enable marking workflow'", ")", ",", "'markingallocation'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'enable marking allocation'", ")", ",", "'requiresubmissionstatement'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'student must accept submission statement'", ")", ",", "'preventsubmissionnotingroup'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'Prevent submission not in group'", ",", "VALUE_OPTIONAL", ")", ",", "'submissionstatement'", "=>", "new", "external_value", "(", "PARAM_RAW", ",", "'Submission statement formatted.'", ",", "VALUE_OPTIONAL", ")", ",", "'submissionstatementformat'", "=>", "new", "external_format_value", "(", "'submissionstatement'", ",", "VALUE_OPTIONAL", ")", ",", "'configs'", "=>", "new", "external_multiple_structure", "(", "self", "::", "get_assignments_config_structure", "(", ")", ",", "'configuration settings'", ")", ",", "'intro'", "=>", "new", "external_value", "(", "PARAM_RAW", ",", "'assignment intro, not allways returned because it deppends on the activity configuration'", ",", "VALUE_OPTIONAL", ")", ",", "'introformat'", "=>", "new", "external_format_value", "(", "'intro'", ",", "VALUE_OPTIONAL", ")", ",", "'introfiles'", "=>", "new", "external_files", "(", "'Files in the introduction text'", ",", "VALUE_OPTIONAL", ")", ",", "'introattachments'", "=>", "new", "external_files", "(", "'intro attachments files'", ",", "VALUE_OPTIONAL", ")", ",", ")", ",", "'assignment information object'", ")", ";", "}" ]
Creates an assignment external_single_structure @return external_single_structure @since Moodle 2.4
[ "Creates", "an", "assignment", "external_single_structure" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/assign/externallib.php#L524-L564
218,103
moodle/moodle
mod/assign/externallib.php
mod_assign_external.get_assignments_config_structure
private static function get_assignments_config_structure() { return new external_single_structure( array( 'id' => new external_value(PARAM_INT, 'assign_plugin_config id', VALUE_OPTIONAL), 'assignment' => new external_value(PARAM_INT, 'assignment id', VALUE_OPTIONAL), 'plugin' => new external_value(PARAM_TEXT, 'plugin'), 'subtype' => new external_value(PARAM_TEXT, 'subtype'), 'name' => new external_value(PARAM_TEXT, 'name'), 'value' => new external_value(PARAM_TEXT, 'value') ), 'assignment configuration object' ); }
php
private static function get_assignments_config_structure() { return new external_single_structure( array( 'id' => new external_value(PARAM_INT, 'assign_plugin_config id', VALUE_OPTIONAL), 'assignment' => new external_value(PARAM_INT, 'assignment id', VALUE_OPTIONAL), 'plugin' => new external_value(PARAM_TEXT, 'plugin'), 'subtype' => new external_value(PARAM_TEXT, 'subtype'), 'name' => new external_value(PARAM_TEXT, 'name'), 'value' => new external_value(PARAM_TEXT, 'value') ), 'assignment configuration object' ); }
[ "private", "static", "function", "get_assignments_config_structure", "(", ")", "{", "return", "new", "external_single_structure", "(", "array", "(", "'id'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'assign_plugin_config id'", ",", "VALUE_OPTIONAL", ")", ",", "'assignment'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'assignment id'", ",", "VALUE_OPTIONAL", ")", ",", "'plugin'", "=>", "new", "external_value", "(", "PARAM_TEXT", ",", "'plugin'", ")", ",", "'subtype'", "=>", "new", "external_value", "(", "PARAM_TEXT", ",", "'subtype'", ")", ",", "'name'", "=>", "new", "external_value", "(", "PARAM_TEXT", ",", "'name'", ")", ",", "'value'", "=>", "new", "external_value", "(", "PARAM_TEXT", ",", "'value'", ")", ")", ",", "'assignment configuration object'", ")", ";", "}" ]
Creates an assign_plugin_config external_single_structure @return external_single_structure @since Moodle 2.4
[ "Creates", "an", "assign_plugin_config", "external_single_structure" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/assign/externallib.php#L572-L583
218,104
moodle/moodle
mod/assign/externallib.php
mod_assign_external.get_assignments_course_structure
private static function get_assignments_course_structure() { return new external_single_structure( array( 'id' => new external_value(PARAM_INT, 'course id'), 'fullname' => new external_value(PARAM_TEXT, 'course full name'), 'shortname' => new external_value(PARAM_TEXT, 'course short name'), 'timemodified' => new external_value(PARAM_INT, 'last time modified'), 'assignments' => new external_multiple_structure(self::get_assignments_assignment_structure(), 'assignment info') ), 'course information object' ); }
php
private static function get_assignments_course_structure() { return new external_single_structure( array( 'id' => new external_value(PARAM_INT, 'course id'), 'fullname' => new external_value(PARAM_TEXT, 'course full name'), 'shortname' => new external_value(PARAM_TEXT, 'course short name'), 'timemodified' => new external_value(PARAM_INT, 'last time modified'), 'assignments' => new external_multiple_structure(self::get_assignments_assignment_structure(), 'assignment info') ), 'course information object' ); }
[ "private", "static", "function", "get_assignments_course_structure", "(", ")", "{", "return", "new", "external_single_structure", "(", "array", "(", "'id'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'course id'", ")", ",", "'fullname'", "=>", "new", "external_value", "(", "PARAM_TEXT", ",", "'course full name'", ")", ",", "'shortname'", "=>", "new", "external_value", "(", "PARAM_TEXT", ",", "'course short name'", ")", ",", "'timemodified'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'last time modified'", ")", ",", "'assignments'", "=>", "new", "external_multiple_structure", "(", "self", "::", "get_assignments_assignment_structure", "(", ")", ",", "'assignment info'", ")", ")", ",", "'course information object'", ")", ";", "}" ]
Creates a course external_single_structure @return external_single_structure @since Moodle 2.4
[ "Creates", "a", "course", "external_single_structure" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/assign/externallib.php#L591-L601
218,105
moodle/moodle
mod/assign/externallib.php
mod_assign_external.get_submissions_parameters
public static function get_submissions_parameters() { return new external_function_parameters( array( 'assignmentids' => new external_multiple_structure( new external_value(PARAM_INT, 'assignment id'), '1 or more assignment ids', VALUE_REQUIRED), 'status' => new external_value(PARAM_ALPHA, 'status', VALUE_DEFAULT, ''), 'since' => new external_value(PARAM_INT, 'submitted since', VALUE_DEFAULT, 0), 'before' => new external_value(PARAM_INT, 'submitted before', VALUE_DEFAULT, 0) ) ); }
php
public static function get_submissions_parameters() { return new external_function_parameters( array( 'assignmentids' => new external_multiple_structure( new external_value(PARAM_INT, 'assignment id'), '1 or more assignment ids', VALUE_REQUIRED), 'status' => new external_value(PARAM_ALPHA, 'status', VALUE_DEFAULT, ''), 'since' => new external_value(PARAM_INT, 'submitted since', VALUE_DEFAULT, 0), 'before' => new external_value(PARAM_INT, 'submitted before', VALUE_DEFAULT, 0) ) ); }
[ "public", "static", "function", "get_submissions_parameters", "(", ")", "{", "return", "new", "external_function_parameters", "(", "array", "(", "'assignmentids'", "=>", "new", "external_multiple_structure", "(", "new", "external_value", "(", "PARAM_INT", ",", "'assignment id'", ")", ",", "'1 or more assignment ids'", ",", "VALUE_REQUIRED", ")", ",", "'status'", "=>", "new", "external_value", "(", "PARAM_ALPHA", ",", "'status'", ",", "VALUE_DEFAULT", ",", "''", ")", ",", "'since'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'submitted since'", ",", "VALUE_DEFAULT", ",", "0", ")", ",", "'before'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'submitted before'", ",", "VALUE_DEFAULT", ",", "0", ")", ")", ")", ";", "}" ]
Describes the parameters for get_submissions @return external_function_parameters @since Moodle 2.5
[ "Describes", "the", "parameters", "for", "get_submissions" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/assign/externallib.php#L690-L702
218,106
moodle/moodle
mod/assign/externallib.php
mod_assign_external.get_plugin_structure
private static function get_plugin_structure() { return new external_single_structure( array( 'type' => new external_value(PARAM_TEXT, 'submission plugin type'), 'name' => new external_value(PARAM_TEXT, 'submission plugin name'), 'fileareas' => new external_multiple_structure( new external_single_structure( array ( 'area' => new external_value (PARAM_TEXT, 'file area'), 'files' => new external_files('files', VALUE_OPTIONAL), ) ), 'fileareas', VALUE_OPTIONAL ), 'editorfields' => new external_multiple_structure( new external_single_structure( array( 'name' => new external_value(PARAM_TEXT, 'field name'), 'description' => new external_value(PARAM_RAW, 'field description'), 'text' => new external_value (PARAM_RAW, 'field value'), 'format' => new external_format_value ('text') ) ) , 'editorfields', VALUE_OPTIONAL ) ) ); }
php
private static function get_plugin_structure() { return new external_single_structure( array( 'type' => new external_value(PARAM_TEXT, 'submission plugin type'), 'name' => new external_value(PARAM_TEXT, 'submission plugin name'), 'fileareas' => new external_multiple_structure( new external_single_structure( array ( 'area' => new external_value (PARAM_TEXT, 'file area'), 'files' => new external_files('files', VALUE_OPTIONAL), ) ), 'fileareas', VALUE_OPTIONAL ), 'editorfields' => new external_multiple_structure( new external_single_structure( array( 'name' => new external_value(PARAM_TEXT, 'field name'), 'description' => new external_value(PARAM_RAW, 'field description'), 'text' => new external_value (PARAM_RAW, 'field value'), 'format' => new external_format_value ('text') ) ) , 'editorfields', VALUE_OPTIONAL ) ) ); }
[ "private", "static", "function", "get_plugin_structure", "(", ")", "{", "return", "new", "external_single_structure", "(", "array", "(", "'type'", "=>", "new", "external_value", "(", "PARAM_TEXT", ",", "'submission plugin type'", ")", ",", "'name'", "=>", "new", "external_value", "(", "PARAM_TEXT", ",", "'submission plugin name'", ")", ",", "'fileareas'", "=>", "new", "external_multiple_structure", "(", "new", "external_single_structure", "(", "array", "(", "'area'", "=>", "new", "external_value", "(", "PARAM_TEXT", ",", "'file area'", ")", ",", "'files'", "=>", "new", "external_files", "(", "'files'", ",", "VALUE_OPTIONAL", ")", ",", ")", ")", ",", "'fileareas'", ",", "VALUE_OPTIONAL", ")", ",", "'editorfields'", "=>", "new", "external_multiple_structure", "(", "new", "external_single_structure", "(", "array", "(", "'name'", "=>", "new", "external_value", "(", "PARAM_TEXT", ",", "'field name'", ")", ",", "'description'", "=>", "new", "external_value", "(", "PARAM_RAW", ",", "'field description'", ")", ",", "'text'", "=>", "new", "external_value", "(", "PARAM_RAW", ",", "'field value'", ")", ",", "'format'", "=>", "new", "external_format_value", "(", "'text'", ")", ")", ")", ",", "'editorfields'", ",", "VALUE_OPTIONAL", ")", ")", ")", ";", "}" ]
Creates an assignment plugin structure. @return external_single_structure the plugin structure
[ "Creates", "an", "assignment", "plugin", "structure", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/assign/externallib.php#L828-L854
218,107
moodle/moodle
mod/assign/externallib.php
mod_assign_external.get_submission_structure
private static function get_submission_structure($required = VALUE_REQUIRED) { return new external_single_structure( array( 'id' => new external_value(PARAM_INT, 'submission id'), 'userid' => new external_value(PARAM_INT, 'student id'), 'attemptnumber' => new external_value(PARAM_INT, 'attempt number'), 'timecreated' => new external_value(PARAM_INT, 'submission creation time'), 'timemodified' => new external_value(PARAM_INT, 'submission last modified time'), 'status' => new external_value(PARAM_TEXT, 'submission status'), 'groupid' => new external_value(PARAM_INT, 'group id'), 'assignment' => new external_value(PARAM_INT, 'assignment id', VALUE_OPTIONAL), 'latest' => new external_value(PARAM_INT, 'latest attempt', VALUE_OPTIONAL), 'plugins' => new external_multiple_structure(self::get_plugin_structure(), 'plugins', VALUE_OPTIONAL), 'gradingstatus' => new external_value(PARAM_ALPHANUMEXT, 'Grading status.', VALUE_OPTIONAL), ), 'submission info', $required ); }
php
private static function get_submission_structure($required = VALUE_REQUIRED) { return new external_single_structure( array( 'id' => new external_value(PARAM_INT, 'submission id'), 'userid' => new external_value(PARAM_INT, 'student id'), 'attemptnumber' => new external_value(PARAM_INT, 'attempt number'), 'timecreated' => new external_value(PARAM_INT, 'submission creation time'), 'timemodified' => new external_value(PARAM_INT, 'submission last modified time'), 'status' => new external_value(PARAM_TEXT, 'submission status'), 'groupid' => new external_value(PARAM_INT, 'group id'), 'assignment' => new external_value(PARAM_INT, 'assignment id', VALUE_OPTIONAL), 'latest' => new external_value(PARAM_INT, 'latest attempt', VALUE_OPTIONAL), 'plugins' => new external_multiple_structure(self::get_plugin_structure(), 'plugins', VALUE_OPTIONAL), 'gradingstatus' => new external_value(PARAM_ALPHANUMEXT, 'Grading status.', VALUE_OPTIONAL), ), 'submission info', $required ); }
[ "private", "static", "function", "get_submission_structure", "(", "$", "required", "=", "VALUE_REQUIRED", ")", "{", "return", "new", "external_single_structure", "(", "array", "(", "'id'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'submission id'", ")", ",", "'userid'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'student id'", ")", ",", "'attemptnumber'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'attempt number'", ")", ",", "'timecreated'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'submission creation time'", ")", ",", "'timemodified'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'submission last modified time'", ")", ",", "'status'", "=>", "new", "external_value", "(", "PARAM_TEXT", ",", "'submission status'", ")", ",", "'groupid'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'group id'", ")", ",", "'assignment'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'assignment id'", ",", "VALUE_OPTIONAL", ")", ",", "'latest'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'latest attempt'", ",", "VALUE_OPTIONAL", ")", ",", "'plugins'", "=>", "new", "external_multiple_structure", "(", "self", "::", "get_plugin_structure", "(", ")", ",", "'plugins'", ",", "VALUE_OPTIONAL", ")", ",", "'gradingstatus'", "=>", "new", "external_value", "(", "PARAM_ALPHANUMEXT", ",", "'Grading status.'", ",", "VALUE_OPTIONAL", ")", ",", ")", ",", "'submission info'", ",", "$", "required", ")", ";", "}" ]
Creates a submission structure. @return external_single_structure the submission structure
[ "Creates", "a", "submission", "structure", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/assign/externallib.php#L861-L877
218,108
moodle/moodle
mod/assign/externallib.php
mod_assign_external.set_user_flags_parameters
public static function set_user_flags_parameters() { return new external_function_parameters( array( 'assignmentid' => new external_value(PARAM_INT, 'assignment id'), 'userflags' => new external_multiple_structure( new external_single_structure( array( 'userid' => new external_value(PARAM_INT, 'student id'), 'locked' => new external_value(PARAM_INT, 'locked', VALUE_OPTIONAL), 'mailed' => new external_value(PARAM_INT, 'mailed', VALUE_OPTIONAL), 'extensionduedate' => new external_value(PARAM_INT, 'extension due date', VALUE_OPTIONAL), 'workflowstate' => new external_value(PARAM_ALPHA, 'marking workflow state', VALUE_OPTIONAL), 'allocatedmarker' => new external_value(PARAM_INT, 'allocated marker', VALUE_OPTIONAL) ) ) ) ) ); }
php
public static function set_user_flags_parameters() { return new external_function_parameters( array( 'assignmentid' => new external_value(PARAM_INT, 'assignment id'), 'userflags' => new external_multiple_structure( new external_single_structure( array( 'userid' => new external_value(PARAM_INT, 'student id'), 'locked' => new external_value(PARAM_INT, 'locked', VALUE_OPTIONAL), 'mailed' => new external_value(PARAM_INT, 'mailed', VALUE_OPTIONAL), 'extensionduedate' => new external_value(PARAM_INT, 'extension due date', VALUE_OPTIONAL), 'workflowstate' => new external_value(PARAM_ALPHA, 'marking workflow state', VALUE_OPTIONAL), 'allocatedmarker' => new external_value(PARAM_INT, 'allocated marker', VALUE_OPTIONAL) ) ) ) ) ); }
[ "public", "static", "function", "set_user_flags_parameters", "(", ")", "{", "return", "new", "external_function_parameters", "(", "array", "(", "'assignmentid'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'assignment id'", ")", ",", "'userflags'", "=>", "new", "external_multiple_structure", "(", "new", "external_single_structure", "(", "array", "(", "'userid'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'student id'", ")", ",", "'locked'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'locked'", ",", "VALUE_OPTIONAL", ")", ",", "'mailed'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'mailed'", ",", "VALUE_OPTIONAL", ")", ",", "'extensionduedate'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'extension due date'", ",", "VALUE_OPTIONAL", ")", ",", "'workflowstate'", "=>", "new", "external_value", "(", "PARAM_ALPHA", ",", "'marking workflow state'", ",", "VALUE_OPTIONAL", ")", ",", "'allocatedmarker'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'allocated marker'", ",", "VALUE_OPTIONAL", ")", ")", ")", ")", ")", ")", ";", "}" ]
Describes the parameters for set_user_flags @return external_function_parameters @since Moodle 2.6
[ "Describes", "the", "parameters", "for", "set_user_flags" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/assign/externallib.php#L914-L932
218,109
moodle/moodle
mod/assign/externallib.php
mod_assign_external.set_user_flags_returns
public static function set_user_flags_returns() { return new external_multiple_structure( new external_single_structure( array( 'id' => new external_value(PARAM_INT, 'id of record if successful, -1 for failure'), 'userid' => new external_value(PARAM_INT, 'userid of record'), 'errormessage' => new external_value(PARAM_TEXT, 'Failure error message', VALUE_OPTIONAL) ) ) ); }
php
public static function set_user_flags_returns() { return new external_multiple_structure( new external_single_structure( array( 'id' => new external_value(PARAM_INT, 'id of record if successful, -1 for failure'), 'userid' => new external_value(PARAM_INT, 'userid of record'), 'errormessage' => new external_value(PARAM_TEXT, 'Failure error message', VALUE_OPTIONAL) ) ) ); }
[ "public", "static", "function", "set_user_flags_returns", "(", ")", "{", "return", "new", "external_multiple_structure", "(", "new", "external_single_structure", "(", "array", "(", "'id'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'id of record if successful, -1 for failure'", ")", ",", "'userid'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'userid of record'", ")", ",", "'errormessage'", "=>", "new", "external_value", "(", "PARAM_TEXT", ",", "'Failure error message'", ",", "VALUE_OPTIONAL", ")", ")", ")", ")", ";", "}" ]
Describes the set_user_flags return value @return external_multiple_structure @since Moodle 2.6
[ "Describes", "the", "set_user_flags", "return", "value" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/assign/externallib.php#L1036-L1046
218,110
moodle/moodle
mod/assign/externallib.php
mod_assign_external.assign_user_flags
private static function assign_user_flags() { return new external_single_structure( array ( 'assignmentid' => new external_value(PARAM_INT, 'assignment id'), 'userflags' => new external_multiple_structure(new external_single_structure( array( 'id' => new external_value(PARAM_INT, 'user flag id'), 'userid' => new external_value(PARAM_INT, 'student id'), 'locked' => new external_value(PARAM_INT, 'locked'), 'mailed' => new external_value(PARAM_INT, 'mailed'), 'extensionduedate' => new external_value(PARAM_INT, 'extension due date'), 'workflowstate' => new external_value(PARAM_ALPHA, 'marking workflow state', VALUE_OPTIONAL), 'allocatedmarker' => new external_value(PARAM_INT, 'allocated marker') ) ) ) ) ); }
php
private static function assign_user_flags() { return new external_single_structure( array ( 'assignmentid' => new external_value(PARAM_INT, 'assignment id'), 'userflags' => new external_multiple_structure(new external_single_structure( array( 'id' => new external_value(PARAM_INT, 'user flag id'), 'userid' => new external_value(PARAM_INT, 'student id'), 'locked' => new external_value(PARAM_INT, 'locked'), 'mailed' => new external_value(PARAM_INT, 'mailed'), 'extensionduedate' => new external_value(PARAM_INT, 'extension due date'), 'workflowstate' => new external_value(PARAM_ALPHA, 'marking workflow state', VALUE_OPTIONAL), 'allocatedmarker' => new external_value(PARAM_INT, 'allocated marker') ) ) ) ) ); }
[ "private", "static", "function", "assign_user_flags", "(", ")", "{", "return", "new", "external_single_structure", "(", "array", "(", "'assignmentid'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'assignment id'", ")", ",", "'userflags'", "=>", "new", "external_multiple_structure", "(", "new", "external_single_structure", "(", "array", "(", "'id'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'user flag id'", ")", ",", "'userid'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'student id'", ")", ",", "'locked'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'locked'", ")", ",", "'mailed'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'mailed'", ")", ",", "'extensionduedate'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'extension due date'", ")", ",", "'workflowstate'", "=>", "new", "external_value", "(", "PARAM_ALPHA", ",", "'marking workflow state'", ",", "VALUE_OPTIONAL", ")", ",", "'allocatedmarker'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'allocated marker'", ")", ")", ")", ")", ")", ")", ";", "}" ]
Creates an assign_user_flags external_single_structure @return external_single_structure @since Moodle 2.6
[ "Creates", "an", "assign_user_flags", "external_single_structure" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/assign/externallib.php#L1166-L1184
218,111
moodle/moodle
mod/assign/externallib.php
mod_assign_external.assign_user_mappings
private static function assign_user_mappings() { return new external_single_structure( array ( 'assignmentid' => new external_value(PARAM_INT, 'assignment id'), 'mappings' => new external_multiple_structure(new external_single_structure( array( 'id' => new external_value(PARAM_INT, 'user mapping id'), 'userid' => new external_value(PARAM_INT, 'student id') ) ) ) ) ); }
php
private static function assign_user_mappings() { return new external_single_structure( array ( 'assignmentid' => new external_value(PARAM_INT, 'assignment id'), 'mappings' => new external_multiple_structure(new external_single_structure( array( 'id' => new external_value(PARAM_INT, 'user mapping id'), 'userid' => new external_value(PARAM_INT, 'student id') ) ) ) ) ); }
[ "private", "static", "function", "assign_user_mappings", "(", ")", "{", "return", "new", "external_single_structure", "(", "array", "(", "'assignmentid'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'assignment id'", ")", ",", "'mappings'", "=>", "new", "external_multiple_structure", "(", "new", "external_single_structure", "(", "array", "(", "'id'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'user mapping id'", ")", ",", "'userid'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'student id'", ")", ")", ")", ")", ")", ")", ";", "}" ]
Creates an assign_user_mappings external_single_structure @return external_single_structure @since Moodle 2.6
[ "Creates", "an", "assign_user_mappings", "external_single_structure" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/assign/externallib.php#L1314-L1327
218,112
moodle/moodle
mod/assign/externallib.php
mod_assign_external.revert_submissions_to_draft
public static function revert_submissions_to_draft($assignmentid, $userids) { global $CFG; $params = self::validate_parameters(self::revert_submissions_to_draft_parameters(), array('assignmentid' => $assignmentid, 'userids' => $userids)); list($assignment, $course, $cm, $context) = self::validate_assign($params['assignmentid']); $warnings = array(); foreach ($params['userids'] as $userid) { if (!$assignment->revert_to_draft($userid)) { $detail = 'User id: ' . $userid . ', Assignment id: ' . $params['assignmentid']; $warnings[] = self::generate_warning($params['assignmentid'], 'couldnotrevert', $detail); } } return $warnings; }
php
public static function revert_submissions_to_draft($assignmentid, $userids) { global $CFG; $params = self::validate_parameters(self::revert_submissions_to_draft_parameters(), array('assignmentid' => $assignmentid, 'userids' => $userids)); list($assignment, $course, $cm, $context) = self::validate_assign($params['assignmentid']); $warnings = array(); foreach ($params['userids'] as $userid) { if (!$assignment->revert_to_draft($userid)) { $detail = 'User id: ' . $userid . ', Assignment id: ' . $params['assignmentid']; $warnings[] = self::generate_warning($params['assignmentid'], 'couldnotrevert', $detail); } } return $warnings; }
[ "public", "static", "function", "revert_submissions_to_draft", "(", "$", "assignmentid", ",", "$", "userids", ")", "{", "global", "$", "CFG", ";", "$", "params", "=", "self", "::", "validate_parameters", "(", "self", "::", "revert_submissions_to_draft_parameters", "(", ")", ",", "array", "(", "'assignmentid'", "=>", "$", "assignmentid", ",", "'userids'", "=>", "$", "userids", ")", ")", ";", "list", "(", "$", "assignment", ",", "$", "course", ",", "$", "cm", ",", "$", "context", ")", "=", "self", "::", "validate_assign", "(", "$", "params", "[", "'assignmentid'", "]", ")", ";", "$", "warnings", "=", "array", "(", ")", ";", "foreach", "(", "$", "params", "[", "'userids'", "]", "as", "$", "userid", ")", "{", "if", "(", "!", "$", "assignment", "->", "revert_to_draft", "(", "$", "userid", ")", ")", "{", "$", "detail", "=", "'User id: '", ".", "$", "userid", ".", "', Assignment id: '", ".", "$", "params", "[", "'assignmentid'", "]", ";", "$", "warnings", "[", "]", "=", "self", "::", "generate_warning", "(", "$", "params", "[", "'assignmentid'", "]", ",", "'couldnotrevert'", ",", "$", "detail", ")", ";", "}", "}", "return", "$", "warnings", ";", "}" ]
Reverts a list of user submissions to draft for a single assignment. @param int $assignmentid The id of the assignment @param array $userids Array of user ids to revert @return array of warnings for each submission that could not be reverted. @since Moodle 2.6
[ "Reverts", "a", "list", "of", "user", "submissions", "to", "draft", "for", "a", "single", "assignment", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/assign/externallib.php#L1427-L1447
218,113
moodle/moodle
mod/assign/externallib.php
mod_assign_external.save_user_extensions_parameters
public static function save_user_extensions_parameters() { return new external_function_parameters( array( 'assignmentid' => new external_value(PARAM_INT, 'The assignment id to operate on'), 'userids' => new external_multiple_structure( new external_value(PARAM_INT, 'user id'), '1 or more user ids', VALUE_REQUIRED), 'dates' => new external_multiple_structure( new external_value(PARAM_INT, 'dates'), '1 or more extension dates (timestamp)', VALUE_REQUIRED), ) ); }
php
public static function save_user_extensions_parameters() { return new external_function_parameters( array( 'assignmentid' => new external_value(PARAM_INT, 'The assignment id to operate on'), 'userids' => new external_multiple_structure( new external_value(PARAM_INT, 'user id'), '1 or more user ids', VALUE_REQUIRED), 'dates' => new external_multiple_structure( new external_value(PARAM_INT, 'dates'), '1 or more extension dates (timestamp)', VALUE_REQUIRED), ) ); }
[ "public", "static", "function", "save_user_extensions_parameters", "(", ")", "{", "return", "new", "external_function_parameters", "(", "array", "(", "'assignmentid'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'The assignment id to operate on'", ")", ",", "'userids'", "=>", "new", "external_multiple_structure", "(", "new", "external_value", "(", "PARAM_INT", ",", "'user id'", ")", ",", "'1 or more user ids'", ",", "VALUE_REQUIRED", ")", ",", "'dates'", "=>", "new", "external_multiple_structure", "(", "new", "external_value", "(", "PARAM_INT", ",", "'dates'", ")", ",", "'1 or more extension dates (timestamp)'", ",", "VALUE_REQUIRED", ")", ",", ")", ")", ";", "}" ]
Describes the parameters for save_user_extensions @return external_function_parameters @since Moodle 2.6
[ "Describes", "the", "parameters", "for", "save_user_extensions" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/assign/externallib.php#L1663-L1677
218,114
moodle/moodle
mod/assign/externallib.php
mod_assign_external.save_user_extensions
public static function save_user_extensions($assignmentid, $userids, $dates) { global $CFG; $params = self::validate_parameters(self::save_user_extensions_parameters(), array('assignmentid' => $assignmentid, 'userids' => $userids, 'dates' => $dates)); if (count($params['userids']) != count($params['dates'])) { $detail = 'Length of userids and dates parameters differ.'; $warnings[] = self::generate_warning($params['assignmentid'], 'invalidparameters', $detail); return $warnings; } list($assignment, $course, $cm, $context) = self::validate_assign($params['assignmentid']); $warnings = array(); foreach ($params['userids'] as $idx => $userid) { $duedate = $params['dates'][$idx]; if (!$assignment->save_user_extension($userid, $duedate)) { $detail = 'User id: ' . $userid . ', Assignment id: ' . $params['assignmentid'] . ', Extension date: ' . $duedate; $warnings[] = self::generate_warning($params['assignmentid'], 'couldnotgrantextensions', $detail); } } return $warnings; }
php
public static function save_user_extensions($assignmentid, $userids, $dates) { global $CFG; $params = self::validate_parameters(self::save_user_extensions_parameters(), array('assignmentid' => $assignmentid, 'userids' => $userids, 'dates' => $dates)); if (count($params['userids']) != count($params['dates'])) { $detail = 'Length of userids and dates parameters differ.'; $warnings[] = self::generate_warning($params['assignmentid'], 'invalidparameters', $detail); return $warnings; } list($assignment, $course, $cm, $context) = self::validate_assign($params['assignmentid']); $warnings = array(); foreach ($params['userids'] as $idx => $userid) { $duedate = $params['dates'][$idx]; if (!$assignment->save_user_extension($userid, $duedate)) { $detail = 'User id: ' . $userid . ', Assignment id: ' . $params['assignmentid'] . ', Extension date: ' . $duedate; $warnings[] = self::generate_warning($params['assignmentid'], 'couldnotgrantextensions', $detail); } } return $warnings; }
[ "public", "static", "function", "save_user_extensions", "(", "$", "assignmentid", ",", "$", "userids", ",", "$", "dates", ")", "{", "global", "$", "CFG", ";", "$", "params", "=", "self", "::", "validate_parameters", "(", "self", "::", "save_user_extensions_parameters", "(", ")", ",", "array", "(", "'assignmentid'", "=>", "$", "assignmentid", ",", "'userids'", "=>", "$", "userids", ",", "'dates'", "=>", "$", "dates", ")", ")", ";", "if", "(", "count", "(", "$", "params", "[", "'userids'", "]", ")", "!=", "count", "(", "$", "params", "[", "'dates'", "]", ")", ")", "{", "$", "detail", "=", "'Length of userids and dates parameters differ.'", ";", "$", "warnings", "[", "]", "=", "self", "::", "generate_warning", "(", "$", "params", "[", "'assignmentid'", "]", ",", "'invalidparameters'", ",", "$", "detail", ")", ";", "return", "$", "warnings", ";", "}", "list", "(", "$", "assignment", ",", "$", "course", ",", "$", "cm", ",", "$", "context", ")", "=", "self", "::", "validate_assign", "(", "$", "params", "[", "'assignmentid'", "]", ")", ";", "$", "warnings", "=", "array", "(", ")", ";", "foreach", "(", "$", "params", "[", "'userids'", "]", "as", "$", "idx", "=>", "$", "userid", ")", "{", "$", "duedate", "=", "$", "params", "[", "'dates'", "]", "[", "$", "idx", "]", ";", "if", "(", "!", "$", "assignment", "->", "save_user_extension", "(", "$", "userid", ",", "$", "duedate", ")", ")", "{", "$", "detail", "=", "'User id: '", ".", "$", "userid", ".", "', Assignment id: '", ".", "$", "params", "[", "'assignmentid'", "]", ".", "', Extension date: '", ".", "$", "duedate", ";", "$", "warnings", "[", "]", "=", "self", "::", "generate_warning", "(", "$", "params", "[", "'assignmentid'", "]", ",", "'couldnotgrantextensions'", ",", "$", "detail", ")", ";", "}", "}", "return", "$", "warnings", ";", "}" ]
Grant extension dates to students for an assignment. @param int $assignmentid The id of the assignment @param array $userids Array of user ids to grant extensions to @param array $dates Array of extension dates @return array of warnings for each extension date that could not be granted @since Moodle 2.6
[ "Grant", "extension", "dates", "to", "students", "for", "an", "assignment", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/assign/externallib.php#L1688-L1719
218,115
moodle/moodle
mod/assign/externallib.php
mod_assign_external.reveal_identities
public static function reveal_identities($assignmentid) { global $CFG, $USER; $params = self::validate_parameters(self::reveal_identities_parameters(), array('assignmentid' => $assignmentid)); list($assignment, $course, $cm, $context) = self::validate_assign($params['assignmentid']); $warnings = array(); if (!$assignment->reveal_identities()) { $detail = 'User id: ' . $USER->id . ', Assignment id: ' . $params['assignmentid']; $warnings[] = self::generate_warning($params['assignmentid'], 'couldnotrevealidentities', $detail); } return $warnings; }
php
public static function reveal_identities($assignmentid) { global $CFG, $USER; $params = self::validate_parameters(self::reveal_identities_parameters(), array('assignmentid' => $assignmentid)); list($assignment, $course, $cm, $context) = self::validate_assign($params['assignmentid']); $warnings = array(); if (!$assignment->reveal_identities()) { $detail = 'User id: ' . $USER->id . ', Assignment id: ' . $params['assignmentid']; $warnings[] = self::generate_warning($params['assignmentid'], 'couldnotrevealidentities', $detail); } return $warnings; }
[ "public", "static", "function", "reveal_identities", "(", "$", "assignmentid", ")", "{", "global", "$", "CFG", ",", "$", "USER", ";", "$", "params", "=", "self", "::", "validate_parameters", "(", "self", "::", "reveal_identities_parameters", "(", ")", ",", "array", "(", "'assignmentid'", "=>", "$", "assignmentid", ")", ")", ";", "list", "(", "$", "assignment", ",", "$", "course", ",", "$", "cm", ",", "$", "context", ")", "=", "self", "::", "validate_assign", "(", "$", "params", "[", "'assignmentid'", "]", ")", ";", "$", "warnings", "=", "array", "(", ")", ";", "if", "(", "!", "$", "assignment", "->", "reveal_identities", "(", ")", ")", "{", "$", "detail", "=", "'User id: '", ".", "$", "USER", "->", "id", ".", "', Assignment id: '", ".", "$", "params", "[", "'assignmentid'", "]", ";", "$", "warnings", "[", "]", "=", "self", "::", "generate_warning", "(", "$", "params", "[", "'assignmentid'", "]", ",", "'couldnotrevealidentities'", ",", "$", "detail", ")", ";", "}", "return", "$", "warnings", ";", "}" ]
Reveal the identities of anonymous students to markers for a single assignment. @param int $assignmentid The id of the assignment @return array of warnings to indicate any errors. @since Moodle 2.6
[ "Reveal", "the", "identities", "of", "anonymous", "students", "to", "markers", "for", "a", "single", "assignment", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/assign/externallib.php#L1751-L1768
218,116
moodle/moodle
mod/assign/externallib.php
mod_assign_external.save_submission_parameters
public static function save_submission_parameters() { global $CFG; $instance = new assign(null, null, null); $pluginsubmissionparams = array(); foreach ($instance->get_submission_plugins() as $plugin) { if ($plugin->is_visible()) { $pluginparams = $plugin->get_external_parameters(); if (!empty($pluginparams)) { $pluginsubmissionparams = array_merge($pluginsubmissionparams, $pluginparams); } } } return new external_function_parameters( array( 'assignmentid' => new external_value(PARAM_INT, 'The assignment id to operate on'), 'plugindata' => new external_single_structure( $pluginsubmissionparams ) ) ); }
php
public static function save_submission_parameters() { global $CFG; $instance = new assign(null, null, null); $pluginsubmissionparams = array(); foreach ($instance->get_submission_plugins() as $plugin) { if ($plugin->is_visible()) { $pluginparams = $plugin->get_external_parameters(); if (!empty($pluginparams)) { $pluginsubmissionparams = array_merge($pluginsubmissionparams, $pluginparams); } } } return new external_function_parameters( array( 'assignmentid' => new external_value(PARAM_INT, 'The assignment id to operate on'), 'plugindata' => new external_single_structure( $pluginsubmissionparams ) ) ); }
[ "public", "static", "function", "save_submission_parameters", "(", ")", "{", "global", "$", "CFG", ";", "$", "instance", "=", "new", "assign", "(", "null", ",", "null", ",", "null", ")", ";", "$", "pluginsubmissionparams", "=", "array", "(", ")", ";", "foreach", "(", "$", "instance", "->", "get_submission_plugins", "(", ")", "as", "$", "plugin", ")", "{", "if", "(", "$", "plugin", "->", "is_visible", "(", ")", ")", "{", "$", "pluginparams", "=", "$", "plugin", "->", "get_external_parameters", "(", ")", ";", "if", "(", "!", "empty", "(", "$", "pluginparams", ")", ")", "{", "$", "pluginsubmissionparams", "=", "array_merge", "(", "$", "pluginsubmissionparams", ",", "$", "pluginparams", ")", ";", "}", "}", "}", "return", "new", "external_function_parameters", "(", "array", "(", "'assignmentid'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'The assignment id to operate on'", ")", ",", "'plugindata'", "=>", "new", "external_single_structure", "(", "$", "pluginsubmissionparams", ")", ")", ")", ";", "}" ]
Describes the parameters for save_submission @return external_function_parameters @since Moodle 2.6
[ "Describes", "the", "parameters", "for", "save_submission" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/assign/externallib.php#L1785-L1807
218,117
moodle/moodle
mod/assign/externallib.php
mod_assign_external.save_submission
public static function save_submission($assignmentid, $plugindata) { global $CFG, $USER; $params = self::validate_parameters(self::save_submission_parameters(), array('assignmentid' => $assignmentid, 'plugindata' => $plugindata)); list($assignment, $course, $cm, $context) = self::validate_assign($params['assignmentid']); $notices = array(); $assignment->update_effective_access($USER->id); if (!$assignment->submissions_open($USER->id)) { $notices[] = get_string('duedatereached', 'assign'); } else { $submissiondata = (object)$params['plugindata']; $assignment->save_submission($submissiondata, $notices); } $warnings = array(); foreach ($notices as $notice) { $warnings[] = self::generate_warning($params['assignmentid'], 'couldnotsavesubmission', $notice); } return $warnings; }
php
public static function save_submission($assignmentid, $plugindata) { global $CFG, $USER; $params = self::validate_parameters(self::save_submission_parameters(), array('assignmentid' => $assignmentid, 'plugindata' => $plugindata)); list($assignment, $course, $cm, $context) = self::validate_assign($params['assignmentid']); $notices = array(); $assignment->update_effective_access($USER->id); if (!$assignment->submissions_open($USER->id)) { $notices[] = get_string('duedatereached', 'assign'); } else { $submissiondata = (object)$params['plugindata']; $assignment->save_submission($submissiondata, $notices); } $warnings = array(); foreach ($notices as $notice) { $warnings[] = self::generate_warning($params['assignmentid'], 'couldnotsavesubmission', $notice); } return $warnings; }
[ "public", "static", "function", "save_submission", "(", "$", "assignmentid", ",", "$", "plugindata", ")", "{", "global", "$", "CFG", ",", "$", "USER", ";", "$", "params", "=", "self", "::", "validate_parameters", "(", "self", "::", "save_submission_parameters", "(", ")", ",", "array", "(", "'assignmentid'", "=>", "$", "assignmentid", ",", "'plugindata'", "=>", "$", "plugindata", ")", ")", ";", "list", "(", "$", "assignment", ",", "$", "course", ",", "$", "cm", ",", "$", "context", ")", "=", "self", "::", "validate_assign", "(", "$", "params", "[", "'assignmentid'", "]", ")", ";", "$", "notices", "=", "array", "(", ")", ";", "$", "assignment", "->", "update_effective_access", "(", "$", "USER", "->", "id", ")", ";", "if", "(", "!", "$", "assignment", "->", "submissions_open", "(", "$", "USER", "->", "id", ")", ")", "{", "$", "notices", "[", "]", "=", "get_string", "(", "'duedatereached'", ",", "'assign'", ")", ";", "}", "else", "{", "$", "submissiondata", "=", "(", "object", ")", "$", "params", "[", "'plugindata'", "]", ";", "$", "assignment", "->", "save_submission", "(", "$", "submissiondata", ",", "$", "notices", ")", ";", "}", "$", "warnings", "=", "array", "(", ")", ";", "foreach", "(", "$", "notices", "as", "$", "notice", ")", "{", "$", "warnings", "[", "]", "=", "self", "::", "generate_warning", "(", "$", "params", "[", "'assignmentid'", "]", ",", "'couldnotsavesubmission'", ",", "$", "notice", ")", ";", "}", "return", "$", "warnings", ";", "}" ]
Save a student submission for a single assignment @param int $assignmentid The id of the assignment @param array $plugindata - The submitted data for plugins @return array of warnings to indicate any errors @since Moodle 2.6
[ "Save", "a", "student", "submission", "for", "a", "single", "assignment" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/assign/externallib.php#L1817-L1844
218,118
moodle/moodle
mod/assign/externallib.php
mod_assign_external.save_grade_parameters
public static function save_grade_parameters() { global $CFG; require_once("$CFG->dirroot/grade/grading/lib.php"); $instance = new assign(null, null, null); $pluginfeedbackparams = array(); foreach ($instance->get_feedback_plugins() as $plugin) { if ($plugin->is_visible()) { $pluginparams = $plugin->get_external_parameters(); if (!empty($pluginparams)) { $pluginfeedbackparams = array_merge($pluginfeedbackparams, $pluginparams); } } } $advancedgradingdata = array(); $methods = array_keys(grading_manager::available_methods(false)); foreach ($methods as $method) { require_once($CFG->dirroot.'/grade/grading/form/'.$method.'/lib.php'); $details = call_user_func('gradingform_'.$method.'_controller::get_external_instance_filling_details'); if (!empty($details)) { $items = array(); foreach ($details as $key => $value) { $value->required = VALUE_OPTIONAL; unset($value->content->keys['id']); $items[$key] = new external_multiple_structure (new external_single_structure( array( 'criterionid' => new external_value(PARAM_INT, 'criterion id'), 'fillings' => $value ) )); } $advancedgradingdata[$method] = new external_single_structure($items, 'items', VALUE_OPTIONAL); } } return new external_function_parameters( array( 'assignmentid' => new external_value(PARAM_INT, 'The assignment id to operate on'), 'userid' => new external_value(PARAM_INT, 'The student id to operate on'), 'grade' => new external_value(PARAM_FLOAT, 'The new grade for this user. Ignored if advanced grading used'), 'attemptnumber' => new external_value(PARAM_INT, 'The attempt number (-1 means latest attempt)'), 'addattempt' => new external_value(PARAM_BOOL, 'Allow another attempt if the attempt reopen method is manual'), 'workflowstate' => new external_value(PARAM_ALPHA, 'The next marking workflow state'), 'applytoall' => new external_value(PARAM_BOOL, 'If true, this grade will be applied ' . 'to all members ' . 'of the group (for group assignments).'), 'plugindata' => new external_single_structure($pluginfeedbackparams, 'plugin data', VALUE_DEFAULT, array()), 'advancedgradingdata' => new external_single_structure($advancedgradingdata, 'advanced grading data', VALUE_DEFAULT, array()) ) ); }
php
public static function save_grade_parameters() { global $CFG; require_once("$CFG->dirroot/grade/grading/lib.php"); $instance = new assign(null, null, null); $pluginfeedbackparams = array(); foreach ($instance->get_feedback_plugins() as $plugin) { if ($plugin->is_visible()) { $pluginparams = $plugin->get_external_parameters(); if (!empty($pluginparams)) { $pluginfeedbackparams = array_merge($pluginfeedbackparams, $pluginparams); } } } $advancedgradingdata = array(); $methods = array_keys(grading_manager::available_methods(false)); foreach ($methods as $method) { require_once($CFG->dirroot.'/grade/grading/form/'.$method.'/lib.php'); $details = call_user_func('gradingform_'.$method.'_controller::get_external_instance_filling_details'); if (!empty($details)) { $items = array(); foreach ($details as $key => $value) { $value->required = VALUE_OPTIONAL; unset($value->content->keys['id']); $items[$key] = new external_multiple_structure (new external_single_structure( array( 'criterionid' => new external_value(PARAM_INT, 'criterion id'), 'fillings' => $value ) )); } $advancedgradingdata[$method] = new external_single_structure($items, 'items', VALUE_OPTIONAL); } } return new external_function_parameters( array( 'assignmentid' => new external_value(PARAM_INT, 'The assignment id to operate on'), 'userid' => new external_value(PARAM_INT, 'The student id to operate on'), 'grade' => new external_value(PARAM_FLOAT, 'The new grade for this user. Ignored if advanced grading used'), 'attemptnumber' => new external_value(PARAM_INT, 'The attempt number (-1 means latest attempt)'), 'addattempt' => new external_value(PARAM_BOOL, 'Allow another attempt if the attempt reopen method is manual'), 'workflowstate' => new external_value(PARAM_ALPHA, 'The next marking workflow state'), 'applytoall' => new external_value(PARAM_BOOL, 'If true, this grade will be applied ' . 'to all members ' . 'of the group (for group assignments).'), 'plugindata' => new external_single_structure($pluginfeedbackparams, 'plugin data', VALUE_DEFAULT, array()), 'advancedgradingdata' => new external_single_structure($advancedgradingdata, 'advanced grading data', VALUE_DEFAULT, array()) ) ); }
[ "public", "static", "function", "save_grade_parameters", "(", ")", "{", "global", "$", "CFG", ";", "require_once", "(", "\"$CFG->dirroot/grade/grading/lib.php\"", ")", ";", "$", "instance", "=", "new", "assign", "(", "null", ",", "null", ",", "null", ")", ";", "$", "pluginfeedbackparams", "=", "array", "(", ")", ";", "foreach", "(", "$", "instance", "->", "get_feedback_plugins", "(", ")", "as", "$", "plugin", ")", "{", "if", "(", "$", "plugin", "->", "is_visible", "(", ")", ")", "{", "$", "pluginparams", "=", "$", "plugin", "->", "get_external_parameters", "(", ")", ";", "if", "(", "!", "empty", "(", "$", "pluginparams", ")", ")", "{", "$", "pluginfeedbackparams", "=", "array_merge", "(", "$", "pluginfeedbackparams", ",", "$", "pluginparams", ")", ";", "}", "}", "}", "$", "advancedgradingdata", "=", "array", "(", ")", ";", "$", "methods", "=", "array_keys", "(", "grading_manager", "::", "available_methods", "(", "false", ")", ")", ";", "foreach", "(", "$", "methods", "as", "$", "method", ")", "{", "require_once", "(", "$", "CFG", "->", "dirroot", ".", "'/grade/grading/form/'", ".", "$", "method", ".", "'/lib.php'", ")", ";", "$", "details", "=", "call_user_func", "(", "'gradingform_'", ".", "$", "method", ".", "'_controller::get_external_instance_filling_details'", ")", ";", "if", "(", "!", "empty", "(", "$", "details", ")", ")", "{", "$", "items", "=", "array", "(", ")", ";", "foreach", "(", "$", "details", "as", "$", "key", "=>", "$", "value", ")", "{", "$", "value", "->", "required", "=", "VALUE_OPTIONAL", ";", "unset", "(", "$", "value", "->", "content", "->", "keys", "[", "'id'", "]", ")", ";", "$", "items", "[", "$", "key", "]", "=", "new", "external_multiple_structure", "(", "new", "external_single_structure", "(", "array", "(", "'criterionid'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'criterion id'", ")", ",", "'fillings'", "=>", "$", "value", ")", ")", ")", ";", "}", "$", "advancedgradingdata", "[", "$", "method", "]", "=", "new", "external_single_structure", "(", "$", "items", ",", "'items'", ",", "VALUE_OPTIONAL", ")", ";", "}", "}", "return", "new", "external_function_parameters", "(", "array", "(", "'assignmentid'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'The assignment id to operate on'", ")", ",", "'userid'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'The student id to operate on'", ")", ",", "'grade'", "=>", "new", "external_value", "(", "PARAM_FLOAT", ",", "'The new grade for this user. Ignored if advanced grading used'", ")", ",", "'attemptnumber'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'The attempt number (-1 means latest attempt)'", ")", ",", "'addattempt'", "=>", "new", "external_value", "(", "PARAM_BOOL", ",", "'Allow another attempt if the attempt reopen method is manual'", ")", ",", "'workflowstate'", "=>", "new", "external_value", "(", "PARAM_ALPHA", ",", "'The next marking workflow state'", ")", ",", "'applytoall'", "=>", "new", "external_value", "(", "PARAM_BOOL", ",", "'If true, this grade will be applied '", ".", "'to all members '", ".", "'of the group (for group assignments).'", ")", ",", "'plugindata'", "=>", "new", "external_single_structure", "(", "$", "pluginfeedbackparams", ",", "'plugin data'", ",", "VALUE_DEFAULT", ",", "array", "(", ")", ")", ",", "'advancedgradingdata'", "=>", "new", "external_single_structure", "(", "$", "advancedgradingdata", ",", "'advanced grading data'", ",", "VALUE_DEFAULT", ",", "array", "(", ")", ")", ")", ")", ";", "}" ]
Describes the parameters for save_grade @return external_function_parameters @since Moodle 2.6
[ "Describes", "the", "parameters", "for", "save_grade" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/assign/externallib.php#L1861-L1913
218,119
moodle/moodle
mod/assign/externallib.php
mod_assign_external.save_grade
public static function save_grade($assignmentid, $userid, $grade, $attemptnumber, $addattempt, $workflowstate, $applytoall, $plugindata = array(), $advancedgradingdata = array()) { global $CFG, $USER; $params = self::validate_parameters(self::save_grade_parameters(), array('assignmentid' => $assignmentid, 'userid' => $userid, 'grade' => $grade, 'attemptnumber' => $attemptnumber, 'workflowstate' => $workflowstate, 'addattempt' => $addattempt, 'applytoall' => $applytoall, 'plugindata' => $plugindata, 'advancedgradingdata' => $advancedgradingdata)); list($assignment, $course, $cm, $context) = self::validate_assign($params['assignmentid']); $gradedata = (object)$params['plugindata']; $gradedata->addattempt = $params['addattempt']; $gradedata->attemptnumber = $params['attemptnumber']; $gradedata->workflowstate = $params['workflowstate']; $gradedata->applytoall = $params['applytoall']; $gradedata->grade = $params['grade']; if (!empty($params['advancedgradingdata'])) { $advancedgrading = array(); $criteria = reset($params['advancedgradingdata']); foreach ($criteria as $key => $criterion) { $details = array(); foreach ($criterion as $value) { foreach ($value['fillings'] as $filling) { $details[$value['criterionid']] = $filling; } } $advancedgrading[$key] = $details; } $gradedata->advancedgrading = $advancedgrading; } $assignment->save_grade($params['userid'], $gradedata); return null; }
php
public static function save_grade($assignmentid, $userid, $grade, $attemptnumber, $addattempt, $workflowstate, $applytoall, $plugindata = array(), $advancedgradingdata = array()) { global $CFG, $USER; $params = self::validate_parameters(self::save_grade_parameters(), array('assignmentid' => $assignmentid, 'userid' => $userid, 'grade' => $grade, 'attemptnumber' => $attemptnumber, 'workflowstate' => $workflowstate, 'addattempt' => $addattempt, 'applytoall' => $applytoall, 'plugindata' => $plugindata, 'advancedgradingdata' => $advancedgradingdata)); list($assignment, $course, $cm, $context) = self::validate_assign($params['assignmentid']); $gradedata = (object)$params['plugindata']; $gradedata->addattempt = $params['addattempt']; $gradedata->attemptnumber = $params['attemptnumber']; $gradedata->workflowstate = $params['workflowstate']; $gradedata->applytoall = $params['applytoall']; $gradedata->grade = $params['grade']; if (!empty($params['advancedgradingdata'])) { $advancedgrading = array(); $criteria = reset($params['advancedgradingdata']); foreach ($criteria as $key => $criterion) { $details = array(); foreach ($criterion as $value) { foreach ($value['fillings'] as $filling) { $details[$value['criterionid']] = $filling; } } $advancedgrading[$key] = $details; } $gradedata->advancedgrading = $advancedgrading; } $assignment->save_grade($params['userid'], $gradedata); return null; }
[ "public", "static", "function", "save_grade", "(", "$", "assignmentid", ",", "$", "userid", ",", "$", "grade", ",", "$", "attemptnumber", ",", "$", "addattempt", ",", "$", "workflowstate", ",", "$", "applytoall", ",", "$", "plugindata", "=", "array", "(", ")", ",", "$", "advancedgradingdata", "=", "array", "(", ")", ")", "{", "global", "$", "CFG", ",", "$", "USER", ";", "$", "params", "=", "self", "::", "validate_parameters", "(", "self", "::", "save_grade_parameters", "(", ")", ",", "array", "(", "'assignmentid'", "=>", "$", "assignmentid", ",", "'userid'", "=>", "$", "userid", ",", "'grade'", "=>", "$", "grade", ",", "'attemptnumber'", "=>", "$", "attemptnumber", ",", "'workflowstate'", "=>", "$", "workflowstate", ",", "'addattempt'", "=>", "$", "addattempt", ",", "'applytoall'", "=>", "$", "applytoall", ",", "'plugindata'", "=>", "$", "plugindata", ",", "'advancedgradingdata'", "=>", "$", "advancedgradingdata", ")", ")", ";", "list", "(", "$", "assignment", ",", "$", "course", ",", "$", "cm", ",", "$", "context", ")", "=", "self", "::", "validate_assign", "(", "$", "params", "[", "'assignmentid'", "]", ")", ";", "$", "gradedata", "=", "(", "object", ")", "$", "params", "[", "'plugindata'", "]", ";", "$", "gradedata", "->", "addattempt", "=", "$", "params", "[", "'addattempt'", "]", ";", "$", "gradedata", "->", "attemptnumber", "=", "$", "params", "[", "'attemptnumber'", "]", ";", "$", "gradedata", "->", "workflowstate", "=", "$", "params", "[", "'workflowstate'", "]", ";", "$", "gradedata", "->", "applytoall", "=", "$", "params", "[", "'applytoall'", "]", ";", "$", "gradedata", "->", "grade", "=", "$", "params", "[", "'grade'", "]", ";", "if", "(", "!", "empty", "(", "$", "params", "[", "'advancedgradingdata'", "]", ")", ")", "{", "$", "advancedgrading", "=", "array", "(", ")", ";", "$", "criteria", "=", "reset", "(", "$", "params", "[", "'advancedgradingdata'", "]", ")", ";", "foreach", "(", "$", "criteria", "as", "$", "key", "=>", "$", "criterion", ")", "{", "$", "details", "=", "array", "(", ")", ";", "foreach", "(", "$", "criterion", "as", "$", "value", ")", "{", "foreach", "(", "$", "value", "[", "'fillings'", "]", "as", "$", "filling", ")", "{", "$", "details", "[", "$", "value", "[", "'criterionid'", "]", "]", "=", "$", "filling", ";", "}", "}", "$", "advancedgrading", "[", "$", "key", "]", "=", "$", "details", ";", "}", "$", "gradedata", "->", "advancedgrading", "=", "$", "advancedgrading", ";", "}", "$", "assignment", "->", "save_grade", "(", "$", "params", "[", "'userid'", "]", ",", "$", "gradedata", ")", ";", "return", "null", ";", "}" ]
Save a student grade for a single assignment. @param int $assignmentid The id of the assignment @param int $userid The id of the user @param float $grade The grade (ignored if the assignment uses advanced grading) @param int $attemptnumber The attempt number @param bool $addattempt Allow another attempt @param string $workflowstate New workflow state @param bool $applytoall Apply the grade to all members of the group @param array $plugindata Custom data used by plugins @param array $advancedgradingdata Advanced grading data @return null @since Moodle 2.6
[ "Save", "a", "student", "grade", "for", "a", "single", "assignment", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/assign/externallib.php#L1930-L1980
218,120
moodle/moodle
mod/assign/externallib.php
mod_assign_external.save_grades
public static function save_grades($assignmentid, $applytoall = false, $grades) { global $CFG, $USER; $params = self::validate_parameters(self::save_grades_parameters(), array('assignmentid' => $assignmentid, 'applytoall' => $applytoall, 'grades' => $grades)); list($assignment, $course, $cm, $context) = self::validate_assign($params['assignmentid']); if ($assignment->get_instance()->teamsubmission && $params['applytoall']) { // Check that only 1 user per submission group is provided. $groupids = array(); foreach ($params['grades'] as $gradeinfo) { $group = $assignment->get_submission_group($gradeinfo['userid']); if (in_array($group->id, $groupids)) { throw new invalid_parameter_exception('Multiple grades for the same team have been supplied ' .' this is not permitted when the applytoall flag is set'); } else { $groupids[] = $group->id; } } } foreach ($params['grades'] as $gradeinfo) { $gradedata = (object)$gradeinfo['plugindata']; $gradedata->addattempt = $gradeinfo['addattempt']; $gradedata->attemptnumber = $gradeinfo['attemptnumber']; $gradedata->workflowstate = $gradeinfo['workflowstate']; $gradedata->applytoall = $params['applytoall']; $gradedata->grade = $gradeinfo['grade']; if (!empty($gradeinfo['advancedgradingdata'])) { $advancedgrading = array(); $criteria = reset($gradeinfo['advancedgradingdata']); foreach ($criteria as $key => $criterion) { $details = array(); foreach ($criterion as $value) { foreach ($value['fillings'] as $filling) { $details[$value['criterionid']] = $filling; } } $advancedgrading[$key] = $details; } $gradedata->advancedgrading = $advancedgrading; } $assignment->save_grade($gradeinfo['userid'], $gradedata); } return null; }
php
public static function save_grades($assignmentid, $applytoall = false, $grades) { global $CFG, $USER; $params = self::validate_parameters(self::save_grades_parameters(), array('assignmentid' => $assignmentid, 'applytoall' => $applytoall, 'grades' => $grades)); list($assignment, $course, $cm, $context) = self::validate_assign($params['assignmentid']); if ($assignment->get_instance()->teamsubmission && $params['applytoall']) { // Check that only 1 user per submission group is provided. $groupids = array(); foreach ($params['grades'] as $gradeinfo) { $group = $assignment->get_submission_group($gradeinfo['userid']); if (in_array($group->id, $groupids)) { throw new invalid_parameter_exception('Multiple grades for the same team have been supplied ' .' this is not permitted when the applytoall flag is set'); } else { $groupids[] = $group->id; } } } foreach ($params['grades'] as $gradeinfo) { $gradedata = (object)$gradeinfo['plugindata']; $gradedata->addattempt = $gradeinfo['addattempt']; $gradedata->attemptnumber = $gradeinfo['attemptnumber']; $gradedata->workflowstate = $gradeinfo['workflowstate']; $gradedata->applytoall = $params['applytoall']; $gradedata->grade = $gradeinfo['grade']; if (!empty($gradeinfo['advancedgradingdata'])) { $advancedgrading = array(); $criteria = reset($gradeinfo['advancedgradingdata']); foreach ($criteria as $key => $criterion) { $details = array(); foreach ($criterion as $value) { foreach ($value['fillings'] as $filling) { $details[$value['criterionid']] = $filling; } } $advancedgrading[$key] = $details; } $gradedata->advancedgrading = $advancedgrading; } $assignment->save_grade($gradeinfo['userid'], $gradedata); } return null; }
[ "public", "static", "function", "save_grades", "(", "$", "assignmentid", ",", "$", "applytoall", "=", "false", ",", "$", "grades", ")", "{", "global", "$", "CFG", ",", "$", "USER", ";", "$", "params", "=", "self", "::", "validate_parameters", "(", "self", "::", "save_grades_parameters", "(", ")", ",", "array", "(", "'assignmentid'", "=>", "$", "assignmentid", ",", "'applytoall'", "=>", "$", "applytoall", ",", "'grades'", "=>", "$", "grades", ")", ")", ";", "list", "(", "$", "assignment", ",", "$", "course", ",", "$", "cm", ",", "$", "context", ")", "=", "self", "::", "validate_assign", "(", "$", "params", "[", "'assignmentid'", "]", ")", ";", "if", "(", "$", "assignment", "->", "get_instance", "(", ")", "->", "teamsubmission", "&&", "$", "params", "[", "'applytoall'", "]", ")", "{", "// Check that only 1 user per submission group is provided.", "$", "groupids", "=", "array", "(", ")", ";", "foreach", "(", "$", "params", "[", "'grades'", "]", "as", "$", "gradeinfo", ")", "{", "$", "group", "=", "$", "assignment", "->", "get_submission_group", "(", "$", "gradeinfo", "[", "'userid'", "]", ")", ";", "if", "(", "in_array", "(", "$", "group", "->", "id", ",", "$", "groupids", ")", ")", "{", "throw", "new", "invalid_parameter_exception", "(", "'Multiple grades for the same team have been supplied '", ".", "' this is not permitted when the applytoall flag is set'", ")", ";", "}", "else", "{", "$", "groupids", "[", "]", "=", "$", "group", "->", "id", ";", "}", "}", "}", "foreach", "(", "$", "params", "[", "'grades'", "]", "as", "$", "gradeinfo", ")", "{", "$", "gradedata", "=", "(", "object", ")", "$", "gradeinfo", "[", "'plugindata'", "]", ";", "$", "gradedata", "->", "addattempt", "=", "$", "gradeinfo", "[", "'addattempt'", "]", ";", "$", "gradedata", "->", "attemptnumber", "=", "$", "gradeinfo", "[", "'attemptnumber'", "]", ";", "$", "gradedata", "->", "workflowstate", "=", "$", "gradeinfo", "[", "'workflowstate'", "]", ";", "$", "gradedata", "->", "applytoall", "=", "$", "params", "[", "'applytoall'", "]", ";", "$", "gradedata", "->", "grade", "=", "$", "gradeinfo", "[", "'grade'", "]", ";", "if", "(", "!", "empty", "(", "$", "gradeinfo", "[", "'advancedgradingdata'", "]", ")", ")", "{", "$", "advancedgrading", "=", "array", "(", ")", ";", "$", "criteria", "=", "reset", "(", "$", "gradeinfo", "[", "'advancedgradingdata'", "]", ")", ";", "foreach", "(", "$", "criteria", "as", "$", "key", "=>", "$", "criterion", ")", "{", "$", "details", "=", "array", "(", ")", ";", "foreach", "(", "$", "criterion", "as", "$", "value", ")", "{", "foreach", "(", "$", "value", "[", "'fillings'", "]", "as", "$", "filling", ")", "{", "$", "details", "[", "$", "value", "[", "'criterionid'", "]", "]", "=", "$", "filling", ";", "}", "}", "$", "advancedgrading", "[", "$", "key", "]", "=", "$", "details", ";", "}", "$", "gradedata", "->", "advancedgrading", "=", "$", "advancedgrading", ";", "}", "$", "assignment", "->", "save_grade", "(", "$", "gradeinfo", "[", "'userid'", "]", ",", "$", "gradedata", ")", ";", "}", "return", "null", ";", "}" ]
Save multiple student grades for a single assignment. @param int $assignmentid The id of the assignment @param boolean $applytoall If set to true and this is a team assignment, apply the grade to all members of the group @param array $grades grade data for one or more students that includes userid - The id of the student being graded grade - The grade (ignored if the assignment uses advanced grading) attemptnumber - The attempt number addattempt - Allow another attempt workflowstate - New workflow state plugindata - Custom data used by plugins advancedgradingdata - Optional Advanced grading data @throws invalid_parameter_exception if multiple grades are supplied for a team assignment that has $applytoall set to true @return null @since Moodle 2.7
[ "Save", "multiple", "student", "grades", "for", "a", "single", "assignment", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/assign/externallib.php#L2078-L2128
218,121
moodle/moodle
mod/assign/externallib.php
mod_assign_external.copy_previous_attempt
public static function copy_previous_attempt($assignmentid) { $params = self::validate_parameters(self::copy_previous_attempt_parameters(), array('assignmentid' => $assignmentid)); list($assignment, $course, $cm, $context) = self::validate_assign($params['assignmentid']); $notices = array(); $assignment->copy_previous_attempt($notices); $warnings = array(); foreach ($notices as $notice) { $warnings[] = self::generate_warning($assignmentid, 'couldnotcopyprevioussubmission', $notice); } return $warnings; }
php
public static function copy_previous_attempt($assignmentid) { $params = self::validate_parameters(self::copy_previous_attempt_parameters(), array('assignmentid' => $assignmentid)); list($assignment, $course, $cm, $context) = self::validate_assign($params['assignmentid']); $notices = array(); $assignment->copy_previous_attempt($notices); $warnings = array(); foreach ($notices as $notice) { $warnings[] = self::generate_warning($assignmentid, 'couldnotcopyprevioussubmission', $notice); } return $warnings; }
[ "public", "static", "function", "copy_previous_attempt", "(", "$", "assignmentid", ")", "{", "$", "params", "=", "self", "::", "validate_parameters", "(", "self", "::", "copy_previous_attempt_parameters", "(", ")", ",", "array", "(", "'assignmentid'", "=>", "$", "assignmentid", ")", ")", ";", "list", "(", "$", "assignment", ",", "$", "course", ",", "$", "cm", ",", "$", "context", ")", "=", "self", "::", "validate_assign", "(", "$", "params", "[", "'assignmentid'", "]", ")", ";", "$", "notices", "=", "array", "(", ")", ";", "$", "assignment", "->", "copy_previous_attempt", "(", "$", "notices", ")", ";", "$", "warnings", "=", "array", "(", ")", ";", "foreach", "(", "$", "notices", "as", "$", "notice", ")", "{", "$", "warnings", "[", "]", "=", "self", "::", "generate_warning", "(", "$", "assignmentid", ",", "'couldnotcopyprevioussubmission'", ",", "$", "notice", ")", ";", "}", "return", "$", "warnings", ";", "}" ]
Copy a students previous attempt to a new attempt. @param int $assignmentid @return array of warnings to indicate any errors. @since Moodle 2.6
[ "Copy", "a", "students", "previous", "attempt", "to", "a", "new", "attempt", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/assign/externallib.php#L2160-L2179
218,122
moodle/moodle
mod/assign/externallib.php
mod_assign_external.view_grading_table
public static function view_grading_table($assignid) { $params = self::validate_parameters(self::view_grading_table_parameters(), array( 'assignid' => $assignid )); $warnings = array(); list($assign, $course, $cm, $context) = self::validate_assign($params['assignid']); $assign->require_view_grades(); \mod_assign\event\grading_table_viewed::create_from_assign($assign)->trigger(); $result = array(); $result['status'] = true; $result['warnings'] = $warnings; return $result; }
php
public static function view_grading_table($assignid) { $params = self::validate_parameters(self::view_grading_table_parameters(), array( 'assignid' => $assignid )); $warnings = array(); list($assign, $course, $cm, $context) = self::validate_assign($params['assignid']); $assign->require_view_grades(); \mod_assign\event\grading_table_viewed::create_from_assign($assign)->trigger(); $result = array(); $result['status'] = true; $result['warnings'] = $warnings; return $result; }
[ "public", "static", "function", "view_grading_table", "(", "$", "assignid", ")", "{", "$", "params", "=", "self", "::", "validate_parameters", "(", "self", "::", "view_grading_table_parameters", "(", ")", ",", "array", "(", "'assignid'", "=>", "$", "assignid", ")", ")", ";", "$", "warnings", "=", "array", "(", ")", ";", "list", "(", "$", "assign", ",", "$", "course", ",", "$", "cm", ",", "$", "context", ")", "=", "self", "::", "validate_assign", "(", "$", "params", "[", "'assignid'", "]", ")", ";", "$", "assign", "->", "require_view_grades", "(", ")", ";", "\\", "mod_assign", "\\", "event", "\\", "grading_table_viewed", "::", "create_from_assign", "(", "$", "assign", ")", "->", "trigger", "(", ")", ";", "$", "result", "=", "array", "(", ")", ";", "$", "result", "[", "'status'", "]", "=", "true", ";", "$", "result", "[", "'warnings'", "]", "=", "$", "warnings", ";", "return", "$", "result", ";", "}" ]
Trigger the grading_table_viewed event. @param int $assignid the assign instance id @return array of warnings and status result @since Moodle 3.0 @throws moodle_exception
[ "Trigger", "the", "grading_table_viewed", "event", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/assign/externallib.php#L2213-L2230
218,123
moodle/moodle
mod/assign/externallib.php
mod_assign_external.view_submission_status
public static function view_submission_status($assignid) { $warnings = array(); $params = array( 'assignid' => $assignid, ); $params = self::validate_parameters(self::view_submission_status_parameters(), $params); list($assign, $course, $cm, $context) = self::validate_assign($params['assignid']); \mod_assign\event\submission_status_viewed::create_from_assign($assign)->trigger(); $result = array(); $result['status'] = true; $result['warnings'] = $warnings; return $result; }
php
public static function view_submission_status($assignid) { $warnings = array(); $params = array( 'assignid' => $assignid, ); $params = self::validate_parameters(self::view_submission_status_parameters(), $params); list($assign, $course, $cm, $context) = self::validate_assign($params['assignid']); \mod_assign\event\submission_status_viewed::create_from_assign($assign)->trigger(); $result = array(); $result['status'] = true; $result['warnings'] = $warnings; return $result; }
[ "public", "static", "function", "view_submission_status", "(", "$", "assignid", ")", "{", "$", "warnings", "=", "array", "(", ")", ";", "$", "params", "=", "array", "(", "'assignid'", "=>", "$", "assignid", ",", ")", ";", "$", "params", "=", "self", "::", "validate_parameters", "(", "self", "::", "view_submission_status_parameters", "(", ")", ",", "$", "params", ")", ";", "list", "(", "$", "assign", ",", "$", "course", ",", "$", "cm", ",", "$", "context", ")", "=", "self", "::", "validate_assign", "(", "$", "params", "[", "'assignid'", "]", ")", ";", "\\", "mod_assign", "\\", "event", "\\", "submission_status_viewed", "::", "create_from_assign", "(", "$", "assign", ")", "->", "trigger", "(", ")", ";", "$", "result", "=", "array", "(", ")", ";", "$", "result", "[", "'status'", "]", "=", "true", ";", "$", "result", "[", "'warnings'", "]", "=", "$", "warnings", ";", "return", "$", "result", ";", "}" ]
Trigger the submission status viewed event. @param int $assignid assign instance id @return array of warnings and status result @since Moodle 3.1
[ "Trigger", "the", "submission", "status", "viewed", "event", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/assign/externallib.php#L2268-L2284
218,124
moodle/moodle
mod/assign/externallib.php
mod_assign_external.get_submission_status_parameters
public static function get_submission_status_parameters() { return new external_function_parameters ( array( 'assignid' => new external_value(PARAM_INT, 'assignment instance id'), 'userid' => new external_value(PARAM_INT, 'user id (empty for current user)', VALUE_DEFAULT, 0), 'groupid' => new external_value(PARAM_INT, 'filter by users in group (used for generating the grading summary). Empty or 0 for all groups information.', VALUE_DEFAULT, 0), ) ); }
php
public static function get_submission_status_parameters() { return new external_function_parameters ( array( 'assignid' => new external_value(PARAM_INT, 'assignment instance id'), 'userid' => new external_value(PARAM_INT, 'user id (empty for current user)', VALUE_DEFAULT, 0), 'groupid' => new external_value(PARAM_INT, 'filter by users in group (used for generating the grading summary). Empty or 0 for all groups information.', VALUE_DEFAULT, 0), ) ); }
[ "public", "static", "function", "get_submission_status_parameters", "(", ")", "{", "return", "new", "external_function_parameters", "(", "array", "(", "'assignid'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'assignment instance id'", ")", ",", "'userid'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'user id (empty for current user)'", ",", "VALUE_DEFAULT", ",", "0", ")", ",", "'groupid'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'filter by users in group (used for generating the grading summary).\n Empty or 0 for all groups information.'", ",", "VALUE_DEFAULT", ",", "0", ")", ",", ")", ")", ";", "}" ]
Describes the parameters for get_submission_status. @return external_function_parameters @since Moodle 3.1
[ "Describes", "the", "parameters", "for", "get_submission_status", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/assign/externallib.php#L2307-L2316
218,125
moodle/moodle
mod/assign/externallib.php
mod_assign_external.get_participant
public static function get_participant($assignid, $userid, $embeduser) { global $DB, $CFG; require_once($CFG->dirroot . "/mod/assign/locallib.php"); require_once($CFG->dirroot . "/user/lib.php"); $params = self::validate_parameters(self::get_participant_parameters(), array( 'assignid' => $assignid, 'userid' => $userid, 'embeduser' => $embeduser )); list($assign, $course, $cm, $context) = self::validate_assign($params['assignid']); $assign->require_view_grades(); $participant = $assign->get_participant($params['userid']); // Update assign with override information. $assign->update_effective_access($params['userid']); if (!$participant) { // No participant found so we can return early. throw new moodle_exception('usernotincourse'); } $return = array( 'id' => $participant->id, 'fullname' => $participant->fullname, 'submitted' => $participant->submitted, 'requiregrading' => $participant->requiregrading, 'grantedextension' => $participant->grantedextension, 'blindmarking' => $assign->is_blind_marking(), 'allowsubmissionsfromdate' => $assign->get_instance()->allowsubmissionsfromdate, 'duedate' => $assign->get_instance()->duedate, 'cutoffdate' => $assign->get_instance()->cutoffdate, 'duedatestr' => userdate($assign->get_instance()->duedate, get_string('strftimedatetime', 'langconfig')), ); if (!empty($participant->groupid)) { $return['groupid'] = $participant->groupid; } if (!empty($participant->groupname)) { $return['groupname'] = $participant->groupname; } // Skip the expensive lookup of user detail if we're blind marking or the caller // hasn't asked for user details to be embedded. if (!$assign->is_blind_marking() && $embeduser) { if ($userdetails = user_get_user_details($participant, $course)) { $return['user'] = $userdetails; } } return $return; }
php
public static function get_participant($assignid, $userid, $embeduser) { global $DB, $CFG; require_once($CFG->dirroot . "/mod/assign/locallib.php"); require_once($CFG->dirroot . "/user/lib.php"); $params = self::validate_parameters(self::get_participant_parameters(), array( 'assignid' => $assignid, 'userid' => $userid, 'embeduser' => $embeduser )); list($assign, $course, $cm, $context) = self::validate_assign($params['assignid']); $assign->require_view_grades(); $participant = $assign->get_participant($params['userid']); // Update assign with override information. $assign->update_effective_access($params['userid']); if (!$participant) { // No participant found so we can return early. throw new moodle_exception('usernotincourse'); } $return = array( 'id' => $participant->id, 'fullname' => $participant->fullname, 'submitted' => $participant->submitted, 'requiregrading' => $participant->requiregrading, 'grantedextension' => $participant->grantedextension, 'blindmarking' => $assign->is_blind_marking(), 'allowsubmissionsfromdate' => $assign->get_instance()->allowsubmissionsfromdate, 'duedate' => $assign->get_instance()->duedate, 'cutoffdate' => $assign->get_instance()->cutoffdate, 'duedatestr' => userdate($assign->get_instance()->duedate, get_string('strftimedatetime', 'langconfig')), ); if (!empty($participant->groupid)) { $return['groupid'] = $participant->groupid; } if (!empty($participant->groupname)) { $return['groupname'] = $participant->groupname; } // Skip the expensive lookup of user detail if we're blind marking or the caller // hasn't asked for user details to be embedded. if (!$assign->is_blind_marking() && $embeduser) { if ($userdetails = user_get_user_details($participant, $course)) { $return['user'] = $userdetails; } } return $return; }
[ "public", "static", "function", "get_participant", "(", "$", "assignid", ",", "$", "userid", ",", "$", "embeduser", ")", "{", "global", "$", "DB", ",", "$", "CFG", ";", "require_once", "(", "$", "CFG", "->", "dirroot", ".", "\"/mod/assign/locallib.php\"", ")", ";", "require_once", "(", "$", "CFG", "->", "dirroot", ".", "\"/user/lib.php\"", ")", ";", "$", "params", "=", "self", "::", "validate_parameters", "(", "self", "::", "get_participant_parameters", "(", ")", ",", "array", "(", "'assignid'", "=>", "$", "assignid", ",", "'userid'", "=>", "$", "userid", ",", "'embeduser'", "=>", "$", "embeduser", ")", ")", ";", "list", "(", "$", "assign", ",", "$", "course", ",", "$", "cm", ",", "$", "context", ")", "=", "self", "::", "validate_assign", "(", "$", "params", "[", "'assignid'", "]", ")", ";", "$", "assign", "->", "require_view_grades", "(", ")", ";", "$", "participant", "=", "$", "assign", "->", "get_participant", "(", "$", "params", "[", "'userid'", "]", ")", ";", "// Update assign with override information.", "$", "assign", "->", "update_effective_access", "(", "$", "params", "[", "'userid'", "]", ")", ";", "if", "(", "!", "$", "participant", ")", "{", "// No participant found so we can return early.", "throw", "new", "moodle_exception", "(", "'usernotincourse'", ")", ";", "}", "$", "return", "=", "array", "(", "'id'", "=>", "$", "participant", "->", "id", ",", "'fullname'", "=>", "$", "participant", "->", "fullname", ",", "'submitted'", "=>", "$", "participant", "->", "submitted", ",", "'requiregrading'", "=>", "$", "participant", "->", "requiregrading", ",", "'grantedextension'", "=>", "$", "participant", "->", "grantedextension", ",", "'blindmarking'", "=>", "$", "assign", "->", "is_blind_marking", "(", ")", ",", "'allowsubmissionsfromdate'", "=>", "$", "assign", "->", "get_instance", "(", ")", "->", "allowsubmissionsfromdate", ",", "'duedate'", "=>", "$", "assign", "->", "get_instance", "(", ")", "->", "duedate", ",", "'cutoffdate'", "=>", "$", "assign", "->", "get_instance", "(", ")", "->", "cutoffdate", ",", "'duedatestr'", "=>", "userdate", "(", "$", "assign", "->", "get_instance", "(", ")", "->", "duedate", ",", "get_string", "(", "'strftimedatetime'", ",", "'langconfig'", ")", ")", ",", ")", ";", "if", "(", "!", "empty", "(", "$", "participant", "->", "groupid", ")", ")", "{", "$", "return", "[", "'groupid'", "]", "=", "$", "participant", "->", "groupid", ";", "}", "if", "(", "!", "empty", "(", "$", "participant", "->", "groupname", ")", ")", "{", "$", "return", "[", "'groupname'", "]", "=", "$", "participant", "->", "groupname", ";", "}", "// Skip the expensive lookup of user detail if we're blind marking or the caller", "// hasn't asked for user details to be embedded.", "if", "(", "!", "$", "assign", "->", "is_blind_marking", "(", ")", "&&", "$", "embeduser", ")", "{", "if", "(", "$", "userdetails", "=", "user_get_user_details", "(", "$", "participant", ",", "$", "course", ")", ")", "{", "$", "return", "[", "'user'", "]", "=", "$", "userdetails", ";", "}", "}", "return", "$", "return", ";", "}" ]
Get the user participating in the given assignment. An error with code 'usernotincourse' is thrown is the user isn't a participant of the given assignment. @param int $assignid the assign instance id @param int $userid the user id @param bool $embeduser return user details (only applicable if not blind marking) @return array of warnings and status result @since Moodle 3.1 @throws moodle_exception
[ "Get", "the", "user", "participating", "in", "the", "given", "assignment", ".", "An", "error", "with", "code", "usernotincourse", "is", "thrown", "is", "the", "user", "isn", "t", "a", "participant", "of", "the", "given", "assignment", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/assign/externallib.php#L2791-L2844
218,126
moodle/moodle
mod/assign/externallib.php
mod_assign_external.validate_assign
protected static function validate_assign($assignid) { global $DB; // Request and permission validation. $assign = $DB->get_record('assign', array('id' => $assignid), 'id', MUST_EXIST); list($course, $cm) = get_course_and_cm_from_instance($assign, 'assign'); $context = context_module::instance($cm->id); // Please, note that is not required to check mod/assign:view because is done by validate_context->require_login. self::validate_context($context); $assign = new assign($context, $cm, $course); return array($assign, $course, $cm, $context); }
php
protected static function validate_assign($assignid) { global $DB; // Request and permission validation. $assign = $DB->get_record('assign', array('id' => $assignid), 'id', MUST_EXIST); list($course, $cm) = get_course_and_cm_from_instance($assign, 'assign'); $context = context_module::instance($cm->id); // Please, note that is not required to check mod/assign:view because is done by validate_context->require_login. self::validate_context($context); $assign = new assign($context, $cm, $course); return array($assign, $course, $cm, $context); }
[ "protected", "static", "function", "validate_assign", "(", "$", "assignid", ")", "{", "global", "$", "DB", ";", "// Request and permission validation.", "$", "assign", "=", "$", "DB", "->", "get_record", "(", "'assign'", ",", "array", "(", "'id'", "=>", "$", "assignid", ")", ",", "'id'", ",", "MUST_EXIST", ")", ";", "list", "(", "$", "course", ",", "$", "cm", ")", "=", "get_course_and_cm_from_instance", "(", "$", "assign", ",", "'assign'", ")", ";", "$", "context", "=", "context_module", "::", "instance", "(", "$", "cm", "->", "id", ")", ";", "// Please, note that is not required to check mod/assign:view because is done by validate_context->require_login.", "self", "::", "validate_context", "(", "$", "context", ")", ";", "$", "assign", "=", "new", "assign", "(", "$", "context", ",", "$", "cm", ",", "$", "course", ")", ";", "return", "array", "(", "$", "assign", ",", "$", "course", ",", "$", "cm", ",", "$", "context", ")", ";", "}" ]
Utility function for validating an assign. @param int $assignid assign instance id @return array array containing the assign, course, context and course module objects @since Moodle 3.2
[ "Utility", "function", "for", "validating", "an", "assign", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/assign/externallib.php#L2881-L2894
218,127
moodle/moodle
mod/assign/externallib.php
mod_assign_external.view_assign
public static function view_assign($assignid) { $warnings = array(); $params = array( 'assignid' => $assignid, ); $params = self::validate_parameters(self::view_assign_parameters(), $params); list($assign, $course, $cm, $context) = self::validate_assign($params['assignid']); $assign->set_module_viewed(); $result = array(); $result['status'] = true; $result['warnings'] = $warnings; return $result; }
php
public static function view_assign($assignid) { $warnings = array(); $params = array( 'assignid' => $assignid, ); $params = self::validate_parameters(self::view_assign_parameters(), $params); list($assign, $course, $cm, $context) = self::validate_assign($params['assignid']); $assign->set_module_viewed(); $result = array(); $result['status'] = true; $result['warnings'] = $warnings; return $result; }
[ "public", "static", "function", "view_assign", "(", "$", "assignid", ")", "{", "$", "warnings", "=", "array", "(", ")", ";", "$", "params", "=", "array", "(", "'assignid'", "=>", "$", "assignid", ",", ")", ";", "$", "params", "=", "self", "::", "validate_parameters", "(", "self", "::", "view_assign_parameters", "(", ")", ",", "$", "params", ")", ";", "list", "(", "$", "assign", ",", "$", "course", ",", "$", "cm", ",", "$", "context", ")", "=", "self", "::", "validate_assign", "(", "$", "params", "[", "'assignid'", "]", ")", ";", "$", "assign", "->", "set_module_viewed", "(", ")", ";", "$", "result", "=", "array", "(", ")", ";", "$", "result", "[", "'status'", "]", "=", "true", ";", "$", "result", "[", "'warnings'", "]", "=", "$", "warnings", ";", "return", "$", "result", ";", "}" ]
Update the module completion status. @param int $assignid assign instance id @return array of warnings and status result @since Moodle 3.2
[ "Update", "the", "module", "completion", "status", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/assign/externallib.php#L2917-L2932
218,128
moodle/moodle
lib/ddl/mssql_sql_generator.php
mssql_sql_generator.getDefaultConstraintName
protected function getDefaultConstraintName($xmldb_table, $xmldb_field) { // Get the quoted name of the table and field $tablename = $this->getTableName($xmldb_table); $fieldname = $xmldb_field->getName(); // Look for any default constraint in this field and drop it if ($default = $this->mdb->get_record_sql("SELECT object_id, object_name(default_object_id) AS defaultconstraint FROM sys.columns WHERE object_id = object_id(?) AND name = ?", array($tablename, $fieldname))) { return $default->defaultconstraint; } else { return false; } }
php
protected function getDefaultConstraintName($xmldb_table, $xmldb_field) { // Get the quoted name of the table and field $tablename = $this->getTableName($xmldb_table); $fieldname = $xmldb_field->getName(); // Look for any default constraint in this field and drop it if ($default = $this->mdb->get_record_sql("SELECT object_id, object_name(default_object_id) AS defaultconstraint FROM sys.columns WHERE object_id = object_id(?) AND name = ?", array($tablename, $fieldname))) { return $default->defaultconstraint; } else { return false; } }
[ "protected", "function", "getDefaultConstraintName", "(", "$", "xmldb_table", ",", "$", "xmldb_field", ")", "{", "// Get the quoted name of the table and field", "$", "tablename", "=", "$", "this", "->", "getTableName", "(", "$", "xmldb_table", ")", ";", "$", "fieldname", "=", "$", "xmldb_field", "->", "getName", "(", ")", ";", "// Look for any default constraint in this field and drop it", "if", "(", "$", "default", "=", "$", "this", "->", "mdb", "->", "get_record_sql", "(", "\"SELECT object_id, object_name(default_object_id) AS defaultconstraint\n FROM sys.columns\n WHERE object_id = object_id(?)\n AND name = ?\"", ",", "array", "(", "$", "tablename", ",", "$", "fieldname", ")", ")", ")", "{", "return", "$", "default", "->", "defaultconstraint", ";", "}", "else", "{", "return", "false", ";", "}", "}" ]
Given one xmldb_table and one xmldb_field, returns the name of its default constraint in DB or false if not found This function should be considered internal and never used outside from generator @param xmldb_table $xmldb_table The xmldb_table object instance. @param xmldb_field $xmldb_field The xmldb_field object instance. @return mixed
[ "Given", "one", "xmldb_table", "and", "one", "xmldb_field", "returns", "the", "name", "of", "its", "default", "constraint", "in", "DB", "or", "false", "if", "not", "found", "This", "function", "should", "be", "considered", "internal", "and", "never", "used", "outside", "from", "generator" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/ddl/mssql_sql_generator.php#L578-L593
218,129
moodle/moodle
lib/tcpdf/tcpdf_parser.php
TCPDF_PARSER.setConfig
protected function setConfig($cfg) { if (isset($cfg['die_for_errors'])) { $this->cfg['die_for_errors'] = !!$cfg['die_for_errors']; } if (isset($cfg['ignore_filter_decoding_errors'])) { $this->cfg['ignore_filter_decoding_errors'] = !!$cfg['ignore_filter_decoding_errors']; } if (isset($cfg['ignore_missing_filter_decoders'])) { $this->cfg['ignore_missing_filter_decoders'] = !!$cfg['ignore_missing_filter_decoders']; } }
php
protected function setConfig($cfg) { if (isset($cfg['die_for_errors'])) { $this->cfg['die_for_errors'] = !!$cfg['die_for_errors']; } if (isset($cfg['ignore_filter_decoding_errors'])) { $this->cfg['ignore_filter_decoding_errors'] = !!$cfg['ignore_filter_decoding_errors']; } if (isset($cfg['ignore_missing_filter_decoders'])) { $this->cfg['ignore_missing_filter_decoders'] = !!$cfg['ignore_missing_filter_decoders']; } }
[ "protected", "function", "setConfig", "(", "$", "cfg", ")", "{", "if", "(", "isset", "(", "$", "cfg", "[", "'die_for_errors'", "]", ")", ")", "{", "$", "this", "->", "cfg", "[", "'die_for_errors'", "]", "=", "!", "!", "$", "cfg", "[", "'die_for_errors'", "]", ";", "}", "if", "(", "isset", "(", "$", "cfg", "[", "'ignore_filter_decoding_errors'", "]", ")", ")", "{", "$", "this", "->", "cfg", "[", "'ignore_filter_decoding_errors'", "]", "=", "!", "!", "$", "cfg", "[", "'ignore_filter_decoding_errors'", "]", ";", "}", "if", "(", "isset", "(", "$", "cfg", "[", "'ignore_missing_filter_decoders'", "]", ")", ")", "{", "$", "this", "->", "cfg", "[", "'ignore_missing_filter_decoders'", "]", "=", "!", "!", "$", "cfg", "[", "'ignore_missing_filter_decoders'", "]", ";", "}", "}" ]
Set the configuration parameters. @param $cfg (array) Array of configuration parameters: 'die_for_errors' : if true termitate the program execution in case of error, otherwise thows an exception; 'ignore_filter_decoding_errors' : if true ignore filter decoding errors; 'ignore_missing_filter_decoders' : if true ignore missing filter decoding errors. @public
[ "Set", "the", "configuration", "parameters", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/tcpdf/tcpdf_parser.php#L139-L149
218,130
moodle/moodle
admin/tool/monitor/classes/rule.php
rule.duplicate_rule
public function duplicate_rule($finalcourseid) { $rule = fullclone($this->rule); unset($rule->id); $rule->courseid = $finalcourseid; $time = time(); $rule->timecreated = $time; $rule->timemodified = $time; rule_manager::add_rule($rule); }
php
public function duplicate_rule($finalcourseid) { $rule = fullclone($this->rule); unset($rule->id); $rule->courseid = $finalcourseid; $time = time(); $rule->timecreated = $time; $rule->timemodified = $time; rule_manager::add_rule($rule); }
[ "public", "function", "duplicate_rule", "(", "$", "finalcourseid", ")", "{", "$", "rule", "=", "fullclone", "(", "$", "this", "->", "rule", ")", ";", "unset", "(", "$", "rule", "->", "id", ")", ";", "$", "rule", "->", "courseid", "=", "$", "finalcourseid", ";", "$", "time", "=", "time", "(", ")", ";", "$", "rule", "->", "timecreated", "=", "$", "time", ";", "$", "rule", "->", "timemodified", "=", "$", "time", ";", "rule_manager", "::", "add_rule", "(", "$", "rule", ")", ";", "}" ]
Api to duplicate a rule in a given courseid. @param int $finalcourseid Final course id.
[ "Api", "to", "duplicate", "a", "rule", "in", "a", "given", "courseid", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/monitor/classes/rule.php#L70-L78
218,131
moodle/moodle
admin/tool/monitor/classes/rule.php
rule.get_subscribe_options
public function get_subscribe_options($courseid) { global $CFG; $url = new \moodle_url($CFG->wwwroot. '/admin/tool/monitor/index.php', array( 'courseid' => $courseid, 'ruleid' => $this->id, 'action' => 'subscribe', 'sesskey' => sesskey() )); if (strpos($this->plugin, 'mod_') !== 0) { return $url; } else { // Single select when the plugin is an activity. $options = array(); $options[0] = get_string('allmodules', 'tool_monitor'); if ($courseid == 0) { // They need to be in a course to select module instance. return get_string('selectcourse', 'tool_monitor'); } // Let them select an instance. $cms = get_fast_modinfo($courseid); $instances = $cms->get_instances_of(str_replace('mod_', '', $this->plugin)); foreach ($instances as $cminfo) { // Don't list instances that are not visible or available to the user. if ($cminfo->uservisible && $cminfo->available) { $options[$cminfo->id] = $cminfo->get_formatted_name(); } } return new \single_select($url, 'cmid', $options); } }
php
public function get_subscribe_options($courseid) { global $CFG; $url = new \moodle_url($CFG->wwwroot. '/admin/tool/monitor/index.php', array( 'courseid' => $courseid, 'ruleid' => $this->id, 'action' => 'subscribe', 'sesskey' => sesskey() )); if (strpos($this->plugin, 'mod_') !== 0) { return $url; } else { // Single select when the plugin is an activity. $options = array(); $options[0] = get_string('allmodules', 'tool_monitor'); if ($courseid == 0) { // They need to be in a course to select module instance. return get_string('selectcourse', 'tool_monitor'); } // Let them select an instance. $cms = get_fast_modinfo($courseid); $instances = $cms->get_instances_of(str_replace('mod_', '', $this->plugin)); foreach ($instances as $cminfo) { // Don't list instances that are not visible or available to the user. if ($cminfo->uservisible && $cminfo->available) { $options[$cminfo->id] = $cminfo->get_formatted_name(); } } return new \single_select($url, 'cmid', $options); } }
[ "public", "function", "get_subscribe_options", "(", "$", "courseid", ")", "{", "global", "$", "CFG", ";", "$", "url", "=", "new", "\\", "moodle_url", "(", "$", "CFG", "->", "wwwroot", ".", "'/admin/tool/monitor/index.php'", ",", "array", "(", "'courseid'", "=>", "$", "courseid", ",", "'ruleid'", "=>", "$", "this", "->", "id", ",", "'action'", "=>", "'subscribe'", ",", "'sesskey'", "=>", "sesskey", "(", ")", ")", ")", ";", "if", "(", "strpos", "(", "$", "this", "->", "plugin", ",", "'mod_'", ")", "!==", "0", ")", "{", "return", "$", "url", ";", "}", "else", "{", "// Single select when the plugin is an activity.", "$", "options", "=", "array", "(", ")", ";", "$", "options", "[", "0", "]", "=", "get_string", "(", "'allmodules'", ",", "'tool_monitor'", ")", ";", "if", "(", "$", "courseid", "==", "0", ")", "{", "// They need to be in a course to select module instance.", "return", "get_string", "(", "'selectcourse'", ",", "'tool_monitor'", ")", ";", "}", "// Let them select an instance.", "$", "cms", "=", "get_fast_modinfo", "(", "$", "courseid", ")", ";", "$", "instances", "=", "$", "cms", "->", "get_instances_of", "(", "str_replace", "(", "'mod_'", ",", "''", ",", "$", "this", "->", "plugin", ")", ")", ";", "foreach", "(", "$", "instances", "as", "$", "cminfo", ")", "{", "// Don't list instances that are not visible or available to the user.", "if", "(", "$", "cminfo", "->", "uservisible", "&&", "$", "cminfo", "->", "available", ")", "{", "$", "options", "[", "$", "cminfo", "->", "id", "]", "=", "$", "cminfo", "->", "get_formatted_name", "(", ")", ";", "}", "}", "return", "new", "\\", "single_select", "(", "$", "url", ",", "'cmid'", ",", "$", "options", ")", ";", "}", "}" ]
Gets the rule subscribe options for a given course and rule. Could be a select drop down with a list of possible module instances or a single link to subscribe if the rule plugin is not a module. @param int $courseid course id @return \single_select|\moodle_url|string @throws \coding_exception
[ "Gets", "the", "rule", "subscribe", "options", "for", "a", "given", "course", "and", "rule", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/monitor/classes/rule.php#L101-L136
218,132
moodle/moodle
admin/tool/monitor/classes/rule.php
rule.subscribe_user
public function subscribe_user($courseid, $cmid, $userid = 0) { global $USER; if ($this->courseid != $courseid && $this->courseid != 0) { // Trying to subscribe to a rule that belongs to a different course. Should never happen. throw new \coding_exception('Can not subscribe to rules from a different course'); } if ($cmid !== 0) { $cms = get_fast_modinfo($courseid); $cminfo = $cms->get_cm($cmid); if (!$cminfo->uservisible || !$cminfo->available) { // Trying to subscribe to a hidden or restricted cm. Should never happen. throw new \coding_exception('You cannot do that'); } } $userid = empty($userid) ? $USER->id : $userid; subscription_manager::create_subscription($this->id, $courseid, $cmid, $userid); }
php
public function subscribe_user($courseid, $cmid, $userid = 0) { global $USER; if ($this->courseid != $courseid && $this->courseid != 0) { // Trying to subscribe to a rule that belongs to a different course. Should never happen. throw new \coding_exception('Can not subscribe to rules from a different course'); } if ($cmid !== 0) { $cms = get_fast_modinfo($courseid); $cminfo = $cms->get_cm($cmid); if (!$cminfo->uservisible || !$cminfo->available) { // Trying to subscribe to a hidden or restricted cm. Should never happen. throw new \coding_exception('You cannot do that'); } } $userid = empty($userid) ? $USER->id : $userid; subscription_manager::create_subscription($this->id, $courseid, $cmid, $userid); }
[ "public", "function", "subscribe_user", "(", "$", "courseid", ",", "$", "cmid", ",", "$", "userid", "=", "0", ")", "{", "global", "$", "USER", ";", "if", "(", "$", "this", "->", "courseid", "!=", "$", "courseid", "&&", "$", "this", "->", "courseid", "!=", "0", ")", "{", "// Trying to subscribe to a rule that belongs to a different course. Should never happen.", "throw", "new", "\\", "coding_exception", "(", "'Can not subscribe to rules from a different course'", ")", ";", "}", "if", "(", "$", "cmid", "!==", "0", ")", "{", "$", "cms", "=", "get_fast_modinfo", "(", "$", "courseid", ")", ";", "$", "cminfo", "=", "$", "cms", "->", "get_cm", "(", "$", "cmid", ")", ";", "if", "(", "!", "$", "cminfo", "->", "uservisible", "||", "!", "$", "cminfo", "->", "available", ")", "{", "// Trying to subscribe to a hidden or restricted cm. Should never happen.", "throw", "new", "\\", "coding_exception", "(", "'You cannot do that'", ")", ";", "}", "}", "$", "userid", "=", "empty", "(", "$", "userid", ")", "?", "$", "USER", "->", "id", ":", "$", "userid", ";", "subscription_manager", "::", "create_subscription", "(", "$", "this", "->", "id", ",", "$", "courseid", ",", "$", "cmid", ",", "$", "userid", ")", ";", "}" ]
Subscribe an user to this rule. @param int $courseid Course id. @param int $cmid Course module id. @param int $userid User id. @throws \coding_exception
[ "Subscribe", "an", "user", "to", "this", "rule", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/monitor/classes/rule.php#L147-L165
218,133
moodle/moodle
admin/tool/monitor/classes/rule.php
rule.get_mform_set_data
public function get_mform_set_data() { if (!empty($this->rule)) { $rule = fullclone($this->rule); $rule->description = array('text' => $rule->description, 'format' => $rule->descriptionformat); $rule->template = array('text' => $rule->template, 'format' => $rule->templateformat); return $rule; } throw new \coding_exception('Invalid call to get_mform_set_data.'); }
php
public function get_mform_set_data() { if (!empty($this->rule)) { $rule = fullclone($this->rule); $rule->description = array('text' => $rule->description, 'format' => $rule->descriptionformat); $rule->template = array('text' => $rule->template, 'format' => $rule->templateformat); return $rule; } throw new \coding_exception('Invalid call to get_mform_set_data.'); }
[ "public", "function", "get_mform_set_data", "(", ")", "{", "if", "(", "!", "empty", "(", "$", "this", "->", "rule", ")", ")", "{", "$", "rule", "=", "fullclone", "(", "$", "this", "->", "rule", ")", ";", "$", "rule", "->", "description", "=", "array", "(", "'text'", "=>", "$", "rule", "->", "description", ",", "'format'", "=>", "$", "rule", "->", "descriptionformat", ")", ";", "$", "rule", "->", "template", "=", "array", "(", "'text'", "=>", "$", "rule", "->", "template", ",", "'format'", "=>", "$", "rule", "->", "templateformat", ")", ";", "return", "$", "rule", ";", "}", "throw", "new", "\\", "coding_exception", "(", "'Invalid call to get_mform_set_data.'", ")", ";", "}" ]
Return the rule data to be used while setting mform. @throws \coding_exception
[ "Return", "the", "rule", "data", "to", "be", "used", "while", "setting", "mform", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/monitor/classes/rule.php#L187-L195
218,134
moodle/moodle
admin/tool/customlang/locallib.php
tool_customlang_utils.list_components
public static function list_components() { $list['moodle'] = 'core'; $coresubsystems = core_component::get_core_subsystems(); ksort($coresubsystems); // should be but just in case foreach ($coresubsystems as $name => $location) { $list[$name] = 'core_'.$name; } $plugintypes = core_component::get_plugin_types(); foreach ($plugintypes as $type => $location) { $pluginlist = core_component::get_plugin_list($type); foreach ($pluginlist as $name => $ununsed) { if ($type == 'mod') { // Plugin names are now automatically validated. $list[$name] = $type.'_'.$name; } else { $list[$type.'_'.$name] = $type.'_'.$name; } } } return $list; }
php
public static function list_components() { $list['moodle'] = 'core'; $coresubsystems = core_component::get_core_subsystems(); ksort($coresubsystems); // should be but just in case foreach ($coresubsystems as $name => $location) { $list[$name] = 'core_'.$name; } $plugintypes = core_component::get_plugin_types(); foreach ($plugintypes as $type => $location) { $pluginlist = core_component::get_plugin_list($type); foreach ($pluginlist as $name => $ununsed) { if ($type == 'mod') { // Plugin names are now automatically validated. $list[$name] = $type.'_'.$name; } else { $list[$type.'_'.$name] = $type.'_'.$name; } } } return $list; }
[ "public", "static", "function", "list_components", "(", ")", "{", "$", "list", "[", "'moodle'", "]", "=", "'core'", ";", "$", "coresubsystems", "=", "core_component", "::", "get_core_subsystems", "(", ")", ";", "ksort", "(", "$", "coresubsystems", ")", ";", "// should be but just in case", "foreach", "(", "$", "coresubsystems", "as", "$", "name", "=>", "$", "location", ")", "{", "$", "list", "[", "$", "name", "]", "=", "'core_'", ".", "$", "name", ";", "}", "$", "plugintypes", "=", "core_component", "::", "get_plugin_types", "(", ")", ";", "foreach", "(", "$", "plugintypes", "as", "$", "type", "=>", "$", "location", ")", "{", "$", "pluginlist", "=", "core_component", "::", "get_plugin_list", "(", "$", "type", ")", ";", "foreach", "(", "$", "pluginlist", "as", "$", "name", "=>", "$", "ununsed", ")", "{", "if", "(", "$", "type", "==", "'mod'", ")", "{", "// Plugin names are now automatically validated.", "$", "list", "[", "$", "name", "]", "=", "$", "type", ".", "'_'", ".", "$", "name", ";", "}", "else", "{", "$", "list", "[", "$", "type", ".", "'_'", ".", "$", "name", "]", "=", "$", "type", ".", "'_'", ".", "$", "name", ";", "}", "}", "}", "return", "$", "list", ";", "}" ]
Returns a list of all components installed on the server @return array (string)legacyname => (string)frankenstylename
[ "Returns", "a", "list", "of", "all", "components", "installed", "on", "the", "server" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/customlang/locallib.php#L55-L79
218,135
moodle/moodle
admin/tool/customlang/locallib.php
tool_customlang_utils.checkin
public static function checkin($lang) { global $DB, $USER, $CFG; require_once($CFG->libdir.'/filelib.php'); if ($lang !== clean_param($lang, PARAM_LANG)) { return false; } // get all customized strings from updated components $sql = "SELECT s.*, c.name AS component FROM {tool_customlang} s JOIN {tool_customlang_components} c ON s.componentid = c.id WHERE s.lang = ? AND (s.local IS NOT NULL OR s.modified = 1) ORDER BY componentid, stringid"; $strings = $DB->get_records_sql($sql, array($lang)); $files = array(); foreach ($strings as $string) { if (!is_null($string->local)) { $files[$string->component][$string->stringid] = $string->local; } } fulldelete(self::get_localpack_location($lang)); foreach ($files as $component => $strings) { self::dump_strings($lang, $component, $strings); } $DB->set_field_select('tool_customlang', 'modified', 0, 'lang = ?', array($lang)); $sm = get_string_manager(); $sm->reset_caches(); }
php
public static function checkin($lang) { global $DB, $USER, $CFG; require_once($CFG->libdir.'/filelib.php'); if ($lang !== clean_param($lang, PARAM_LANG)) { return false; } // get all customized strings from updated components $sql = "SELECT s.*, c.name AS component FROM {tool_customlang} s JOIN {tool_customlang_components} c ON s.componentid = c.id WHERE s.lang = ? AND (s.local IS NOT NULL OR s.modified = 1) ORDER BY componentid, stringid"; $strings = $DB->get_records_sql($sql, array($lang)); $files = array(); foreach ($strings as $string) { if (!is_null($string->local)) { $files[$string->component][$string->stringid] = $string->local; } } fulldelete(self::get_localpack_location($lang)); foreach ($files as $component => $strings) { self::dump_strings($lang, $component, $strings); } $DB->set_field_select('tool_customlang', 'modified', 0, 'lang = ?', array($lang)); $sm = get_string_manager(); $sm->reset_caches(); }
[ "public", "static", "function", "checkin", "(", "$", "lang", ")", "{", "global", "$", "DB", ",", "$", "USER", ",", "$", "CFG", ";", "require_once", "(", "$", "CFG", "->", "libdir", ".", "'/filelib.php'", ")", ";", "if", "(", "$", "lang", "!==", "clean_param", "(", "$", "lang", ",", "PARAM_LANG", ")", ")", "{", "return", "false", ";", "}", "// get all customized strings from updated components", "$", "sql", "=", "\"SELECT s.*, c.name AS component\n FROM {tool_customlang} s\n JOIN {tool_customlang_components} c ON s.componentid = c.id\n WHERE s.lang = ?\n AND (s.local IS NOT NULL OR s.modified = 1)\n ORDER BY componentid, stringid\"", ";", "$", "strings", "=", "$", "DB", "->", "get_records_sql", "(", "$", "sql", ",", "array", "(", "$", "lang", ")", ")", ";", "$", "files", "=", "array", "(", ")", ";", "foreach", "(", "$", "strings", "as", "$", "string", ")", "{", "if", "(", "!", "is_null", "(", "$", "string", "->", "local", ")", ")", "{", "$", "files", "[", "$", "string", "->", "component", "]", "[", "$", "string", "->", "stringid", "]", "=", "$", "string", "->", "local", ";", "}", "}", "fulldelete", "(", "self", "::", "get_localpack_location", "(", "$", "lang", ")", ")", ";", "foreach", "(", "$", "files", "as", "$", "component", "=>", "$", "strings", ")", "{", "self", "::", "dump_strings", "(", "$", "lang", ",", "$", "component", ",", "$", "strings", ")", ";", "}", "$", "DB", "->", "set_field_select", "(", "'tool_customlang'", ",", "'modified'", ",", "0", ",", "'lang = ?'", ",", "array", "(", "$", "lang", ")", ")", ";", "$", "sm", "=", "get_string_manager", "(", ")", ";", "$", "sm", "->", "reset_caches", "(", ")", ";", "}" ]
Exports the translator database into disk files @param mixed $lang language code
[ "Exports", "the", "translator", "database", "into", "disk", "files" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/customlang/locallib.php#L206-L238
218,136
moodle/moodle
admin/tool/customlang/locallib.php
tool_customlang_utils.dump_strings
protected static function dump_strings($lang, $component, $strings) { global $CFG; if ($lang !== clean_param($lang, PARAM_LANG)) { debugging('Unable to dump local strings for non-installed language pack .'.s($lang)); return false; } if ($component !== clean_param($component, PARAM_COMPONENT)) { throw new coding_exception('Incorrect component name'); } if (!$filename = self::get_component_filename($component)) { debugging('Unable to find the filename for the component '.s($component)); return false; } if ($filename !== clean_param($filename, PARAM_FILE)) { throw new coding_exception('Incorrect file name '.s($filename)); } list($package, $subpackage) = core_component::normalize_component($component); $packageinfo = " * @package $package"; if (!is_null($subpackage)) { $packageinfo .= "\n * @subpackage $subpackage"; } $filepath = self::get_localpack_location($lang); $filepath = $filepath.'/'.$filename; if (!is_dir(dirname($filepath))) { check_dir_exists(dirname($filepath)); } if (!$f = fopen($filepath, 'w')) { debugging('Unable to write '.s($filepath)); return false; } fwrite($f, <<<EOF <?php // This file is part of Moodle - http://moodle.org/ // // Moodle is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // // Moodle is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with Moodle. If not, see <http://www.gnu.org/licenses/>. /** * Local language pack from $CFG->wwwroot * $packageinfo * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ defined('MOODLE_INTERNAL') || die(); EOF ); foreach ($strings as $stringid => $text) { if ($stringid !== clean_param($stringid, PARAM_STRINGID)) { debugging('Invalid string identifier '.s($stringid)); continue; } fwrite($f, '$string[\'' . $stringid . '\'] = '); fwrite($f, var_export($text, true)); fwrite($f, ";\n"); } fclose($f); @chmod($filepath, $CFG->filepermissions); }
php
protected static function dump_strings($lang, $component, $strings) { global $CFG; if ($lang !== clean_param($lang, PARAM_LANG)) { debugging('Unable to dump local strings for non-installed language pack .'.s($lang)); return false; } if ($component !== clean_param($component, PARAM_COMPONENT)) { throw new coding_exception('Incorrect component name'); } if (!$filename = self::get_component_filename($component)) { debugging('Unable to find the filename for the component '.s($component)); return false; } if ($filename !== clean_param($filename, PARAM_FILE)) { throw new coding_exception('Incorrect file name '.s($filename)); } list($package, $subpackage) = core_component::normalize_component($component); $packageinfo = " * @package $package"; if (!is_null($subpackage)) { $packageinfo .= "\n * @subpackage $subpackage"; } $filepath = self::get_localpack_location($lang); $filepath = $filepath.'/'.$filename; if (!is_dir(dirname($filepath))) { check_dir_exists(dirname($filepath)); } if (!$f = fopen($filepath, 'w')) { debugging('Unable to write '.s($filepath)); return false; } fwrite($f, <<<EOF <?php // This file is part of Moodle - http://moodle.org/ // // Moodle is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // // Moodle is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with Moodle. If not, see <http://www.gnu.org/licenses/>. /** * Local language pack from $CFG->wwwroot * $packageinfo * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ defined('MOODLE_INTERNAL') || die(); EOF ); foreach ($strings as $stringid => $text) { if ($stringid !== clean_param($stringid, PARAM_STRINGID)) { debugging('Invalid string identifier '.s($stringid)); continue; } fwrite($f, '$string[\'' . $stringid . '\'] = '); fwrite($f, var_export($text, true)); fwrite($f, ";\n"); } fclose($f); @chmod($filepath, $CFG->filepermissions); }
[ "protected", "static", "function", "dump_strings", "(", "$", "lang", ",", "$", "component", ",", "$", "strings", ")", "{", "global", "$", "CFG", ";", "if", "(", "$", "lang", "!==", "clean_param", "(", "$", "lang", ",", "PARAM_LANG", ")", ")", "{", "debugging", "(", "'Unable to dump local strings for non-installed language pack .'", ".", "s", "(", "$", "lang", ")", ")", ";", "return", "false", ";", "}", "if", "(", "$", "component", "!==", "clean_param", "(", "$", "component", ",", "PARAM_COMPONENT", ")", ")", "{", "throw", "new", "coding_exception", "(", "'Incorrect component name'", ")", ";", "}", "if", "(", "!", "$", "filename", "=", "self", "::", "get_component_filename", "(", "$", "component", ")", ")", "{", "debugging", "(", "'Unable to find the filename for the component '", ".", "s", "(", "$", "component", ")", ")", ";", "return", "false", ";", "}", "if", "(", "$", "filename", "!==", "clean_param", "(", "$", "filename", ",", "PARAM_FILE", ")", ")", "{", "throw", "new", "coding_exception", "(", "'Incorrect file name '", ".", "s", "(", "$", "filename", ")", ")", ";", "}", "list", "(", "$", "package", ",", "$", "subpackage", ")", "=", "core_component", "::", "normalize_component", "(", "$", "component", ")", ";", "$", "packageinfo", "=", "\" * @package $package\"", ";", "if", "(", "!", "is_null", "(", "$", "subpackage", ")", ")", "{", "$", "packageinfo", ".=", "\"\\n * @subpackage $subpackage\"", ";", "}", "$", "filepath", "=", "self", "::", "get_localpack_location", "(", "$", "lang", ")", ";", "$", "filepath", "=", "$", "filepath", ".", "'/'", ".", "$", "filename", ";", "if", "(", "!", "is_dir", "(", "dirname", "(", "$", "filepath", ")", ")", ")", "{", "check_dir_exists", "(", "dirname", "(", "$", "filepath", ")", ")", ";", "}", "if", "(", "!", "$", "f", "=", "fopen", "(", "$", "filepath", ",", "'w'", ")", ")", "{", "debugging", "(", "'Unable to write '", ".", "s", "(", "$", "filepath", ")", ")", ";", "return", "false", ";", "}", "fwrite", "(", "$", "f", ",", " <<<EOF\n<?php\n\n// This file is part of Moodle - http://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle. If not, see <http://www.gnu.org/licenses/>.\n\n/**\n * Local language pack from $CFG->wwwroot\n *\n$packageinfo\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\ndefined('MOODLE_INTERNAL') || die();\n\n\nEOF", ")", ";", "foreach", "(", "$", "strings", "as", "$", "stringid", "=>", "$", "text", ")", "{", "if", "(", "$", "stringid", "!==", "clean_param", "(", "$", "stringid", ",", "PARAM_STRINGID", ")", ")", "{", "debugging", "(", "'Invalid string identifier '", ".", "s", "(", "$", "stringid", ")", ")", ";", "continue", ";", "}", "fwrite", "(", "$", "f", ",", "'$string[\\''", ".", "$", "stringid", ".", "'\\'] = '", ")", ";", "fwrite", "(", "$", "f", ",", "var_export", "(", "$", "text", ",", "true", ")", ")", ";", "fwrite", "(", "$", "f", ",", "\";\\n\"", ")", ";", "}", "fclose", "(", "$", "f", ")", ";", "@", "chmod", "(", "$", "filepath", ",", "$", "CFG", "->", "filepermissions", ")", ";", "}" ]
Writes strings into a local language pack file @param string $component the name of the component @param array $strings
[ "Writes", "strings", "into", "a", "local", "language", "pack", "file" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/customlang/locallib.php#L258-L332
218,137
moodle/moodle
admin/tool/customlang/locallib.php
tool_customlang_utils.get_component_filename
protected static function get_component_filename($component) { if (is_null(self::$components)) { self::$components = self::list_components(); } $return = false; foreach (self::$components as $legacy => $normalized) { if ($component === $normalized) { $return = $legacy.'.php'; break; } } return $return; }
php
protected static function get_component_filename($component) { if (is_null(self::$components)) { self::$components = self::list_components(); } $return = false; foreach (self::$components as $legacy => $normalized) { if ($component === $normalized) { $return = $legacy.'.php'; break; } } return $return; }
[ "protected", "static", "function", "get_component_filename", "(", "$", "component", ")", "{", "if", "(", "is_null", "(", "self", "::", "$", "components", ")", ")", "{", "self", "::", "$", "components", "=", "self", "::", "list_components", "(", ")", ";", "}", "$", "return", "=", "false", ";", "foreach", "(", "self", "::", "$", "components", "as", "$", "legacy", "=>", "$", "normalized", ")", "{", "if", "(", "$", "component", "===", "$", "normalized", ")", "{", "$", "return", "=", "$", "legacy", ".", "'.php'", ";", "break", ";", "}", "}", "return", "$", "return", ";", "}" ]
Returns the name of the file where the component's local strings should be exported into @param string $component normalized name of the component, eg 'core' or 'mod_workshop' @return string|boolean filename eg 'moodle.php' or 'workshop.php', false if not found
[ "Returns", "the", "name", "of", "the", "file", "where", "the", "component", "s", "local", "strings", "should", "be", "exported", "into" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/customlang/locallib.php#L340-L352
218,138
moodle/moodle
admin/tool/customlang/locallib.php
tool_customlang_utils.save_filter
public static function save_filter(stdclass $data, stdclass $persistant) { if (!isset($persistant->tool_customlang_filter)) { $persistant->tool_customlang_filter = array(); } foreach ($data as $key => $value) { if ($key !== 'submit') { $persistant->tool_customlang_filter[$key] = serialize($value); } } }
php
public static function save_filter(stdclass $data, stdclass $persistant) { if (!isset($persistant->tool_customlang_filter)) { $persistant->tool_customlang_filter = array(); } foreach ($data as $key => $value) { if ($key !== 'submit') { $persistant->tool_customlang_filter[$key] = serialize($value); } } }
[ "public", "static", "function", "save_filter", "(", "stdclass", "$", "data", ",", "stdclass", "$", "persistant", ")", "{", "if", "(", "!", "isset", "(", "$", "persistant", "->", "tool_customlang_filter", ")", ")", "{", "$", "persistant", "->", "tool_customlang_filter", "=", "array", "(", ")", ";", "}", "foreach", "(", "$", "data", "as", "$", "key", "=>", "$", "value", ")", "{", "if", "(", "$", "key", "!==", "'submit'", ")", "{", "$", "persistant", "->", "tool_customlang_filter", "[", "$", "key", "]", "=", "serialize", "(", "$", "value", ")", ";", "}", "}", "}" ]
Saves filter data into a persistant storage such as user session @see self::load_filter() @param stdclass $data filter values @param stdclass $persistant storage object
[ "Saves", "filter", "data", "into", "a", "persistant", "storage", "such", "as", "user", "session" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/customlang/locallib.php#L373-L382
218,139
moodle/moodle
admin/tool/customlang/locallib.php
tool_customlang_utils.load_filter
public static function load_filter(stdclass $persistant) { $data = new stdclass(); if (isset($persistant->tool_customlang_filter)) { foreach ($persistant->tool_customlang_filter as $key => $value) { $data->{$key} = unserialize($value); } } return $data; }
php
public static function load_filter(stdclass $persistant) { $data = new stdclass(); if (isset($persistant->tool_customlang_filter)) { foreach ($persistant->tool_customlang_filter as $key => $value) { $data->{$key} = unserialize($value); } } return $data; }
[ "public", "static", "function", "load_filter", "(", "stdclass", "$", "persistant", ")", "{", "$", "data", "=", "new", "stdclass", "(", ")", ";", "if", "(", "isset", "(", "$", "persistant", "->", "tool_customlang_filter", ")", ")", "{", "foreach", "(", "$", "persistant", "->", "tool_customlang_filter", "as", "$", "key", "=>", "$", "value", ")", "{", "$", "data", "->", "{", "$", "key", "}", "=", "unserialize", "(", "$", "value", ")", ";", "}", "}", "return", "$", "data", ";", "}" ]
Loads the previously saved filter settings from a persistent storage @see self::save_filter() @param stdclass $persistant storage object @return stdclass filter data
[ "Loads", "the", "previously", "saved", "filter", "settings", "from", "a", "persistent", "storage" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/customlang/locallib.php#L391-L399
218,140
moodle/moodle
admin/tool/customlang/locallib.php
tool_customlang_menu.add_item
public function add_item($key, $title, moodle_url $url, $method) { if (isset($this->items[$key])) { throw new coding_exception('Menu item already exists'); } if (empty($title) or empty($key)) { throw new coding_exception('Empty title or item key not allowed'); } $item = new stdclass(); $item->title = $title; $item->url = $url; $item->method = $method; $this->items[$key] = $item; }
php
public function add_item($key, $title, moodle_url $url, $method) { if (isset($this->items[$key])) { throw new coding_exception('Menu item already exists'); } if (empty($title) or empty($key)) { throw new coding_exception('Empty title or item key not allowed'); } $item = new stdclass(); $item->title = $title; $item->url = $url; $item->method = $method; $this->items[$key] = $item; }
[ "public", "function", "add_item", "(", "$", "key", ",", "$", "title", ",", "moodle_url", "$", "url", ",", "$", "method", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "items", "[", "$", "key", "]", ")", ")", "{", "throw", "new", "coding_exception", "(", "'Menu item already exists'", ")", ";", "}", "if", "(", "empty", "(", "$", "title", ")", "or", "empty", "(", "$", "key", ")", ")", "{", "throw", "new", "coding_exception", "(", "'Empty title or item key not allowed'", ")", ";", "}", "$", "item", "=", "new", "stdclass", "(", ")", ";", "$", "item", "->", "title", "=", "$", "title", ";", "$", "item", "->", "url", "=", "$", "url", ";", "$", "item", "->", "method", "=", "$", "method", ";", "$", "this", "->", "items", "[", "$", "key", "]", "=", "$", "item", ";", "}" ]
Adds item into the menu @param string $key item identifier @param string $title localized action title @param moodle_url $url action handler @param string $method form method
[ "Adds", "item", "into", "the", "menu" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/customlang/locallib.php#L435-L447
218,141
moodle/moodle
mod/assign/feedback/editpdf/classes/document_services.php
document_services.get_assignment_from_param
private static function get_assignment_from_param($assignment) { global $CFG; require_once($CFG->dirroot . '/mod/assign/locallib.php'); if (!is_object($assignment)) { $cm = get_coursemodule_from_instance('assign', $assignment, 0, false, MUST_EXIST); $context = \context_module::instance($cm->id); $assignment = new \assign($context, null, null); } return $assignment; }
php
private static function get_assignment_from_param($assignment) { global $CFG; require_once($CFG->dirroot . '/mod/assign/locallib.php'); if (!is_object($assignment)) { $cm = get_coursemodule_from_instance('assign', $assignment, 0, false, MUST_EXIST); $context = \context_module::instance($cm->id); $assignment = new \assign($context, null, null); } return $assignment; }
[ "private", "static", "function", "get_assignment_from_param", "(", "$", "assignment", ")", "{", "global", "$", "CFG", ";", "require_once", "(", "$", "CFG", "->", "dirroot", ".", "'/mod/assign/locallib.php'", ")", ";", "if", "(", "!", "is_object", "(", "$", "assignment", ")", ")", "{", "$", "cm", "=", "get_coursemodule_from_instance", "(", "'assign'", ",", "$", "assignment", ",", "0", ",", "false", ",", "MUST_EXIST", ")", ";", "$", "context", "=", "\\", "context_module", "::", "instance", "(", "$", "cm", "->", "id", ")", ";", "$", "assignment", "=", "new", "\\", "assign", "(", "$", "context", ",", "null", ",", "null", ")", ";", "}", "return", "$", "assignment", ";", "}" ]
This function will take an int or an assignment instance and return an assignment instance. It is just for convenience. @param int|\assign $assignment @return assign
[ "This", "function", "will", "take", "an", "int", "or", "an", "assignment", "instance", "and", "return", "an", "assignment", "instance", ".", "It", "is", "just", "for", "convenience", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/assign/feedback/editpdf/classes/document_services.php#L92-L104
218,142
moodle/moodle
mod/assign/feedback/editpdf/classes/document_services.php
document_services.hash
private static function hash($assignment, $userid, $attemptnumber) { if (is_object($assignment)) { $assignmentid = $assignment->get_instance()->id; } else { $assignmentid = $assignment; } return sha1($assignmentid . '_' . $userid . '_' . $attemptnumber); }
php
private static function hash($assignment, $userid, $attemptnumber) { if (is_object($assignment)) { $assignmentid = $assignment->get_instance()->id; } else { $assignmentid = $assignment; } return sha1($assignmentid . '_' . $userid . '_' . $attemptnumber); }
[ "private", "static", "function", "hash", "(", "$", "assignment", ",", "$", "userid", ",", "$", "attemptnumber", ")", "{", "if", "(", "is_object", "(", "$", "assignment", ")", ")", "{", "$", "assignmentid", "=", "$", "assignment", "->", "get_instance", "(", ")", "->", "id", ";", "}", "else", "{", "$", "assignmentid", "=", "$", "assignment", ";", "}", "return", "sha1", "(", "$", "assignmentid", ".", "'_'", ".", "$", "userid", ".", "'_'", ".", "$", "attemptnumber", ")", ";", "}" ]
Get a hash that will be unique and can be used in a path name. @param int|\assign $assignment @param int $userid @param int $attemptnumber (-1 means latest attempt)
[ "Get", "a", "hash", "that", "will", "be", "unique", "and", "can", "be", "used", "in", "a", "path", "name", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/assign/feedback/editpdf/classes/document_services.php#L112-L119
218,143
moodle/moodle
mod/assign/feedback/editpdf/classes/document_services.php
document_services.strip_images
protected static function strip_images($html) { // Load HTML and suppress any parsing errors (DOMDocument->loadHTML() does not current support HTML5 tags). $dom = new DOMDocument(); libxml_use_internal_errors(true); $dom->loadHTML('<?xml version="1.0" encoding="UTF-8" ?>' . $html); libxml_clear_errors(); // Find all img tags. if ($imgnodes = $dom->getElementsByTagName('img')) { // Replace img nodes with the img alt text without overriding DOM elements. for ($i = ($imgnodes->length - 1); $i >= 0; $i--) { $imgnode = $imgnodes->item($i); $alt = ($imgnode->hasAttribute('alt')) ? ' [ ' . $imgnode->getAttribute('alt') . ' ] ' : ' '; $textnode = $dom->createTextNode($alt); $imgnode->parentNode->replaceChild($textnode, $imgnode); } } $count = 1; return str_replace("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>", "", $dom->saveHTML(), $count); }
php
protected static function strip_images($html) { // Load HTML and suppress any parsing errors (DOMDocument->loadHTML() does not current support HTML5 tags). $dom = new DOMDocument(); libxml_use_internal_errors(true); $dom->loadHTML('<?xml version="1.0" encoding="UTF-8" ?>' . $html); libxml_clear_errors(); // Find all img tags. if ($imgnodes = $dom->getElementsByTagName('img')) { // Replace img nodes with the img alt text without overriding DOM elements. for ($i = ($imgnodes->length - 1); $i >= 0; $i--) { $imgnode = $imgnodes->item($i); $alt = ($imgnode->hasAttribute('alt')) ? ' [ ' . $imgnode->getAttribute('alt') . ' ] ' : ' '; $textnode = $dom->createTextNode($alt); $imgnode->parentNode->replaceChild($textnode, $imgnode); } } $count = 1; return str_replace("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>", "", $dom->saveHTML(), $count); }
[ "protected", "static", "function", "strip_images", "(", "$", "html", ")", "{", "// Load HTML and suppress any parsing errors (DOMDocument->loadHTML() does not current support HTML5 tags).", "$", "dom", "=", "new", "DOMDocument", "(", ")", ";", "libxml_use_internal_errors", "(", "true", ")", ";", "$", "dom", "->", "loadHTML", "(", "'<?xml version=\"1.0\" encoding=\"UTF-8\" ?>'", ".", "$", "html", ")", ";", "libxml_clear_errors", "(", ")", ";", "// Find all img tags.", "if", "(", "$", "imgnodes", "=", "$", "dom", "->", "getElementsByTagName", "(", "'img'", ")", ")", "{", "// Replace img nodes with the img alt text without overriding DOM elements.", "for", "(", "$", "i", "=", "(", "$", "imgnodes", "->", "length", "-", "1", ")", ";", "$", "i", ">=", "0", ";", "$", "i", "--", ")", "{", "$", "imgnode", "=", "$", "imgnodes", "->", "item", "(", "$", "i", ")", ";", "$", "alt", "=", "(", "$", "imgnode", "->", "hasAttribute", "(", "'alt'", ")", ")", "?", "' [ '", ".", "$", "imgnode", "->", "getAttribute", "(", "'alt'", ")", ".", "' ] '", ":", "' '", ";", "$", "textnode", "=", "$", "dom", "->", "createTextNode", "(", "$", "alt", ")", ";", "$", "imgnode", "->", "parentNode", "->", "replaceChild", "(", "$", "textnode", ",", "$", "imgnode", ")", ";", "}", "}", "$", "count", "=", "1", ";", "return", "str_replace", "(", "\"<?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" ?>\"", ",", "\"\"", ",", "$", "dom", "->", "saveHTML", "(", ")", ",", "$", "count", ")", ";", "}" ]
Use a DOM parser to accurately replace images with their alt text. @param string $html @return string New html with no image tags.
[ "Use", "a", "DOM", "parser", "to", "accurately", "replace", "images", "with", "their", "alt", "text", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/assign/feedback/editpdf/classes/document_services.php#L126-L146
218,144
moodle/moodle
mod/assign/feedback/editpdf/classes/document_services.php
document_services.get_combined_document_for_attempt
public static function get_combined_document_for_attempt($assignment, $userid, $attemptnumber) { global $USER, $DB; $assignment = self::get_assignment_from_param($assignment); // Capability checks. if (!$assignment->can_view_submission($userid)) { print_error('nopermission'); } $grade = $assignment->get_user_grade($userid, true, $attemptnumber); if ($assignment->get_instance()->teamsubmission) { $submission = $assignment->get_group_submission($userid, 0, false, $attemptnumber); } else { $submission = $assignment->get_user_submission($userid, false, $attemptnumber); } $contextid = $assignment->get_context()->id; $component = 'assignfeedback_editpdf'; $filearea = self::COMBINED_PDF_FILEAREA; $partialfilearea = self::PARTIAL_PDF_FILEAREA; $itemid = $grade->id; $filepath = '/'; $filename = self::COMBINED_PDF_FILENAME; $fs = get_file_storage(); $partialpdf = $fs->get_file($contextid, $component, $partialfilearea, $itemid, $filepath, $filename); if (!empty($partialpdf)) { $combinedpdf = $partialpdf; } else { $combinedpdf = $fs->get_file($contextid, $component, $filearea, $itemid, $filepath, $filename); } if ($combinedpdf && $submission) { if ($combinedpdf->get_timemodified() < $submission->timemodified) { // The submission has been updated since the PDF was generated. $combinedpdf = false; } else if ($combinedpdf->get_contenthash() == self::BLANK_PDF_HASH) { // The PDF is for a blank page. $combinedpdf = false; } } if (empty($combinedpdf)) { // The combined PDF does not exist yet. Return the list of files to be combined. return self::list_compatible_submission_files_for_attempt($assignment, $userid, $attemptnumber); } else { // The combined PDF aleady exists. Return it in a new combined_document object. $combineddocument = new combined_document(); return $combineddocument->set_combined_file($combinedpdf); } }
php
public static function get_combined_document_for_attempt($assignment, $userid, $attemptnumber) { global $USER, $DB; $assignment = self::get_assignment_from_param($assignment); // Capability checks. if (!$assignment->can_view_submission($userid)) { print_error('nopermission'); } $grade = $assignment->get_user_grade($userid, true, $attemptnumber); if ($assignment->get_instance()->teamsubmission) { $submission = $assignment->get_group_submission($userid, 0, false, $attemptnumber); } else { $submission = $assignment->get_user_submission($userid, false, $attemptnumber); } $contextid = $assignment->get_context()->id; $component = 'assignfeedback_editpdf'; $filearea = self::COMBINED_PDF_FILEAREA; $partialfilearea = self::PARTIAL_PDF_FILEAREA; $itemid = $grade->id; $filepath = '/'; $filename = self::COMBINED_PDF_FILENAME; $fs = get_file_storage(); $partialpdf = $fs->get_file($contextid, $component, $partialfilearea, $itemid, $filepath, $filename); if (!empty($partialpdf)) { $combinedpdf = $partialpdf; } else { $combinedpdf = $fs->get_file($contextid, $component, $filearea, $itemid, $filepath, $filename); } if ($combinedpdf && $submission) { if ($combinedpdf->get_timemodified() < $submission->timemodified) { // The submission has been updated since the PDF was generated. $combinedpdf = false; } else if ($combinedpdf->get_contenthash() == self::BLANK_PDF_HASH) { // The PDF is for a blank page. $combinedpdf = false; } } if (empty($combinedpdf)) { // The combined PDF does not exist yet. Return the list of files to be combined. return self::list_compatible_submission_files_for_attempt($assignment, $userid, $attemptnumber); } else { // The combined PDF aleady exists. Return it in a new combined_document object. $combineddocument = new combined_document(); return $combineddocument->set_combined_file($combinedpdf); } }
[ "public", "static", "function", "get_combined_document_for_attempt", "(", "$", "assignment", ",", "$", "userid", ",", "$", "attemptnumber", ")", "{", "global", "$", "USER", ",", "$", "DB", ";", "$", "assignment", "=", "self", "::", "get_assignment_from_param", "(", "$", "assignment", ")", ";", "// Capability checks.", "if", "(", "!", "$", "assignment", "->", "can_view_submission", "(", "$", "userid", ")", ")", "{", "print_error", "(", "'nopermission'", ")", ";", "}", "$", "grade", "=", "$", "assignment", "->", "get_user_grade", "(", "$", "userid", ",", "true", ",", "$", "attemptnumber", ")", ";", "if", "(", "$", "assignment", "->", "get_instance", "(", ")", "->", "teamsubmission", ")", "{", "$", "submission", "=", "$", "assignment", "->", "get_group_submission", "(", "$", "userid", ",", "0", ",", "false", ",", "$", "attemptnumber", ")", ";", "}", "else", "{", "$", "submission", "=", "$", "assignment", "->", "get_user_submission", "(", "$", "userid", ",", "false", ",", "$", "attemptnumber", ")", ";", "}", "$", "contextid", "=", "$", "assignment", "->", "get_context", "(", ")", "->", "id", ";", "$", "component", "=", "'assignfeedback_editpdf'", ";", "$", "filearea", "=", "self", "::", "COMBINED_PDF_FILEAREA", ";", "$", "partialfilearea", "=", "self", "::", "PARTIAL_PDF_FILEAREA", ";", "$", "itemid", "=", "$", "grade", "->", "id", ";", "$", "filepath", "=", "'/'", ";", "$", "filename", "=", "self", "::", "COMBINED_PDF_FILENAME", ";", "$", "fs", "=", "get_file_storage", "(", ")", ";", "$", "partialpdf", "=", "$", "fs", "->", "get_file", "(", "$", "contextid", ",", "$", "component", ",", "$", "partialfilearea", ",", "$", "itemid", ",", "$", "filepath", ",", "$", "filename", ")", ";", "if", "(", "!", "empty", "(", "$", "partialpdf", ")", ")", "{", "$", "combinedpdf", "=", "$", "partialpdf", ";", "}", "else", "{", "$", "combinedpdf", "=", "$", "fs", "->", "get_file", "(", "$", "contextid", ",", "$", "component", ",", "$", "filearea", ",", "$", "itemid", ",", "$", "filepath", ",", "$", "filename", ")", ";", "}", "if", "(", "$", "combinedpdf", "&&", "$", "submission", ")", "{", "if", "(", "$", "combinedpdf", "->", "get_timemodified", "(", ")", "<", "$", "submission", "->", "timemodified", ")", "{", "// The submission has been updated since the PDF was generated.", "$", "combinedpdf", "=", "false", ";", "}", "else", "if", "(", "$", "combinedpdf", "->", "get_contenthash", "(", ")", "==", "self", "::", "BLANK_PDF_HASH", ")", "{", "// The PDF is for a blank page.", "$", "combinedpdf", "=", "false", ";", "}", "}", "if", "(", "empty", "(", "$", "combinedpdf", ")", ")", "{", "// The combined PDF does not exist yet. Return the list of files to be combined.", "return", "self", "::", "list_compatible_submission_files_for_attempt", "(", "$", "assignment", ",", "$", "userid", ",", "$", "attemptnumber", ")", ";", "}", "else", "{", "// The combined PDF aleady exists. Return it in a new combined_document object.", "$", "combineddocument", "=", "new", "combined_document", "(", ")", ";", "return", "$", "combineddocument", "->", "set_combined_file", "(", "$", "combinedpdf", ")", ";", "}", "}" ]
Fetch the current combined document ready for state checking. @param int|\assign $assignment @param int $userid @param int $attemptnumber (-1 means latest attempt) @return combined_document
[ "Fetch", "the", "current", "combined", "document", "ready", "for", "state", "checking", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/assign/feedback/editpdf/classes/document_services.php#L251-L302
218,145
moodle/moodle
mod/assign/feedback/editpdf/classes/document_services.php
document_services.get_combined_pdf_for_attempt
public static function get_combined_pdf_for_attempt($assignment, $userid, $attemptnumber) { $document = self::get_combined_document_for_attempt($assignment, $userid, $attemptnumber); if ($document->get_status() === combined_document::STATUS_COMPLETE) { // The combined document is already ready. return $document; } else { // Attempt to combined the files in the document. $grade = $assignment->get_user_grade($userid, true, $attemptnumber); $document->combine_files($assignment->get_context()->id, $grade->id); return $document; } }
php
public static function get_combined_pdf_for_attempt($assignment, $userid, $attemptnumber) { $document = self::get_combined_document_for_attempt($assignment, $userid, $attemptnumber); if ($document->get_status() === combined_document::STATUS_COMPLETE) { // The combined document is already ready. return $document; } else { // Attempt to combined the files in the document. $grade = $assignment->get_user_grade($userid, true, $attemptnumber); $document->combine_files($assignment->get_context()->id, $grade->id); return $document; } }
[ "public", "static", "function", "get_combined_pdf_for_attempt", "(", "$", "assignment", ",", "$", "userid", ",", "$", "attemptnumber", ")", "{", "$", "document", "=", "self", "::", "get_combined_document_for_attempt", "(", "$", "assignment", ",", "$", "userid", ",", "$", "attemptnumber", ")", ";", "if", "(", "$", "document", "->", "get_status", "(", ")", "===", "combined_document", "::", "STATUS_COMPLETE", ")", "{", "// The combined document is already ready.", "return", "$", "document", ";", "}", "else", "{", "// Attempt to combined the files in the document.", "$", "grade", "=", "$", "assignment", "->", "get_user_grade", "(", "$", "userid", ",", "true", ",", "$", "attemptnumber", ")", ";", "$", "document", "->", "combine_files", "(", "$", "assignment", "->", "get_context", "(", ")", "->", "id", ",", "$", "grade", "->", "id", ")", ";", "return", "$", "document", ";", "}", "}" ]
This function return the combined pdf for all valid submission files. @param int|\assign $assignment @param int $userid @param int $attemptnumber (-1 means latest attempt) @return combined_document
[ "This", "function", "return", "the", "combined", "pdf", "for", "all", "valid", "submission", "files", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/assign/feedback/editpdf/classes/document_services.php#L312-L324
218,146
moodle/moodle
mod/assign/feedback/editpdf/classes/document_services.php
document_services.page_number_for_attempt
public static function page_number_for_attempt($assignment, $userid, $attemptnumber, $readonly = false) { global $CFG; require_once($CFG->libdir . '/pdflib.php'); $assignment = self::get_assignment_from_param($assignment); if (!$assignment->can_view_submission($userid)) { print_error('nopermission'); } // When in readonly we can return the number of images in the DB because they should already exist, // if for some reason they do not, then we proceed as for the normal version. if ($readonly) { $grade = $assignment->get_user_grade($userid, true, $attemptnumber); $fs = get_file_storage(); $files = $fs->get_directory_files($assignment->get_context()->id, 'assignfeedback_editpdf', self::PAGE_IMAGE_READONLY_FILEAREA, $grade->id, '/'); $pagecount = count($files); if ($pagecount > 0) { return $pagecount; } } // Get a combined pdf file from all submitted pdf files. $document = self::get_combined_pdf_for_attempt($assignment, $userid, $attemptnumber); return $document->get_page_count(); }
php
public static function page_number_for_attempt($assignment, $userid, $attemptnumber, $readonly = false) { global $CFG; require_once($CFG->libdir . '/pdflib.php'); $assignment = self::get_assignment_from_param($assignment); if (!$assignment->can_view_submission($userid)) { print_error('nopermission'); } // When in readonly we can return the number of images in the DB because they should already exist, // if for some reason they do not, then we proceed as for the normal version. if ($readonly) { $grade = $assignment->get_user_grade($userid, true, $attemptnumber); $fs = get_file_storage(); $files = $fs->get_directory_files($assignment->get_context()->id, 'assignfeedback_editpdf', self::PAGE_IMAGE_READONLY_FILEAREA, $grade->id, '/'); $pagecount = count($files); if ($pagecount > 0) { return $pagecount; } } // Get a combined pdf file from all submitted pdf files. $document = self::get_combined_pdf_for_attempt($assignment, $userid, $attemptnumber); return $document->get_page_count(); }
[ "public", "static", "function", "page_number_for_attempt", "(", "$", "assignment", ",", "$", "userid", ",", "$", "attemptnumber", ",", "$", "readonly", "=", "false", ")", "{", "global", "$", "CFG", ";", "require_once", "(", "$", "CFG", "->", "libdir", ".", "'/pdflib.php'", ")", ";", "$", "assignment", "=", "self", "::", "get_assignment_from_param", "(", "$", "assignment", ")", ";", "if", "(", "!", "$", "assignment", "->", "can_view_submission", "(", "$", "userid", ")", ")", "{", "print_error", "(", "'nopermission'", ")", ";", "}", "// When in readonly we can return the number of images in the DB because they should already exist,", "// if for some reason they do not, then we proceed as for the normal version.", "if", "(", "$", "readonly", ")", "{", "$", "grade", "=", "$", "assignment", "->", "get_user_grade", "(", "$", "userid", ",", "true", ",", "$", "attemptnumber", ")", ";", "$", "fs", "=", "get_file_storage", "(", ")", ";", "$", "files", "=", "$", "fs", "->", "get_directory_files", "(", "$", "assignment", "->", "get_context", "(", ")", "->", "id", ",", "'assignfeedback_editpdf'", ",", "self", "::", "PAGE_IMAGE_READONLY_FILEAREA", ",", "$", "grade", "->", "id", ",", "'/'", ")", ";", "$", "pagecount", "=", "count", "(", "$", "files", ")", ";", "if", "(", "$", "pagecount", ">", "0", ")", "{", "return", "$", "pagecount", ";", "}", "}", "// Get a combined pdf file from all submitted pdf files.", "$", "document", "=", "self", "::", "get_combined_pdf_for_attempt", "(", "$", "assignment", ",", "$", "userid", ",", "$", "attemptnumber", ")", ";", "return", "$", "document", "->", "get_page_count", "(", ")", ";", "}" ]
This function will return the number of pages of a pdf. @param int|\assign $assignment @param int $userid @param int $attemptnumber (-1 means latest attempt) @param bool $readonly When true we get the number of pages for the readonly version. @return int number of pages
[ "This", "function", "will", "return", "the", "number", "of", "pages", "of", "a", "pdf", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/assign/feedback/editpdf/classes/document_services.php#L335-L362
218,147
moodle/moodle
mod/assign/feedback/editpdf/classes/document_services.php
document_services.get_downloadable_feedback_filename
protected static function get_downloadable_feedback_filename($assignment, $userid, $attemptnumber) { global $DB; $assignment = self::get_assignment_from_param($assignment); $groupmode = groups_get_activity_groupmode($assignment->get_course_module()); $groupname = ''; if ($groupmode) { $groupid = groups_get_activity_group($assignment->get_course_module(), true); $groupname = groups_get_group_name($groupid).'-'; } if ($groupname == '-') { $groupname = ''; } $grade = $assignment->get_user_grade($userid, true, $attemptnumber); $user = $DB->get_record('user', array('id'=>$userid), '*', MUST_EXIST); if ($assignment->is_blind_marking()) { $prefix = $groupname . get_string('participant', 'assign'); $prefix = str_replace('_', ' ', $prefix); $prefix = clean_filename($prefix . '_' . $assignment->get_uniqueid_for_user($userid) . '_'); } else { $prefix = $groupname . fullname($user); $prefix = str_replace('_', ' ', $prefix); $prefix = clean_filename($prefix . '_' . $assignment->get_uniqueid_for_user($userid) . '_'); } $prefix .= $grade->attemptnumber; return $prefix . '.pdf'; }
php
protected static function get_downloadable_feedback_filename($assignment, $userid, $attemptnumber) { global $DB; $assignment = self::get_assignment_from_param($assignment); $groupmode = groups_get_activity_groupmode($assignment->get_course_module()); $groupname = ''; if ($groupmode) { $groupid = groups_get_activity_group($assignment->get_course_module(), true); $groupname = groups_get_group_name($groupid).'-'; } if ($groupname == '-') { $groupname = ''; } $grade = $assignment->get_user_grade($userid, true, $attemptnumber); $user = $DB->get_record('user', array('id'=>$userid), '*', MUST_EXIST); if ($assignment->is_blind_marking()) { $prefix = $groupname . get_string('participant', 'assign'); $prefix = str_replace('_', ' ', $prefix); $prefix = clean_filename($prefix . '_' . $assignment->get_uniqueid_for_user($userid) . '_'); } else { $prefix = $groupname . fullname($user); $prefix = str_replace('_', ' ', $prefix); $prefix = clean_filename($prefix . '_' . $assignment->get_uniqueid_for_user($userid) . '_'); } $prefix .= $grade->attemptnumber; return $prefix . '.pdf'; }
[ "protected", "static", "function", "get_downloadable_feedback_filename", "(", "$", "assignment", ",", "$", "userid", ",", "$", "attemptnumber", ")", "{", "global", "$", "DB", ";", "$", "assignment", "=", "self", "::", "get_assignment_from_param", "(", "$", "assignment", ")", ";", "$", "groupmode", "=", "groups_get_activity_groupmode", "(", "$", "assignment", "->", "get_course_module", "(", ")", ")", ";", "$", "groupname", "=", "''", ";", "if", "(", "$", "groupmode", ")", "{", "$", "groupid", "=", "groups_get_activity_group", "(", "$", "assignment", "->", "get_course_module", "(", ")", ",", "true", ")", ";", "$", "groupname", "=", "groups_get_group_name", "(", "$", "groupid", ")", ".", "'-'", ";", "}", "if", "(", "$", "groupname", "==", "'-'", ")", "{", "$", "groupname", "=", "''", ";", "}", "$", "grade", "=", "$", "assignment", "->", "get_user_grade", "(", "$", "userid", ",", "true", ",", "$", "attemptnumber", ")", ";", "$", "user", "=", "$", "DB", "->", "get_record", "(", "'user'", ",", "array", "(", "'id'", "=>", "$", "userid", ")", ",", "'*'", ",", "MUST_EXIST", ")", ";", "if", "(", "$", "assignment", "->", "is_blind_marking", "(", ")", ")", "{", "$", "prefix", "=", "$", "groupname", ".", "get_string", "(", "'participant'", ",", "'assign'", ")", ";", "$", "prefix", "=", "str_replace", "(", "'_'", ",", "' '", ",", "$", "prefix", ")", ";", "$", "prefix", "=", "clean_filename", "(", "$", "prefix", ".", "'_'", ".", "$", "assignment", "->", "get_uniqueid_for_user", "(", "$", "userid", ")", ".", "'_'", ")", ";", "}", "else", "{", "$", "prefix", "=", "$", "groupname", ".", "fullname", "(", "$", "user", ")", ";", "$", "prefix", "=", "str_replace", "(", "'_'", ",", "' '", ",", "$", "prefix", ")", ";", "$", "prefix", "=", "clean_filename", "(", "$", "prefix", ".", "'_'", ".", "$", "assignment", "->", "get_uniqueid_for_user", "(", "$", "userid", ")", ".", "'_'", ")", ";", "}", "$", "prefix", ".=", "$", "grade", "->", "attemptnumber", ";", "return", "$", "prefix", ".", "'.pdf'", ";", "}" ]
This function returns sensible filename for a feedback file. @param int|\assign $assignment @param int $userid @param int $attemptnumber (-1 means latest attempt) @return string
[ "This", "function", "returns", "sensible", "filename", "for", "a", "feedback", "file", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/assign/feedback/editpdf/classes/document_services.php#L575-L604
218,148
moodle/moodle
mod/assign/feedback/editpdf/classes/document_services.php
document_services.copy_pages_to_readonly_area
public static function copy_pages_to_readonly_area($assignment, $grade) { $fs = get_file_storage(); $assignment = self::get_assignment_from_param($assignment); $contextid = $assignment->get_context()->id; $component = 'assignfeedback_editpdf'; $itemid = $grade->id; // Get all the pages. $originalfiles = $fs->get_area_files($contextid, $component, self::PAGE_IMAGE_FILEAREA, $itemid); if (empty($originalfiles)) { // Nothing to do here... return; } // Delete the old readonly files. $fs->delete_area_files($contextid, $component, self::PAGE_IMAGE_READONLY_FILEAREA, $itemid); // Do the copying. foreach ($originalfiles as $originalfile) { $fs->create_file_from_storedfile(array('filearea' => self::PAGE_IMAGE_READONLY_FILEAREA), $originalfile); } }
php
public static function copy_pages_to_readonly_area($assignment, $grade) { $fs = get_file_storage(); $assignment = self::get_assignment_from_param($assignment); $contextid = $assignment->get_context()->id; $component = 'assignfeedback_editpdf'; $itemid = $grade->id; // Get all the pages. $originalfiles = $fs->get_area_files($contextid, $component, self::PAGE_IMAGE_FILEAREA, $itemid); if (empty($originalfiles)) { // Nothing to do here... return; } // Delete the old readonly files. $fs->delete_area_files($contextid, $component, self::PAGE_IMAGE_READONLY_FILEAREA, $itemid); // Do the copying. foreach ($originalfiles as $originalfile) { $fs->create_file_from_storedfile(array('filearea' => self::PAGE_IMAGE_READONLY_FILEAREA), $originalfile); } }
[ "public", "static", "function", "copy_pages_to_readonly_area", "(", "$", "assignment", ",", "$", "grade", ")", "{", "$", "fs", "=", "get_file_storage", "(", ")", ";", "$", "assignment", "=", "self", "::", "get_assignment_from_param", "(", "$", "assignment", ")", ";", "$", "contextid", "=", "$", "assignment", "->", "get_context", "(", ")", "->", "id", ";", "$", "component", "=", "'assignfeedback_editpdf'", ";", "$", "itemid", "=", "$", "grade", "->", "id", ";", "// Get all the pages.", "$", "originalfiles", "=", "$", "fs", "->", "get_area_files", "(", "$", "contextid", ",", "$", "component", ",", "self", "::", "PAGE_IMAGE_FILEAREA", ",", "$", "itemid", ")", ";", "if", "(", "empty", "(", "$", "originalfiles", ")", ")", "{", "// Nothing to do here...", "return", ";", "}", "// Delete the old readonly files.", "$", "fs", "->", "delete_area_files", "(", "$", "contextid", ",", "$", "component", ",", "self", "::", "PAGE_IMAGE_READONLY_FILEAREA", ",", "$", "itemid", ")", ";", "// Do the copying.", "foreach", "(", "$", "originalfiles", "as", "$", "originalfile", ")", "{", "$", "fs", "->", "create_file_from_storedfile", "(", "array", "(", "'filearea'", "=>", "self", "::", "PAGE_IMAGE_READONLY_FILEAREA", ")", ",", "$", "originalfile", ")", ";", "}", "}" ]
Copy the pages image to the readonly area. @param int|\assign $assignment The assignment. @param \stdClass $grade The grade record. @return void
[ "Copy", "the", "pages", "image", "to", "the", "readonly", "area", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/assign/feedback/editpdf/classes/document_services.php#L757-L778
218,149
moodle/moodle
mod/assign/feedback/editpdf/classes/document_services.php
document_services.delete_feedback_document
public static function delete_feedback_document($assignment, $userid, $attemptnumber) { $assignment = self::get_assignment_from_param($assignment); if (!$assignment->can_view_submission($userid)) { print_error('nopermission'); } if (!$assignment->can_grade()) { print_error('nopermission'); } $grade = $assignment->get_user_grade($userid, true, $attemptnumber); $contextid = $assignment->get_context()->id; $component = 'assignfeedback_editpdf'; $filearea = self::FINAL_PDF_FILEAREA; $itemid = $grade->id; $fs = get_file_storage(); return $fs->delete_area_files($contextid, $component, $filearea, $itemid); }
php
public static function delete_feedback_document($assignment, $userid, $attemptnumber) { $assignment = self::get_assignment_from_param($assignment); if (!$assignment->can_view_submission($userid)) { print_error('nopermission'); } if (!$assignment->can_grade()) { print_error('nopermission'); } $grade = $assignment->get_user_grade($userid, true, $attemptnumber); $contextid = $assignment->get_context()->id; $component = 'assignfeedback_editpdf'; $filearea = self::FINAL_PDF_FILEAREA; $itemid = $grade->id; $fs = get_file_storage(); return $fs->delete_area_files($contextid, $component, $filearea, $itemid); }
[ "public", "static", "function", "delete_feedback_document", "(", "$", "assignment", ",", "$", "userid", ",", "$", "attemptnumber", ")", "{", "$", "assignment", "=", "self", "::", "get_assignment_from_param", "(", "$", "assignment", ")", ";", "if", "(", "!", "$", "assignment", "->", "can_view_submission", "(", "$", "userid", ")", ")", "{", "print_error", "(", "'nopermission'", ")", ";", "}", "if", "(", "!", "$", "assignment", "->", "can_grade", "(", ")", ")", "{", "print_error", "(", "'nopermission'", ")", ";", "}", "$", "grade", "=", "$", "assignment", "->", "get_user_grade", "(", "$", "userid", ",", "true", ",", "$", "attemptnumber", ")", ";", "$", "contextid", "=", "$", "assignment", "->", "get_context", "(", ")", "->", "id", ";", "$", "component", "=", "'assignfeedback_editpdf'", ";", "$", "filearea", "=", "self", "::", "FINAL_PDF_FILEAREA", ";", "$", "itemid", "=", "$", "grade", "->", "id", ";", "$", "fs", "=", "get_file_storage", "(", ")", ";", "return", "$", "fs", "->", "delete_area_files", "(", "$", "contextid", ",", "$", "component", ",", "$", "filearea", ",", "$", "itemid", ")", ";", "}" ]
This function deletes the generated pdf for a student. @param int|\assign $assignment @param int $userid @param int $attemptnumber (-1 means latest attempt) @return bool
[ "This", "function", "deletes", "the", "generated", "pdf", "for", "a", "student", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/assign/feedback/editpdf/classes/document_services.php#L823-L843
218,150
moodle/moodle
mod/assign/feedback/editpdf/classes/document_services.php
document_services.get_files
private static function get_files($assignment, $userid, $attemptnumber, $filearea, $filepath = '/') { $grade = $assignment->get_user_grade($userid, true, $attemptnumber); $itemid = $grade->id; $contextid = $assignment->get_context()->id; $component = self::COMPONENT; $fs = get_file_storage(); $files = $fs->get_directory_files($contextid, $component, $filearea, $itemid, $filepath); return $files; }
php
private static function get_files($assignment, $userid, $attemptnumber, $filearea, $filepath = '/') { $grade = $assignment->get_user_grade($userid, true, $attemptnumber); $itemid = $grade->id; $contextid = $assignment->get_context()->id; $component = self::COMPONENT; $fs = get_file_storage(); $files = $fs->get_directory_files($contextid, $component, $filearea, $itemid, $filepath); return $files; }
[ "private", "static", "function", "get_files", "(", "$", "assignment", ",", "$", "userid", ",", "$", "attemptnumber", ",", "$", "filearea", ",", "$", "filepath", "=", "'/'", ")", "{", "$", "grade", "=", "$", "assignment", "->", "get_user_grade", "(", "$", "userid", ",", "true", ",", "$", "attemptnumber", ")", ";", "$", "itemid", "=", "$", "grade", "->", "id", ";", "$", "contextid", "=", "$", "assignment", "->", "get_context", "(", ")", "->", "id", ";", "$", "component", "=", "self", "::", "COMPONENT", ";", "$", "fs", "=", "get_file_storage", "(", ")", ";", "$", "files", "=", "$", "fs", "->", "get_directory_files", "(", "$", "contextid", ",", "$", "component", ",", "$", "filearea", ",", "$", "itemid", ",", "$", "filepath", ")", ";", "return", "$", "files", ";", "}" ]
Get All files in a File area @param int|\assign $assignment Assignment @param int $userid User ID @param int $attemptnumber Attempt Number @param string $filearea File Area @param string $filepath File Path @return array
[ "Get", "All", "files", "in", "a", "File", "area" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/assign/feedback/editpdf/classes/document_services.php#L854-L862
218,151
moodle/moodle
mod/assign/feedback/editpdf/classes/document_services.php
document_services.rotate_page
public static function rotate_page($assignment, $userid, $attemptnumber, $index, $rotateleft) { $assignment = self::get_assignment_from_param($assignment); $grade = $assignment->get_user_grade($userid, true, $attemptnumber); // Check permission. if (!$assignment->can_view_submission($userid)) { print_error('nopermission'); } $filearea = self::PAGE_IMAGE_FILEAREA; $files = self::get_files($assignment, $userid, $attemptnumber, $filearea); if (!empty($files)) { foreach ($files as $file) { preg_match('/' . pdf::IMAGE_PAGE . '([\d]+)\./', $file->get_filename(), $matches); if (empty($matches) or !is_numeric($matches[1])) { throw new \coding_exception("'" . $file->get_filename() . "' file hasn't the expected format filename: image_pageXXXX.png."); } $pagenumber = (int)$matches[1]; if ($pagenumber == $index) { $source = imagecreatefromstring($file->get_content()); $pagerotation = page_editor::get_page_rotation($grade->id, $index); $degree = empty($pagerotation) ? 0 : $pagerotation->degree; if ($rotateleft) { $content = imagerotate($source, 90, 0); $degree = ($degree + 90) % 360; } else { $content = imagerotate($source, -90, 0); $degree = ($degree - 90) % 360; } $filename = $matches[0].'png'; $tmpdir = make_temp_directory(self::COMPONENT . '/' . self::PAGE_IMAGE_FILEAREA . '/' . self::hash($assignment, $userid, $attemptnumber)); $tempfile = $tmpdir . '/' . time() . '_' . $filename; imagepng($content, $tempfile); $filearea = self::PAGE_IMAGE_FILEAREA; $newfile = self::save_file($assignment, $userid, $attemptnumber, $filearea, $tempfile); unlink($tempfile); rmdir($tmpdir); imagedestroy($source); imagedestroy($content); $file->delete(); if (!empty($newfile)) { page_editor::set_page_rotation($grade->id, $pagenumber, true, $newfile->get_pathnamehash(), $degree); } return $newfile; } } } return null; }
php
public static function rotate_page($assignment, $userid, $attemptnumber, $index, $rotateleft) { $assignment = self::get_assignment_from_param($assignment); $grade = $assignment->get_user_grade($userid, true, $attemptnumber); // Check permission. if (!$assignment->can_view_submission($userid)) { print_error('nopermission'); } $filearea = self::PAGE_IMAGE_FILEAREA; $files = self::get_files($assignment, $userid, $attemptnumber, $filearea); if (!empty($files)) { foreach ($files as $file) { preg_match('/' . pdf::IMAGE_PAGE . '([\d]+)\./', $file->get_filename(), $matches); if (empty($matches) or !is_numeric($matches[1])) { throw new \coding_exception("'" . $file->get_filename() . "' file hasn't the expected format filename: image_pageXXXX.png."); } $pagenumber = (int)$matches[1]; if ($pagenumber == $index) { $source = imagecreatefromstring($file->get_content()); $pagerotation = page_editor::get_page_rotation($grade->id, $index); $degree = empty($pagerotation) ? 0 : $pagerotation->degree; if ($rotateleft) { $content = imagerotate($source, 90, 0); $degree = ($degree + 90) % 360; } else { $content = imagerotate($source, -90, 0); $degree = ($degree - 90) % 360; } $filename = $matches[0].'png'; $tmpdir = make_temp_directory(self::COMPONENT . '/' . self::PAGE_IMAGE_FILEAREA . '/' . self::hash($assignment, $userid, $attemptnumber)); $tempfile = $tmpdir . '/' . time() . '_' . $filename; imagepng($content, $tempfile); $filearea = self::PAGE_IMAGE_FILEAREA; $newfile = self::save_file($assignment, $userid, $attemptnumber, $filearea, $tempfile); unlink($tempfile); rmdir($tmpdir); imagedestroy($source); imagedestroy($content); $file->delete(); if (!empty($newfile)) { page_editor::set_page_rotation($grade->id, $pagenumber, true, $newfile->get_pathnamehash(), $degree); } return $newfile; } } } return null; }
[ "public", "static", "function", "rotate_page", "(", "$", "assignment", ",", "$", "userid", ",", "$", "attemptnumber", ",", "$", "index", ",", "$", "rotateleft", ")", "{", "$", "assignment", "=", "self", "::", "get_assignment_from_param", "(", "$", "assignment", ")", ";", "$", "grade", "=", "$", "assignment", "->", "get_user_grade", "(", "$", "userid", ",", "true", ",", "$", "attemptnumber", ")", ";", "// Check permission.", "if", "(", "!", "$", "assignment", "->", "can_view_submission", "(", "$", "userid", ")", ")", "{", "print_error", "(", "'nopermission'", ")", ";", "}", "$", "filearea", "=", "self", "::", "PAGE_IMAGE_FILEAREA", ";", "$", "files", "=", "self", "::", "get_files", "(", "$", "assignment", ",", "$", "userid", ",", "$", "attemptnumber", ",", "$", "filearea", ")", ";", "if", "(", "!", "empty", "(", "$", "files", ")", ")", "{", "foreach", "(", "$", "files", "as", "$", "file", ")", "{", "preg_match", "(", "'/'", ".", "pdf", "::", "IMAGE_PAGE", ".", "'([\\d]+)\\./'", ",", "$", "file", "->", "get_filename", "(", ")", ",", "$", "matches", ")", ";", "if", "(", "empty", "(", "$", "matches", ")", "or", "!", "is_numeric", "(", "$", "matches", "[", "1", "]", ")", ")", "{", "throw", "new", "\\", "coding_exception", "(", "\"'\"", ".", "$", "file", "->", "get_filename", "(", ")", ".", "\"' file hasn't the expected format filename: image_pageXXXX.png.\"", ")", ";", "}", "$", "pagenumber", "=", "(", "int", ")", "$", "matches", "[", "1", "]", ";", "if", "(", "$", "pagenumber", "==", "$", "index", ")", "{", "$", "source", "=", "imagecreatefromstring", "(", "$", "file", "->", "get_content", "(", ")", ")", ";", "$", "pagerotation", "=", "page_editor", "::", "get_page_rotation", "(", "$", "grade", "->", "id", ",", "$", "index", ")", ";", "$", "degree", "=", "empty", "(", "$", "pagerotation", ")", "?", "0", ":", "$", "pagerotation", "->", "degree", ";", "if", "(", "$", "rotateleft", ")", "{", "$", "content", "=", "imagerotate", "(", "$", "source", ",", "90", ",", "0", ")", ";", "$", "degree", "=", "(", "$", "degree", "+", "90", ")", "%", "360", ";", "}", "else", "{", "$", "content", "=", "imagerotate", "(", "$", "source", ",", "-", "90", ",", "0", ")", ";", "$", "degree", "=", "(", "$", "degree", "-", "90", ")", "%", "360", ";", "}", "$", "filename", "=", "$", "matches", "[", "0", "]", ".", "'png'", ";", "$", "tmpdir", "=", "make_temp_directory", "(", "self", "::", "COMPONENT", ".", "'/'", ".", "self", "::", "PAGE_IMAGE_FILEAREA", ".", "'/'", ".", "self", "::", "hash", "(", "$", "assignment", ",", "$", "userid", ",", "$", "attemptnumber", ")", ")", ";", "$", "tempfile", "=", "$", "tmpdir", ".", "'/'", ".", "time", "(", ")", ".", "'_'", ".", "$", "filename", ";", "imagepng", "(", "$", "content", ",", "$", "tempfile", ")", ";", "$", "filearea", "=", "self", "::", "PAGE_IMAGE_FILEAREA", ";", "$", "newfile", "=", "self", "::", "save_file", "(", "$", "assignment", ",", "$", "userid", ",", "$", "attemptnumber", ",", "$", "filearea", ",", "$", "tempfile", ")", ";", "unlink", "(", "$", "tempfile", ")", ";", "rmdir", "(", "$", "tmpdir", ")", ";", "imagedestroy", "(", "$", "source", ")", ";", "imagedestroy", "(", "$", "content", ")", ";", "$", "file", "->", "delete", "(", ")", ";", "if", "(", "!", "empty", "(", "$", "newfile", ")", ")", "{", "page_editor", "::", "set_page_rotation", "(", "$", "grade", "->", "id", ",", "$", "pagenumber", ",", "true", ",", "$", "newfile", "->", "get_pathnamehash", "(", ")", ",", "$", "degree", ")", ";", "}", "return", "$", "newfile", ";", "}", "}", "}", "return", "null", ";", "}" ]
This function rotate a page, and mark the page as rotated. @param int|\assign $assignment Assignment @param int $userid User ID @param int $attemptnumber Attempt Number @param int $index Index of Current Page @param bool $rotateleft To determine whether the page is rotated left or right. @return null|\stored_file return rotated File @throws \coding_exception @throws \file_exception @throws \moodle_exception @throws \stored_file_creation_exception
[ "This", "function", "rotate", "a", "page", "and", "mark", "the", "page", "as", "rotated", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/assign/feedback/editpdf/classes/document_services.php#L917-L969
218,152
moodle/moodle
mod/chat/mod_form.php
mod_chat_mod_form.definition
public function definition() { global $CFG; $mform = $this->_form; $mform->addElement('header', 'general', get_string('general', 'form')); $mform->addElement('text', 'name', get_string('chatname', 'chat'), array('size' => '64')); if (!empty($CFG->formatstringstriptags)) { $mform->setType('name', PARAM_TEXT); } else { $mform->setType('name', PARAM_CLEANHTML); } $mform->addRule('name', null, 'required', null, 'client'); $mform->addRule('name', get_string('maximumchars', '', 255), 'maxlength', 255, 'client'); $this->standard_intro_elements(get_string('chatintro', 'chat')); // Chat sessions. $mform->addElement('header', 'sessionshdr', get_string('sessions', 'chat')); $mform->addElement('date_time_selector', 'chattime', get_string('chattime', 'chat')); $options = array(); $options[0] = get_string('donotusechattime', 'chat'); $options[1] = get_string('repeatnone', 'chat'); $options[2] = get_string('repeatdaily', 'chat'); $options[3] = get_string('repeatweekly', 'chat'); $mform->addElement('select', 'schedule', get_string('repeattimes', 'chat'), $options); $options = array(); $options[0] = get_string('neverdeletemessages', 'chat'); $options[365] = get_string('numdays', '', 365); $options[180] = get_string('numdays', '', 180); $options[150] = get_string('numdays', '', 150); $options[120] = get_string('numdays', '', 120); $options[90] = get_string('numdays', '', 90); $options[60] = get_string('numdays', '', 60); $options[30] = get_string('numdays', '', 30); $options[21] = get_string('numdays', '', 21); $options[14] = get_string('numdays', '', 14); $options[7] = get_string('numdays', '', 7); $options[2] = get_string('numdays', '', 2); $mform->addElement('select', 'keepdays', get_string('savemessages', 'chat'), $options); $mform->addElement('selectyesno', 'studentlogs', get_string('studentseereports', 'chat')); $mform->addHelpButton('studentlogs', 'studentseereports', 'chat'); $this->standard_coursemodule_elements(); $this->add_action_buttons(); }
php
public function definition() { global $CFG; $mform = $this->_form; $mform->addElement('header', 'general', get_string('general', 'form')); $mform->addElement('text', 'name', get_string('chatname', 'chat'), array('size' => '64')); if (!empty($CFG->formatstringstriptags)) { $mform->setType('name', PARAM_TEXT); } else { $mform->setType('name', PARAM_CLEANHTML); } $mform->addRule('name', null, 'required', null, 'client'); $mform->addRule('name', get_string('maximumchars', '', 255), 'maxlength', 255, 'client'); $this->standard_intro_elements(get_string('chatintro', 'chat')); // Chat sessions. $mform->addElement('header', 'sessionshdr', get_string('sessions', 'chat')); $mform->addElement('date_time_selector', 'chattime', get_string('chattime', 'chat')); $options = array(); $options[0] = get_string('donotusechattime', 'chat'); $options[1] = get_string('repeatnone', 'chat'); $options[2] = get_string('repeatdaily', 'chat'); $options[3] = get_string('repeatweekly', 'chat'); $mform->addElement('select', 'schedule', get_string('repeattimes', 'chat'), $options); $options = array(); $options[0] = get_string('neverdeletemessages', 'chat'); $options[365] = get_string('numdays', '', 365); $options[180] = get_string('numdays', '', 180); $options[150] = get_string('numdays', '', 150); $options[120] = get_string('numdays', '', 120); $options[90] = get_string('numdays', '', 90); $options[60] = get_string('numdays', '', 60); $options[30] = get_string('numdays', '', 30); $options[21] = get_string('numdays', '', 21); $options[14] = get_string('numdays', '', 14); $options[7] = get_string('numdays', '', 7); $options[2] = get_string('numdays', '', 2); $mform->addElement('select', 'keepdays', get_string('savemessages', 'chat'), $options); $mform->addElement('selectyesno', 'studentlogs', get_string('studentseereports', 'chat')); $mform->addHelpButton('studentlogs', 'studentseereports', 'chat'); $this->standard_coursemodule_elements(); $this->add_action_buttons(); }
[ "public", "function", "definition", "(", ")", "{", "global", "$", "CFG", ";", "$", "mform", "=", "$", "this", "->", "_form", ";", "$", "mform", "->", "addElement", "(", "'header'", ",", "'general'", ",", "get_string", "(", "'general'", ",", "'form'", ")", ")", ";", "$", "mform", "->", "addElement", "(", "'text'", ",", "'name'", ",", "get_string", "(", "'chatname'", ",", "'chat'", ")", ",", "array", "(", "'size'", "=>", "'64'", ")", ")", ";", "if", "(", "!", "empty", "(", "$", "CFG", "->", "formatstringstriptags", ")", ")", "{", "$", "mform", "->", "setType", "(", "'name'", ",", "PARAM_TEXT", ")", ";", "}", "else", "{", "$", "mform", "->", "setType", "(", "'name'", ",", "PARAM_CLEANHTML", ")", ";", "}", "$", "mform", "->", "addRule", "(", "'name'", ",", "null", ",", "'required'", ",", "null", ",", "'client'", ")", ";", "$", "mform", "->", "addRule", "(", "'name'", ",", "get_string", "(", "'maximumchars'", ",", "''", ",", "255", ")", ",", "'maxlength'", ",", "255", ",", "'client'", ")", ";", "$", "this", "->", "standard_intro_elements", "(", "get_string", "(", "'chatintro'", ",", "'chat'", ")", ")", ";", "// Chat sessions.", "$", "mform", "->", "addElement", "(", "'header'", ",", "'sessionshdr'", ",", "get_string", "(", "'sessions'", ",", "'chat'", ")", ")", ";", "$", "mform", "->", "addElement", "(", "'date_time_selector'", ",", "'chattime'", ",", "get_string", "(", "'chattime'", ",", "'chat'", ")", ")", ";", "$", "options", "=", "array", "(", ")", ";", "$", "options", "[", "0", "]", "=", "get_string", "(", "'donotusechattime'", ",", "'chat'", ")", ";", "$", "options", "[", "1", "]", "=", "get_string", "(", "'repeatnone'", ",", "'chat'", ")", ";", "$", "options", "[", "2", "]", "=", "get_string", "(", "'repeatdaily'", ",", "'chat'", ")", ";", "$", "options", "[", "3", "]", "=", "get_string", "(", "'repeatweekly'", ",", "'chat'", ")", ";", "$", "mform", "->", "addElement", "(", "'select'", ",", "'schedule'", ",", "get_string", "(", "'repeattimes'", ",", "'chat'", ")", ",", "$", "options", ")", ";", "$", "options", "=", "array", "(", ")", ";", "$", "options", "[", "0", "]", "=", "get_string", "(", "'neverdeletemessages'", ",", "'chat'", ")", ";", "$", "options", "[", "365", "]", "=", "get_string", "(", "'numdays'", ",", "''", ",", "365", ")", ";", "$", "options", "[", "180", "]", "=", "get_string", "(", "'numdays'", ",", "''", ",", "180", ")", ";", "$", "options", "[", "150", "]", "=", "get_string", "(", "'numdays'", ",", "''", ",", "150", ")", ";", "$", "options", "[", "120", "]", "=", "get_string", "(", "'numdays'", ",", "''", ",", "120", ")", ";", "$", "options", "[", "90", "]", "=", "get_string", "(", "'numdays'", ",", "''", ",", "90", ")", ";", "$", "options", "[", "60", "]", "=", "get_string", "(", "'numdays'", ",", "''", ",", "60", ")", ";", "$", "options", "[", "30", "]", "=", "get_string", "(", "'numdays'", ",", "''", ",", "30", ")", ";", "$", "options", "[", "21", "]", "=", "get_string", "(", "'numdays'", ",", "''", ",", "21", ")", ";", "$", "options", "[", "14", "]", "=", "get_string", "(", "'numdays'", ",", "''", ",", "14", ")", ";", "$", "options", "[", "7", "]", "=", "get_string", "(", "'numdays'", ",", "''", ",", "7", ")", ";", "$", "options", "[", "2", "]", "=", "get_string", "(", "'numdays'", ",", "''", ",", "2", ")", ";", "$", "mform", "->", "addElement", "(", "'select'", ",", "'keepdays'", ",", "get_string", "(", "'savemessages'", ",", "'chat'", ")", ",", "$", "options", ")", ";", "$", "mform", "->", "addElement", "(", "'selectyesno'", ",", "'studentlogs'", ",", "get_string", "(", "'studentseereports'", ",", "'chat'", ")", ")", ";", "$", "mform", "->", "addHelpButton", "(", "'studentlogs'", ",", "'studentseereports'", ",", "'chat'", ")", ";", "$", "this", "->", "standard_coursemodule_elements", "(", ")", ";", "$", "this", "->", "add_action_buttons", "(", ")", ";", "}" ]
Define the chat activity settings form
[ "Define", "the", "chat", "activity", "settings", "form" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/chat/mod_form.php#L28-L79
218,153
moodle/moodle
mod/workshop/eval/best/lib.php
workshop_best_evaluation.update_grading_grades
public function update_grading_grades(stdclass $settings, $restrict=null) { global $DB; // Remember the recently used settings for this workshop. if (empty($this->settings)) { $record = new stdclass(); $record->workshopid = $this->workshop->id; $record->comparison = $settings->comparison; $DB->insert_record('workshopeval_best_settings', $record); } elseif ($this->settings->comparison != $settings->comparison) { $DB->set_field('workshopeval_best_settings', 'comparison', $settings->comparison, array('workshopid' => $this->workshop->id)); } // Get the grading strategy instance. $grader = $this->workshop->grading_strategy_instance(); // get the information about the assessment dimensions $diminfo = $grader->get_dimensions_info(); // fetch a recordset with all assessments to process $rs = $grader->get_assessments_recordset($restrict); $batch = array(); // will contain a set of all assessments of a single submission $previous = null; // a previous record in the recordset foreach ($rs as $current) { if (is_null($previous)) { // we are processing the very first record in the recordset $previous = $current; } if ($current->submissionid == $previous->submissionid) { $batch[] = $current; } else { // process all the assessments of a single submission $this->process_assessments($batch, $diminfo, $settings); // start with a new batch to be processed $batch = array($current); $previous = $current; } } // do not forget to process the last batch! $this->process_assessments($batch, $diminfo, $settings); $rs->close(); }
php
public function update_grading_grades(stdclass $settings, $restrict=null) { global $DB; // Remember the recently used settings for this workshop. if (empty($this->settings)) { $record = new stdclass(); $record->workshopid = $this->workshop->id; $record->comparison = $settings->comparison; $DB->insert_record('workshopeval_best_settings', $record); } elseif ($this->settings->comparison != $settings->comparison) { $DB->set_field('workshopeval_best_settings', 'comparison', $settings->comparison, array('workshopid' => $this->workshop->id)); } // Get the grading strategy instance. $grader = $this->workshop->grading_strategy_instance(); // get the information about the assessment dimensions $diminfo = $grader->get_dimensions_info(); // fetch a recordset with all assessments to process $rs = $grader->get_assessments_recordset($restrict); $batch = array(); // will contain a set of all assessments of a single submission $previous = null; // a previous record in the recordset foreach ($rs as $current) { if (is_null($previous)) { // we are processing the very first record in the recordset $previous = $current; } if ($current->submissionid == $previous->submissionid) { $batch[] = $current; } else { // process all the assessments of a single submission $this->process_assessments($batch, $diminfo, $settings); // start with a new batch to be processed $batch = array($current); $previous = $current; } } // do not forget to process the last batch! $this->process_assessments($batch, $diminfo, $settings); $rs->close(); }
[ "public", "function", "update_grading_grades", "(", "stdclass", "$", "settings", ",", "$", "restrict", "=", "null", ")", "{", "global", "$", "DB", ";", "// Remember the recently used settings for this workshop.", "if", "(", "empty", "(", "$", "this", "->", "settings", ")", ")", "{", "$", "record", "=", "new", "stdclass", "(", ")", ";", "$", "record", "->", "workshopid", "=", "$", "this", "->", "workshop", "->", "id", ";", "$", "record", "->", "comparison", "=", "$", "settings", "->", "comparison", ";", "$", "DB", "->", "insert_record", "(", "'workshopeval_best_settings'", ",", "$", "record", ")", ";", "}", "elseif", "(", "$", "this", "->", "settings", "->", "comparison", "!=", "$", "settings", "->", "comparison", ")", "{", "$", "DB", "->", "set_field", "(", "'workshopeval_best_settings'", ",", "'comparison'", ",", "$", "settings", "->", "comparison", ",", "array", "(", "'workshopid'", "=>", "$", "this", "->", "workshop", "->", "id", ")", ")", ";", "}", "// Get the grading strategy instance.", "$", "grader", "=", "$", "this", "->", "workshop", "->", "grading_strategy_instance", "(", ")", ";", "// get the information about the assessment dimensions", "$", "diminfo", "=", "$", "grader", "->", "get_dimensions_info", "(", ")", ";", "// fetch a recordset with all assessments to process", "$", "rs", "=", "$", "grader", "->", "get_assessments_recordset", "(", "$", "restrict", ")", ";", "$", "batch", "=", "array", "(", ")", ";", "// will contain a set of all assessments of a single submission", "$", "previous", "=", "null", ";", "// a previous record in the recordset", "foreach", "(", "$", "rs", "as", "$", "current", ")", "{", "if", "(", "is_null", "(", "$", "previous", ")", ")", "{", "// we are processing the very first record in the recordset", "$", "previous", "=", "$", "current", ";", "}", "if", "(", "$", "current", "->", "submissionid", "==", "$", "previous", "->", "submissionid", ")", "{", "$", "batch", "[", "]", "=", "$", "current", ";", "}", "else", "{", "// process all the assessments of a single submission", "$", "this", "->", "process_assessments", "(", "$", "batch", ",", "$", "diminfo", ",", "$", "settings", ")", ";", "// start with a new batch to be processed", "$", "batch", "=", "array", "(", "$", "current", ")", ";", "$", "previous", "=", "$", "current", ";", "}", "}", "// do not forget to process the last batch!", "$", "this", "->", "process_assessments", "(", "$", "batch", ",", "$", "diminfo", ",", "$", "settings", ")", ";", "$", "rs", "->", "close", "(", ")", ";", "}" ]
Calculates the grades for assessment and updates 'gradinggrade' fields in 'workshop_assessments' table This function relies on the grading strategy subplugin providing get_assessments_recordset() method. {@see self::process_assessments()} for the required structure of the recordset. @param stdClass $settings The settings for this round of evaluation @param null|int|array $restrict If null, update all reviewers, otherwise update just grades for the given reviewers(s) @return void
[ "Calculates", "the", "grades", "for", "assessment", "and", "updates", "gradinggrade", "fields", "in", "workshop_assessments", "table" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/workshop/eval/best/lib.php#L67-L109
218,154
moodle/moodle
mod/workshop/eval/best/lib.php
workshop_best_evaluation.process_assessments
protected function process_assessments(array $assessments, array $diminfo, stdclass $settings) { global $DB; if (empty($assessments)) { return; } // reindex the passed flat structure to be indexed by assessmentid $assessments = $this->prepare_data_from_recordset($assessments); // normalize the dimension grades to the interval 0 - 100 $assessments = $this->normalize_grades($assessments, $diminfo); // get a hypothetical average assessment $average = $this->average_assessment($assessments); // if unable to calculate the average assessment, set the grading grades to null if (is_null($average)) { foreach ($assessments as $asid => $assessment) { if (!is_null($assessment->gradinggrade)) { $DB->set_field('workshop_assessments', 'gradinggrade', null, array('id' => $asid)); } } return; } // calculate variance of dimension grades $variances = $this->weighted_variance($assessments); foreach ($variances as $dimid => $variance) { $diminfo[$dimid]->variance = $variance; } // for every assessment, calculate its distance from the average one $distances = array(); foreach ($assessments as $asid => $assessment) { $distances[$asid] = $this->assessments_distance($assessment, $average, $diminfo, $settings); } // identify the best assessments - that is those with the shortest distance from the best assessment $bestids = array_keys($distances, min($distances)); // for every assessment, calculate its distance from the nearest best assessment $distances = array(); foreach ($bestids as $bestid) { $best = $assessments[$bestid]; foreach ($assessments as $asid => $assessment) { $d = $this->assessments_distance($assessment, $best, $diminfo, $settings); if (!is_null($d) and (!isset($distances[$asid]) or $d < $distances[$asid])) { $distances[$asid] = $d; } } } // calculate the grading grade foreach ($distances as $asid => $distance) { $gradinggrade = (100 - $distance); if ($gradinggrade < 0) { $gradinggrade = 0; } if ($gradinggrade > 100) { $gradinggrade = 100; } $grades[$asid] = grade_floatval($gradinggrade); } // if the new grading grade differs from the one stored in database, update it // we do not use set_field() here because we want to pass $bulk param foreach ($grades as $assessmentid => $grade) { if (grade_floats_different($grade, $assessments[$assessmentid]->gradinggrade)) { // the value has changed $record = new stdclass(); $record->id = $assessmentid; $record->gradinggrade = grade_floatval($grade); // do not set timemodified here, it contains the timestamp of when the form was // saved by the peer reviewer, not when it was aggregated $DB->update_record('workshop_assessments', $record, true); // bulk operations expected } } // done. easy, heh? ;-) }
php
protected function process_assessments(array $assessments, array $diminfo, stdclass $settings) { global $DB; if (empty($assessments)) { return; } // reindex the passed flat structure to be indexed by assessmentid $assessments = $this->prepare_data_from_recordset($assessments); // normalize the dimension grades to the interval 0 - 100 $assessments = $this->normalize_grades($assessments, $diminfo); // get a hypothetical average assessment $average = $this->average_assessment($assessments); // if unable to calculate the average assessment, set the grading grades to null if (is_null($average)) { foreach ($assessments as $asid => $assessment) { if (!is_null($assessment->gradinggrade)) { $DB->set_field('workshop_assessments', 'gradinggrade', null, array('id' => $asid)); } } return; } // calculate variance of dimension grades $variances = $this->weighted_variance($assessments); foreach ($variances as $dimid => $variance) { $diminfo[$dimid]->variance = $variance; } // for every assessment, calculate its distance from the average one $distances = array(); foreach ($assessments as $asid => $assessment) { $distances[$asid] = $this->assessments_distance($assessment, $average, $diminfo, $settings); } // identify the best assessments - that is those with the shortest distance from the best assessment $bestids = array_keys($distances, min($distances)); // for every assessment, calculate its distance from the nearest best assessment $distances = array(); foreach ($bestids as $bestid) { $best = $assessments[$bestid]; foreach ($assessments as $asid => $assessment) { $d = $this->assessments_distance($assessment, $best, $diminfo, $settings); if (!is_null($d) and (!isset($distances[$asid]) or $d < $distances[$asid])) { $distances[$asid] = $d; } } } // calculate the grading grade foreach ($distances as $asid => $distance) { $gradinggrade = (100 - $distance); if ($gradinggrade < 0) { $gradinggrade = 0; } if ($gradinggrade > 100) { $gradinggrade = 100; } $grades[$asid] = grade_floatval($gradinggrade); } // if the new grading grade differs from the one stored in database, update it // we do not use set_field() here because we want to pass $bulk param foreach ($grades as $assessmentid => $grade) { if (grade_floats_different($grade, $assessments[$assessmentid]->gradinggrade)) { // the value has changed $record = new stdclass(); $record->id = $assessmentid; $record->gradinggrade = grade_floatval($grade); // do not set timemodified here, it contains the timestamp of when the form was // saved by the peer reviewer, not when it was aggregated $DB->update_record('workshop_assessments', $record, true); // bulk operations expected } } // done. easy, heh? ;-) }
[ "protected", "function", "process_assessments", "(", "array", "$", "assessments", ",", "array", "$", "diminfo", ",", "stdclass", "$", "settings", ")", "{", "global", "$", "DB", ";", "if", "(", "empty", "(", "$", "assessments", ")", ")", "{", "return", ";", "}", "// reindex the passed flat structure to be indexed by assessmentid", "$", "assessments", "=", "$", "this", "->", "prepare_data_from_recordset", "(", "$", "assessments", ")", ";", "// normalize the dimension grades to the interval 0 - 100", "$", "assessments", "=", "$", "this", "->", "normalize_grades", "(", "$", "assessments", ",", "$", "diminfo", ")", ";", "// get a hypothetical average assessment", "$", "average", "=", "$", "this", "->", "average_assessment", "(", "$", "assessments", ")", ";", "// if unable to calculate the average assessment, set the grading grades to null", "if", "(", "is_null", "(", "$", "average", ")", ")", "{", "foreach", "(", "$", "assessments", "as", "$", "asid", "=>", "$", "assessment", ")", "{", "if", "(", "!", "is_null", "(", "$", "assessment", "->", "gradinggrade", ")", ")", "{", "$", "DB", "->", "set_field", "(", "'workshop_assessments'", ",", "'gradinggrade'", ",", "null", ",", "array", "(", "'id'", "=>", "$", "asid", ")", ")", ";", "}", "}", "return", ";", "}", "// calculate variance of dimension grades", "$", "variances", "=", "$", "this", "->", "weighted_variance", "(", "$", "assessments", ")", ";", "foreach", "(", "$", "variances", "as", "$", "dimid", "=>", "$", "variance", ")", "{", "$", "diminfo", "[", "$", "dimid", "]", "->", "variance", "=", "$", "variance", ";", "}", "// for every assessment, calculate its distance from the average one", "$", "distances", "=", "array", "(", ")", ";", "foreach", "(", "$", "assessments", "as", "$", "asid", "=>", "$", "assessment", ")", "{", "$", "distances", "[", "$", "asid", "]", "=", "$", "this", "->", "assessments_distance", "(", "$", "assessment", ",", "$", "average", ",", "$", "diminfo", ",", "$", "settings", ")", ";", "}", "// identify the best assessments - that is those with the shortest distance from the best assessment", "$", "bestids", "=", "array_keys", "(", "$", "distances", ",", "min", "(", "$", "distances", ")", ")", ";", "// for every assessment, calculate its distance from the nearest best assessment", "$", "distances", "=", "array", "(", ")", ";", "foreach", "(", "$", "bestids", "as", "$", "bestid", ")", "{", "$", "best", "=", "$", "assessments", "[", "$", "bestid", "]", ";", "foreach", "(", "$", "assessments", "as", "$", "asid", "=>", "$", "assessment", ")", "{", "$", "d", "=", "$", "this", "->", "assessments_distance", "(", "$", "assessment", ",", "$", "best", ",", "$", "diminfo", ",", "$", "settings", ")", ";", "if", "(", "!", "is_null", "(", "$", "d", ")", "and", "(", "!", "isset", "(", "$", "distances", "[", "$", "asid", "]", ")", "or", "$", "d", "<", "$", "distances", "[", "$", "asid", "]", ")", ")", "{", "$", "distances", "[", "$", "asid", "]", "=", "$", "d", ";", "}", "}", "}", "// calculate the grading grade", "foreach", "(", "$", "distances", "as", "$", "asid", "=>", "$", "distance", ")", "{", "$", "gradinggrade", "=", "(", "100", "-", "$", "distance", ")", ";", "if", "(", "$", "gradinggrade", "<", "0", ")", "{", "$", "gradinggrade", "=", "0", ";", "}", "if", "(", "$", "gradinggrade", ">", "100", ")", "{", "$", "gradinggrade", "=", "100", ";", "}", "$", "grades", "[", "$", "asid", "]", "=", "grade_floatval", "(", "$", "gradinggrade", ")", ";", "}", "// if the new grading grade differs from the one stored in database, update it", "// we do not use set_field() here because we want to pass $bulk param", "foreach", "(", "$", "grades", "as", "$", "assessmentid", "=>", "$", "grade", ")", "{", "if", "(", "grade_floats_different", "(", "$", "grade", ",", "$", "assessments", "[", "$", "assessmentid", "]", "->", "gradinggrade", ")", ")", "{", "// the value has changed", "$", "record", "=", "new", "stdclass", "(", ")", ";", "$", "record", "->", "id", "=", "$", "assessmentid", ";", "$", "record", "->", "gradinggrade", "=", "grade_floatval", "(", "$", "grade", ")", ";", "// do not set timemodified here, it contains the timestamp of when the form was", "// saved by the peer reviewer, not when it was aggregated", "$", "DB", "->", "update_record", "(", "'workshop_assessments'", ",", "$", "record", ",", "true", ")", ";", "// bulk operations expected", "}", "}", "// done. easy, heh? ;-)", "}" ]
Given a list of all assessments of a single submission, updates the grading grades in database @param array $assessments of stdclass (->assessmentid ->assessmentweight ->reviewerid ->gradinggrade ->submissionid ->dimensionid ->grade) @param array $diminfo of stdclass (->id ->weight ->max ->min) @param stdClass grading evaluation settings @return void
[ "Given", "a", "list", "of", "all", "assessments", "of", "a", "single", "submission", "updates", "the", "grading", "grades", "in", "database" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/workshop/eval/best/lib.php#L150-L230
218,155
moodle/moodle
mod/workshop/eval/best/lib.php
workshop_best_evaluation.prepare_data_from_recordset
protected function prepare_data_from_recordset($assessments) { $data = array(); // to be returned foreach ($assessments as $a) { $id = $a->assessmentid; // just an abbreviation if (!isset($data[$id])) { $data[$id] = new stdclass(); $data[$id]->assessmentid = $a->assessmentid; $data[$id]->weight = $a->assessmentweight; $data[$id]->reviewerid = $a->reviewerid; $data[$id]->gradinggrade = $a->gradinggrade; $data[$id]->submissionid = $a->submissionid; $data[$id]->dimgrades = array(); } $data[$id]->dimgrades[$a->dimensionid] = $a->grade; } return $data; }
php
protected function prepare_data_from_recordset($assessments) { $data = array(); // to be returned foreach ($assessments as $a) { $id = $a->assessmentid; // just an abbreviation if (!isset($data[$id])) { $data[$id] = new stdclass(); $data[$id]->assessmentid = $a->assessmentid; $data[$id]->weight = $a->assessmentweight; $data[$id]->reviewerid = $a->reviewerid; $data[$id]->gradinggrade = $a->gradinggrade; $data[$id]->submissionid = $a->submissionid; $data[$id]->dimgrades = array(); } $data[$id]->dimgrades[$a->dimensionid] = $a->grade; } return $data; }
[ "protected", "function", "prepare_data_from_recordset", "(", "$", "assessments", ")", "{", "$", "data", "=", "array", "(", ")", ";", "// to be returned", "foreach", "(", "$", "assessments", "as", "$", "a", ")", "{", "$", "id", "=", "$", "a", "->", "assessmentid", ";", "// just an abbreviation", "if", "(", "!", "isset", "(", "$", "data", "[", "$", "id", "]", ")", ")", "{", "$", "data", "[", "$", "id", "]", "=", "new", "stdclass", "(", ")", ";", "$", "data", "[", "$", "id", "]", "->", "assessmentid", "=", "$", "a", "->", "assessmentid", ";", "$", "data", "[", "$", "id", "]", "->", "weight", "=", "$", "a", "->", "assessmentweight", ";", "$", "data", "[", "$", "id", "]", "->", "reviewerid", "=", "$", "a", "->", "reviewerid", ";", "$", "data", "[", "$", "id", "]", "->", "gradinggrade", "=", "$", "a", "->", "gradinggrade", ";", "$", "data", "[", "$", "id", "]", "->", "submissionid", "=", "$", "a", "->", "submissionid", ";", "$", "data", "[", "$", "id", "]", "->", "dimgrades", "=", "array", "(", ")", ";", "}", "$", "data", "[", "$", "id", "]", "->", "dimgrades", "[", "$", "a", "->", "dimensionid", "]", "=", "$", "a", "->", "grade", ";", "}", "return", "$", "data", ";", "}" ]
Prepares a structure of assessments and given grades @param array $assessments batch of recordset items as returned by the grading strategy @return array
[ "Prepares", "a", "structure", "of", "assessments", "and", "given", "grades" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/workshop/eval/best/lib.php#L238-L254
218,156
moodle/moodle
mod/workshop/eval/best/lib.php
workshop_best_evaluation.normalize_grades
protected function normalize_grades(array $assessments, array $diminfo) { foreach ($assessments as $asid => $assessment) { foreach ($assessment->dimgrades as $dimid => $dimgrade) { $dimmin = $diminfo[$dimid]->min; $dimmax = $diminfo[$dimid]->max; if ($dimmin == $dimmax) { $assessment->dimgrades[$dimid] = grade_floatval($dimmax); } else { $assessment->dimgrades[$dimid] = grade_floatval(($dimgrade - $dimmin) / ($dimmax - $dimmin) * 100); } } } return $assessments; }
php
protected function normalize_grades(array $assessments, array $diminfo) { foreach ($assessments as $asid => $assessment) { foreach ($assessment->dimgrades as $dimid => $dimgrade) { $dimmin = $diminfo[$dimid]->min; $dimmax = $diminfo[$dimid]->max; if ($dimmin == $dimmax) { $assessment->dimgrades[$dimid] = grade_floatval($dimmax); } else { $assessment->dimgrades[$dimid] = grade_floatval(($dimgrade - $dimmin) / ($dimmax - $dimmin) * 100); } } } return $assessments; }
[ "protected", "function", "normalize_grades", "(", "array", "$", "assessments", ",", "array", "$", "diminfo", ")", "{", "foreach", "(", "$", "assessments", "as", "$", "asid", "=>", "$", "assessment", ")", "{", "foreach", "(", "$", "assessment", "->", "dimgrades", "as", "$", "dimid", "=>", "$", "dimgrade", ")", "{", "$", "dimmin", "=", "$", "diminfo", "[", "$", "dimid", "]", "->", "min", ";", "$", "dimmax", "=", "$", "diminfo", "[", "$", "dimid", "]", "->", "max", ";", "if", "(", "$", "dimmin", "==", "$", "dimmax", ")", "{", "$", "assessment", "->", "dimgrades", "[", "$", "dimid", "]", "=", "grade_floatval", "(", "$", "dimmax", ")", ";", "}", "else", "{", "$", "assessment", "->", "dimgrades", "[", "$", "dimid", "]", "=", "grade_floatval", "(", "(", "$", "dimgrade", "-", "$", "dimmin", ")", "/", "(", "$", "dimmax", "-", "$", "dimmin", ")", "*", "100", ")", ";", "}", "}", "}", "return", "$", "assessments", ";", "}" ]
Normalizes the dimension grades to the interval 0.00000 - 100.00000 Note: this heavily relies on PHP5 way of handling references in array of stdclasses. Hopefully it will not change again soon. @param array $assessments of stdclass as returned by {@see self::prepare_data_from_recordset()} @param array $diminfo of stdclass @return array of stdclass with the same structure as $assessments
[ "Normalizes", "the", "dimension", "grades", "to", "the", "interval", "0", ".", "00000", "-", "100", ".", "00000" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/workshop/eval/best/lib.php#L266-L279
218,157
moodle/moodle
mod/workshop/eval/best/lib.php
workshop_best_evaluation.average_assessment
protected function average_assessment(array $assessments) { $sumdimgrades = array(); foreach ($assessments as $a) { foreach ($a->dimgrades as $dimid => $dimgrade) { if (!isset($sumdimgrades[$dimid])) { $sumdimgrades[$dimid] = 0; } $sumdimgrades[$dimid] += $dimgrade * $a->weight; } } $sumweights = 0; foreach ($assessments as $a) { $sumweights += $a->weight; } if ($sumweights == 0) { // unable to calculate average assessment return null; } $average = new stdclass(); $average->dimgrades = array(); foreach ($sumdimgrades as $dimid => $sumdimgrade) { $average->dimgrades[$dimid] = grade_floatval($sumdimgrade / $sumweights); } return $average; }
php
protected function average_assessment(array $assessments) { $sumdimgrades = array(); foreach ($assessments as $a) { foreach ($a->dimgrades as $dimid => $dimgrade) { if (!isset($sumdimgrades[$dimid])) { $sumdimgrades[$dimid] = 0; } $sumdimgrades[$dimid] += $dimgrade * $a->weight; } } $sumweights = 0; foreach ($assessments as $a) { $sumweights += $a->weight; } if ($sumweights == 0) { // unable to calculate average assessment return null; } $average = new stdclass(); $average->dimgrades = array(); foreach ($sumdimgrades as $dimid => $sumdimgrade) { $average->dimgrades[$dimid] = grade_floatval($sumdimgrade / $sumweights); } return $average; }
[ "protected", "function", "average_assessment", "(", "array", "$", "assessments", ")", "{", "$", "sumdimgrades", "=", "array", "(", ")", ";", "foreach", "(", "$", "assessments", "as", "$", "a", ")", "{", "foreach", "(", "$", "a", "->", "dimgrades", "as", "$", "dimid", "=>", "$", "dimgrade", ")", "{", "if", "(", "!", "isset", "(", "$", "sumdimgrades", "[", "$", "dimid", "]", ")", ")", "{", "$", "sumdimgrades", "[", "$", "dimid", "]", "=", "0", ";", "}", "$", "sumdimgrades", "[", "$", "dimid", "]", "+=", "$", "dimgrade", "*", "$", "a", "->", "weight", ";", "}", "}", "$", "sumweights", "=", "0", ";", "foreach", "(", "$", "assessments", "as", "$", "a", ")", "{", "$", "sumweights", "+=", "$", "a", "->", "weight", ";", "}", "if", "(", "$", "sumweights", "==", "0", ")", "{", "// unable to calculate average assessment", "return", "null", ";", "}", "$", "average", "=", "new", "stdclass", "(", ")", ";", "$", "average", "->", "dimgrades", "=", "array", "(", ")", ";", "foreach", "(", "$", "sumdimgrades", "as", "$", "dimid", "=>", "$", "sumdimgrade", ")", "{", "$", "average", "->", "dimgrades", "[", "$", "dimid", "]", "=", "grade_floatval", "(", "$", "sumdimgrade", "/", "$", "sumweights", ")", ";", "}", "return", "$", "average", ";", "}" ]
Given a set of a submission's assessments, returns a hypothetical average assessment The passed structure must be array of assessments objects with ->weight and ->dimgrades properties. Returns null if all passed assessments have zero weight as there is nothing to choose from then. @param array $assessments as prepared by {@link self::prepare_data_from_recordset()} @return null|stdClass
[ "Given", "a", "set", "of", "a", "submission", "s", "assessments", "returns", "a", "hypothetical", "average", "assessment" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/workshop/eval/best/lib.php#L291-L317
218,158
moodle/moodle
mod/workshop/eval/best/lib.php
workshop_best_evaluation.weighted_variance
protected function weighted_variance(array $assessments) { $first = reset($assessments); if (empty($first)) { return null; } $dimids = array_keys($first->dimgrades); $asids = array_keys($assessments); $vars = array(); // to be returned foreach ($dimids as $dimid) { $n = 0; $s = 0; $sumweight = 0; foreach ($asids as $asid) { $x = $assessments[$asid]->dimgrades[$dimid]; // value (data point) $weight = $assessments[$asid]->weight; // the values' weight if ($weight == 0) { continue; } if ($n == 0) { $n = 1; $mean = $x; $s = 0; $sumweight = $weight; } else { $n++; $temp = $weight + $sumweight; $q = $x - $mean; $r = $q * $weight / $temp; $s = $s + $sumweight * $q * $r; $mean = $mean + $r; $sumweight = $temp; } } if ($sumweight > 0 and $n > 1) { // for the sample: $vars[$dimid] = ($s * $n) / (($n - 1) * $sumweight); // for the population: $vars[$dimid] = $s / $sumweight; } else { $vars[$dimid] = null; } } return $vars; }
php
protected function weighted_variance(array $assessments) { $first = reset($assessments); if (empty($first)) { return null; } $dimids = array_keys($first->dimgrades); $asids = array_keys($assessments); $vars = array(); // to be returned foreach ($dimids as $dimid) { $n = 0; $s = 0; $sumweight = 0; foreach ($asids as $asid) { $x = $assessments[$asid]->dimgrades[$dimid]; // value (data point) $weight = $assessments[$asid]->weight; // the values' weight if ($weight == 0) { continue; } if ($n == 0) { $n = 1; $mean = $x; $s = 0; $sumweight = $weight; } else { $n++; $temp = $weight + $sumweight; $q = $x - $mean; $r = $q * $weight / $temp; $s = $s + $sumweight * $q * $r; $mean = $mean + $r; $sumweight = $temp; } } if ($sumweight > 0 and $n > 1) { // for the sample: $vars[$dimid] = ($s * $n) / (($n - 1) * $sumweight); // for the population: $vars[$dimid] = $s / $sumweight; } else { $vars[$dimid] = null; } } return $vars; }
[ "protected", "function", "weighted_variance", "(", "array", "$", "assessments", ")", "{", "$", "first", "=", "reset", "(", "$", "assessments", ")", ";", "if", "(", "empty", "(", "$", "first", ")", ")", "{", "return", "null", ";", "}", "$", "dimids", "=", "array_keys", "(", "$", "first", "->", "dimgrades", ")", ";", "$", "asids", "=", "array_keys", "(", "$", "assessments", ")", ";", "$", "vars", "=", "array", "(", ")", ";", "// to be returned", "foreach", "(", "$", "dimids", "as", "$", "dimid", ")", "{", "$", "n", "=", "0", ";", "$", "s", "=", "0", ";", "$", "sumweight", "=", "0", ";", "foreach", "(", "$", "asids", "as", "$", "asid", ")", "{", "$", "x", "=", "$", "assessments", "[", "$", "asid", "]", "->", "dimgrades", "[", "$", "dimid", "]", ";", "// value (data point)", "$", "weight", "=", "$", "assessments", "[", "$", "asid", "]", "->", "weight", ";", "// the values' weight", "if", "(", "$", "weight", "==", "0", ")", "{", "continue", ";", "}", "if", "(", "$", "n", "==", "0", ")", "{", "$", "n", "=", "1", ";", "$", "mean", "=", "$", "x", ";", "$", "s", "=", "0", ";", "$", "sumweight", "=", "$", "weight", ";", "}", "else", "{", "$", "n", "++", ";", "$", "temp", "=", "$", "weight", "+", "$", "sumweight", ";", "$", "q", "=", "$", "x", "-", "$", "mean", ";", "$", "r", "=", "$", "q", "*", "$", "weight", "/", "$", "temp", ";", "$", "s", "=", "$", "s", "+", "$", "sumweight", "*", "$", "q", "*", "$", "r", ";", "$", "mean", "=", "$", "mean", "+", "$", "r", ";", "$", "sumweight", "=", "$", "temp", ";", "}", "}", "if", "(", "$", "sumweight", ">", "0", "and", "$", "n", ">", "1", ")", "{", "// for the sample: $vars[$dimid] = ($s * $n) / (($n - 1) * $sumweight);", "// for the population:", "$", "vars", "[", "$", "dimid", "]", "=", "$", "s", "/", "$", "sumweight", ";", "}", "else", "{", "$", "vars", "[", "$", "dimid", "]", "=", "null", ";", "}", "}", "return", "$", "vars", ";", "}" ]
Given a set of a submission's assessments, returns standard deviations of all their dimensions The passed structure must be array of assessments objects with at least ->weight and ->dimgrades properties. This implementation uses weighted incremental algorithm as suggested in "D. H. D. West (1979). Communications of the ACM, 22, 9, 532-535: Updating Mean and Variance Estimates: An Improved Method" {@link http://en.wikipedia.org/wiki/Algorithms_for_calculating_variance#Weighted_incremental_algorithm} @param array $assessments as prepared by {@link self::prepare_data_from_recordset()} @return null|array indexed by dimension id
[ "Given", "a", "set", "of", "a", "submission", "s", "assessments", "returns", "standard", "deviations", "of", "all", "their", "dimensions" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/workshop/eval/best/lib.php#L331-L373
218,159
moodle/moodle
mod/workshop/eval/best/lib.php
workshop_best_evaluation.assessments_distance
protected function assessments_distance(stdclass $assessment, stdclass $referential, array $diminfo, stdclass $settings) { $distance = 0; $n = 0; foreach (array_keys($assessment->dimgrades) as $dimid) { $agrade = $assessment->dimgrades[$dimid]; $rgrade = $referential->dimgrades[$dimid]; $var = $diminfo[$dimid]->variance; $weight = $diminfo[$dimid]->weight; $n += $weight; // variations very close to zero are too sensitive to a small change of data values $var = max($var, 0.01); if ($agrade != $rgrade) { $absdelta = abs($agrade - $rgrade); $reldelta = pow($agrade - $rgrade, 2) / ($settings->comparison * $var); $distance += $absdelta * $reldelta * $weight; } } if ($n > 0) { // average distance across all dimensions return round($distance / $n, 4); } else { return null; } }
php
protected function assessments_distance(stdclass $assessment, stdclass $referential, array $diminfo, stdclass $settings) { $distance = 0; $n = 0; foreach (array_keys($assessment->dimgrades) as $dimid) { $agrade = $assessment->dimgrades[$dimid]; $rgrade = $referential->dimgrades[$dimid]; $var = $diminfo[$dimid]->variance; $weight = $diminfo[$dimid]->weight; $n += $weight; // variations very close to zero are too sensitive to a small change of data values $var = max($var, 0.01); if ($agrade != $rgrade) { $absdelta = abs($agrade - $rgrade); $reldelta = pow($agrade - $rgrade, 2) / ($settings->comparison * $var); $distance += $absdelta * $reldelta * $weight; } } if ($n > 0) { // average distance across all dimensions return round($distance / $n, 4); } else { return null; } }
[ "protected", "function", "assessments_distance", "(", "stdclass", "$", "assessment", ",", "stdclass", "$", "referential", ",", "array", "$", "diminfo", ",", "stdclass", "$", "settings", ")", "{", "$", "distance", "=", "0", ";", "$", "n", "=", "0", ";", "foreach", "(", "array_keys", "(", "$", "assessment", "->", "dimgrades", ")", "as", "$", "dimid", ")", "{", "$", "agrade", "=", "$", "assessment", "->", "dimgrades", "[", "$", "dimid", "]", ";", "$", "rgrade", "=", "$", "referential", "->", "dimgrades", "[", "$", "dimid", "]", ";", "$", "var", "=", "$", "diminfo", "[", "$", "dimid", "]", "->", "variance", ";", "$", "weight", "=", "$", "diminfo", "[", "$", "dimid", "]", "->", "weight", ";", "$", "n", "+=", "$", "weight", ";", "// variations very close to zero are too sensitive to a small change of data values", "$", "var", "=", "max", "(", "$", "var", ",", "0.01", ")", ";", "if", "(", "$", "agrade", "!=", "$", "rgrade", ")", "{", "$", "absdelta", "=", "abs", "(", "$", "agrade", "-", "$", "rgrade", ")", ";", "$", "reldelta", "=", "pow", "(", "$", "agrade", "-", "$", "rgrade", ",", "2", ")", "/", "(", "$", "settings", "->", "comparison", "*", "$", "var", ")", ";", "$", "distance", "+=", "$", "absdelta", "*", "$", "reldelta", "*", "$", "weight", ";", "}", "}", "if", "(", "$", "n", ">", "0", ")", "{", "// average distance across all dimensions", "return", "round", "(", "$", "distance", "/", "$", "n", ",", "4", ")", ";", "}", "else", "{", "return", "null", ";", "}", "}" ]
Measures the distance of the assessment from a referential one The passed data structures must contain ->dimgrades property. The referential assessment is supposed to be close to the average assessment. All dimension grades are supposed to be normalized to the interval 0 - 100. Returned value is rounded to 4 valid decimals to prevent some rounding issues - see the unit test for an example. @param stdClass $assessment the assessment being measured @param stdClass $referential assessment @param array $diminfo of stdclass(->weight ->min ->max ->variance) indexed by dimension id @param stdClass $settings @return float|null rounded to 4 valid decimals
[ "Measures", "the", "distance", "of", "the", "assessment", "from", "a", "referential", "one" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/workshop/eval/best/lib.php#L390-L415
218,160
moodle/moodle
mod/workshop/eval/best/lib.php
workshop_best_evaluation_settings_form.definition_sub
protected function definition_sub() { $mform = $this->_form; $plugindefaults = get_config('workshopeval_best'); $current = $this->_customdata['current']; $options = array(); for ($i = 9; $i >= 1; $i = $i-2) { $options[$i] = get_string('comparisonlevel' . $i, 'workshopeval_best'); } $mform->addElement('select', 'comparison', get_string('comparison', 'workshopeval_best'), $options); $mform->addHelpButton('comparison', 'comparison', 'workshopeval_best'); $mform->setDefault('comparison', $plugindefaults->comparison); $this->set_data($current); }
php
protected function definition_sub() { $mform = $this->_form; $plugindefaults = get_config('workshopeval_best'); $current = $this->_customdata['current']; $options = array(); for ($i = 9; $i >= 1; $i = $i-2) { $options[$i] = get_string('comparisonlevel' . $i, 'workshopeval_best'); } $mform->addElement('select', 'comparison', get_string('comparison', 'workshopeval_best'), $options); $mform->addHelpButton('comparison', 'comparison', 'workshopeval_best'); $mform->setDefault('comparison', $plugindefaults->comparison); $this->set_data($current); }
[ "protected", "function", "definition_sub", "(", ")", "{", "$", "mform", "=", "$", "this", "->", "_form", ";", "$", "plugindefaults", "=", "get_config", "(", "'workshopeval_best'", ")", ";", "$", "current", "=", "$", "this", "->", "_customdata", "[", "'current'", "]", ";", "$", "options", "=", "array", "(", ")", ";", "for", "(", "$", "i", "=", "9", ";", "$", "i", ">=", "1", ";", "$", "i", "=", "$", "i", "-", "2", ")", "{", "$", "options", "[", "$", "i", "]", "=", "get_string", "(", "'comparisonlevel'", ".", "$", "i", ",", "'workshopeval_best'", ")", ";", "}", "$", "mform", "->", "addElement", "(", "'select'", ",", "'comparison'", ",", "get_string", "(", "'comparison'", ",", "'workshopeval_best'", ")", ",", "$", "options", ")", ";", "$", "mform", "->", "addHelpButton", "(", "'comparison'", ",", "'comparison'", ",", "'workshopeval_best'", ")", ";", "$", "mform", "->", "setDefault", "(", "'comparison'", ",", "$", "plugindefaults", "->", "comparison", ")", ";", "$", "this", "->", "set_data", "(", "$", "current", ")", ";", "}" ]
Defines specific fields for this evaluation method.
[ "Defines", "specific", "fields", "for", "this", "evaluation", "method", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/workshop/eval/best/lib.php#L427-L442
218,161
moodle/moodle
mod/workshop/classes/task/cron_task.php
cron_task.execute
public function execute() { global $CFG, $DB; $now = time(); mtrace(' processing workshop subplugins ...'); // Now when the scheduled allocator had a chance to do its job. // Check if there are some workshops to switch into the assessment phase. $workshops = $DB->get_records_select("workshop", "phase = 20 AND phaseswitchassessment = 1 AND submissionend > 0 AND submissionend < ?", [$now]); if (!empty($workshops)) { mtrace('Processing automatic assessment phase switch in ' . count($workshops) . ' workshop(s) ... ', ''); require_once($CFG->dirroot . '/mod/workshop/locallib.php'); foreach ($workshops as $workshop) { $cm = get_coursemodule_from_instance('workshop', $workshop->id, $workshop->course, false, MUST_EXIST); $course = $DB->get_record('course', ['id' => $cm->course], '*', MUST_EXIST); $workshop = new \workshop($workshop, $cm, $course); $workshop->switch_phase(workshop::PHASE_ASSESSMENT); $params = [ 'objectid' => $workshop->id, 'context' => $workshop->context, 'courseid' => $workshop->course->id, 'other' => [ 'workshopphase' => $workshop->phase ] ]; $event = \mod_workshop\event\phase_switched::create($params); $event->trigger(); // Disable the automatic switching now so that it is not executed again by accident. // That can happen if the teacher changes the phase back to the submission one. $DB->set_field('workshop', 'phaseswitchassessment', 0, ['id' => $workshop->id]); } mtrace('done'); } }
php
public function execute() { global $CFG, $DB; $now = time(); mtrace(' processing workshop subplugins ...'); // Now when the scheduled allocator had a chance to do its job. // Check if there are some workshops to switch into the assessment phase. $workshops = $DB->get_records_select("workshop", "phase = 20 AND phaseswitchassessment = 1 AND submissionend > 0 AND submissionend < ?", [$now]); if (!empty($workshops)) { mtrace('Processing automatic assessment phase switch in ' . count($workshops) . ' workshop(s) ... ', ''); require_once($CFG->dirroot . '/mod/workshop/locallib.php'); foreach ($workshops as $workshop) { $cm = get_coursemodule_from_instance('workshop', $workshop->id, $workshop->course, false, MUST_EXIST); $course = $DB->get_record('course', ['id' => $cm->course], '*', MUST_EXIST); $workshop = new \workshop($workshop, $cm, $course); $workshop->switch_phase(workshop::PHASE_ASSESSMENT); $params = [ 'objectid' => $workshop->id, 'context' => $workshop->context, 'courseid' => $workshop->course->id, 'other' => [ 'workshopphase' => $workshop->phase ] ]; $event = \mod_workshop\event\phase_switched::create($params); $event->trigger(); // Disable the automatic switching now so that it is not executed again by accident. // That can happen if the teacher changes the phase back to the submission one. $DB->set_field('workshop', 'phaseswitchassessment', 0, ['id' => $workshop->id]); } mtrace('done'); } }
[ "public", "function", "execute", "(", ")", "{", "global", "$", "CFG", ",", "$", "DB", ";", "$", "now", "=", "time", "(", ")", ";", "mtrace", "(", "' processing workshop subplugins ...'", ")", ";", "// Now when the scheduled allocator had a chance to do its job.", "// Check if there are some workshops to switch into the assessment phase.", "$", "workshops", "=", "$", "DB", "->", "get_records_select", "(", "\"workshop\"", ",", "\"phase = 20 AND phaseswitchassessment = 1 AND submissionend > 0 AND submissionend < ?\"", ",", "[", "$", "now", "]", ")", ";", "if", "(", "!", "empty", "(", "$", "workshops", ")", ")", "{", "mtrace", "(", "'Processing automatic assessment phase switch in '", ".", "count", "(", "$", "workshops", ")", ".", "' workshop(s) ... '", ",", "''", ")", ";", "require_once", "(", "$", "CFG", "->", "dirroot", ".", "'/mod/workshop/locallib.php'", ")", ";", "foreach", "(", "$", "workshops", "as", "$", "workshop", ")", "{", "$", "cm", "=", "get_coursemodule_from_instance", "(", "'workshop'", ",", "$", "workshop", "->", "id", ",", "$", "workshop", "->", "course", ",", "false", ",", "MUST_EXIST", ")", ";", "$", "course", "=", "$", "DB", "->", "get_record", "(", "'course'", ",", "[", "'id'", "=>", "$", "cm", "->", "course", "]", ",", "'*'", ",", "MUST_EXIST", ")", ";", "$", "workshop", "=", "new", "\\", "workshop", "(", "$", "workshop", ",", "$", "cm", ",", "$", "course", ")", ";", "$", "workshop", "->", "switch_phase", "(", "workshop", "::", "PHASE_ASSESSMENT", ")", ";", "$", "params", "=", "[", "'objectid'", "=>", "$", "workshop", "->", "id", ",", "'context'", "=>", "$", "workshop", "->", "context", ",", "'courseid'", "=>", "$", "workshop", "->", "course", "->", "id", ",", "'other'", "=>", "[", "'workshopphase'", "=>", "$", "workshop", "->", "phase", "]", "]", ";", "$", "event", "=", "\\", "mod_workshop", "\\", "event", "\\", "phase_switched", "::", "create", "(", "$", "params", ")", ";", "$", "event", "->", "trigger", "(", ")", ";", "// Disable the automatic switching now so that it is not executed again by accident.", "// That can happen if the teacher changes the phase back to the submission one.", "$", "DB", "->", "set_field", "(", "'workshop'", ",", "'phaseswitchassessment'", ",", "0", ",", "[", "'id'", "=>", "$", "workshop", "->", "id", "]", ")", ";", "}", "mtrace", "(", "'done'", ")", ";", "}", "}" ]
Run workshop cron.
[ "Run", "workshop", "cron", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/workshop/classes/task/cron_task.php#L49-L87
218,162
moodle/moodle
mod/assignment/backup/moodle1/lib.php
moodle1_mod_assignment_handler.get_subplugin_handler
protected function get_subplugin_handler($subplugin) { global $CFG; // we include other files here if (is_null($this->subpluginhandlers)) { $this->subpluginhandlers = array(); $subplugins = core_component::get_plugin_list('assignment'); foreach ($subplugins as $name => $dir) { $handlerfile = $dir.'/backup/moodle1/lib.php'; $handlerclass = "moodle1_mod_assignment_{$name}_subplugin_handler"; if (!file_exists($handlerfile)) { continue; } require_once($handlerfile); if (!class_exists($handlerclass)) { throw new moodle1_convert_exception('missing_handler_class', $handlerclass); } $this->log('preparing assignment subplugin handler', backup::LOG_DEBUG, $handlerclass); $this->subpluginhandlers[$name] = new $handlerclass($this, $name); if (!$this->subpluginhandlers[$name] instanceof moodle1_assignment_subplugin_handler) { throw new moodle1_convert_exception('wrong_handler_class', get_class($this->subpluginhandlers[$name])); } } } if (!isset($this->subpluginhandlers[$subplugin])) { // Generic handling, prevents breaking conversion process... $this->subpluginhandlers[$subplugin] = new moodle1_assignment_unsupported_subplugin_handler($this, $subplugin); } return $this->subpluginhandlers[$subplugin]; }
php
protected function get_subplugin_handler($subplugin) { global $CFG; // we include other files here if (is_null($this->subpluginhandlers)) { $this->subpluginhandlers = array(); $subplugins = core_component::get_plugin_list('assignment'); foreach ($subplugins as $name => $dir) { $handlerfile = $dir.'/backup/moodle1/lib.php'; $handlerclass = "moodle1_mod_assignment_{$name}_subplugin_handler"; if (!file_exists($handlerfile)) { continue; } require_once($handlerfile); if (!class_exists($handlerclass)) { throw new moodle1_convert_exception('missing_handler_class', $handlerclass); } $this->log('preparing assignment subplugin handler', backup::LOG_DEBUG, $handlerclass); $this->subpluginhandlers[$name] = new $handlerclass($this, $name); if (!$this->subpluginhandlers[$name] instanceof moodle1_assignment_subplugin_handler) { throw new moodle1_convert_exception('wrong_handler_class', get_class($this->subpluginhandlers[$name])); } } } if (!isset($this->subpluginhandlers[$subplugin])) { // Generic handling, prevents breaking conversion process... $this->subpluginhandlers[$subplugin] = new moodle1_assignment_unsupported_subplugin_handler($this, $subplugin); } return $this->subpluginhandlers[$subplugin]; }
[ "protected", "function", "get_subplugin_handler", "(", "$", "subplugin", ")", "{", "global", "$", "CFG", ";", "// we include other files here", "if", "(", "is_null", "(", "$", "this", "->", "subpluginhandlers", ")", ")", "{", "$", "this", "->", "subpluginhandlers", "=", "array", "(", ")", ";", "$", "subplugins", "=", "core_component", "::", "get_plugin_list", "(", "'assignment'", ")", ";", "foreach", "(", "$", "subplugins", "as", "$", "name", "=>", "$", "dir", ")", "{", "$", "handlerfile", "=", "$", "dir", ".", "'/backup/moodle1/lib.php'", ";", "$", "handlerclass", "=", "\"moodle1_mod_assignment_{$name}_subplugin_handler\"", ";", "if", "(", "!", "file_exists", "(", "$", "handlerfile", ")", ")", "{", "continue", ";", "}", "require_once", "(", "$", "handlerfile", ")", ";", "if", "(", "!", "class_exists", "(", "$", "handlerclass", ")", ")", "{", "throw", "new", "moodle1_convert_exception", "(", "'missing_handler_class'", ",", "$", "handlerclass", ")", ";", "}", "$", "this", "->", "log", "(", "'preparing assignment subplugin handler'", ",", "backup", "::", "LOG_DEBUG", ",", "$", "handlerclass", ")", ";", "$", "this", "->", "subpluginhandlers", "[", "$", "name", "]", "=", "new", "$", "handlerclass", "(", "$", "this", ",", "$", "name", ")", ";", "if", "(", "!", "$", "this", "->", "subpluginhandlers", "[", "$", "name", "]", "instanceof", "moodle1_assignment_subplugin_handler", ")", "{", "throw", "new", "moodle1_convert_exception", "(", "'wrong_handler_class'", ",", "get_class", "(", "$", "this", "->", "subpluginhandlers", "[", "$", "name", "]", ")", ")", ";", "}", "}", "}", "if", "(", "!", "isset", "(", "$", "this", "->", "subpluginhandlers", "[", "$", "subplugin", "]", ")", ")", "{", "// Generic handling, prevents breaking conversion process...", "$", "this", "->", "subpluginhandlers", "[", "$", "subplugin", "]", "=", "new", "moodle1_assignment_unsupported_subplugin_handler", "(", "$", "this", ",", "$", "subplugin", ")", ";", "}", "return", "$", "this", "->", "subpluginhandlers", "[", "$", "subplugin", "]", ";", "}" ]
Factory method returning the handler of the given assignment subplugin @param string $subplugin the name of the subplugin @throws moodle1_convert_exception @return moodle1_assignment_subplugin_handler the instance of the handler
[ "Factory", "method", "returning", "the", "handler", "of", "the", "given", "assignment", "subplugin" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/assignment/backup/moodle1/lib.php#L178-L209
218,163
moodle/moodle
admin/roles/classes/preset_form.php
core_role_preset_form.definition
protected function definition() { $mform = $this->_form; $data = $this->_customdata; $options = array(); $group = get_string('other'); $options[$group] = array(); $options[$group][0] = get_string('norole', 'core_role'); $group = get_string('role', 'core'); $options[$group] = array(); foreach (role_get_names(null, ROLENAME_BOTH) as $role) { // Allow reset to self too, it may be useful when importing incomplete XML preset. $options[$group][$role->id] = $role->localname; } $group = get_string('archetype', 'core_role'); $options[$group] = array(); foreach (get_role_archetypes() as $type) { $options[$group][$type] = get_string('archetype'.$type, 'core_role'); } $mform->addElement('header', 'presetheader', get_string('roleresetdefaults', 'core_role')); $mform->addElement('selectgroups', 'resettype', get_string('roleresetrole', 'core_role'), $options); $mform->addElement('filepicker', 'rolepreset', get_string('rolerepreset', 'core_role')); if ($data['roleid']) { $mform->addElement('header', 'resetheader', get_string('resetrole', 'core_role')); $mform->addElement('advcheckbox', 'shortname', get_string('roleshortname', 'core_role')); $mform->addElement('advcheckbox', 'name', get_string('customrolename', 'core_role')); $mform->addElement('advcheckbox', 'description', get_string('customroledescription', 'core_role')); $mform->addElement('advcheckbox', 'archetype', get_string('archetype', 'core_role')); $mform->addElement('advcheckbox', 'contextlevels', get_string('maybeassignedin', 'core_role')); $mform->addElement('advcheckbox', 'allowassign', get_string('allowassign', 'core_role')); $mform->addElement('advcheckbox', 'allowoverride', get_string('allowoverride', 'core_role')); $mform->addElement('advcheckbox', 'allowswitch', get_string('allowswitch', 'core_role')); $mform->addElement('advcheckbox', 'allowview', get_string('allowview', 'core_role')); $mform->addElement('advcheckbox', 'permissions', get_string('permissions', 'core_role')); } $mform->addElement('hidden', 'roleid'); $mform->setType('roleid', PARAM_INT); $mform->addElement('hidden', 'action'); $mform->setType('action', PARAM_ALPHA); $mform->addElement('hidden', 'return'); $mform->setType('return', PARAM_ALPHA); $this->add_action_buttons(true, get_string('continue', 'core')); $this->set_data($data); }
php
protected function definition() { $mform = $this->_form; $data = $this->_customdata; $options = array(); $group = get_string('other'); $options[$group] = array(); $options[$group][0] = get_string('norole', 'core_role'); $group = get_string('role', 'core'); $options[$group] = array(); foreach (role_get_names(null, ROLENAME_BOTH) as $role) { // Allow reset to self too, it may be useful when importing incomplete XML preset. $options[$group][$role->id] = $role->localname; } $group = get_string('archetype', 'core_role'); $options[$group] = array(); foreach (get_role_archetypes() as $type) { $options[$group][$type] = get_string('archetype'.$type, 'core_role'); } $mform->addElement('header', 'presetheader', get_string('roleresetdefaults', 'core_role')); $mform->addElement('selectgroups', 'resettype', get_string('roleresetrole', 'core_role'), $options); $mform->addElement('filepicker', 'rolepreset', get_string('rolerepreset', 'core_role')); if ($data['roleid']) { $mform->addElement('header', 'resetheader', get_string('resetrole', 'core_role')); $mform->addElement('advcheckbox', 'shortname', get_string('roleshortname', 'core_role')); $mform->addElement('advcheckbox', 'name', get_string('customrolename', 'core_role')); $mform->addElement('advcheckbox', 'description', get_string('customroledescription', 'core_role')); $mform->addElement('advcheckbox', 'archetype', get_string('archetype', 'core_role')); $mform->addElement('advcheckbox', 'contextlevels', get_string('maybeassignedin', 'core_role')); $mform->addElement('advcheckbox', 'allowassign', get_string('allowassign', 'core_role')); $mform->addElement('advcheckbox', 'allowoverride', get_string('allowoverride', 'core_role')); $mform->addElement('advcheckbox', 'allowswitch', get_string('allowswitch', 'core_role')); $mform->addElement('advcheckbox', 'allowview', get_string('allowview', 'core_role')); $mform->addElement('advcheckbox', 'permissions', get_string('permissions', 'core_role')); } $mform->addElement('hidden', 'roleid'); $mform->setType('roleid', PARAM_INT); $mform->addElement('hidden', 'action'); $mform->setType('action', PARAM_ALPHA); $mform->addElement('hidden', 'return'); $mform->setType('return', PARAM_ALPHA); $this->add_action_buttons(true, get_string('continue', 'core')); $this->set_data($data); }
[ "protected", "function", "definition", "(", ")", "{", "$", "mform", "=", "$", "this", "->", "_form", ";", "$", "data", "=", "$", "this", "->", "_customdata", ";", "$", "options", "=", "array", "(", ")", ";", "$", "group", "=", "get_string", "(", "'other'", ")", ";", "$", "options", "[", "$", "group", "]", "=", "array", "(", ")", ";", "$", "options", "[", "$", "group", "]", "[", "0", "]", "=", "get_string", "(", "'norole'", ",", "'core_role'", ")", ";", "$", "group", "=", "get_string", "(", "'role'", ",", "'core'", ")", ";", "$", "options", "[", "$", "group", "]", "=", "array", "(", ")", ";", "foreach", "(", "role_get_names", "(", "null", ",", "ROLENAME_BOTH", ")", "as", "$", "role", ")", "{", "// Allow reset to self too, it may be useful when importing incomplete XML preset.", "$", "options", "[", "$", "group", "]", "[", "$", "role", "->", "id", "]", "=", "$", "role", "->", "localname", ";", "}", "$", "group", "=", "get_string", "(", "'archetype'", ",", "'core_role'", ")", ";", "$", "options", "[", "$", "group", "]", "=", "array", "(", ")", ";", "foreach", "(", "get_role_archetypes", "(", ")", "as", "$", "type", ")", "{", "$", "options", "[", "$", "group", "]", "[", "$", "type", "]", "=", "get_string", "(", "'archetype'", ".", "$", "type", ",", "'core_role'", ")", ";", "}", "$", "mform", "->", "addElement", "(", "'header'", ",", "'presetheader'", ",", "get_string", "(", "'roleresetdefaults'", ",", "'core_role'", ")", ")", ";", "$", "mform", "->", "addElement", "(", "'selectgroups'", ",", "'resettype'", ",", "get_string", "(", "'roleresetrole'", ",", "'core_role'", ")", ",", "$", "options", ")", ";", "$", "mform", "->", "addElement", "(", "'filepicker'", ",", "'rolepreset'", ",", "get_string", "(", "'rolerepreset'", ",", "'core_role'", ")", ")", ";", "if", "(", "$", "data", "[", "'roleid'", "]", ")", "{", "$", "mform", "->", "addElement", "(", "'header'", ",", "'resetheader'", ",", "get_string", "(", "'resetrole'", ",", "'core_role'", ")", ")", ";", "$", "mform", "->", "addElement", "(", "'advcheckbox'", ",", "'shortname'", ",", "get_string", "(", "'roleshortname'", ",", "'core_role'", ")", ")", ";", "$", "mform", "->", "addElement", "(", "'advcheckbox'", ",", "'name'", ",", "get_string", "(", "'customrolename'", ",", "'core_role'", ")", ")", ";", "$", "mform", "->", "addElement", "(", "'advcheckbox'", ",", "'description'", ",", "get_string", "(", "'customroledescription'", ",", "'core_role'", ")", ")", ";", "$", "mform", "->", "addElement", "(", "'advcheckbox'", ",", "'archetype'", ",", "get_string", "(", "'archetype'", ",", "'core_role'", ")", ")", ";", "$", "mform", "->", "addElement", "(", "'advcheckbox'", ",", "'contextlevels'", ",", "get_string", "(", "'maybeassignedin'", ",", "'core_role'", ")", ")", ";", "$", "mform", "->", "addElement", "(", "'advcheckbox'", ",", "'allowassign'", ",", "get_string", "(", "'allowassign'", ",", "'core_role'", ")", ")", ";", "$", "mform", "->", "addElement", "(", "'advcheckbox'", ",", "'allowoverride'", ",", "get_string", "(", "'allowoverride'", ",", "'core_role'", ")", ")", ";", "$", "mform", "->", "addElement", "(", "'advcheckbox'", ",", "'allowswitch'", ",", "get_string", "(", "'allowswitch'", ",", "'core_role'", ")", ")", ";", "$", "mform", "->", "addElement", "(", "'advcheckbox'", ",", "'allowview'", ",", "get_string", "(", "'allowview'", ",", "'core_role'", ")", ")", ";", "$", "mform", "->", "addElement", "(", "'advcheckbox'", ",", "'permissions'", ",", "get_string", "(", "'permissions'", ",", "'core_role'", ")", ")", ";", "}", "$", "mform", "->", "addElement", "(", "'hidden'", ",", "'roleid'", ")", ";", "$", "mform", "->", "setType", "(", "'roleid'", ",", "PARAM_INT", ")", ";", "$", "mform", "->", "addElement", "(", "'hidden'", ",", "'action'", ")", ";", "$", "mform", "->", "setType", "(", "'action'", ",", "PARAM_ALPHA", ")", ";", "$", "mform", "->", "addElement", "(", "'hidden'", ",", "'return'", ")", ";", "$", "mform", "->", "setType", "(", "'return'", ",", "PARAM_ALPHA", ")", ";", "$", "this", "->", "add_action_buttons", "(", "true", ",", "get_string", "(", "'continue'", ",", "'core'", ")", ")", ";", "$", "this", "->", "set_data", "(", "$", "data", ")", ";", "}" ]
Definition of this form.
[ "Definition", "of", "this", "form", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/roles/classes/preset_form.php#L42-L98
218,164
moodle/moodle
admin/roles/classes/preset_form.php
core_role_preset_form.validation
public function validation($data, $files) { $errors = parent::validation($data, $files); if ($files = $this->get_draft_files('rolepreset')) { /** @var stored_file $file */ $file = reset($files); $xml = $file->get_content(); if (!core_role_preset::is_valid_preset($xml)) { $errors['rolepreset'] = get_string('invalidpresetfile', 'core_role'); } } return $errors; }
php
public function validation($data, $files) { $errors = parent::validation($data, $files); if ($files = $this->get_draft_files('rolepreset')) { /** @var stored_file $file */ $file = reset($files); $xml = $file->get_content(); if (!core_role_preset::is_valid_preset($xml)) { $errors['rolepreset'] = get_string('invalidpresetfile', 'core_role'); } } return $errors; }
[ "public", "function", "validation", "(", "$", "data", ",", "$", "files", ")", "{", "$", "errors", "=", "parent", "::", "validation", "(", "$", "data", ",", "$", "files", ")", ";", "if", "(", "$", "files", "=", "$", "this", "->", "get_draft_files", "(", "'rolepreset'", ")", ")", "{", "/** @var stored_file $file */", "$", "file", "=", "reset", "(", "$", "files", ")", ";", "$", "xml", "=", "$", "file", "->", "get_content", "(", ")", ";", "if", "(", "!", "core_role_preset", "::", "is_valid_preset", "(", "$", "xml", ")", ")", "{", "$", "errors", "[", "'rolepreset'", "]", "=", "get_string", "(", "'invalidpresetfile'", ",", "'core_role'", ")", ";", "}", "}", "return", "$", "errors", ";", "}" ]
Validate this form. @param array $data submitted data @param array $files not used @return array errors
[ "Validate", "this", "form", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/roles/classes/preset_form.php#L107-L120
218,165
moodle/moodle
files/renderer.php
core_files_renderer.render_form_filemanager
public function render_form_filemanager($fm) { $html = $this->fm_print_generallayout($fm); $module = array( 'name'=>'form_filemanager', 'fullpath'=>'/lib/form/filemanager.js', 'requires' => array('moodle-core-notification-dialogue', 'core_filepicker', 'base', 'io-base', 'node', 'json', 'core_dndupload', 'panel', 'resize-plugin', 'dd-plugin'), 'strings' => array( array('error', 'moodle'), array('info', 'moodle'), array('confirmdeletefile', 'repository'), array('draftareanofiles', 'repository'), array('entername', 'repository'), array('enternewname', 'repository'), array('invalidjson', 'repository'), array('popupblockeddownload', 'repository'), array('unknownoriginal', 'repository'), array('confirmdeletefolder', 'repository'), array('confirmdeletefilewithhref', 'repository'), array('confirmrenamefolder', 'repository'), array('confirmrenamefile', 'repository'), array('newfolder', 'repository'), array('edit', 'moodle') ) ); if ($this->page->requires->should_create_one_time_item_now('core_file_managertemplate')) { $this->page->requires->js_init_call('M.form_filemanager.set_templates', array($this->filemanager_js_templates()), true, $module); } $this->page->requires->js_init_call('M.form_filemanager.init', array($fm->options), true, $module); // non javascript file manager $html .= '<noscript>'; $html .= "<div><object type='text/html' data='".$fm->get_nonjsurl()."' height='160' width='600' style='border:1px solid #000'></object></div>"; $html .= '</noscript>'; return $html; }
php
public function render_form_filemanager($fm) { $html = $this->fm_print_generallayout($fm); $module = array( 'name'=>'form_filemanager', 'fullpath'=>'/lib/form/filemanager.js', 'requires' => array('moodle-core-notification-dialogue', 'core_filepicker', 'base', 'io-base', 'node', 'json', 'core_dndupload', 'panel', 'resize-plugin', 'dd-plugin'), 'strings' => array( array('error', 'moodle'), array('info', 'moodle'), array('confirmdeletefile', 'repository'), array('draftareanofiles', 'repository'), array('entername', 'repository'), array('enternewname', 'repository'), array('invalidjson', 'repository'), array('popupblockeddownload', 'repository'), array('unknownoriginal', 'repository'), array('confirmdeletefolder', 'repository'), array('confirmdeletefilewithhref', 'repository'), array('confirmrenamefolder', 'repository'), array('confirmrenamefile', 'repository'), array('newfolder', 'repository'), array('edit', 'moodle') ) ); if ($this->page->requires->should_create_one_time_item_now('core_file_managertemplate')) { $this->page->requires->js_init_call('M.form_filemanager.set_templates', array($this->filemanager_js_templates()), true, $module); } $this->page->requires->js_init_call('M.form_filemanager.init', array($fm->options), true, $module); // non javascript file manager $html .= '<noscript>'; $html .= "<div><object type='text/html' data='".$fm->get_nonjsurl()."' height='160' width='600' style='border:1px solid #000'></object></div>"; $html .= '</noscript>'; return $html; }
[ "public", "function", "render_form_filemanager", "(", "$", "fm", ")", "{", "$", "html", "=", "$", "this", "->", "fm_print_generallayout", "(", "$", "fm", ")", ";", "$", "module", "=", "array", "(", "'name'", "=>", "'form_filemanager'", ",", "'fullpath'", "=>", "'/lib/form/filemanager.js'", ",", "'requires'", "=>", "array", "(", "'moodle-core-notification-dialogue'", ",", "'core_filepicker'", ",", "'base'", ",", "'io-base'", ",", "'node'", ",", "'json'", ",", "'core_dndupload'", ",", "'panel'", ",", "'resize-plugin'", ",", "'dd-plugin'", ")", ",", "'strings'", "=>", "array", "(", "array", "(", "'error'", ",", "'moodle'", ")", ",", "array", "(", "'info'", ",", "'moodle'", ")", ",", "array", "(", "'confirmdeletefile'", ",", "'repository'", ")", ",", "array", "(", "'draftareanofiles'", ",", "'repository'", ")", ",", "array", "(", "'entername'", ",", "'repository'", ")", ",", "array", "(", "'enternewname'", ",", "'repository'", ")", ",", "array", "(", "'invalidjson'", ",", "'repository'", ")", ",", "array", "(", "'popupblockeddownload'", ",", "'repository'", ")", ",", "array", "(", "'unknownoriginal'", ",", "'repository'", ")", ",", "array", "(", "'confirmdeletefolder'", ",", "'repository'", ")", ",", "array", "(", "'confirmdeletefilewithhref'", ",", "'repository'", ")", ",", "array", "(", "'confirmrenamefolder'", ",", "'repository'", ")", ",", "array", "(", "'confirmrenamefile'", ",", "'repository'", ")", ",", "array", "(", "'newfolder'", ",", "'repository'", ")", ",", "array", "(", "'edit'", ",", "'moodle'", ")", ")", ")", ";", "if", "(", "$", "this", "->", "page", "->", "requires", "->", "should_create_one_time_item_now", "(", "'core_file_managertemplate'", ")", ")", "{", "$", "this", "->", "page", "->", "requires", "->", "js_init_call", "(", "'M.form_filemanager.set_templates'", ",", "array", "(", "$", "this", "->", "filemanager_js_templates", "(", ")", ")", ",", "true", ",", "$", "module", ")", ";", "}", "$", "this", "->", "page", "->", "requires", "->", "js_init_call", "(", "'M.form_filemanager.init'", ",", "array", "(", "$", "fm", "->", "options", ")", ",", "true", ",", "$", "module", ")", ";", "// non javascript file manager", "$", "html", ".=", "'<noscript>'", ";", "$", "html", ".=", "\"<div><object type='text/html' data='\"", ".", "$", "fm", "->", "get_nonjsurl", "(", ")", ".", "\"' height='160' width='600' style='border:1px solid #000'></object></div>\"", ";", "$", "html", ".=", "'</noscript>'", ";", "return", "$", "html", ";", "}" ]
Prints the file manager and initializes all necessary libraries <pre> $fm = new form_filemanager($options); $output = get_renderer('core', 'files'); echo $output->render($fm); </pre> @param form_filemanager $fm File manager to render @return string HTML fragment
[ "Prints", "the", "file", "manager", "and", "initializes", "all", "necessary", "libraries" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/files/renderer.php#L104-L132
218,166
moodle/moodle
files/renderer.php
core_files_renderer.fm_print_generallayout
protected function fm_print_generallayout($fm) { $context = [ 'client_id' => $fm->options->client_id, 'helpicon' => $this->help_icon('setmainfile', 'repository'), 'restrictions' => $this->fm_print_restrictions($fm) ]; return $this->render_from_template('core/filemanager_page_generallayout', $context); }
php
protected function fm_print_generallayout($fm) { $context = [ 'client_id' => $fm->options->client_id, 'helpicon' => $this->help_icon('setmainfile', 'repository'), 'restrictions' => $this->fm_print_restrictions($fm) ]; return $this->render_from_template('core/filemanager_page_generallayout', $context); }
[ "protected", "function", "fm_print_generallayout", "(", "$", "fm", ")", "{", "$", "context", "=", "[", "'client_id'", "=>", "$", "fm", "->", "options", "->", "client_id", ",", "'helpicon'", "=>", "$", "this", "->", "help_icon", "(", "'setmainfile'", ",", "'repository'", ")", ",", "'restrictions'", "=>", "$", "this", "->", "fm_print_restrictions", "(", "$", "fm", ")", "]", ";", "return", "$", "this", "->", "render_from_template", "(", "'core/filemanager_page_generallayout'", ",", "$", "context", ")", ";", "}" ]
Returns html for displaying one file manager @param form_filemanager $fm @return string
[ "Returns", "html", "for", "displaying", "one", "file", "manager" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/files/renderer.php#L140-L147
218,167
moodle/moodle
files/renderer.php
core_files_renderer.filemanager_js_templates
public function filemanager_js_templates() { $class_methods = get_class_methods($this); $templates = array(); foreach ($class_methods as $method_name) { if (preg_match('/^fm_js_template_(.*)$/', $method_name, $matches)) $templates[$matches[1]] = $this->$method_name(); } return $templates; }
php
public function filemanager_js_templates() { $class_methods = get_class_methods($this); $templates = array(); foreach ($class_methods as $method_name) { if (preg_match('/^fm_js_template_(.*)$/', $method_name, $matches)) $templates[$matches[1]] = $this->$method_name(); } return $templates; }
[ "public", "function", "filemanager_js_templates", "(", ")", "{", "$", "class_methods", "=", "get_class_methods", "(", "$", "this", ")", ";", "$", "templates", "=", "array", "(", ")", ";", "foreach", "(", "$", "class_methods", "as", "$", "method_name", ")", "{", "if", "(", "preg_match", "(", "'/^fm_js_template_(.*)$/'", ",", "$", "method_name", ",", "$", "matches", ")", ")", "$", "templates", "[", "$", "matches", "[", "1", "]", "]", "=", "$", "this", "->", "$", "method_name", "(", ")", ";", "}", "return", "$", "templates", ";", "}" ]
Returns all FileManager JavaScript templates as an array. @return array
[ "Returns", "all", "FileManager", "JavaScript", "templates", "as", "an", "array", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/files/renderer.php#L267-L275
218,168
moodle/moodle
files/renderer.php
core_files_renderer.fm_print_restrictions
protected function fm_print_restrictions($fm) { $maxbytes = display_size($fm->options->maxbytes); $strparam = (object) array('size' => $maxbytes, 'attachments' => $fm->options->maxfiles, 'areasize' => display_size($fm->options->areamaxbytes)); $hasmaxfiles = !empty($fm->options->maxfiles) && $fm->options->maxfiles > 0; $hasarealimit = !empty($fm->options->areamaxbytes) && $fm->options->areamaxbytes != -1; if ($hasmaxfiles && $hasarealimit) { $maxsize = get_string('maxsizeandattachmentsandareasize', 'moodle', $strparam); } else if ($hasmaxfiles) { $maxsize = get_string('maxsizeandattachments', 'moodle', $strparam); } else if ($hasarealimit) { $maxsize = get_string('maxsizeandareasize', 'moodle', $strparam); } else { $maxsize = get_string('maxfilesize', 'moodle', $maxbytes); } // TODO MDL-32020 also should say about 'File types accepted' return '<span>'. $maxsize . '</span>'; }
php
protected function fm_print_restrictions($fm) { $maxbytes = display_size($fm->options->maxbytes); $strparam = (object) array('size' => $maxbytes, 'attachments' => $fm->options->maxfiles, 'areasize' => display_size($fm->options->areamaxbytes)); $hasmaxfiles = !empty($fm->options->maxfiles) && $fm->options->maxfiles > 0; $hasarealimit = !empty($fm->options->areamaxbytes) && $fm->options->areamaxbytes != -1; if ($hasmaxfiles && $hasarealimit) { $maxsize = get_string('maxsizeandattachmentsandareasize', 'moodle', $strparam); } else if ($hasmaxfiles) { $maxsize = get_string('maxsizeandattachments', 'moodle', $strparam); } else if ($hasarealimit) { $maxsize = get_string('maxsizeandareasize', 'moodle', $strparam); } else { $maxsize = get_string('maxfilesize', 'moodle', $maxbytes); } // TODO MDL-32020 also should say about 'File types accepted' return '<span>'. $maxsize . '</span>'; }
[ "protected", "function", "fm_print_restrictions", "(", "$", "fm", ")", "{", "$", "maxbytes", "=", "display_size", "(", "$", "fm", "->", "options", "->", "maxbytes", ")", ";", "$", "strparam", "=", "(", "object", ")", "array", "(", "'size'", "=>", "$", "maxbytes", ",", "'attachments'", "=>", "$", "fm", "->", "options", "->", "maxfiles", ",", "'areasize'", "=>", "display_size", "(", "$", "fm", "->", "options", "->", "areamaxbytes", ")", ")", ";", "$", "hasmaxfiles", "=", "!", "empty", "(", "$", "fm", "->", "options", "->", "maxfiles", ")", "&&", "$", "fm", "->", "options", "->", "maxfiles", ">", "0", ";", "$", "hasarealimit", "=", "!", "empty", "(", "$", "fm", "->", "options", "->", "areamaxbytes", ")", "&&", "$", "fm", "->", "options", "->", "areamaxbytes", "!=", "-", "1", ";", "if", "(", "$", "hasmaxfiles", "&&", "$", "hasarealimit", ")", "{", "$", "maxsize", "=", "get_string", "(", "'maxsizeandattachmentsandareasize'", ",", "'moodle'", ",", "$", "strparam", ")", ";", "}", "else", "if", "(", "$", "hasmaxfiles", ")", "{", "$", "maxsize", "=", "get_string", "(", "'maxsizeandattachments'", ",", "'moodle'", ",", "$", "strparam", ")", ";", "}", "else", "if", "(", "$", "hasarealimit", ")", "{", "$", "maxsize", "=", "get_string", "(", "'maxsizeandareasize'", ",", "'moodle'", ",", "$", "strparam", ")", ";", "}", "else", "{", "$", "maxsize", "=", "get_string", "(", "'maxfilesize'", ",", "'moodle'", ",", "$", "maxbytes", ")", ";", "}", "// TODO MDL-32020 also should say about 'File types accepted'", "return", "'<span>'", ".", "$", "maxsize", ".", "'</span>'", ";", "}" ]
Displays restrictions for the file manager @param form_filemanager $fm @return string
[ "Displays", "restrictions", "for", "the", "file", "manager" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/files/renderer.php#L283-L300
218,169
moodle/moodle
dataformat/pdf/classes/writer.php
writer.print_heading
private function print_heading() { $fontfamily = $this->pdf->getFontFamily(); $fontstyle = $this->pdf->getFontStyle(); $this->pdf->SetFont($fontfamily, 'B'); $rowheight = 0; foreach ($this->columns as $columns) { $rowheight = max($rowheight, $this->pdf->getStringHeight($this->colwidth, $columns, false, true, '', 1)); } $total = count($this->columns); $counter = 1; foreach ($this->columns as $columns) { $nextposition = ($counter == $total) ? 1 : 0; $this->pdf->Multicell($this->colwidth, $rowheight, $columns, 1, 'C', true, $nextposition); $counter++; } $this->pdf->SetFont($fontfamily, $fontstyle); }
php
private function print_heading() { $fontfamily = $this->pdf->getFontFamily(); $fontstyle = $this->pdf->getFontStyle(); $this->pdf->SetFont($fontfamily, 'B'); $rowheight = 0; foreach ($this->columns as $columns) { $rowheight = max($rowheight, $this->pdf->getStringHeight($this->colwidth, $columns, false, true, '', 1)); } $total = count($this->columns); $counter = 1; foreach ($this->columns as $columns) { $nextposition = ($counter == $total) ? 1 : 0; $this->pdf->Multicell($this->colwidth, $rowheight, $columns, 1, 'C', true, $nextposition); $counter++; } $this->pdf->SetFont($fontfamily, $fontstyle); }
[ "private", "function", "print_heading", "(", ")", "{", "$", "fontfamily", "=", "$", "this", "->", "pdf", "->", "getFontFamily", "(", ")", ";", "$", "fontstyle", "=", "$", "this", "->", "pdf", "->", "getFontStyle", "(", ")", ";", "$", "this", "->", "pdf", "->", "SetFont", "(", "$", "fontfamily", ",", "'B'", ")", ";", "$", "rowheight", "=", "0", ";", "foreach", "(", "$", "this", "->", "columns", "as", "$", "columns", ")", "{", "$", "rowheight", "=", "max", "(", "$", "rowheight", ",", "$", "this", "->", "pdf", "->", "getStringHeight", "(", "$", "this", "->", "colwidth", ",", "$", "columns", ",", "false", ",", "true", ",", "''", ",", "1", ")", ")", ";", "}", "$", "total", "=", "count", "(", "$", "this", "->", "columns", ")", ";", "$", "counter", "=", "1", ";", "foreach", "(", "$", "this", "->", "columns", "as", "$", "columns", ")", "{", "$", "nextposition", "=", "(", "$", "counter", "==", "$", "total", ")", "?", "1", ":", "0", ";", "$", "this", "->", "pdf", "->", "Multicell", "(", "$", "this", "->", "colwidth", ",", "$", "rowheight", ",", "$", "columns", ",", "1", ",", "'C'", ",", "true", ",", "$", "nextposition", ")", ";", "$", "counter", "++", ";", "}", "$", "this", "->", "pdf", "->", "SetFont", "(", "$", "fontfamily", ",", "$", "fontstyle", ")", ";", "}" ]
Prints the heading row.
[ "Prints", "the", "heading", "row", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/dataformat/pdf/classes/writer.php#L120-L138
218,170
moodle/moodle
badges/criteria/award_criteria_manual.php
award_criteria_manual.get_role_name
private function get_role_name($rid) { global $DB, $PAGE; $rec = $DB->get_record('role', array('id' => $rid)); if ($rec) { return role_get_name($rec, $PAGE->context, ROLENAME_ALIAS); } else { return null; } }
php
private function get_role_name($rid) { global $DB, $PAGE; $rec = $DB->get_record('role', array('id' => $rid)); if ($rec) { return role_get_name($rec, $PAGE->context, ROLENAME_ALIAS); } else { return null; } }
[ "private", "function", "get_role_name", "(", "$", "rid", ")", "{", "global", "$", "DB", ",", "$", "PAGE", ";", "$", "rec", "=", "$", "DB", "->", "get_record", "(", "'role'", ",", "array", "(", "'id'", "=>", "$", "rid", ")", ")", ";", "if", "(", "$", "rec", ")", "{", "return", "role_get_name", "(", "$", "rec", ",", "$", "PAGE", "->", "context", ",", "ROLENAME_ALIAS", ")", ";", "}", "else", "{", "return", "null", ";", "}", "}" ]
Gets role name. If no such role exists this function returns null. @return string|null
[ "Gets", "role", "name", ".", "If", "no", "such", "role", "exists", "this", "function", "returns", "null", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/badges/criteria/award_criteria_manual.php#L47-L56
218,171
moodle/moodle
question/type/ddmarker/backup/moodle2/restore_qtype_ddmarker_plugin.class.php
restore_qtype_ddmarker_plugin.define_decode_contents
public static function define_decode_contents() { $prefix = 'qtype_'.self::qtype_name(); $contents = array(); $fields = array('correctfeedback', 'partiallycorrectfeedback', 'incorrectfeedback'); $contents[] = new restore_decode_content($prefix, $fields, $prefix); return $contents; }
php
public static function define_decode_contents() { $prefix = 'qtype_'.self::qtype_name(); $contents = array(); $fields = array('correctfeedback', 'partiallycorrectfeedback', 'incorrectfeedback'); $contents[] = new restore_decode_content($prefix, $fields, $prefix); return $contents; }
[ "public", "static", "function", "define_decode_contents", "(", ")", "{", "$", "prefix", "=", "'qtype_'", ".", "self", "::", "qtype_name", "(", ")", ";", "$", "contents", "=", "array", "(", ")", ";", "$", "fields", "=", "array", "(", "'correctfeedback'", ",", "'partiallycorrectfeedback'", ",", "'incorrectfeedback'", ")", ";", "$", "contents", "[", "]", "=", "new", "restore_decode_content", "(", "$", "prefix", ",", "$", "fields", ",", "$", "prefix", ")", ";", "return", "$", "contents", ";", "}" ]
Return the contents of this qtype to be processed by the links decoder @return array
[ "Return", "the", "contents", "of", "this", "qtype", "to", "be", "processed", "by", "the", "links", "decoder" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/type/ddmarker/backup/moodle2/restore_qtype_ddmarker_plugin.class.php#L159-L170
218,172
moodle/moodle
competency/classes/user_competency.php
user_competency.get_status_list
public static function get_status_list() { static $list = null; if ($list === null) { $list = array( self::STATUS_IDLE => self::get_status_name(self::STATUS_IDLE), self::STATUS_WAITING_FOR_REVIEW => self::get_status_name(self::STATUS_WAITING_FOR_REVIEW), self::STATUS_IN_REVIEW => self::get_status_name(self::STATUS_IN_REVIEW)); } return $list; }
php
public static function get_status_list() { static $list = null; if ($list === null) { $list = array( self::STATUS_IDLE => self::get_status_name(self::STATUS_IDLE), self::STATUS_WAITING_FOR_REVIEW => self::get_status_name(self::STATUS_WAITING_FOR_REVIEW), self::STATUS_IN_REVIEW => self::get_status_name(self::STATUS_IN_REVIEW)); } return $list; }
[ "public", "static", "function", "get_status_list", "(", ")", "{", "static", "$", "list", "=", "null", ";", "if", "(", "$", "list", "===", "null", ")", "{", "$", "list", "=", "array", "(", "self", "::", "STATUS_IDLE", "=>", "self", "::", "get_status_name", "(", "self", "::", "STATUS_IDLE", ")", ",", "self", "::", "STATUS_WAITING_FOR_REVIEW", "=>", "self", "::", "get_status_name", "(", "self", "::", "STATUS_WAITING_FOR_REVIEW", ")", ",", "self", "::", "STATUS_IN_REVIEW", "=>", "self", "::", "get_status_name", "(", "self", "::", "STATUS_IN_REVIEW", ")", ")", ";", "}", "return", "$", "list", ";", "}" ]
Get list of competency status. @return array
[ "Get", "list", "of", "competency", "status", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/competency/classes/user_competency.php#L169-L181
218,173
moodle/moodle
competency/classes/user_competency.php
user_competency.validate_reviewerid
protected function validate_reviewerid($value) { global $DB; if ($value !== null && !$DB->record_exists('user', array('id' => $value))) { return new lang_string('invaliduserid', 'error'); } return true; }
php
protected function validate_reviewerid($value) { global $DB; if ($value !== null && !$DB->record_exists('user', array('id' => $value))) { return new lang_string('invaliduserid', 'error'); } return true; }
[ "protected", "function", "validate_reviewerid", "(", "$", "value", ")", "{", "global", "$", "DB", ";", "if", "(", "$", "value", "!==", "null", "&&", "!", "$", "DB", "->", "record_exists", "(", "'user'", ",", "array", "(", "'id'", "=>", "$", "value", ")", ")", ")", "{", "return", "new", "lang_string", "(", "'invaliduserid'", ",", "'error'", ")", ";", "}", "return", "true", ";", "}" ]
Validate the reviewer ID. @param int $value The value. @return true|lang_string
[ "Validate", "the", "reviewer", "ID", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/competency/classes/user_competency.php#L296-L304
218,174
moodle/moodle
competency/classes/user_competency.php
user_competency.can_comment_user
public static function can_comment_user($userid) { global $USER; $capabilities = array('moodle/competency:usercompetencycomment'); if ($USER->id == $userid) { $capabilities[] = 'moodle/competency:usercompetencycommentown'; } if (has_any_capability($capabilities, context_user::instance($userid))) { return true; } return false; }
php
public static function can_comment_user($userid) { global $USER; $capabilities = array('moodle/competency:usercompetencycomment'); if ($USER->id == $userid) { $capabilities[] = 'moodle/competency:usercompetencycommentown'; } if (has_any_capability($capabilities, context_user::instance($userid))) { return true; } return false; }
[ "public", "static", "function", "can_comment_user", "(", "$", "userid", ")", "{", "global", "$", "USER", ";", "$", "capabilities", "=", "array", "(", "'moodle/competency:usercompetencycomment'", ")", ";", "if", "(", "$", "USER", "->", "id", "==", "$", "userid", ")", "{", "$", "capabilities", "[", "]", "=", "'moodle/competency:usercompetencycommentown'", ";", "}", "if", "(", "has_any_capability", "(", "$", "capabilities", ",", "context_user", "::", "instance", "(", "$", "userid", ")", ")", ")", "{", "return", "true", ";", "}", "return", "false", ";", "}" ]
Can the current user comment on a user's competency? @param int $userid The user ID the competency belongs to. @return bool
[ "Can", "the", "current", "user", "comment", "on", "a", "user", "s", "competency?" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/competency/classes/user_competency.php#L335-L348
218,175
moodle/moodle
competency/classes/user_competency.php
user_competency.can_grade_user_in_course
public static function can_grade_user_in_course($userid, $courseid) { $ratecap = 'moodle/competency:competencygrade'; return has_capability($ratecap, context_course::instance($courseid)) || static::can_grade_user($userid); }
php
public static function can_grade_user_in_course($userid, $courseid) { $ratecap = 'moodle/competency:competencygrade'; return has_capability($ratecap, context_course::instance($courseid)) || static::can_grade_user($userid); }
[ "public", "static", "function", "can_grade_user_in_course", "(", "$", "userid", ",", "$", "courseid", ")", "{", "$", "ratecap", "=", "'moodle/competency:competencygrade'", ";", "return", "has_capability", "(", "$", "ratecap", ",", "context_course", "::", "instance", "(", "$", "courseid", ")", ")", "||", "static", "::", "can_grade_user", "(", "$", "userid", ")", ";", "}" ]
Can the current user grade a user's user competency in a course? @param int $userid The user ID the competency belongs to. @param int $courseid The course ID. @return bool
[ "Can", "the", "current", "user", "grade", "a", "user", "s", "user", "competency", "in", "a", "course?" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/competency/classes/user_competency.php#L368-L372
218,176
moodle/moodle
competency/classes/user_competency.php
user_competency.can_read_user_in_course
public static function can_read_user_in_course($userid, $courseid) { $capability = 'moodle/competency:usercompetencyview'; return has_capability($capability, context_course::instance($courseid)) || static::can_read_user($userid); }
php
public static function can_read_user_in_course($userid, $courseid) { $capability = 'moodle/competency:usercompetencyview'; return has_capability($capability, context_course::instance($courseid)) || static::can_read_user($userid); }
[ "public", "static", "function", "can_read_user_in_course", "(", "$", "userid", ",", "$", "courseid", ")", "{", "$", "capability", "=", "'moodle/competency:usercompetencyview'", ";", "return", "has_capability", "(", "$", "capability", ",", "context_course", "::", "instance", "(", "$", "courseid", ")", ")", "||", "static", "::", "can_read_user", "(", "$", "userid", ")", ";", "}" ]
Can the current user read the user competencies of a user in a course? @param int $userid The user ID the competency belongs to. @param int $courseid The course ID. @return bool
[ "Can", "the", "current", "user", "read", "the", "user", "competencies", "of", "a", "user", "in", "a", "course?" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/competency/classes/user_competency.php#L392-L396
218,177
moodle/moodle
competency/classes/user_competency.php
user_competency.can_read_user
public static function can_read_user($userid) { $capability = 'moodle/competency:usercompetencyview'; return has_capability($capability, context_user::instance($userid)) || plan::can_read_user($userid); }
php
public static function can_read_user($userid) { $capability = 'moodle/competency:usercompetencyview'; return has_capability($capability, context_user::instance($userid)) || plan::can_read_user($userid); }
[ "public", "static", "function", "can_read_user", "(", "$", "userid", ")", "{", "$", "capability", "=", "'moodle/competency:usercompetencyview'", ";", "return", "has_capability", "(", "$", "capability", ",", "context_user", "::", "instance", "(", "$", "userid", ")", ")", "||", "plan", "::", "can_read_user", "(", "$", "userid", ")", ";", "}" ]
Can the current user read a user's competency? @param int $userid The user ID the competency belongs to. @return bool
[ "Can", "the", "current", "user", "read", "a", "user", "s", "competency?" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/competency/classes/user_competency.php#L404-L408
218,178
moodle/moodle
competency/classes/user_competency.php
user_competency.get_competency_by_usercompetencyid
public static function get_competency_by_usercompetencyid($id) { global $DB; $sql = "SELECT c.* FROM {" . self::TABLE . "} uc JOIN {" . competency::TABLE . "} c ON c.id = uc.competencyid WHERE uc.id = ?"; $record = $DB->get_record_sql($sql, array($id), MUST_EXIST); return new competency(0, $record); }
php
public static function get_competency_by_usercompetencyid($id) { global $DB; $sql = "SELECT c.* FROM {" . self::TABLE . "} uc JOIN {" . competency::TABLE . "} c ON c.id = uc.competencyid WHERE uc.id = ?"; $record = $DB->get_record_sql($sql, array($id), MUST_EXIST); return new competency(0, $record); }
[ "public", "static", "function", "get_competency_by_usercompetencyid", "(", "$", "id", ")", "{", "global", "$", "DB", ";", "$", "sql", "=", "\"SELECT c.*\n FROM {\"", ".", "self", "::", "TABLE", ".", "\"} uc\n JOIN {\"", ".", "competency", "::", "TABLE", ".", "\"} c\n ON c.id = uc.competencyid\n WHERE uc.id = ?\"", ";", "$", "record", "=", "$", "DB", "->", "get_record_sql", "(", "$", "sql", ",", "array", "(", "$", "id", ")", ",", "MUST_EXIST", ")", ";", "return", "new", "competency", "(", "0", ",", "$", "record", ")", ";", "}" ]
Fetch a competency by user competency ID. This is a convenience method to attempt to efficiently fetch a competency when the only information we have is the user_competency ID, in evidence for instance. @param int $id The user competency ID. @return competency
[ "Fetch", "a", "competency", "by", "user", "competency", "ID", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/competency/classes/user_competency.php#L470-L479
218,179
moodle/moodle
competency/classes/user_competency.php
user_competency.get_multiple
public static function get_multiple($userid, array $competenciesorids = null) { global $DB; $params = array(); $params['userid'] = $userid; $sql = '1 = 1'; if (!empty($competenciesorids)) { $test = reset($competenciesorids); if (is_number($test)) { $ids = $competenciesorids; } else { $ids = array(); foreach ($competenciesorids as $comp) { $ids[] = $comp->get('id'); } } list($insql, $inparams) = $DB->get_in_or_equal($ids, SQL_PARAMS_NAMED); $params += $inparams; $sql = "competencyid $insql"; } // Order by ID to prevent random ordering. return self::get_records_select("userid = :userid AND $sql", $params, 'id ASC'); }
php
public static function get_multiple($userid, array $competenciesorids = null) { global $DB; $params = array(); $params['userid'] = $userid; $sql = '1 = 1'; if (!empty($competenciesorids)) { $test = reset($competenciesorids); if (is_number($test)) { $ids = $competenciesorids; } else { $ids = array(); foreach ($competenciesorids as $comp) { $ids[] = $comp->get('id'); } } list($insql, $inparams) = $DB->get_in_or_equal($ids, SQL_PARAMS_NAMED); $params += $inparams; $sql = "competencyid $insql"; } // Order by ID to prevent random ordering. return self::get_records_select("userid = :userid AND $sql", $params, 'id ASC'); }
[ "public", "static", "function", "get_multiple", "(", "$", "userid", ",", "array", "$", "competenciesorids", "=", "null", ")", "{", "global", "$", "DB", ";", "$", "params", "=", "array", "(", ")", ";", "$", "params", "[", "'userid'", "]", "=", "$", "userid", ";", "$", "sql", "=", "'1 = 1'", ";", "if", "(", "!", "empty", "(", "$", "competenciesorids", ")", ")", "{", "$", "test", "=", "reset", "(", "$", "competenciesorids", ")", ";", "if", "(", "is_number", "(", "$", "test", ")", ")", "{", "$", "ids", "=", "$", "competenciesorids", ";", "}", "else", "{", "$", "ids", "=", "array", "(", ")", ";", "foreach", "(", "$", "competenciesorids", "as", "$", "comp", ")", "{", "$", "ids", "[", "]", "=", "$", "comp", "->", "get", "(", "'id'", ")", ";", "}", "}", "list", "(", "$", "insql", ",", "$", "inparams", ")", "=", "$", "DB", "->", "get_in_or_equal", "(", "$", "ids", ",", "SQL_PARAMS_NAMED", ")", ";", "$", "params", "+=", "$", "inparams", ";", "$", "sql", "=", "\"competencyid $insql\"", ";", "}", "// Order by ID to prevent random ordering.", "return", "self", "::", "get_records_select", "(", "\"userid = :userid AND $sql\"", ",", "$", "params", ",", "'id ASC'", ")", ";", "}" ]
Get multiple user_competency for a user. @param int $userid @param array $competenciesorids Limit search to those competencies, or competency IDs. @return \core_competency\user_competency[]
[ "Get", "multiple", "user_competency", "for", "a", "user", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/competency/classes/user_competency.php#L488-L513
218,180
moodle/moodle
competency/classes/user_competency.php
user_competency.has_records_for_framework
public static function has_records_for_framework($frameworkid) { global $DB; $sql = "SELECT 'x' FROM {" . self::TABLE . "} uc JOIN {" . competency::TABLE . "} c ON uc.competencyid = c.id WHERE c.competencyframeworkid = ?"; $params = array($frameworkid); return $DB->record_exists_sql($sql, $params); }
php
public static function has_records_for_framework($frameworkid) { global $DB; $sql = "SELECT 'x' FROM {" . self::TABLE . "} uc JOIN {" . competency::TABLE . "} c ON uc.competencyid = c.id WHERE c.competencyframeworkid = ?"; $params = array($frameworkid); return $DB->record_exists_sql($sql, $params); }
[ "public", "static", "function", "has_records_for_framework", "(", "$", "frameworkid", ")", "{", "global", "$", "DB", ";", "$", "sql", "=", "\"SELECT 'x'\n FROM {\"", ".", "self", "::", "TABLE", ".", "\"} uc\n JOIN {\"", ".", "competency", "::", "TABLE", ".", "\"} c\n ON uc.competencyid = c.id\n WHERE c.competencyframeworkid = ?\"", ";", "$", "params", "=", "array", "(", "$", "frameworkid", ")", ";", "return", "$", "DB", "->", "record_exists_sql", "(", "$", "sql", ",", "$", "params", ")", ";", "}" ]
Checks if any of the competencies of a framework has a user competency record. @param int $frameworkid The competency framework ID. @return boolean
[ "Checks", "if", "any", "of", "the", "competencies", "of", "a", "framework", "has", "a", "user", "competency", "record", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/competency/classes/user_competency.php#L531-L542
218,181
moodle/moodle
competency/classes/user_evidence.php
user_evidence.get_files
public function get_files() { $fs = get_file_storage(); $files = $fs->get_area_files($this->get_context()->id, 'core_competency', 'userevidence', $this->get('id'), 'filename', false); return $files; }
php
public function get_files() { $fs = get_file_storage(); $files = $fs->get_area_files($this->get_context()->id, 'core_competency', 'userevidence', $this->get('id'), 'filename', false); return $files; }
[ "public", "function", "get_files", "(", ")", "{", "$", "fs", "=", "get_file_storage", "(", ")", ";", "$", "files", "=", "$", "fs", "->", "get_area_files", "(", "$", "this", "->", "get_context", "(", ")", "->", "id", ",", "'core_competency'", ",", "'userevidence'", ",", "$", "this", "->", "get", "(", "'id'", ")", ",", "'filename'", ",", "false", ")", ";", "return", "$", "files", ";", "}" ]
Return the files associated with this evidence. @return object[]
[ "Return", "the", "files", "associated", "with", "this", "evidence", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/competency/classes/user_evidence.php#L127-L132
218,182
moodle/moodle
competency/classes/user_evidence.php
user_evidence.can_read_user
public static function can_read_user($evidenceuserid) { $context = context_user::instance($evidenceuserid); $capabilities = array('moodle/competency:userevidenceview'); return has_any_capability($capabilities, $context) || self::can_manage_user($evidenceuserid); }
php
public static function can_read_user($evidenceuserid) { $context = context_user::instance($evidenceuserid); $capabilities = array('moodle/competency:userevidenceview'); return has_any_capability($capabilities, $context) || self::can_manage_user($evidenceuserid); }
[ "public", "static", "function", "can_read_user", "(", "$", "evidenceuserid", ")", "{", "$", "context", "=", "context_user", "::", "instance", "(", "$", "evidenceuserid", ")", ";", "$", "capabilities", "=", "array", "(", "'moodle/competency:userevidenceview'", ")", ";", "return", "has_any_capability", "(", "$", "capabilities", ",", "$", "context", ")", "||", "self", "::", "can_manage_user", "(", "$", "evidenceuserid", ")", ";", "}" ]
Can the current user view a user's evidence? @param int $evidenceuserid The user to whom the evidence would belong. @return bool
[ "Can", "the", "current", "user", "view", "a", "user", "s", "evidence?" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/competency/classes/user_evidence.php#L197-L203
218,183
moodle/moodle
mod/choice/renderer.php
mod_choice_renderer.display_publish_anonymous
public function display_publish_anonymous($choices, $displaylayout) { global $OUTPUT; $count = 0; $data = []; $numberofuser = 0; $percentageamount = 0; foreach ($choices->options as $optionid => $option) { if (!empty($option->user)) { $numberofuser = count($option->user); } if($choices->numberofuser > 0) { $percentageamount = ((float)$numberofuser / (float)$choices->numberofuser) * 100.0; } $data['labels'][$count] = $option->text; $data['series'][$count] = $numberofuser; $data['series_labels'][$count] = $numberofuser . ' (' . format_float($percentageamount, 1) . '%)'; $count++; $numberofuser = 0; } $chart = new \core\chart_bar(); if ($displaylayout == DISPLAY_HORIZONTAL_LAYOUT) { $chart->set_horizontal(true); } $series = new \core\chart_series(format_string(get_string("responses", "choice")), $data['series']); $series->set_labels($data['series_labels']); $chart->add_series($series); $chart->set_labels($data['labels']); $yaxis = $chart->get_yaxis(0, true); $yaxis->set_stepsize(max(1, round(max($data['series']) / 10))); return $OUTPUT->render($chart); }
php
public function display_publish_anonymous($choices, $displaylayout) { global $OUTPUT; $count = 0; $data = []; $numberofuser = 0; $percentageamount = 0; foreach ($choices->options as $optionid => $option) { if (!empty($option->user)) { $numberofuser = count($option->user); } if($choices->numberofuser > 0) { $percentageamount = ((float)$numberofuser / (float)$choices->numberofuser) * 100.0; } $data['labels'][$count] = $option->text; $data['series'][$count] = $numberofuser; $data['series_labels'][$count] = $numberofuser . ' (' . format_float($percentageamount, 1) . '%)'; $count++; $numberofuser = 0; } $chart = new \core\chart_bar(); if ($displaylayout == DISPLAY_HORIZONTAL_LAYOUT) { $chart->set_horizontal(true); } $series = new \core\chart_series(format_string(get_string("responses", "choice")), $data['series']); $series->set_labels($data['series_labels']); $chart->add_series($series); $chart->set_labels($data['labels']); $yaxis = $chart->get_yaxis(0, true); $yaxis->set_stepsize(max(1, round(max($data['series']) / 10))); return $OUTPUT->render($chart); }
[ "public", "function", "display_publish_anonymous", "(", "$", "choices", ",", "$", "displaylayout", ")", "{", "global", "$", "OUTPUT", ";", "$", "count", "=", "0", ";", "$", "data", "=", "[", "]", ";", "$", "numberofuser", "=", "0", ";", "$", "percentageamount", "=", "0", ";", "foreach", "(", "$", "choices", "->", "options", "as", "$", "optionid", "=>", "$", "option", ")", "{", "if", "(", "!", "empty", "(", "$", "option", "->", "user", ")", ")", "{", "$", "numberofuser", "=", "count", "(", "$", "option", "->", "user", ")", ";", "}", "if", "(", "$", "choices", "->", "numberofuser", ">", "0", ")", "{", "$", "percentageamount", "=", "(", "(", "float", ")", "$", "numberofuser", "/", "(", "float", ")", "$", "choices", "->", "numberofuser", ")", "*", "100.0", ";", "}", "$", "data", "[", "'labels'", "]", "[", "$", "count", "]", "=", "$", "option", "->", "text", ";", "$", "data", "[", "'series'", "]", "[", "$", "count", "]", "=", "$", "numberofuser", ";", "$", "data", "[", "'series_labels'", "]", "[", "$", "count", "]", "=", "$", "numberofuser", ".", "' ('", ".", "format_float", "(", "$", "percentageamount", ",", "1", ")", ".", "'%)'", ";", "$", "count", "++", ";", "$", "numberofuser", "=", "0", ";", "}", "$", "chart", "=", "new", "\\", "core", "\\", "chart_bar", "(", ")", ";", "if", "(", "$", "displaylayout", "==", "DISPLAY_HORIZONTAL_LAYOUT", ")", "{", "$", "chart", "->", "set_horizontal", "(", "true", ")", ";", "}", "$", "series", "=", "new", "\\", "core", "\\", "chart_series", "(", "format_string", "(", "get_string", "(", "\"responses\"", ",", "\"choice\"", ")", ")", ",", "$", "data", "[", "'series'", "]", ")", ";", "$", "series", "->", "set_labels", "(", "$", "data", "[", "'series_labels'", "]", ")", ";", "$", "chart", "->", "add_series", "(", "$", "series", ")", ";", "$", "chart", "->", "set_labels", "(", "$", "data", "[", "'labels'", "]", ")", ";", "$", "yaxis", "=", "$", "chart", "->", "get_yaxis", "(", "0", ",", "true", ")", ";", "$", "yaxis", "->", "set_stepsize", "(", "max", "(", "1", ",", "round", "(", "max", "(", "$", "data", "[", "'series'", "]", ")", "/", "10", ")", ")", ")", ";", "return", "$", "OUTPUT", "->", "render", "(", "$", "chart", ")", ";", "}" ]
Generate the choice result chart. Can be displayed either in the vertical or horizontal position. @param stdClass $choices Choices responses object. @param int $displaylayout The constants DISPLAY_HORIZONTAL_LAYOUT or DISPLAY_VERTICAL_LAYOUT. @return string the rendered chart.
[ "Generate", "the", "choice", "result", "chart", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/choice/renderer.php#L334-L365
218,184
moodle/moodle
lib/editor/tinymce/lib.php
tinymce_texteditor.use_editor
public function use_editor($elementid, array $options=null, $fpoptions=null) { global $PAGE, $CFG; // Note: use full moodle_url instance to prevent standard JS loader, make sure we are using https on profile page if required. if ($CFG->debugdeveloper) { $PAGE->requires->js(new moodle_url('/lib/editor/tinymce/tiny_mce/'.$this->version.'/tiny_mce_src.js')); } else { $PAGE->requires->js(new moodle_url('/lib/editor/tinymce/tiny_mce/'.$this->version.'/tiny_mce.js')); } $PAGE->requires->js_init_call('M.editor_tinymce.init_editor', array($elementid, $this->get_init_params($elementid, $options)), true); if ($fpoptions) { $PAGE->requires->js_init_call('M.editor_tinymce.init_filepicker', array($elementid, $fpoptions), true); } }
php
public function use_editor($elementid, array $options=null, $fpoptions=null) { global $PAGE, $CFG; // Note: use full moodle_url instance to prevent standard JS loader, make sure we are using https on profile page if required. if ($CFG->debugdeveloper) { $PAGE->requires->js(new moodle_url('/lib/editor/tinymce/tiny_mce/'.$this->version.'/tiny_mce_src.js')); } else { $PAGE->requires->js(new moodle_url('/lib/editor/tinymce/tiny_mce/'.$this->version.'/tiny_mce.js')); } $PAGE->requires->js_init_call('M.editor_tinymce.init_editor', array($elementid, $this->get_init_params($elementid, $options)), true); if ($fpoptions) { $PAGE->requires->js_init_call('M.editor_tinymce.init_filepicker', array($elementid, $fpoptions), true); } }
[ "public", "function", "use_editor", "(", "$", "elementid", ",", "array", "$", "options", "=", "null", ",", "$", "fpoptions", "=", "null", ")", "{", "global", "$", "PAGE", ",", "$", "CFG", ";", "// Note: use full moodle_url instance to prevent standard JS loader, make sure we are using https on profile page if required.", "if", "(", "$", "CFG", "->", "debugdeveloper", ")", "{", "$", "PAGE", "->", "requires", "->", "js", "(", "new", "moodle_url", "(", "'/lib/editor/tinymce/tiny_mce/'", ".", "$", "this", "->", "version", ".", "'/tiny_mce_src.js'", ")", ")", ";", "}", "else", "{", "$", "PAGE", "->", "requires", "->", "js", "(", "new", "moodle_url", "(", "'/lib/editor/tinymce/tiny_mce/'", ".", "$", "this", "->", "version", ".", "'/tiny_mce.js'", ")", ")", ";", "}", "$", "PAGE", "->", "requires", "->", "js_init_call", "(", "'M.editor_tinymce.init_editor'", ",", "array", "(", "$", "elementid", ",", "$", "this", "->", "get_init_params", "(", "$", "elementid", ",", "$", "options", ")", ")", ",", "true", ")", ";", "if", "(", "$", "fpoptions", ")", "{", "$", "PAGE", "->", "requires", "->", "js_init_call", "(", "'M.editor_tinymce.init_filepicker'", ",", "array", "(", "$", "elementid", ",", "$", "fpoptions", ")", ",", "true", ")", ";", "}", "}" ]
Use this editor for give element. @param string $elementid @param array $options @param null $fpoptions
[ "Use", "this", "editor", "for", "give", "element", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/editor/tinymce/lib.php#L79-L91
218,185
moodle/moodle
lib/editor/tinymce/lib.php
tinymce_texteditor.parse_toolbar_setting
public static function parse_toolbar_setting($customtoolbar) { $result = array(); $customtoolbar = trim($customtoolbar); if ($customtoolbar === '') { return $result; } $customtoolbar = str_replace("\r", "\n", $customtoolbar); $customtoolbar = strtolower($customtoolbar); $i = 0; foreach (explode("\n", $customtoolbar) as $line) { $line = preg_replace('/[^a-z0-9_,\|\-]/', ',', $line); $line = str_replace('|', ',|,', $line); $line = preg_replace('/,,+/', ',', $line); $line = trim($line, ',|'); if ($line === '') { continue; } if ($i == 10) { // Maximum is ten lines, merge the rest to the last line. $result[9] = $result[9].','.$line; } else { $result[] = $line; $i++; } } return $result; }
php
public static function parse_toolbar_setting($customtoolbar) { $result = array(); $customtoolbar = trim($customtoolbar); if ($customtoolbar === '') { return $result; } $customtoolbar = str_replace("\r", "\n", $customtoolbar); $customtoolbar = strtolower($customtoolbar); $i = 0; foreach (explode("\n", $customtoolbar) as $line) { $line = preg_replace('/[^a-z0-9_,\|\-]/', ',', $line); $line = str_replace('|', ',|,', $line); $line = preg_replace('/,,+/', ',', $line); $line = trim($line, ',|'); if ($line === '') { continue; } if ($i == 10) { // Maximum is ten lines, merge the rest to the last line. $result[9] = $result[9].','.$line; } else { $result[] = $line; $i++; } } return $result; }
[ "public", "static", "function", "parse_toolbar_setting", "(", "$", "customtoolbar", ")", "{", "$", "result", "=", "array", "(", ")", ";", "$", "customtoolbar", "=", "trim", "(", "$", "customtoolbar", ")", ";", "if", "(", "$", "customtoolbar", "===", "''", ")", "{", "return", "$", "result", ";", "}", "$", "customtoolbar", "=", "str_replace", "(", "\"\\r\"", ",", "\"\\n\"", ",", "$", "customtoolbar", ")", ";", "$", "customtoolbar", "=", "strtolower", "(", "$", "customtoolbar", ")", ";", "$", "i", "=", "0", ";", "foreach", "(", "explode", "(", "\"\\n\"", ",", "$", "customtoolbar", ")", "as", "$", "line", ")", "{", "$", "line", "=", "preg_replace", "(", "'/[^a-z0-9_,\\|\\-]/'", ",", "','", ",", "$", "line", ")", ";", "$", "line", "=", "str_replace", "(", "'|'", ",", "',|,'", ",", "$", "line", ")", ";", "$", "line", "=", "preg_replace", "(", "'/,,+/'", ",", "','", ",", "$", "line", ")", ";", "$", "line", "=", "trim", "(", "$", "line", ",", "',|'", ")", ";", "if", "(", "$", "line", "===", "''", ")", "{", "continue", ";", "}", "if", "(", "$", "i", "==", "10", ")", "{", "// Maximum is ten lines, merge the rest to the last line.", "$", "result", "[", "9", "]", "=", "$", "result", "[", "9", "]", ".", "','", ".", "$", "line", ";", "}", "else", "{", "$", "result", "[", "]", "=", "$", "line", ";", "$", "i", "++", ";", "}", "}", "return", "$", "result", ";", "}" ]
Parse the custom toolbar setting. @param string $customtoolbar @return array csv toolbar lines
[ "Parse", "the", "custom", "toolbar", "setting", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/editor/tinymce/lib.php#L212-L238
218,186
moodle/moodle
lib/classes/chart_base.php
chart_base.get_axis
private function get_axis($type, $index, $createifnotexists) { $isx = $type === 'x'; if ($isx) { $axis = isset($this->xaxes[$index]) ? $this->xaxes[$index] : null; } else { $axis = isset($this->yaxes[$index]) ? $this->yaxes[$index] : null; } if ($axis === null) { if (!$createifnotexists) { throw new coding_exception('Unknown axis.'); } $axis = new chart_axis(); if ($isx) { $this->set_xaxis($axis, $index); } else { $this->set_yaxis($axis, $index); } } return $axis; }
php
private function get_axis($type, $index, $createifnotexists) { $isx = $type === 'x'; if ($isx) { $axis = isset($this->xaxes[$index]) ? $this->xaxes[$index] : null; } else { $axis = isset($this->yaxes[$index]) ? $this->yaxes[$index] : null; } if ($axis === null) { if (!$createifnotexists) { throw new coding_exception('Unknown axis.'); } $axis = new chart_axis(); if ($isx) { $this->set_xaxis($axis, $index); } else { $this->set_yaxis($axis, $index); } } return $axis; }
[ "private", "function", "get_axis", "(", "$", "type", ",", "$", "index", ",", "$", "createifnotexists", ")", "{", "$", "isx", "=", "$", "type", "===", "'x'", ";", "if", "(", "$", "isx", ")", "{", "$", "axis", "=", "isset", "(", "$", "this", "->", "xaxes", "[", "$", "index", "]", ")", "?", "$", "this", "->", "xaxes", "[", "$", "index", "]", ":", "null", ";", "}", "else", "{", "$", "axis", "=", "isset", "(", "$", "this", "->", "yaxes", "[", "$", "index", "]", ")", "?", "$", "this", "->", "yaxes", "[", "$", "index", "]", ":", "null", ";", "}", "if", "(", "$", "axis", "===", "null", ")", "{", "if", "(", "!", "$", "createifnotexists", ")", "{", "throw", "new", "coding_exception", "(", "'Unknown axis.'", ")", ";", "}", "$", "axis", "=", "new", "chart_axis", "(", ")", ";", "if", "(", "$", "isx", ")", "{", "$", "this", "->", "set_xaxis", "(", "$", "axis", ",", "$", "index", ")", ";", "}", "else", "{", "$", "this", "->", "set_yaxis", "(", "$", "axis", ",", "$", "index", ")", ";", "}", "}", "return", "$", "axis", ";", "}" ]
Get an axis. @param string $type Accepts values 'x' or 'y'. @param int $index The index of this axis. @param bool $createifnotexists Whether to create the axis if not found. @return chart_axis
[ "Get", "an", "axis", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/chart_base.php#L101-L123
218,187
moodle/moodle
lib/classes/chart_base.php
chart_base.set_xaxis
public function set_xaxis(chart_axis $axis, $index = 0) { $this->validate_axis('x', $axis, $index); return $this->xaxes[$index] = $axis; }
php
public function set_xaxis(chart_axis $axis, $index = 0) { $this->validate_axis('x', $axis, $index); return $this->xaxes[$index] = $axis; }
[ "public", "function", "set_xaxis", "(", "chart_axis", "$", "axis", ",", "$", "index", "=", "0", ")", "{", "$", "this", "->", "validate_axis", "(", "'x'", ",", "$", "axis", ",", "$", "index", ")", ";", "return", "$", "this", "->", "xaxes", "[", "$", "index", "]", "=", "$", "axis", ";", "}" ]
Set an X axis. Note that this will override any predefined axis without warning. @param chart_axis $axis The axis. @param int $index The index of the axis.
[ "Set", "an", "X", "axis", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/chart_base.php#L241-L244
218,188
moodle/moodle
lib/classes/chart_base.php
chart_base.set_yaxis
public function set_yaxis(chart_axis $axis, $index = 0) { $this->validate_axis('y', $axis, $index); return $this->yaxes[$index] = $axis; }
php
public function set_yaxis(chart_axis $axis, $index = 0) { $this->validate_axis('y', $axis, $index); return $this->yaxes[$index] = $axis; }
[ "public", "function", "set_yaxis", "(", "chart_axis", "$", "axis", ",", "$", "index", "=", "0", ")", "{", "$", "this", "->", "validate_axis", "(", "'y'", ",", "$", "axis", ",", "$", "index", ")", ";", "return", "$", "this", "->", "yaxes", "[", "$", "index", "]", "=", "$", "axis", ";", "}" ]
Set an Y axis. Note that this will override any predefined axis without warning. @param chart_axis $axis The axis. @param int $index The index of the axis.
[ "Set", "an", "Y", "axis", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/chart_base.php#L254-L257
218,189
moodle/moodle
lib/classes/chart_base.php
chart_base.validate_axis
protected function validate_axis($xy, chart_axis $axis, $index = 0) { if ($index > 0) { $axes = $xy == 'x' ? $this->xaxes : $this->yaxes; if (!isset($axes[$index - 1])) { throw new coding_exception('Missing ' . $xy . ' axis at index lower than ' . $index); } } }
php
protected function validate_axis($xy, chart_axis $axis, $index = 0) { if ($index > 0) { $axes = $xy == 'x' ? $this->xaxes : $this->yaxes; if (!isset($axes[$index - 1])) { throw new coding_exception('Missing ' . $xy . ' axis at index lower than ' . $index); } } }
[ "protected", "function", "validate_axis", "(", "$", "xy", ",", "chart_axis", "$", "axis", ",", "$", "index", "=", "0", ")", "{", "if", "(", "$", "index", ">", "0", ")", "{", "$", "axes", "=", "$", "xy", "==", "'x'", "?", "$", "this", "->", "xaxes", ":", "$", "this", "->", "yaxes", ";", "if", "(", "!", "isset", "(", "$", "axes", "[", "$", "index", "-", "1", "]", ")", ")", "{", "throw", "new", "coding_exception", "(", "'Missing '", ".", "$", "xy", ".", "' axis at index lower than '", ".", "$", "index", ")", ";", "}", "}", "}" ]
Validate an axis. We validate this from PHP because not doing it here could result in errors being hard to trace down. For instance, if we were to add axis at keys without another axis preceding, we would effectively contain the axes in an associative array rather than a simple array, and that would have consequences on serialisation. @param string $xy Accepts x or y. @param chart_axis $axis The axis to validate. @param index $index The index of the axis.
[ "Validate", "an", "axis", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/chart_base.php#L271-L278
218,190
moodle/moodle
calendar/classes/local/event/forms/update.php
update.add_event_repeat_elements
protected function add_event_repeat_elements($mform) { $event = $this->_customdata['event']; $mform->addElement('hidden', 'repeatid'); $mform->setType('repeatid', PARAM_INT); if (!empty($event->repeatid)) { $group = []; $group[] = $mform->createElement('radio', 'repeateditall', null, get_string('repeateditall', 'calendar', $event->eventrepeats), 1); $group[] = $mform->createElement('radio', 'repeateditall', null, get_string('repeateditthis', 'calendar'), 0); $mform->addGroup($group, 'repeatgroup', get_string('repeatedevents', 'calendar'), '<br />', false); $mform->setDefault('repeateditall', 1); $mform->setAdvanced('repeatgroup'); } }
php
protected function add_event_repeat_elements($mform) { $event = $this->_customdata['event']; $mform->addElement('hidden', 'repeatid'); $mform->setType('repeatid', PARAM_INT); if (!empty($event->repeatid)) { $group = []; $group[] = $mform->createElement('radio', 'repeateditall', null, get_string('repeateditall', 'calendar', $event->eventrepeats), 1); $group[] = $mform->createElement('radio', 'repeateditall', null, get_string('repeateditthis', 'calendar'), 0); $mform->addGroup($group, 'repeatgroup', get_string('repeatedevents', 'calendar'), '<br />', false); $mform->setDefault('repeateditall', 1); $mform->setAdvanced('repeatgroup'); } }
[ "protected", "function", "add_event_repeat_elements", "(", "$", "mform", ")", "{", "$", "event", "=", "$", "this", "->", "_customdata", "[", "'event'", "]", ";", "$", "mform", "->", "addElement", "(", "'hidden'", ",", "'repeatid'", ")", ";", "$", "mform", "->", "setType", "(", "'repeatid'", ",", "PARAM_INT", ")", ";", "if", "(", "!", "empty", "(", "$", "event", "->", "repeatid", ")", ")", "{", "$", "group", "=", "[", "]", ";", "$", "group", "[", "]", "=", "$", "mform", "->", "createElement", "(", "'radio'", ",", "'repeateditall'", ",", "null", ",", "get_string", "(", "'repeateditall'", ",", "'calendar'", ",", "$", "event", "->", "eventrepeats", ")", ",", "1", ")", ";", "$", "group", "[", "]", "=", "$", "mform", "->", "createElement", "(", "'radio'", ",", "'repeateditall'", ",", "null", ",", "get_string", "(", "'repeateditthis'", ",", "'calendar'", ")", ",", "0", ")", ";", "$", "mform", "->", "addGroup", "(", "$", "group", ",", "'repeatgroup'", ",", "get_string", "(", "'repeatedevents'", ",", "'calendar'", ")", ",", "'<br />'", ",", "false", ")", ";", "$", "mform", "->", "setDefault", "(", "'repeateditall'", ",", "1", ")", ";", "$", "mform", "->", "setAdvanced", "(", "'repeatgroup'", ")", ";", "}", "}" ]
Add the repeat elements for the form when editing an existing event. @param MoodleQuickForm $mform
[ "Add", "the", "repeat", "elements", "for", "the", "form", "when", "editing", "an", "existing", "event", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/calendar/classes/local/event/forms/update.php#L42-L58
218,191
moodle/moodle
cache/stores/mongodb/MongoDB/Operation/Aggregate.php
Aggregate.createCommand
private function createCommand(Server $server) { $cmd = [ 'aggregate' => isset($this->collectionName) ? $this->collectionName : 1, 'pipeline' => $this->pipeline, ]; $cmdOptions = []; $cmd['allowDiskUse'] = $this->options['allowDiskUse']; if (isset($this->options['bypassDocumentValidation']) && \MongoDB\server_supports_feature($server, self::$wireVersionForDocumentLevelValidation)) { $cmd['bypassDocumentValidation'] = $this->options['bypassDocumentValidation']; } foreach (['comment', 'explain', 'maxTimeMS'] as $option) { if (isset($this->options[$option])) { $cmd[$option] = $this->options[$option]; } } if (isset($this->options['collation'])) { $cmd['collation'] = (object) $this->options['collation']; } if (isset($this->options['hint'])) { $cmd['hint'] = is_array($this->options['hint']) ? (object) $this->options['hint'] : $this->options['hint']; } if (isset($this->options['maxAwaitTimeMS'])) { $cmdOptions['maxAwaitTimeMS'] = $this->options['maxAwaitTimeMS']; } if ($this->options['useCursor']) { $cmd['cursor'] = isset($this->options["batchSize"]) ? ['batchSize' => $this->options["batchSize"]] : new stdClass; } return new Command($cmd, $cmdOptions); }
php
private function createCommand(Server $server) { $cmd = [ 'aggregate' => isset($this->collectionName) ? $this->collectionName : 1, 'pipeline' => $this->pipeline, ]; $cmdOptions = []; $cmd['allowDiskUse'] = $this->options['allowDiskUse']; if (isset($this->options['bypassDocumentValidation']) && \MongoDB\server_supports_feature($server, self::$wireVersionForDocumentLevelValidation)) { $cmd['bypassDocumentValidation'] = $this->options['bypassDocumentValidation']; } foreach (['comment', 'explain', 'maxTimeMS'] as $option) { if (isset($this->options[$option])) { $cmd[$option] = $this->options[$option]; } } if (isset($this->options['collation'])) { $cmd['collation'] = (object) $this->options['collation']; } if (isset($this->options['hint'])) { $cmd['hint'] = is_array($this->options['hint']) ? (object) $this->options['hint'] : $this->options['hint']; } if (isset($this->options['maxAwaitTimeMS'])) { $cmdOptions['maxAwaitTimeMS'] = $this->options['maxAwaitTimeMS']; } if ($this->options['useCursor']) { $cmd['cursor'] = isset($this->options["batchSize"]) ? ['batchSize' => $this->options["batchSize"]] : new stdClass; } return new Command($cmd, $cmdOptions); }
[ "private", "function", "createCommand", "(", "Server", "$", "server", ")", "{", "$", "cmd", "=", "[", "'aggregate'", "=>", "isset", "(", "$", "this", "->", "collectionName", ")", "?", "$", "this", "->", "collectionName", ":", "1", ",", "'pipeline'", "=>", "$", "this", "->", "pipeline", ",", "]", ";", "$", "cmdOptions", "=", "[", "]", ";", "$", "cmd", "[", "'allowDiskUse'", "]", "=", "$", "this", "->", "options", "[", "'allowDiskUse'", "]", ";", "if", "(", "isset", "(", "$", "this", "->", "options", "[", "'bypassDocumentValidation'", "]", ")", "&&", "\\", "MongoDB", "\\", "server_supports_feature", "(", "$", "server", ",", "self", "::", "$", "wireVersionForDocumentLevelValidation", ")", ")", "{", "$", "cmd", "[", "'bypassDocumentValidation'", "]", "=", "$", "this", "->", "options", "[", "'bypassDocumentValidation'", "]", ";", "}", "foreach", "(", "[", "'comment'", ",", "'explain'", ",", "'maxTimeMS'", "]", "as", "$", "option", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "options", "[", "$", "option", "]", ")", ")", "{", "$", "cmd", "[", "$", "option", "]", "=", "$", "this", "->", "options", "[", "$", "option", "]", ";", "}", "}", "if", "(", "isset", "(", "$", "this", "->", "options", "[", "'collation'", "]", ")", ")", "{", "$", "cmd", "[", "'collation'", "]", "=", "(", "object", ")", "$", "this", "->", "options", "[", "'collation'", "]", ";", "}", "if", "(", "isset", "(", "$", "this", "->", "options", "[", "'hint'", "]", ")", ")", "{", "$", "cmd", "[", "'hint'", "]", "=", "is_array", "(", "$", "this", "->", "options", "[", "'hint'", "]", ")", "?", "(", "object", ")", "$", "this", "->", "options", "[", "'hint'", "]", ":", "$", "this", "->", "options", "[", "'hint'", "]", ";", "}", "if", "(", "isset", "(", "$", "this", "->", "options", "[", "'maxAwaitTimeMS'", "]", ")", ")", "{", "$", "cmdOptions", "[", "'maxAwaitTimeMS'", "]", "=", "$", "this", "->", "options", "[", "'maxAwaitTimeMS'", "]", ";", "}", "if", "(", "$", "this", "->", "options", "[", "'useCursor'", "]", ")", "{", "$", "cmd", "[", "'cursor'", "]", "=", "isset", "(", "$", "this", "->", "options", "[", "\"batchSize\"", "]", ")", "?", "[", "'batchSize'", "=>", "$", "this", "->", "options", "[", "\"batchSize\"", "]", "]", ":", "new", "stdClass", ";", "}", "return", "new", "Command", "(", "$", "cmd", ",", "$", "cmdOptions", ")", ";", "}" ]
Create the aggregate command. @param Server $server @return Command
[ "Create", "the", "aggregate", "command", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/cache/stores/mongodb/MongoDB/Operation/Aggregate.php#L292-L331
218,192
moodle/moodle
course/classes/analytics/indicator/completion_enabled.php
completion_enabled.calculate_sample
public function calculate_sample($sampleid, $sampleorigin, $notusedstarttime = false, $notusedendtime = false) { $course = $this->retrieve('course', $sampleid); // It may not be available, but if it is the indicator checks if completion is enabled for the cm. $cm = $this->retrieve('course_modules', $sampleid); $completion = new \completion_info($course); if (!$completion->is_enabled($cm)) { $value = self::get_min_value(); } else if (!$cm && !$completion->has_criteria()) { // Course completion enabled with no criteria counts as nothing. $value = self::get_min_value(); } else { $value = self::get_max_value(); } return $value; }
php
public function calculate_sample($sampleid, $sampleorigin, $notusedstarttime = false, $notusedendtime = false) { $course = $this->retrieve('course', $sampleid); // It may not be available, but if it is the indicator checks if completion is enabled for the cm. $cm = $this->retrieve('course_modules', $sampleid); $completion = new \completion_info($course); if (!$completion->is_enabled($cm)) { $value = self::get_min_value(); } else if (!$cm && !$completion->has_criteria()) { // Course completion enabled with no criteria counts as nothing. $value = self::get_min_value(); } else { $value = self::get_max_value(); } return $value; }
[ "public", "function", "calculate_sample", "(", "$", "sampleid", ",", "$", "sampleorigin", ",", "$", "notusedstarttime", "=", "false", ",", "$", "notusedendtime", "=", "false", ")", "{", "$", "course", "=", "$", "this", "->", "retrieve", "(", "'course'", ",", "$", "sampleid", ")", ";", "// It may not be available, but if it is the indicator checks if completion is enabled for the cm.", "$", "cm", "=", "$", "this", "->", "retrieve", "(", "'course_modules'", ",", "$", "sampleid", ")", ";", "$", "completion", "=", "new", "\\", "completion_info", "(", "$", "course", ")", ";", "if", "(", "!", "$", "completion", "->", "is_enabled", "(", "$", "cm", ")", ")", "{", "$", "value", "=", "self", "::", "get_min_value", "(", ")", ";", "}", "else", "if", "(", "!", "$", "cm", "&&", "!", "$", "completion", "->", "has_criteria", "(", ")", ")", "{", "// Course completion enabled with no criteria counts as nothing.", "$", "value", "=", "self", "::", "get_min_value", "(", ")", ";", "}", "else", "{", "$", "value", "=", "self", "::", "get_max_value", "(", ")", ";", "}", "return", "$", "value", ";", "}" ]
Is completion enabled? Work both with courses and activities. @param int $sampleid @param string $sampleorigin @param int|false $notusedstarttime @param int|false $notusedendtime @return float
[ "Is", "completion", "enabled?", "Work", "both", "with", "courses", "and", "activities", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/course/classes/analytics/indicator/completion_enabled.php#L68-L86
218,193
moodle/moodle
backup/util/structure/backup_optigroup_element.class.php
backup_optigroup_element.set_condition
public function set_condition($conditionparam, $conditionvalue) { // We only resolve the condition if the parent of the element (optigroup) already has parent // else, we'll resolve it once the optigroup parent is defined if ($this->get_parent() && $this->get_parent()->get_parent() && $conditionparam !== null) { $this->procconditionparam = $this->find_element($conditionparam); } $this->conditionparam = $conditionparam; $this->conditionvalue = $conditionvalue; }
php
public function set_condition($conditionparam, $conditionvalue) { // We only resolve the condition if the parent of the element (optigroup) already has parent // else, we'll resolve it once the optigroup parent is defined if ($this->get_parent() && $this->get_parent()->get_parent() && $conditionparam !== null) { $this->procconditionparam = $this->find_element($conditionparam); } $this->conditionparam = $conditionparam; $this->conditionvalue = $conditionvalue; }
[ "public", "function", "set_condition", "(", "$", "conditionparam", ",", "$", "conditionvalue", ")", "{", "// We only resolve the condition if the parent of the element (optigroup) already has parent", "// else, we'll resolve it once the optigroup parent is defined", "if", "(", "$", "this", "->", "get_parent", "(", ")", "&&", "$", "this", "->", "get_parent", "(", ")", "->", "get_parent", "(", ")", "&&", "$", "conditionparam", "!==", "null", ")", "{", "$", "this", "->", "procconditionparam", "=", "$", "this", "->", "find_element", "(", "$", "conditionparam", ")", ";", "}", "$", "this", "->", "conditionparam", "=", "$", "conditionparam", ";", "$", "this", "->", "conditionvalue", "=", "$", "conditionvalue", ";", "}" ]
Sets the condition for this optigroup
[ "Sets", "the", "condition", "for", "this", "optigroup" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/util/structure/backup_optigroup_element.class.php#L69-L77
218,194
moodle/moodle
backup/util/structure/backup_optigroup_element.class.php
backup_optigroup_element.process
public function process($processor) { if (!$processor instanceof base_processor) { // No correct processor, throw exception throw new base_element_struct_exception('incorrect_processor'); } $iterator = $this->get_iterator($processor); // Get the iterator over backup-able data $itcounter = 0; // To check that the iterator only has 1 ocurrence foreach ($iterator as $key => $values) { // Process each "ocurrrence" of the nested element (recordset or array) // Fill the values of the attributes and final elements with the $values from the iterator $this->fill_values($values); // Delegate the process of each final_element foreach ($this->get_final_elements() as $final_element) { $final_element->process($processor); } // Everything processed, clean values before next iteration $this->clean_values(); // Increment counters for this element $this->counter++; $itcounter++; // optigroup_element, check we only have 1 element always if ($itcounter > 1) { throw new base_element_struct_exception('optigroup_element_only_one_ocurrence', $this->get_name()); } } // Close the iterator (DB recordset / array iterator) $iterator->close(); }
php
public function process($processor) { if (!$processor instanceof base_processor) { // No correct processor, throw exception throw new base_element_struct_exception('incorrect_processor'); } $iterator = $this->get_iterator($processor); // Get the iterator over backup-able data $itcounter = 0; // To check that the iterator only has 1 ocurrence foreach ($iterator as $key => $values) { // Process each "ocurrrence" of the nested element (recordset or array) // Fill the values of the attributes and final elements with the $values from the iterator $this->fill_values($values); // Delegate the process of each final_element foreach ($this->get_final_elements() as $final_element) { $final_element->process($processor); } // Everything processed, clean values before next iteration $this->clean_values(); // Increment counters for this element $this->counter++; $itcounter++; // optigroup_element, check we only have 1 element always if ($itcounter > 1) { throw new base_element_struct_exception('optigroup_element_only_one_ocurrence', $this->get_name()); } } // Close the iterator (DB recordset / array iterator) $iterator->close(); }
[ "public", "function", "process", "(", "$", "processor", ")", "{", "if", "(", "!", "$", "processor", "instanceof", "base_processor", ")", "{", "// No correct processor, throw exception", "throw", "new", "base_element_struct_exception", "(", "'incorrect_processor'", ")", ";", "}", "$", "iterator", "=", "$", "this", "->", "get_iterator", "(", "$", "processor", ")", ";", "// Get the iterator over backup-able data", "$", "itcounter", "=", "0", ";", "// To check that the iterator only has 1 ocurrence", "foreach", "(", "$", "iterator", "as", "$", "key", "=>", "$", "values", ")", "{", "// Process each \"ocurrrence\" of the nested element (recordset or array)", "// Fill the values of the attributes and final elements with the $values from the iterator", "$", "this", "->", "fill_values", "(", "$", "values", ")", ";", "// Delegate the process of each final_element", "foreach", "(", "$", "this", "->", "get_final_elements", "(", ")", "as", "$", "final_element", ")", "{", "$", "final_element", "->", "process", "(", "$", "processor", ")", ";", "}", "// Everything processed, clean values before next iteration", "$", "this", "->", "clean_values", "(", ")", ";", "// Increment counters for this element", "$", "this", "->", "counter", "++", ";", "$", "itcounter", "++", ";", "// optigroup_element, check we only have 1 element always", "if", "(", "$", "itcounter", ">", "1", ")", "{", "throw", "new", "base_element_struct_exception", "(", "'optigroup_element_only_one_ocurrence'", ",", "$", "this", "->", "get_name", "(", ")", ")", ";", "}", "}", "// Close the iterator (DB recordset / array iterator)", "$", "iterator", "->", "close", "(", ")", ";", "}" ]
process one optigroup_element Note that this ONLY processes the final elements in order to get all them before processing any nested element. Pending nested elements are processed by the optigroup caller.
[ "process", "one", "optigroup_element" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/util/structure/backup_optigroup_element.class.php#L117-L149
218,195
moodle/moodle
backup/util/structure/backup_optigroup_element.class.php
backup_optigroup_element.set_parent
protected function set_parent($element) { parent::set_parent($element); // Force condition param calculation $this->set_condition($this->conditionparam, $this->conditionvalue); }
php
protected function set_parent($element) { parent::set_parent($element); // Force condition param calculation $this->set_condition($this->conditionparam, $this->conditionvalue); }
[ "protected", "function", "set_parent", "(", "$", "element", ")", "{", "parent", "::", "set_parent", "(", "$", "element", ")", ";", "// Force condition param calculation", "$", "this", "->", "set_condition", "(", "$", "this", "->", "conditionparam", ",", "$", "this", "->", "conditionvalue", ")", ";", "}" ]
Set the parent of the optigroup_element and, at the same time, process the condition param
[ "Set", "the", "parent", "of", "the", "optigroup_element", "and", "at", "the", "same", "time", "process", "the", "condition", "param" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/util/structure/backup_optigroup_element.class.php#L188-L192
218,196
moodle/moodle
admin/tool/generator/classes/backend.php
tool_generator_backend.size_for_name
public static function size_for_name($sizename) { for ($size = self::MIN_SIZE; $size <= self::MAX_SIZE; $size++) { if ($sizename == get_string('shortsize_' . $size, 'tool_generator')) { return $size; } } throw new coding_exception("Unknown size name '$sizename'"); }
php
public static function size_for_name($sizename) { for ($size = self::MIN_SIZE; $size <= self::MAX_SIZE; $size++) { if ($sizename == get_string('shortsize_' . $size, 'tool_generator')) { return $size; } } throw new coding_exception("Unknown size name '$sizename'"); }
[ "public", "static", "function", "size_for_name", "(", "$", "sizename", ")", "{", "for", "(", "$", "size", "=", "self", "::", "MIN_SIZE", ";", "$", "size", "<=", "self", "::", "MAX_SIZE", ";", "$", "size", "++", ")", "{", "if", "(", "$", "sizename", "==", "get_string", "(", "'shortsize_'", ".", "$", "size", ",", "'tool_generator'", ")", ")", "{", "return", "$", "size", ";", "}", "}", "throw", "new", "coding_exception", "(", "\"Unknown size name '$sizename'\"", ")", ";", "}" ]
Converts a size name into the numeric constant. @param string $sizename Size name e.g. 'L' @return int Numeric version @throws coding_exception If the size name is not known
[ "Converts", "a", "size", "name", "into", "the", "numeric", "constant", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/generator/classes/backend.php#L114-L121
218,197
moodle/moodle
admin/tool/generator/classes/backend.php
tool_generator_backend.log
protected function log($langstring, $a = null, $leaveopen = false) { if (!$this->progress) { return; } if (CLI_SCRIPT) { echo '* '; } else { echo html_writer::start_tag('li'); } echo get_string('progress_' . $langstring, 'tool_generator', $a); if (!$leaveopen) { if (CLI_SCRIPT) { echo "\n"; } else { echo html_writer::end_tag('li'); } } else { echo ': '; $this->lastdot = time(); $this->lastpercentage = $this->lastdot; $this->starttime = microtime(true); } }
php
protected function log($langstring, $a = null, $leaveopen = false) { if (!$this->progress) { return; } if (CLI_SCRIPT) { echo '* '; } else { echo html_writer::start_tag('li'); } echo get_string('progress_' . $langstring, 'tool_generator', $a); if (!$leaveopen) { if (CLI_SCRIPT) { echo "\n"; } else { echo html_writer::end_tag('li'); } } else { echo ': '; $this->lastdot = time(); $this->lastpercentage = $this->lastdot; $this->starttime = microtime(true); } }
[ "protected", "function", "log", "(", "$", "langstring", ",", "$", "a", "=", "null", ",", "$", "leaveopen", "=", "false", ")", "{", "if", "(", "!", "$", "this", "->", "progress", ")", "{", "return", ";", "}", "if", "(", "CLI_SCRIPT", ")", "{", "echo", "'* '", ";", "}", "else", "{", "echo", "html_writer", "::", "start_tag", "(", "'li'", ")", ";", "}", "echo", "get_string", "(", "'progress_'", ".", "$", "langstring", ",", "'tool_generator'", ",", "$", "a", ")", ";", "if", "(", "!", "$", "leaveopen", ")", "{", "if", "(", "CLI_SCRIPT", ")", "{", "echo", "\"\\n\"", ";", "}", "else", "{", "echo", "html_writer", "::", "end_tag", "(", "'li'", ")", ";", "}", "}", "else", "{", "echo", "': '", ";", "$", "this", "->", "lastdot", "=", "time", "(", ")", ";", "$", "this", "->", "lastpercentage", "=", "$", "this", "->", "lastdot", ";", "$", "this", "->", "starttime", "=", "microtime", "(", "true", ")", ";", "}", "}" ]
Displays information as part of progress. @param string $langstring Part of langstring (after progress_) @param mixed $a Optional lang string parameters @param bool $leaveopen If true, doesn't close LI tag (ready for dots)
[ "Displays", "information", "as", "part", "of", "progress", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/generator/classes/backend.php#L129-L151
218,198
moodle/moodle
admin/tool/generator/classes/backend.php
tool_generator_backend.dot
protected function dot($number, $total) { if (!$this->progress) { return; } $now = time(); if ($now == $this->lastdot) { return; } $this->lastdot = $now; if (CLI_SCRIPT) { echo '.'; } else { echo ' . '; } if ($now - $this->lastpercentage >= 30) { echo round(100.0 * $number / $total, 1) . '%'; $this->lastpercentage = $now; } // Update time limit so PHP doesn't time out. if (!CLI_SCRIPT) { core_php_time_limit::raise(120); } }
php
protected function dot($number, $total) { if (!$this->progress) { return; } $now = time(); if ($now == $this->lastdot) { return; } $this->lastdot = $now; if (CLI_SCRIPT) { echo '.'; } else { echo ' . '; } if ($now - $this->lastpercentage >= 30) { echo round(100.0 * $number / $total, 1) . '%'; $this->lastpercentage = $now; } // Update time limit so PHP doesn't time out. if (!CLI_SCRIPT) { core_php_time_limit::raise(120); } }
[ "protected", "function", "dot", "(", "$", "number", ",", "$", "total", ")", "{", "if", "(", "!", "$", "this", "->", "progress", ")", "{", "return", ";", "}", "$", "now", "=", "time", "(", ")", ";", "if", "(", "$", "now", "==", "$", "this", "->", "lastdot", ")", "{", "return", ";", "}", "$", "this", "->", "lastdot", "=", "$", "now", ";", "if", "(", "CLI_SCRIPT", ")", "{", "echo", "'.'", ";", "}", "else", "{", "echo", "' . '", ";", "}", "if", "(", "$", "now", "-", "$", "this", "->", "lastpercentage", ">=", "30", ")", "{", "echo", "round", "(", "100.0", "*", "$", "number", "/", "$", "total", ",", "1", ")", ".", "'%'", ";", "$", "this", "->", "lastpercentage", "=", "$", "now", ";", "}", "// Update time limit so PHP doesn't time out.", "if", "(", "!", "CLI_SCRIPT", ")", "{", "core_php_time_limit", "::", "raise", "(", "120", ")", ";", "}", "}" ]
Outputs dots. There is up to one dot per second. Once a minute, it displays a percentage. @param int $number Number of completed items @param int $total Total number of items to complete
[ "Outputs", "dots", ".", "There", "is", "up", "to", "one", "dot", "per", "second", ".", "Once", "a", "minute", "it", "displays", "a", "percentage", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/generator/classes/backend.php#L159-L182
218,199
moodle/moodle
lib/adodb/adodb-active-record.inc.php
ADODB_Active_Record.Replace
function Replace() { global $ADODB_ASSOC_CASE; $db = $this->DB(); if (!$db) { return false; } $table = $this->TableInfo(); $pkey = $table->keys; foreach($table->flds as $name=>$fld) { $val = $this->$name; /* if (is_null($val)) { if (isset($fld->not_null) && $fld->not_null) { if (isset($fld->default_value) && strlen($fld->default_value)) { continue; } else { $this->Error("Cannot update null into $name","Replace"); return false; } } }*/ if (is_null($val) && !empty($fld->auto_increment)) { continue; } if (is_array($val)) { continue; } $t = $db->MetaType($fld->type); $arr[$name] = $this->doquote($db,$val,$t); $valarr[] = $val; } if (!is_array($pkey)) { $pkey = array($pkey); } if ($ADODB_ASSOC_CASE == 0) { foreach($pkey as $k => $v) $pkey[$k] = strtolower($v); } elseif ($ADODB_ASSOC_CASE == 1) { foreach($pkey as $k => $v) { $pkey[$k] = strtoupper($v); } } $ok = $db->Replace($this->_table,$arr,$pkey); if ($ok) { $this->_saved = true; // 1= update 2=insert if ($ok == 2) { $autoinc = false; foreach($table->keys as $k) { if (is_null($this->$k)) { $autoinc = true; break; } } if ($autoinc && sizeof($table->keys) == 1) { $k = reset($table->keys); $this->$k = $this->LastInsertID($db,$k); } } $this->_original = $valarr; } return $ok; }
php
function Replace() { global $ADODB_ASSOC_CASE; $db = $this->DB(); if (!$db) { return false; } $table = $this->TableInfo(); $pkey = $table->keys; foreach($table->flds as $name=>$fld) { $val = $this->$name; /* if (is_null($val)) { if (isset($fld->not_null) && $fld->not_null) { if (isset($fld->default_value) && strlen($fld->default_value)) { continue; } else { $this->Error("Cannot update null into $name","Replace"); return false; } } }*/ if (is_null($val) && !empty($fld->auto_increment)) { continue; } if (is_array($val)) { continue; } $t = $db->MetaType($fld->type); $arr[$name] = $this->doquote($db,$val,$t); $valarr[] = $val; } if (!is_array($pkey)) { $pkey = array($pkey); } if ($ADODB_ASSOC_CASE == 0) { foreach($pkey as $k => $v) $pkey[$k] = strtolower($v); } elseif ($ADODB_ASSOC_CASE == 1) { foreach($pkey as $k => $v) { $pkey[$k] = strtoupper($v); } } $ok = $db->Replace($this->_table,$arr,$pkey); if ($ok) { $this->_saved = true; // 1= update 2=insert if ($ok == 2) { $autoinc = false; foreach($table->keys as $k) { if (is_null($this->$k)) { $autoinc = true; break; } } if ($autoinc && sizeof($table->keys) == 1) { $k = reset($table->keys); $this->$k = $this->LastInsertID($db,$k); } } $this->_original = $valarr; } return $ok; }
[ "function", "Replace", "(", ")", "{", "global", "$", "ADODB_ASSOC_CASE", ";", "$", "db", "=", "$", "this", "->", "DB", "(", ")", ";", "if", "(", "!", "$", "db", ")", "{", "return", "false", ";", "}", "$", "table", "=", "$", "this", "->", "TableInfo", "(", ")", ";", "$", "pkey", "=", "$", "table", "->", "keys", ";", "foreach", "(", "$", "table", "->", "flds", "as", "$", "name", "=>", "$", "fld", ")", "{", "$", "val", "=", "$", "this", "->", "$", "name", ";", "/*\n\t\t\tif (is_null($val)) {\n\t\t\t\tif (isset($fld->not_null) && $fld->not_null) {\n\t\t\t\t\tif (isset($fld->default_value) && strlen($fld->default_value)) {\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\t\telse {\n\t\t\t\t\t\t$this->Error(\"Cannot update null into $name\",\"Replace\");\n\t\t\t\t\t\treturn false;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}*/", "if", "(", "is_null", "(", "$", "val", ")", "&&", "!", "empty", "(", "$", "fld", "->", "auto_increment", ")", ")", "{", "continue", ";", "}", "if", "(", "is_array", "(", "$", "val", ")", ")", "{", "continue", ";", "}", "$", "t", "=", "$", "db", "->", "MetaType", "(", "$", "fld", "->", "type", ")", ";", "$", "arr", "[", "$", "name", "]", "=", "$", "this", "->", "doquote", "(", "$", "db", ",", "$", "val", ",", "$", "t", ")", ";", "$", "valarr", "[", "]", "=", "$", "val", ";", "}", "if", "(", "!", "is_array", "(", "$", "pkey", ")", ")", "{", "$", "pkey", "=", "array", "(", "$", "pkey", ")", ";", "}", "if", "(", "$", "ADODB_ASSOC_CASE", "==", "0", ")", "{", "foreach", "(", "$", "pkey", "as", "$", "k", "=>", "$", "v", ")", "$", "pkey", "[", "$", "k", "]", "=", "strtolower", "(", "$", "v", ")", ";", "}", "elseif", "(", "$", "ADODB_ASSOC_CASE", "==", "1", ")", "{", "foreach", "(", "$", "pkey", "as", "$", "k", "=>", "$", "v", ")", "{", "$", "pkey", "[", "$", "k", "]", "=", "strtoupper", "(", "$", "v", ")", ";", "}", "}", "$", "ok", "=", "$", "db", "->", "Replace", "(", "$", "this", "->", "_table", ",", "$", "arr", ",", "$", "pkey", ")", ";", "if", "(", "$", "ok", ")", "{", "$", "this", "->", "_saved", "=", "true", ";", "// 1= update 2=insert", "if", "(", "$", "ok", "==", "2", ")", "{", "$", "autoinc", "=", "false", ";", "foreach", "(", "$", "table", "->", "keys", "as", "$", "k", ")", "{", "if", "(", "is_null", "(", "$", "this", "->", "$", "k", ")", ")", "{", "$", "autoinc", "=", "true", ";", "break", ";", "}", "}", "if", "(", "$", "autoinc", "&&", "sizeof", "(", "$", "table", "->", "keys", ")", "==", "1", ")", "{", "$", "k", "=", "reset", "(", "$", "table", "->", "keys", ")", ";", "$", "this", "->", "$", "k", "=", "$", "this", "->", "LastInsertID", "(", "$", "db", ",", "$", "k", ")", ";", "}", "}", "$", "this", "->", "_original", "=", "$", "valarr", ";", "}", "return", "$", "ok", ";", "}" ]
returns 0 on error, 1 on update, 2 on insert
[ "returns", "0", "on", "error", "1", "on", "update", "2", "on", "insert" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/adodb/adodb-active-record.inc.php#L928-L1001