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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
213,600 | moodle/moodle | mod/assign/feedback/editpdf/classes/page_editor.php | page_editor.get_annotation | public static function get_annotation($annotationid) {
global $DB;
$record = $DB->get_record('assignfeedback_editpdf_annot', array('id'=>$annotationid), '*', IGNORE_MISSING);
if ($record) {
return new annotation($record);
}
return false;
} | php | public static function get_annotation($annotationid) {
global $DB;
$record = $DB->get_record('assignfeedback_editpdf_annot', array('id'=>$annotationid), '*', IGNORE_MISSING);
if ($record) {
return new annotation($record);
}
return false;
} | [
"public",
"static",
"function",
"get_annotation",
"(",
"$",
"annotationid",
")",
"{",
"global",
"$",
"DB",
";",
"$",
"record",
"=",
"$",
"DB",
"->",
"get_record",
"(",
"'assignfeedback_editpdf_annot'",
",",
"array",
"(",
"'id'",
"=>",
"$",
"annotationid",
")",
",",
"'*'",
",",
"IGNORE_MISSING",
")",
";",
"if",
"(",
"$",
"record",
")",
"{",
"return",
"new",
"annotation",
"(",
"$",
"record",
")",
";",
"}",
"return",
"false",
";",
"}"
] | Get a single annotation by id.
@param int $annotationid
@return annotation or false | [
"Get",
"a",
"single",
"annotation",
"by",
"id",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/assign/feedback/editpdf/classes/page_editor.php#L188-L196 |
213,601 | moodle/moodle | mod/assign/feedback/editpdf/classes/page_editor.php | page_editor.release_drafts | public static function release_drafts($gradeid) {
global $DB;
// Delete the previous non-draft annotations and comments.
$DB->delete_records('assignfeedback_editpdf_cmnt', array('gradeid'=>$gradeid, 'draft'=>0));
$DB->delete_records('assignfeedback_editpdf_annot', array('gradeid'=>$gradeid, 'draft'=>0));
// Copy all the draft annotations and comments to non-drafts.
$records = $DB->get_records('assignfeedback_editpdf_annot', array('gradeid'=>$gradeid, 'draft'=>1));
foreach ($records as $record) {
unset($record->id);
$record->draft = 0;
$DB->insert_record('assignfeedback_editpdf_annot', $record);
}
$records = $DB->get_records('assignfeedback_editpdf_cmnt', array('gradeid'=>$gradeid, 'draft'=>1));
foreach ($records as $record) {
unset($record->id);
$record->draft = 0;
$DB->insert_record('assignfeedback_editpdf_cmnt', $record);
}
return true;
} | php | public static function release_drafts($gradeid) {
global $DB;
// Delete the previous non-draft annotations and comments.
$DB->delete_records('assignfeedback_editpdf_cmnt', array('gradeid'=>$gradeid, 'draft'=>0));
$DB->delete_records('assignfeedback_editpdf_annot', array('gradeid'=>$gradeid, 'draft'=>0));
// Copy all the draft annotations and comments to non-drafts.
$records = $DB->get_records('assignfeedback_editpdf_annot', array('gradeid'=>$gradeid, 'draft'=>1));
foreach ($records as $record) {
unset($record->id);
$record->draft = 0;
$DB->insert_record('assignfeedback_editpdf_annot', $record);
}
$records = $DB->get_records('assignfeedback_editpdf_cmnt', array('gradeid'=>$gradeid, 'draft'=>1));
foreach ($records as $record) {
unset($record->id);
$record->draft = 0;
$DB->insert_record('assignfeedback_editpdf_cmnt', $record);
}
return true;
} | [
"public",
"static",
"function",
"release_drafts",
"(",
"$",
"gradeid",
")",
"{",
"global",
"$",
"DB",
";",
"// Delete the previous non-draft annotations and comments.",
"$",
"DB",
"->",
"delete_records",
"(",
"'assignfeedback_editpdf_cmnt'",
",",
"array",
"(",
"'gradeid'",
"=>",
"$",
"gradeid",
",",
"'draft'",
"=>",
"0",
")",
")",
";",
"$",
"DB",
"->",
"delete_records",
"(",
"'assignfeedback_editpdf_annot'",
",",
"array",
"(",
"'gradeid'",
"=>",
"$",
"gradeid",
",",
"'draft'",
"=>",
"0",
")",
")",
";",
"// Copy all the draft annotations and comments to non-drafts.",
"$",
"records",
"=",
"$",
"DB",
"->",
"get_records",
"(",
"'assignfeedback_editpdf_annot'",
",",
"array",
"(",
"'gradeid'",
"=>",
"$",
"gradeid",
",",
"'draft'",
"=>",
"1",
")",
")",
";",
"foreach",
"(",
"$",
"records",
"as",
"$",
"record",
")",
"{",
"unset",
"(",
"$",
"record",
"->",
"id",
")",
";",
"$",
"record",
"->",
"draft",
"=",
"0",
";",
"$",
"DB",
"->",
"insert_record",
"(",
"'assignfeedback_editpdf_annot'",
",",
"$",
"record",
")",
";",
"}",
"$",
"records",
"=",
"$",
"DB",
"->",
"get_records",
"(",
"'assignfeedback_editpdf_cmnt'",
",",
"array",
"(",
"'gradeid'",
"=>",
"$",
"gradeid",
",",
"'draft'",
"=>",
"1",
")",
")",
";",
"foreach",
"(",
"$",
"records",
"as",
"$",
"record",
")",
"{",
"unset",
"(",
"$",
"record",
"->",
"id",
")",
";",
"$",
"record",
"->",
"draft",
"=",
"0",
";",
"$",
"DB",
"->",
"insert_record",
"(",
"'assignfeedback_editpdf_cmnt'",
",",
"$",
"record",
")",
";",
"}",
"return",
"true",
";",
"}"
] | Release the draft comments and annotations to students.
@param int $gradeid
@return bool | [
"Release",
"the",
"draft",
"comments",
"and",
"annotations",
"to",
"students",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/assign/feedback/editpdf/classes/page_editor.php#L217-L239 |
213,602 | moodle/moodle | mod/assign/feedback/editpdf/classes/page_editor.php | page_editor.has_annotations_or_comments | public static function has_annotations_or_comments($gradeid, $includedraft) {
global $DB;
$params = array('gradeid'=>$gradeid);
if (!$includedraft) {
$params['draft'] = 0;
}
if ($DB->count_records('assignfeedback_editpdf_cmnt', $params)) {
return true;
}
if ($DB->count_records('assignfeedback_editpdf_annot', $params)) {
return true;
}
return false;
} | php | public static function has_annotations_or_comments($gradeid, $includedraft) {
global $DB;
$params = array('gradeid'=>$gradeid);
if (!$includedraft) {
$params['draft'] = 0;
}
if ($DB->count_records('assignfeedback_editpdf_cmnt', $params)) {
return true;
}
if ($DB->count_records('assignfeedback_editpdf_annot', $params)) {
return true;
}
return false;
} | [
"public",
"static",
"function",
"has_annotations_or_comments",
"(",
"$",
"gradeid",
",",
"$",
"includedraft",
")",
"{",
"global",
"$",
"DB",
";",
"$",
"params",
"=",
"array",
"(",
"'gradeid'",
"=>",
"$",
"gradeid",
")",
";",
"if",
"(",
"!",
"$",
"includedraft",
")",
"{",
"$",
"params",
"[",
"'draft'",
"]",
"=",
"0",
";",
"}",
"if",
"(",
"$",
"DB",
"->",
"count_records",
"(",
"'assignfeedback_editpdf_cmnt'",
",",
"$",
"params",
")",
")",
"{",
"return",
"true",
";",
"}",
"if",
"(",
"$",
"DB",
"->",
"count_records",
"(",
"'assignfeedback_editpdf_annot'",
",",
"$",
"params",
")",
")",
"{",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
] | Has annotations or comments.
@param int $gradeid
@return bool | [
"Has",
"annotations",
"or",
"comments",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/assign/feedback/editpdf/classes/page_editor.php#L246-L259 |
213,603 | moodle/moodle | mod/assign/feedback/editpdf/classes/page_editor.php | page_editor.add_annotation | public static function add_annotation(annotation $annotation) {
global $DB;
$annotation->id = null;
return $DB->insert_record('assignfeedback_editpdf_annot', $annotation);
} | php | public static function add_annotation(annotation $annotation) {
global $DB;
$annotation->id = null;
return $DB->insert_record('assignfeedback_editpdf_annot', $annotation);
} | [
"public",
"static",
"function",
"add_annotation",
"(",
"annotation",
"$",
"annotation",
")",
"{",
"global",
"$",
"DB",
";",
"$",
"annotation",
"->",
"id",
"=",
"null",
";",
"return",
"$",
"DB",
"->",
"insert_record",
"(",
"'assignfeedback_editpdf_annot'",
",",
"$",
"annotation",
")",
";",
"}"
] | Add a annotation to a page.
@param annotation $annotation
@return bool | [
"Add",
"a",
"annotation",
"to",
"a",
"page",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/assign/feedback/editpdf/classes/page_editor.php#L295-L300 |
213,604 | moodle/moodle | mod/assign/feedback/editpdf/classes/page_editor.php | page_editor.copy_drafts_from_to | public static function copy_drafts_from_to($assignment, $grade, $sourceuserid) {
global $DB;
// Delete any existing annotations and comments from current user.
$DB->delete_records('assignfeedback_editpdf_annot', array('gradeid' => $grade->id));
$DB->delete_records('assignfeedback_editpdf_cmnt', array('gradeid' => $grade->id));
// Get gradeid, annotations and comments from sourceuserid.
$sourceusergrade = $assignment->get_user_grade($sourceuserid, true, $grade->attemptnumber);
$annotations = $DB->get_records('assignfeedback_editpdf_annot', array('gradeid' => $sourceusergrade->id, 'draft' => 1));
$comments = $DB->get_records('assignfeedback_editpdf_cmnt', array('gradeid' => $sourceusergrade->id, 'draft' => 1));
$contextid = $assignment->get_context()->id;
$sourceitemid = $sourceusergrade->id;
// Add annotations and comments to current user to generate feedback file.
foreach ($annotations as $annotation) {
$annotation->gradeid = $grade->id;
$DB->insert_record('assignfeedback_editpdf_annot', $annotation);
}
foreach ($comments as $comment) {
$comment->gradeid = $grade->id;
$DB->insert_record('assignfeedback_editpdf_cmnt', $comment);
}
$fs = get_file_storage();
// Copy the stamp files.
self::replace_files_from_to($fs, $contextid, $sourceitemid, $grade->id, document_services::STAMPS_FILEAREA, true);
// Copy the PAGE_IMAGE_FILEAREA files.
self::replace_files_from_to($fs, $contextid, $sourceitemid, $grade->id, document_services::PAGE_IMAGE_FILEAREA);
return true;
} | php | public static function copy_drafts_from_to($assignment, $grade, $sourceuserid) {
global $DB;
// Delete any existing annotations and comments from current user.
$DB->delete_records('assignfeedback_editpdf_annot', array('gradeid' => $grade->id));
$DB->delete_records('assignfeedback_editpdf_cmnt', array('gradeid' => $grade->id));
// Get gradeid, annotations and comments from sourceuserid.
$sourceusergrade = $assignment->get_user_grade($sourceuserid, true, $grade->attemptnumber);
$annotations = $DB->get_records('assignfeedback_editpdf_annot', array('gradeid' => $sourceusergrade->id, 'draft' => 1));
$comments = $DB->get_records('assignfeedback_editpdf_cmnt', array('gradeid' => $sourceusergrade->id, 'draft' => 1));
$contextid = $assignment->get_context()->id;
$sourceitemid = $sourceusergrade->id;
// Add annotations and comments to current user to generate feedback file.
foreach ($annotations as $annotation) {
$annotation->gradeid = $grade->id;
$DB->insert_record('assignfeedback_editpdf_annot', $annotation);
}
foreach ($comments as $comment) {
$comment->gradeid = $grade->id;
$DB->insert_record('assignfeedback_editpdf_cmnt', $comment);
}
$fs = get_file_storage();
// Copy the stamp files.
self::replace_files_from_to($fs, $contextid, $sourceitemid, $grade->id, document_services::STAMPS_FILEAREA, true);
// Copy the PAGE_IMAGE_FILEAREA files.
self::replace_files_from_to($fs, $contextid, $sourceitemid, $grade->id, document_services::PAGE_IMAGE_FILEAREA);
return true;
} | [
"public",
"static",
"function",
"copy_drafts_from_to",
"(",
"$",
"assignment",
",",
"$",
"grade",
",",
"$",
"sourceuserid",
")",
"{",
"global",
"$",
"DB",
";",
"// Delete any existing annotations and comments from current user.",
"$",
"DB",
"->",
"delete_records",
"(",
"'assignfeedback_editpdf_annot'",
",",
"array",
"(",
"'gradeid'",
"=>",
"$",
"grade",
"->",
"id",
")",
")",
";",
"$",
"DB",
"->",
"delete_records",
"(",
"'assignfeedback_editpdf_cmnt'",
",",
"array",
"(",
"'gradeid'",
"=>",
"$",
"grade",
"->",
"id",
")",
")",
";",
"// Get gradeid, annotations and comments from sourceuserid.",
"$",
"sourceusergrade",
"=",
"$",
"assignment",
"->",
"get_user_grade",
"(",
"$",
"sourceuserid",
",",
"true",
",",
"$",
"grade",
"->",
"attemptnumber",
")",
";",
"$",
"annotations",
"=",
"$",
"DB",
"->",
"get_records",
"(",
"'assignfeedback_editpdf_annot'",
",",
"array",
"(",
"'gradeid'",
"=>",
"$",
"sourceusergrade",
"->",
"id",
",",
"'draft'",
"=>",
"1",
")",
")",
";",
"$",
"comments",
"=",
"$",
"DB",
"->",
"get_records",
"(",
"'assignfeedback_editpdf_cmnt'",
",",
"array",
"(",
"'gradeid'",
"=>",
"$",
"sourceusergrade",
"->",
"id",
",",
"'draft'",
"=>",
"1",
")",
")",
";",
"$",
"contextid",
"=",
"$",
"assignment",
"->",
"get_context",
"(",
")",
"->",
"id",
";",
"$",
"sourceitemid",
"=",
"$",
"sourceusergrade",
"->",
"id",
";",
"// Add annotations and comments to current user to generate feedback file.",
"foreach",
"(",
"$",
"annotations",
"as",
"$",
"annotation",
")",
"{",
"$",
"annotation",
"->",
"gradeid",
"=",
"$",
"grade",
"->",
"id",
";",
"$",
"DB",
"->",
"insert_record",
"(",
"'assignfeedback_editpdf_annot'",
",",
"$",
"annotation",
")",
";",
"}",
"foreach",
"(",
"$",
"comments",
"as",
"$",
"comment",
")",
"{",
"$",
"comment",
"->",
"gradeid",
"=",
"$",
"grade",
"->",
"id",
";",
"$",
"DB",
"->",
"insert_record",
"(",
"'assignfeedback_editpdf_cmnt'",
",",
"$",
"comment",
")",
";",
"}",
"$",
"fs",
"=",
"get_file_storage",
"(",
")",
";",
"// Copy the stamp files.",
"self",
"::",
"replace_files_from_to",
"(",
"$",
"fs",
",",
"$",
"contextid",
",",
"$",
"sourceitemid",
",",
"$",
"grade",
"->",
"id",
",",
"document_services",
"::",
"STAMPS_FILEAREA",
",",
"true",
")",
";",
"// Copy the PAGE_IMAGE_FILEAREA files.",
"self",
"::",
"replace_files_from_to",
"(",
"$",
"fs",
",",
"$",
"contextid",
",",
"$",
"sourceitemid",
",",
"$",
"grade",
"->",
"id",
",",
"document_services",
"::",
"PAGE_IMAGE_FILEAREA",
")",
";",
"return",
"true",
";",
"}"
] | Copy annotations, comments, pages, and other required content from the source user to the current group member
being procssed when using applytoall.
@param int|\assign $assignment
@param stdClass $grade
@param int $sourceuserid
@return bool | [
"Copy",
"annotations",
"comments",
"pages",
"and",
"other",
"required",
"content",
"from",
"the",
"source",
"user",
"to",
"the",
"current",
"group",
"member",
"being",
"procssed",
"when",
"using",
"applytoall",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/assign/feedback/editpdf/classes/page_editor.php#L322-L354 |
213,605 | moodle/moodle | mod/assign/feedback/editpdf/classes/page_editor.php | page_editor.replace_files_from_to | public static function replace_files_from_to($fs, $contextid, $sourceitemid, $itemid, $area, $includesubdirs = false) {
$component = 'assignfeedback_editpdf';
// Remove the existing files within this area.
$fs->delete_area_files($contextid, $component, $area, $itemid);
// Copy the files from the source area.
if ($files = $fs->get_area_files($contextid, $component, $area, $sourceitemid,
"filename", $includesubdirs)) {
foreach ($files as $file) {
$newrecord = new \stdClass();
$newrecord->contextid = $contextid;
$newrecord->itemid = $itemid;
$fs->create_file_from_storedfile($newrecord, $file);
}
}
} | php | public static function replace_files_from_to($fs, $contextid, $sourceitemid, $itemid, $area, $includesubdirs = false) {
$component = 'assignfeedback_editpdf';
// Remove the existing files within this area.
$fs->delete_area_files($contextid, $component, $area, $itemid);
// Copy the files from the source area.
if ($files = $fs->get_area_files($contextid, $component, $area, $sourceitemid,
"filename", $includesubdirs)) {
foreach ($files as $file) {
$newrecord = new \stdClass();
$newrecord->contextid = $contextid;
$newrecord->itemid = $itemid;
$fs->create_file_from_storedfile($newrecord, $file);
}
}
} | [
"public",
"static",
"function",
"replace_files_from_to",
"(",
"$",
"fs",
",",
"$",
"contextid",
",",
"$",
"sourceitemid",
",",
"$",
"itemid",
",",
"$",
"area",
",",
"$",
"includesubdirs",
"=",
"false",
")",
"{",
"$",
"component",
"=",
"'assignfeedback_editpdf'",
";",
"// Remove the existing files within this area.",
"$",
"fs",
"->",
"delete_area_files",
"(",
"$",
"contextid",
",",
"$",
"component",
",",
"$",
"area",
",",
"$",
"itemid",
")",
";",
"// Copy the files from the source area.",
"if",
"(",
"$",
"files",
"=",
"$",
"fs",
"->",
"get_area_files",
"(",
"$",
"contextid",
",",
"$",
"component",
",",
"$",
"area",
",",
"$",
"sourceitemid",
",",
"\"filename\"",
",",
"$",
"includesubdirs",
")",
")",
"{",
"foreach",
"(",
"$",
"files",
"as",
"$",
"file",
")",
"{",
"$",
"newrecord",
"=",
"new",
"\\",
"stdClass",
"(",
")",
";",
"$",
"newrecord",
"->",
"contextid",
"=",
"$",
"contextid",
";",
"$",
"newrecord",
"->",
"itemid",
"=",
"$",
"itemid",
";",
"$",
"fs",
"->",
"create_file_from_storedfile",
"(",
"$",
"newrecord",
",",
"$",
"file",
")",
";",
"}",
"}",
"}"
] | Replace the area files in the specified area with those in the source item id.
@param \file_storage $fs The file storage class
@param int $contextid The ID of the context for the assignment.
@param int $sourceitemid The itemid to copy from - typically the source grade id.
@param int $itemid The itemid to copy to - typically the target grade id.
@param string $area The file storage area.
@param bool $includesubdirs Whether to copy the content of sub-directories too. | [
"Replace",
"the",
"area",
"files",
"in",
"the",
"specified",
"area",
"with",
"those",
"in",
"the",
"source",
"item",
"id",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/assign/feedback/editpdf/classes/page_editor.php#L366-L381 |
213,606 | moodle/moodle | mod/assign/feedback/editpdf/classes/page_editor.php | page_editor.delete_draft_content | public static function delete_draft_content($gradeid) {
global $DB;
$conditions = array('gradeid' => $gradeid, 'draft' => 1);
$result = $DB->delete_records('assignfeedback_editpdf_annot', $conditions);
$result = $result && $DB->delete_records('assignfeedback_editpdf_cmnt', $conditions);
return $result;
} | php | public static function delete_draft_content($gradeid) {
global $DB;
$conditions = array('gradeid' => $gradeid, 'draft' => 1);
$result = $DB->delete_records('assignfeedback_editpdf_annot', $conditions);
$result = $result && $DB->delete_records('assignfeedback_editpdf_cmnt', $conditions);
return $result;
} | [
"public",
"static",
"function",
"delete_draft_content",
"(",
"$",
"gradeid",
")",
"{",
"global",
"$",
"DB",
";",
"$",
"conditions",
"=",
"array",
"(",
"'gradeid'",
"=>",
"$",
"gradeid",
",",
"'draft'",
"=>",
"1",
")",
";",
"$",
"result",
"=",
"$",
"DB",
"->",
"delete_records",
"(",
"'assignfeedback_editpdf_annot'",
",",
"$",
"conditions",
")",
";",
"$",
"result",
"=",
"$",
"result",
"&&",
"$",
"DB",
"->",
"delete_records",
"(",
"'assignfeedback_editpdf_cmnt'",
",",
"$",
"conditions",
")",
";",
"return",
"$",
"result",
";",
"}"
] | Delete the draft annotations and comments.
This is intended to be used when the version of the PDF has changed and the annotations
might not be relevant any more, therefore we should delete them.
@param int $gradeid The grade ID.
@return bool | [
"Delete",
"the",
"draft",
"annotations",
"and",
"comments",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/assign/feedback/editpdf/classes/page_editor.php#L392-L398 |
213,607 | moodle/moodle | mod/assign/feedback/editpdf/classes/page_editor.php | page_editor.set_page_rotation | public static function set_page_rotation($gradeid, $pageno, $isrotated, $pathnamehash, $degree = 0) {
global $DB;
$oldrecord = self::get_page_rotation($gradeid, $pageno);
if ($oldrecord == null) {
$record = new \stdClass();
$record->gradeid = $gradeid;
$record->pageno = $pageno;
$record->isrotated = $isrotated;
$record->pathnamehash = $pathnamehash;
$record->degree = $degree;
$DB->insert_record('assignfeedback_editpdf_rot', $record, false);
} else {
$oldrecord->isrotated = $isrotated;
$oldrecord->pathnamehash = $pathnamehash;
$oldrecord->degree = $degree;
$DB->update_record('assignfeedback_editpdf_rot', $oldrecord, false);
}
} | php | public static function set_page_rotation($gradeid, $pageno, $isrotated, $pathnamehash, $degree = 0) {
global $DB;
$oldrecord = self::get_page_rotation($gradeid, $pageno);
if ($oldrecord == null) {
$record = new \stdClass();
$record->gradeid = $gradeid;
$record->pageno = $pageno;
$record->isrotated = $isrotated;
$record->pathnamehash = $pathnamehash;
$record->degree = $degree;
$DB->insert_record('assignfeedback_editpdf_rot', $record, false);
} else {
$oldrecord->isrotated = $isrotated;
$oldrecord->pathnamehash = $pathnamehash;
$oldrecord->degree = $degree;
$DB->update_record('assignfeedback_editpdf_rot', $oldrecord, false);
}
} | [
"public",
"static",
"function",
"set_page_rotation",
"(",
"$",
"gradeid",
",",
"$",
"pageno",
",",
"$",
"isrotated",
",",
"$",
"pathnamehash",
",",
"$",
"degree",
"=",
"0",
")",
"{",
"global",
"$",
"DB",
";",
"$",
"oldrecord",
"=",
"self",
"::",
"get_page_rotation",
"(",
"$",
"gradeid",
",",
"$",
"pageno",
")",
";",
"if",
"(",
"$",
"oldrecord",
"==",
"null",
")",
"{",
"$",
"record",
"=",
"new",
"\\",
"stdClass",
"(",
")",
";",
"$",
"record",
"->",
"gradeid",
"=",
"$",
"gradeid",
";",
"$",
"record",
"->",
"pageno",
"=",
"$",
"pageno",
";",
"$",
"record",
"->",
"isrotated",
"=",
"$",
"isrotated",
";",
"$",
"record",
"->",
"pathnamehash",
"=",
"$",
"pathnamehash",
";",
"$",
"record",
"->",
"degree",
"=",
"$",
"degree",
";",
"$",
"DB",
"->",
"insert_record",
"(",
"'assignfeedback_editpdf_rot'",
",",
"$",
"record",
",",
"false",
")",
";",
"}",
"else",
"{",
"$",
"oldrecord",
"->",
"isrotated",
"=",
"$",
"isrotated",
";",
"$",
"oldrecord",
"->",
"pathnamehash",
"=",
"$",
"pathnamehash",
";",
"$",
"oldrecord",
"->",
"degree",
"=",
"$",
"degree",
";",
"$",
"DB",
"->",
"update_record",
"(",
"'assignfeedback_editpdf_rot'",
",",
"$",
"oldrecord",
",",
"false",
")",
";",
"}",
"}"
] | Set page rotation value.
@param int $gradeid grade id.
@param int $pageno page number.
@param bool $isrotated whether the page is rotated or not.
@param string $pathnamehash path name hash
@param int $degree rotation degree.
@throws \dml_exception | [
"Set",
"page",
"rotation",
"value",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/assign/feedback/editpdf/classes/page_editor.php#L409-L426 |
213,608 | moodle/moodle | mod/assign/feedback/editpdf/classes/page_editor.php | page_editor.get_page_rotation | public static function get_page_rotation($gradeid, $pageno) {
global $DB;
$result = $DB->get_record('assignfeedback_editpdf_rot', array('gradeid' => $gradeid, 'pageno' => $pageno));
return $result;
} | php | public static function get_page_rotation($gradeid, $pageno) {
global $DB;
$result = $DB->get_record('assignfeedback_editpdf_rot', array('gradeid' => $gradeid, 'pageno' => $pageno));
return $result;
} | [
"public",
"static",
"function",
"get_page_rotation",
"(",
"$",
"gradeid",
",",
"$",
"pageno",
")",
"{",
"global",
"$",
"DB",
";",
"$",
"result",
"=",
"$",
"DB",
"->",
"get_record",
"(",
"'assignfeedback_editpdf_rot'",
",",
"array",
"(",
"'gradeid'",
"=>",
"$",
"gradeid",
",",
"'pageno'",
"=>",
"$",
"pageno",
")",
")",
";",
"return",
"$",
"result",
";",
"}"
] | Get Page Rotation Value.
@param int $gradeid grade id.
@param int $pageno page number.
@return mixed
@throws \dml_exception | [
"Get",
"Page",
"Rotation",
"Value",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/assign/feedback/editpdf/classes/page_editor.php#L435-L439 |
213,609 | moodle/moodle | analytics/classes/local/analyser/base.php | base.get_static_data | public function get_static_data() {
// Delegates all processing to the analysis.
$result = new \core_analytics\local\analysis\result_array($this->get_modelid(), false, $this->get_options());
$analysis = new \core_analytics\analysis($this, false, $result);
$analysis->run();
return $result->get();
} | php | public function get_static_data() {
// Delegates all processing to the analysis.
$result = new \core_analytics\local\analysis\result_array($this->get_modelid(), false, $this->get_options());
$analysis = new \core_analytics\analysis($this, false, $result);
$analysis->run();
return $result->get();
} | [
"public",
"function",
"get_static_data",
"(",
")",
"{",
"// Delegates all processing to the analysis.",
"$",
"result",
"=",
"new",
"\\",
"core_analytics",
"\\",
"local",
"\\",
"analysis",
"\\",
"result_array",
"(",
"$",
"this",
"->",
"get_modelid",
"(",
")",
",",
"false",
",",
"$",
"this",
"->",
"get_options",
"(",
")",
")",
";",
"$",
"analysis",
"=",
"new",
"\\",
"core_analytics",
"\\",
"analysis",
"(",
"$",
"this",
",",
"false",
",",
"$",
"result",
")",
";",
"$",
"analysis",
"->",
"run",
"(",
")",
";",
"return",
"$",
"result",
"->",
"get",
"(",
")",
";",
"}"
] | Returns indicator calculations as an array.
@return array | [
"Returns",
"indicator",
"calculations",
"as",
"an",
"array",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/analytics/classes/local/analyser/base.php#L279-L285 |
213,610 | moodle/moodle | analytics/classes/local/analyser/base.php | base.check_indicators_requirements | protected function check_indicators_requirements() {
foreach ($this->indicators as $indicator) {
$missingrequired = $this->check_indicator_requirements($indicator);
if ($missingrequired !== true) {
throw new \core_analytics\requirements_exception(get_class($indicator) . ' indicator requires ' .
json_encode($missingrequired) . ' sample data which is not provided by ' . get_class($this));
}
}
} | php | protected function check_indicators_requirements() {
foreach ($this->indicators as $indicator) {
$missingrequired = $this->check_indicator_requirements($indicator);
if ($missingrequired !== true) {
throw new \core_analytics\requirements_exception(get_class($indicator) . ' indicator requires ' .
json_encode($missingrequired) . ' sample data which is not provided by ' . get_class($this));
}
}
} | [
"protected",
"function",
"check_indicators_requirements",
"(",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"indicators",
"as",
"$",
"indicator",
")",
"{",
"$",
"missingrequired",
"=",
"$",
"this",
"->",
"check_indicator_requirements",
"(",
"$",
"indicator",
")",
";",
"if",
"(",
"$",
"missingrequired",
"!==",
"true",
")",
"{",
"throw",
"new",
"\\",
"core_analytics",
"\\",
"requirements_exception",
"(",
"get_class",
"(",
"$",
"indicator",
")",
".",
"' indicator requires '",
".",
"json_encode",
"(",
"$",
"missingrequired",
")",
".",
"' sample data which is not provided by '",
".",
"get_class",
"(",
"$",
"this",
")",
")",
";",
"}",
"}",
"}"
] | Checks if the analyser satisfies all the model indicators requirements.
@throws \core_analytics\requirements_exception
@return void | [
"Checks",
"if",
"the",
"analyser",
"satisfies",
"all",
"the",
"model",
"indicators",
"requirements",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/analytics/classes/local/analyser/base.php#L293-L302 |
213,611 | moodle/moodle | analytics/classes/local/analyser/base.php | base.check_indicator_requirements | public function check_indicator_requirements(\core_analytics\local\indicator\base $indicator) {
$providedsampledata = $this->provided_sample_data();
$requiredsampledata = $indicator::required_sample_data();
if (empty($requiredsampledata)) {
// The indicator does not need any sample data.
return true;
}
$missingrequired = array_diff($requiredsampledata, $providedsampledata);
if (empty($missingrequired)) {
return true;
}
return $missingrequired;
} | php | public function check_indicator_requirements(\core_analytics\local\indicator\base $indicator) {
$providedsampledata = $this->provided_sample_data();
$requiredsampledata = $indicator::required_sample_data();
if (empty($requiredsampledata)) {
// The indicator does not need any sample data.
return true;
}
$missingrequired = array_diff($requiredsampledata, $providedsampledata);
if (empty($missingrequired)) {
return true;
}
return $missingrequired;
} | [
"public",
"function",
"check_indicator_requirements",
"(",
"\\",
"core_analytics",
"\\",
"local",
"\\",
"indicator",
"\\",
"base",
"$",
"indicator",
")",
"{",
"$",
"providedsampledata",
"=",
"$",
"this",
"->",
"provided_sample_data",
"(",
")",
";",
"$",
"requiredsampledata",
"=",
"$",
"indicator",
"::",
"required_sample_data",
"(",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"requiredsampledata",
")",
")",
"{",
"// The indicator does not need any sample data.",
"return",
"true",
";",
"}",
"$",
"missingrequired",
"=",
"array_diff",
"(",
"$",
"requiredsampledata",
",",
"$",
"providedsampledata",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"missingrequired",
")",
")",
"{",
"return",
"true",
";",
"}",
"return",
"$",
"missingrequired",
";",
"}"
] | Checks that this analyser satisfies the provided indicator requirements.
@param \core_analytics\local\indicator\base $indicator
@return true|string[] True if all good, missing requirements list otherwise | [
"Checks",
"that",
"this",
"analyser",
"satisfies",
"the",
"provided",
"indicator",
"requirements",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/analytics/classes/local/analyser/base.php#L310-L326 |
213,612 | moodle/moodle | analytics/classes/local/analyser/base.php | base.get_iterator_sql | protected function get_iterator_sql(string $tablename, int $contextlevel, ?string $action = null, ?string $tablealias = null) {
if (!$tablealias) {
$tablealias = 'analysable';
}
$params = ['contextlevel' => $contextlevel, 'modelid' => $this->get_modelid()];
$select = $tablealias . '.*, ' . \context_helper::get_preload_record_columns_sql('ctx');
// We add the action filter on ON instead of on WHERE because otherwise records are not returned if there are existing
// records for another action or model.
$usedanalysablesjoin = ' LEFT JOIN {analytics_used_analysables} aua ON ' . $tablealias . '.id = aua.analysableid AND ' .
'(aua.modelid = :modelid OR aua.modelid IS NULL)';
if ($action) {
$usedanalysablesjoin .= " AND aua.action = :action";
$params = $params + ['action' => $action];
}
// Adding the 1 = 1 just to have the WHERE part so that all further conditions added by callers can be
// appended to $sql with and ' AND'.
$sql = 'SELECT ' . $select . '
FROM {' . $tablename . '} ' . $tablealias . '
' . $usedanalysablesjoin . '
JOIN {context} ctx ON (ctx.contextlevel = :contextlevel AND ctx.instanceid = ' . $tablealias . '.id)
WHERE 1 = 1';
return [$sql, $params];
} | php | protected function get_iterator_sql(string $tablename, int $contextlevel, ?string $action = null, ?string $tablealias = null) {
if (!$tablealias) {
$tablealias = 'analysable';
}
$params = ['contextlevel' => $contextlevel, 'modelid' => $this->get_modelid()];
$select = $tablealias . '.*, ' . \context_helper::get_preload_record_columns_sql('ctx');
// We add the action filter on ON instead of on WHERE because otherwise records are not returned if there are existing
// records for another action or model.
$usedanalysablesjoin = ' LEFT JOIN {analytics_used_analysables} aua ON ' . $tablealias . '.id = aua.analysableid AND ' .
'(aua.modelid = :modelid OR aua.modelid IS NULL)';
if ($action) {
$usedanalysablesjoin .= " AND aua.action = :action";
$params = $params + ['action' => $action];
}
// Adding the 1 = 1 just to have the WHERE part so that all further conditions added by callers can be
// appended to $sql with and ' AND'.
$sql = 'SELECT ' . $select . '
FROM {' . $tablename . '} ' . $tablealias . '
' . $usedanalysablesjoin . '
JOIN {context} ctx ON (ctx.contextlevel = :contextlevel AND ctx.instanceid = ' . $tablealias . '.id)
WHERE 1 = 1';
return [$sql, $params];
} | [
"protected",
"function",
"get_iterator_sql",
"(",
"string",
"$",
"tablename",
",",
"int",
"$",
"contextlevel",
",",
"?",
"string",
"$",
"action",
"=",
"null",
",",
"?",
"string",
"$",
"tablealias",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"$",
"tablealias",
")",
"{",
"$",
"tablealias",
"=",
"'analysable'",
";",
"}",
"$",
"params",
"=",
"[",
"'contextlevel'",
"=>",
"$",
"contextlevel",
",",
"'modelid'",
"=>",
"$",
"this",
"->",
"get_modelid",
"(",
")",
"]",
";",
"$",
"select",
"=",
"$",
"tablealias",
".",
"'.*, '",
".",
"\\",
"context_helper",
"::",
"get_preload_record_columns_sql",
"(",
"'ctx'",
")",
";",
"// We add the action filter on ON instead of on WHERE because otherwise records are not returned if there are existing",
"// records for another action or model.",
"$",
"usedanalysablesjoin",
"=",
"' LEFT JOIN {analytics_used_analysables} aua ON '",
".",
"$",
"tablealias",
".",
"'.id = aua.analysableid AND '",
".",
"'(aua.modelid = :modelid OR aua.modelid IS NULL)'",
";",
"if",
"(",
"$",
"action",
")",
"{",
"$",
"usedanalysablesjoin",
".=",
"\" AND aua.action = :action\"",
";",
"$",
"params",
"=",
"$",
"params",
"+",
"[",
"'action'",
"=>",
"$",
"action",
"]",
";",
"}",
"// Adding the 1 = 1 just to have the WHERE part so that all further conditions added by callers can be",
"// appended to $sql with and ' AND'.",
"$",
"sql",
"=",
"'SELECT '",
".",
"$",
"select",
".",
"'\n FROM {'",
".",
"$",
"tablename",
".",
"'} '",
".",
"$",
"tablealias",
".",
"'\n '",
".",
"$",
"usedanalysablesjoin",
".",
"'\n JOIN {context} ctx ON (ctx.contextlevel = :contextlevel AND ctx.instanceid = '",
".",
"$",
"tablealias",
".",
"'.id)\n WHERE 1 = 1'",
";",
"return",
"[",
"$",
"sql",
",",
"$",
"params",
"]",
";",
"}"
] | Get the sql of a default implementation of the iterator.
This method only works for analysers that return analysable elements which ids map to a context instance ids.
@param string $tablename The name of the table
@param int $contextlevel The context level of the analysable
@param string|null $action
@param string|null $tablealias The table alias
@return array [0] => sql and [1] => params array | [
"Get",
"the",
"sql",
"of",
"a",
"default",
"implementation",
"of",
"the",
"iterator",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/analytics/classes/local/analyser/base.php#L419-L447 |
213,613 | moodle/moodle | analytics/classes/local/analyser/base.php | base.order_sql | protected function order_sql(?string $fieldname = null, string $order = 'ASC', ?string $tablealias = null) {
if (!$tablealias) {
$tablealias = 'analysable';
}
if ($order != 'ASC' && $order != 'DESC') {
throw new \coding_exception('The order can only be ASC or DESC');
}
$ordersql = ' ORDER BY (CASE WHEN aua.timeanalysed IS NULL THEN 0 ELSE aua.timeanalysed END) ASC';
if ($fieldname) {
$ordersql .= ', ' . $tablealias . '.' . $fieldname .' ' . $order;
}
return $ordersql;
} | php | protected function order_sql(?string $fieldname = null, string $order = 'ASC', ?string $tablealias = null) {
if (!$tablealias) {
$tablealias = 'analysable';
}
if ($order != 'ASC' && $order != 'DESC') {
throw new \coding_exception('The order can only be ASC or DESC');
}
$ordersql = ' ORDER BY (CASE WHEN aua.timeanalysed IS NULL THEN 0 ELSE aua.timeanalysed END) ASC';
if ($fieldname) {
$ordersql .= ', ' . $tablealias . '.' . $fieldname .' ' . $order;
}
return $ordersql;
} | [
"protected",
"function",
"order_sql",
"(",
"?",
"string",
"$",
"fieldname",
"=",
"null",
",",
"string",
"$",
"order",
"=",
"'ASC'",
",",
"?",
"string",
"$",
"tablealias",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"$",
"tablealias",
")",
"{",
"$",
"tablealias",
"=",
"'analysable'",
";",
"}",
"if",
"(",
"$",
"order",
"!=",
"'ASC'",
"&&",
"$",
"order",
"!=",
"'DESC'",
")",
"{",
"throw",
"new",
"\\",
"coding_exception",
"(",
"'The order can only be ASC or DESC'",
")",
";",
"}",
"$",
"ordersql",
"=",
"' ORDER BY (CASE WHEN aua.timeanalysed IS NULL THEN 0 ELSE aua.timeanalysed END) ASC'",
";",
"if",
"(",
"$",
"fieldname",
")",
"{",
"$",
"ordersql",
".=",
"', '",
".",
"$",
"tablealias",
".",
"'.'",
".",
"$",
"fieldname",
".",
"' '",
".",
"$",
"order",
";",
"}",
"return",
"$",
"ordersql",
";",
"}"
] | Returns the order by clause.
@param string|null $fieldname The field name
@param string $order 'ASC' or 'DESC'
@param string|null $tablealias The table alias of the field
@return string | [
"Returns",
"the",
"order",
"by",
"clause",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/analytics/classes/local/analyser/base.php#L457-L473 |
213,614 | moodle/moodle | user/classes/analytics/target/upcoming_activities_due.php | upcoming_activities_due.calculate_sample | protected function calculate_sample($sampleid, \core_analytics\analysable $analysable, $starttime = false, $endtime = false) {
$activitiesdueindicator = $this->retrieve('\core_course\analytics\indicator\activities_due', $sampleid);
if ($activitiesdueindicator == \core_course\analytics\indicator\activities_due::get_max_value()) {
return 1;
}
return 0;
} | php | protected function calculate_sample($sampleid, \core_analytics\analysable $analysable, $starttime = false, $endtime = false) {
$activitiesdueindicator = $this->retrieve('\core_course\analytics\indicator\activities_due', $sampleid);
if ($activitiesdueindicator == \core_course\analytics\indicator\activities_due::get_max_value()) {
return 1;
}
return 0;
} | [
"protected",
"function",
"calculate_sample",
"(",
"$",
"sampleid",
",",
"\\",
"core_analytics",
"\\",
"analysable",
"$",
"analysable",
",",
"$",
"starttime",
"=",
"false",
",",
"$",
"endtime",
"=",
"false",
")",
"{",
"$",
"activitiesdueindicator",
"=",
"$",
"this",
"->",
"retrieve",
"(",
"'\\core_course\\analytics\\indicator\\activities_due'",
",",
"$",
"sampleid",
")",
";",
"if",
"(",
"$",
"activitiesdueindicator",
"==",
"\\",
"core_course",
"\\",
"analytics",
"\\",
"indicator",
"\\",
"activities_due",
"::",
"get_max_value",
"(",
")",
")",
"{",
"return",
"1",
";",
"}",
"return",
"0",
";",
"}"
] | Calculation based on activities due indicator.
@param int $sampleid
@param \core_analytics\analysable $analysable
@param int $starttime
@param int $endtime
@return float | [
"Calculation",
"based",
"on",
"activities",
"due",
"indicator",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/user/classes/analytics/target/upcoming_activities_due.php#L144-L151 |
213,615 | moodle/moodle | user/classes/analytics/target/upcoming_activities_due.php | upcoming_activities_due.prediction_actions | public function prediction_actions(\core_analytics\prediction $prediction, $includedetailsaction = false,
$isinsightuser = false) {
global $CFG, $USER;
$parentactions = parent::prediction_actions($prediction, $includedetailsaction);
if (!$isinsightuser && $USER->id != $prediction->get_prediction_data()->sampleid) {
return $parentactions;
}
// We force a lookahead of 30 days so we are sure that the upcoming activities due are shown.
$url = new \moodle_url('/calendar/view.php', ['view' => 'upcoming', 'lookahead' => '30']);
$pix = new \pix_icon('i/calendar', get_string('upcomingevents', 'calendar'));
$action = new \core_analytics\prediction_action('viewupcoming', $prediction,
$url, $pix, get_string('upcomingevents', 'calendar'));
return array_merge([$action], $parentactions);
} | php | public function prediction_actions(\core_analytics\prediction $prediction, $includedetailsaction = false,
$isinsightuser = false) {
global $CFG, $USER;
$parentactions = parent::prediction_actions($prediction, $includedetailsaction);
if (!$isinsightuser && $USER->id != $prediction->get_prediction_data()->sampleid) {
return $parentactions;
}
// We force a lookahead of 30 days so we are sure that the upcoming activities due are shown.
$url = new \moodle_url('/calendar/view.php', ['view' => 'upcoming', 'lookahead' => '30']);
$pix = new \pix_icon('i/calendar', get_string('upcomingevents', 'calendar'));
$action = new \core_analytics\prediction_action('viewupcoming', $prediction,
$url, $pix, get_string('upcomingevents', 'calendar'));
return array_merge([$action], $parentactions);
} | [
"public",
"function",
"prediction_actions",
"(",
"\\",
"core_analytics",
"\\",
"prediction",
"$",
"prediction",
",",
"$",
"includedetailsaction",
"=",
"false",
",",
"$",
"isinsightuser",
"=",
"false",
")",
"{",
"global",
"$",
"CFG",
",",
"$",
"USER",
";",
"$",
"parentactions",
"=",
"parent",
"::",
"prediction_actions",
"(",
"$",
"prediction",
",",
"$",
"includedetailsaction",
")",
";",
"if",
"(",
"!",
"$",
"isinsightuser",
"&&",
"$",
"USER",
"->",
"id",
"!=",
"$",
"prediction",
"->",
"get_prediction_data",
"(",
")",
"->",
"sampleid",
")",
"{",
"return",
"$",
"parentactions",
";",
"}",
"// We force a lookahead of 30 days so we are sure that the upcoming activities due are shown.",
"$",
"url",
"=",
"new",
"\\",
"moodle_url",
"(",
"'/calendar/view.php'",
",",
"[",
"'view'",
"=>",
"'upcoming'",
",",
"'lookahead'",
"=>",
"'30'",
"]",
")",
";",
"$",
"pix",
"=",
"new",
"\\",
"pix_icon",
"(",
"'i/calendar'",
",",
"get_string",
"(",
"'upcomingevents'",
",",
"'calendar'",
")",
")",
";",
"$",
"action",
"=",
"new",
"\\",
"core_analytics",
"\\",
"prediction_action",
"(",
"'viewupcoming'",
",",
"$",
"prediction",
",",
"$",
"url",
",",
"$",
"pix",
",",
"get_string",
"(",
"'upcomingevents'",
",",
"'calendar'",
")",
")",
";",
"return",
"array_merge",
"(",
"[",
"$",
"action",
"]",
",",
"$",
"parentactions",
")",
";",
"}"
] | Adds a view upcoming events action.
@param \core_analytics\prediction $prediction
@param mixed $includedetailsaction
@param bool $isinsightuser
@return \core_analytics\prediction_action[] | [
"Adds",
"a",
"view",
"upcoming",
"events",
"action",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/user/classes/analytics/target/upcoming_activities_due.php#L161-L178 |
213,616 | moodle/moodle | course/classes/external/course_summary_exporter.php | course_summary_exporter.get_course_image | public static function get_course_image($course) {
global $CFG;
$courseinlist = new \core_course_list_element($course);
foreach ($courseinlist->get_course_overviewfiles() as $file) {
if ($file->is_valid_image()) {
$pathcomponents = [
'/pluginfile.php',
$file->get_contextid(),
$file->get_component(),
$file->get_filearea() . $file->get_filepath() . $file->get_filename()
];
$path = implode('/', $pathcomponents);
return (new moodle_url($path))->out();
}
}
return false;
} | php | public static function get_course_image($course) {
global $CFG;
$courseinlist = new \core_course_list_element($course);
foreach ($courseinlist->get_course_overviewfiles() as $file) {
if ($file->is_valid_image()) {
$pathcomponents = [
'/pluginfile.php',
$file->get_contextid(),
$file->get_component(),
$file->get_filearea() . $file->get_filepath() . $file->get_filename()
];
$path = implode('/', $pathcomponents);
return (new moodle_url($path))->out();
}
}
return false;
} | [
"public",
"static",
"function",
"get_course_image",
"(",
"$",
"course",
")",
"{",
"global",
"$",
"CFG",
";",
"$",
"courseinlist",
"=",
"new",
"\\",
"core_course_list_element",
"(",
"$",
"course",
")",
";",
"foreach",
"(",
"$",
"courseinlist",
"->",
"get_course_overviewfiles",
"(",
")",
"as",
"$",
"file",
")",
"{",
"if",
"(",
"$",
"file",
"->",
"is_valid_image",
"(",
")",
")",
"{",
"$",
"pathcomponents",
"=",
"[",
"'/pluginfile.php'",
",",
"$",
"file",
"->",
"get_contextid",
"(",
")",
",",
"$",
"file",
"->",
"get_component",
"(",
")",
",",
"$",
"file",
"->",
"get_filearea",
"(",
")",
".",
"$",
"file",
"->",
"get_filepath",
"(",
")",
".",
"$",
"file",
"->",
"get_filename",
"(",
")",
"]",
";",
"$",
"path",
"=",
"implode",
"(",
"'/'",
",",
"$",
"pathcomponents",
")",
";",
"return",
"(",
"new",
"moodle_url",
"(",
"$",
"path",
")",
")",
"->",
"out",
"(",
")",
";",
"}",
"}",
"return",
"false",
";",
"}"
] | Get the course image if added to course.
@param object $course
@return string url of course image | [
"Get",
"the",
"course",
"image",
"if",
"added",
"to",
"course",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/course/classes/external/course_summary_exporter.php#L167-L183 |
213,617 | moodle/moodle | course/classes/external/course_summary_exporter.php | course_summary_exporter.get_course_pattern | public static function get_course_pattern($course) {
$color = self::coursecolor($course->id);
$pattern = new \core_geopattern();
$pattern->setColor($color);
$pattern->patternbyid($course->id);
return $pattern->datauri();
} | php | public static function get_course_pattern($course) {
$color = self::coursecolor($course->id);
$pattern = new \core_geopattern();
$pattern->setColor($color);
$pattern->patternbyid($course->id);
return $pattern->datauri();
} | [
"public",
"static",
"function",
"get_course_pattern",
"(",
"$",
"course",
")",
"{",
"$",
"color",
"=",
"self",
"::",
"coursecolor",
"(",
"$",
"course",
"->",
"id",
")",
";",
"$",
"pattern",
"=",
"new",
"\\",
"core_geopattern",
"(",
")",
";",
"$",
"pattern",
"->",
"setColor",
"(",
"$",
"color",
")",
";",
"$",
"pattern",
"->",
"patternbyid",
"(",
"$",
"course",
"->",
"id",
")",
";",
"return",
"$",
"pattern",
"->",
"datauri",
"(",
")",
";",
"}"
] | Get the course pattern datauri.
The datauri is an encoded svg that can be passed as a url.
@param object $course
@return string datauri | [
"Get",
"the",
"course",
"pattern",
"datauri",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/course/classes/external/course_summary_exporter.php#L192-L198 |
213,618 | moodle/moodle | mod/quiz/report/grading/report.php | quiz_grading_report.list_questions_url | protected function list_questions_url($includeauto = null) {
$url = $this->base_url();
$url->params($this->viewoptions);
if (!is_null($includeauto)) {
$url->param('includeauto', $includeauto);
}
return $url;
} | php | protected function list_questions_url($includeauto = null) {
$url = $this->base_url();
$url->params($this->viewoptions);
if (!is_null($includeauto)) {
$url->param('includeauto', $includeauto);
}
return $url;
} | [
"protected",
"function",
"list_questions_url",
"(",
"$",
"includeauto",
"=",
"null",
")",
"{",
"$",
"url",
"=",
"$",
"this",
"->",
"base_url",
"(",
")",
";",
"$",
"url",
"->",
"params",
"(",
"$",
"this",
"->",
"viewoptions",
")",
";",
"if",
"(",
"!",
"is_null",
"(",
"$",
"includeauto",
")",
")",
"{",
"$",
"url",
"->",
"param",
"(",
"'includeauto'",
",",
"$",
"includeauto",
")",
";",
"}",
"return",
"$",
"url",
";",
"}"
] | Get the URL of the front page of the report that lists all the questions.
@param $includeauto if not given, use the current setting, otherwise,
force a paricular value of includeauto in the URL.
@return string the URL. | [
"Get",
"the",
"URL",
"of",
"the",
"front",
"page",
"of",
"the",
"report",
"that",
"lists",
"all",
"the",
"questions",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/quiz/report/grading/report.php#L226-L236 |
213,619 | moodle/moodle | mod/quiz/report/grading/report.php | quiz_grading_report.get_question_heading | protected function get_question_heading($attempt, $shownames, $showidnumbers) {
$a = new stdClass();
$a->attempt = $attempt->attempt;
$a->fullname = fullname($attempt);
$a->idnumber = $attempt->idnumber;
$showidnumbers = $showidnumbers && !empty($attempt->idnumber);
if ($shownames && $showidnumbers) {
return get_string('gradingattemptwithidnumber', 'quiz_grading', $a);
} else if ($shownames) {
return get_string('gradingattempt', 'quiz_grading', $a);
} else if ($showidnumbers) {
$a->fullname = $attempt->idnumber;
return get_string('gradingattempt', 'quiz_grading', $a);
} else {
return '';
}
} | php | protected function get_question_heading($attempt, $shownames, $showidnumbers) {
$a = new stdClass();
$a->attempt = $attempt->attempt;
$a->fullname = fullname($attempt);
$a->idnumber = $attempt->idnumber;
$showidnumbers = $showidnumbers && !empty($attempt->idnumber);
if ($shownames && $showidnumbers) {
return get_string('gradingattemptwithidnumber', 'quiz_grading', $a);
} else if ($shownames) {
return get_string('gradingattempt', 'quiz_grading', $a);
} else if ($showidnumbers) {
$a->fullname = $attempt->idnumber;
return get_string('gradingattempt', 'quiz_grading', $a);
} else {
return '';
}
} | [
"protected",
"function",
"get_question_heading",
"(",
"$",
"attempt",
",",
"$",
"shownames",
",",
"$",
"showidnumbers",
")",
"{",
"$",
"a",
"=",
"new",
"stdClass",
"(",
")",
";",
"$",
"a",
"->",
"attempt",
"=",
"$",
"attempt",
"->",
"attempt",
";",
"$",
"a",
"->",
"fullname",
"=",
"fullname",
"(",
"$",
"attempt",
")",
";",
"$",
"a",
"->",
"idnumber",
"=",
"$",
"attempt",
"->",
"idnumber",
";",
"$",
"showidnumbers",
"=",
"$",
"showidnumbers",
"&&",
"!",
"empty",
"(",
"$",
"attempt",
"->",
"idnumber",
")",
";",
"if",
"(",
"$",
"shownames",
"&&",
"$",
"showidnumbers",
")",
"{",
"return",
"get_string",
"(",
"'gradingattemptwithidnumber'",
",",
"'quiz_grading'",
",",
"$",
"a",
")",
";",
"}",
"else",
"if",
"(",
"$",
"shownames",
")",
"{",
"return",
"get_string",
"(",
"'gradingattempt'",
",",
"'quiz_grading'",
",",
"$",
"a",
")",
";",
"}",
"else",
"if",
"(",
"$",
"showidnumbers",
")",
"{",
"$",
"a",
"->",
"fullname",
"=",
"$",
"attempt",
"->",
"idnumber",
";",
"return",
"get_string",
"(",
"'gradingattempt'",
",",
"'quiz_grading'",
",",
"$",
"a",
")",
";",
"}",
"else",
"{",
"return",
"''",
";",
"}",
"}"
] | Get question heading.
@param object $attempt an instance of quiz_attempt.
@param bool $shownames True to show the question name.
@param bool $showidnumbers True to show the question id number.
@return string The string text for the question heading.
@throws coding_exception | [
"Get",
"question",
"heading",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/quiz/report/grading/report.php#L584-L602 |
213,620 | moodle/moodle | lib/form/text.php | MoodleQuickForm_text.getFrozenHtml | function getFrozenHtml()
{
$attributes = array('readonly' => 'readonly');
$this->updateAttributes($attributes);
return $this->_getTabs() . '<input' . $this->_getAttrString($this->_attributes) . ' />' . $this->_getPersistantData();
} | php | function getFrozenHtml()
{
$attributes = array('readonly' => 'readonly');
$this->updateAttributes($attributes);
return $this->_getTabs() . '<input' . $this->_getAttrString($this->_attributes) . ' />' . $this->_getPersistantData();
} | [
"function",
"getFrozenHtml",
"(",
")",
"{",
"$",
"attributes",
"=",
"array",
"(",
"'readonly'",
"=>",
"'readonly'",
")",
";",
"$",
"this",
"->",
"updateAttributes",
"(",
"$",
"attributes",
")",
";",
"return",
"$",
"this",
"->",
"_getTabs",
"(",
")",
".",
"'<input'",
".",
"$",
"this",
"->",
"_getAttrString",
"(",
"$",
"this",
"->",
"_attributes",
")",
".",
"' />'",
".",
"$",
"this",
"->",
"_getPersistantData",
"(",
")",
";",
"}"
] | Returns the html to be used when the element is frozen
@since Moodle 2.4
@return string Frozen html | [
"Returns",
"the",
"html",
"to",
"be",
"used",
"when",
"the",
"element",
"is",
"frozen"
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/form/text.php#L103-L108 |
213,621 | moodle/moodle | cache/classes/config.php | cache_config.get_config_file_path | protected static function get_config_file_path() {
global $CFG;
if (!empty($CFG->altcacheconfigpath)) {
$path = $CFG->altcacheconfigpath;
if (is_dir($path) && is_writable($path)) {
// Its a writable directory, thats fine.
return $path.'/cacheconfig.php';
} else if (is_writable(dirname($path)) && (!file_exists($path) || is_writable($path))) {
// Its a file, either it doesn't exist and the directory is writable or the file exists and is writable.
return $path;
}
}
// Return the default location within dataroot.
return $CFG->dataroot.'/muc/config.php';
} | php | protected static function get_config_file_path() {
global $CFG;
if (!empty($CFG->altcacheconfigpath)) {
$path = $CFG->altcacheconfigpath;
if (is_dir($path) && is_writable($path)) {
// Its a writable directory, thats fine.
return $path.'/cacheconfig.php';
} else if (is_writable(dirname($path)) && (!file_exists($path) || is_writable($path))) {
// Its a file, either it doesn't exist and the directory is writable or the file exists and is writable.
return $path;
}
}
// Return the default location within dataroot.
return $CFG->dataroot.'/muc/config.php';
} | [
"protected",
"static",
"function",
"get_config_file_path",
"(",
")",
"{",
"global",
"$",
"CFG",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"CFG",
"->",
"altcacheconfigpath",
")",
")",
"{",
"$",
"path",
"=",
"$",
"CFG",
"->",
"altcacheconfigpath",
";",
"if",
"(",
"is_dir",
"(",
"$",
"path",
")",
"&&",
"is_writable",
"(",
"$",
"path",
")",
")",
"{",
"// Its a writable directory, thats fine.",
"return",
"$",
"path",
".",
"'/cacheconfig.php'",
";",
"}",
"else",
"if",
"(",
"is_writable",
"(",
"dirname",
"(",
"$",
"path",
")",
")",
"&&",
"(",
"!",
"file_exists",
"(",
"$",
"path",
")",
"||",
"is_writable",
"(",
"$",
"path",
")",
")",
")",
"{",
"// Its a file, either it doesn't exist and the directory is writable or the file exists and is writable.",
"return",
"$",
"path",
";",
"}",
"}",
"// Return the default location within dataroot.",
"return",
"$",
"CFG",
"->",
"dataroot",
".",
"'/muc/config.php'",
";",
"}"
] | Returns the expected path to the configuration file.
@return string The absolute path | [
"Returns",
"the",
"expected",
"path",
"to",
"the",
"configuration",
"file",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/cache/classes/config.php#L112-L126 |
213,622 | moodle/moodle | cache/classes/config.php | cache_config.include_configuration | protected function include_configuration() {
$configuration = array();
// We need to allow for late static bindings to allow for class path mudling happending for unit tests.
$cachefile = static::get_config_file_path();
if (!file_exists($cachefile)) {
throw new cache_exception('Default cache config could not be found. It should have already been created by now.');
}
if (!include($cachefile)) {
throw new cache_exception('Unable to load the cache configuration file');
}
if (!is_array($configuration)) {
throw new cache_exception('Invalid cache configuration file');
}
if (!array_key_exists('stores', $configuration) || !is_array($configuration['stores'])) {
$configuration['stores'] = array();
}
if (!array_key_exists('modemappings', $configuration) || !is_array($configuration['modemappings'])) {
$configuration['modemappings'] = array();
}
if (!array_key_exists('definitions', $configuration) || !is_array($configuration['definitions'])) {
$configuration['definitions'] = array();
}
if (!array_key_exists('definitionmappings', $configuration) || !is_array($configuration['definitionmappings'])) {
$configuration['definitionmappings'] = array();
}
if (!array_key_exists('locks', $configuration) || !is_array($configuration['locks'])) {
$configuration['locks'] = array();
}
return $configuration;
} | php | protected function include_configuration() {
$configuration = array();
// We need to allow for late static bindings to allow for class path mudling happending for unit tests.
$cachefile = static::get_config_file_path();
if (!file_exists($cachefile)) {
throw new cache_exception('Default cache config could not be found. It should have already been created by now.');
}
if (!include($cachefile)) {
throw new cache_exception('Unable to load the cache configuration file');
}
if (!is_array($configuration)) {
throw new cache_exception('Invalid cache configuration file');
}
if (!array_key_exists('stores', $configuration) || !is_array($configuration['stores'])) {
$configuration['stores'] = array();
}
if (!array_key_exists('modemappings', $configuration) || !is_array($configuration['modemappings'])) {
$configuration['modemappings'] = array();
}
if (!array_key_exists('definitions', $configuration) || !is_array($configuration['definitions'])) {
$configuration['definitions'] = array();
}
if (!array_key_exists('definitionmappings', $configuration) || !is_array($configuration['definitionmappings'])) {
$configuration['definitionmappings'] = array();
}
if (!array_key_exists('locks', $configuration) || !is_array($configuration['locks'])) {
$configuration['locks'] = array();
}
return $configuration;
} | [
"protected",
"function",
"include_configuration",
"(",
")",
"{",
"$",
"configuration",
"=",
"array",
"(",
")",
";",
"// We need to allow for late static bindings to allow for class path mudling happending for unit tests.",
"$",
"cachefile",
"=",
"static",
"::",
"get_config_file_path",
"(",
")",
";",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"cachefile",
")",
")",
"{",
"throw",
"new",
"cache_exception",
"(",
"'Default cache config could not be found. It should have already been created by now.'",
")",
";",
"}",
"if",
"(",
"!",
"include",
"(",
"$",
"cachefile",
")",
")",
"{",
"throw",
"new",
"cache_exception",
"(",
"'Unable to load the cache configuration file'",
")",
";",
"}",
"if",
"(",
"!",
"is_array",
"(",
"$",
"configuration",
")",
")",
"{",
"throw",
"new",
"cache_exception",
"(",
"'Invalid cache configuration file'",
")",
";",
"}",
"if",
"(",
"!",
"array_key_exists",
"(",
"'stores'",
",",
"$",
"configuration",
")",
"||",
"!",
"is_array",
"(",
"$",
"configuration",
"[",
"'stores'",
"]",
")",
")",
"{",
"$",
"configuration",
"[",
"'stores'",
"]",
"=",
"array",
"(",
")",
";",
"}",
"if",
"(",
"!",
"array_key_exists",
"(",
"'modemappings'",
",",
"$",
"configuration",
")",
"||",
"!",
"is_array",
"(",
"$",
"configuration",
"[",
"'modemappings'",
"]",
")",
")",
"{",
"$",
"configuration",
"[",
"'modemappings'",
"]",
"=",
"array",
"(",
")",
";",
"}",
"if",
"(",
"!",
"array_key_exists",
"(",
"'definitions'",
",",
"$",
"configuration",
")",
"||",
"!",
"is_array",
"(",
"$",
"configuration",
"[",
"'definitions'",
"]",
")",
")",
"{",
"$",
"configuration",
"[",
"'definitions'",
"]",
"=",
"array",
"(",
")",
";",
"}",
"if",
"(",
"!",
"array_key_exists",
"(",
"'definitionmappings'",
",",
"$",
"configuration",
")",
"||",
"!",
"is_array",
"(",
"$",
"configuration",
"[",
"'definitionmappings'",
"]",
")",
")",
"{",
"$",
"configuration",
"[",
"'definitionmappings'",
"]",
"=",
"array",
"(",
")",
";",
"}",
"if",
"(",
"!",
"array_key_exists",
"(",
"'locks'",
",",
"$",
"configuration",
")",
"||",
"!",
"is_array",
"(",
"$",
"configuration",
"[",
"'locks'",
"]",
")",
")",
"{",
"$",
"configuration",
"[",
"'locks'",
"]",
"=",
"array",
"(",
")",
";",
"}",
"return",
"$",
"configuration",
";",
"}"
] | Includes the configuration file and makes sure it contains the expected bits.
You need to ensure that the config file exists before this is called.
@return array
@throws cache_exception | [
"Includes",
"the",
"configuration",
"file",
"and",
"makes",
"sure",
"it",
"contains",
"the",
"expected",
"bits",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/cache/classes/config.php#L325-L358 |
213,623 | moodle/moodle | cache/classes/config.php | cache_config.get_definition_by_id | public function get_definition_by_id($id) {
if (array_key_exists($id, $this->configdefinitions)) {
return $this->configdefinitions[$id];
}
return false;
} | php | public function get_definition_by_id($id) {
if (array_key_exists($id, $this->configdefinitions)) {
return $this->configdefinitions[$id];
}
return false;
} | [
"public",
"function",
"get_definition_by_id",
"(",
"$",
"id",
")",
"{",
"if",
"(",
"array_key_exists",
"(",
"$",
"id",
",",
"$",
"this",
"->",
"configdefinitions",
")",
")",
"{",
"return",
"$",
"this",
"->",
"configdefinitions",
"[",
"$",
"id",
"]",
";",
"}",
"return",
"false",
";",
"}"
] | Gets a definition from the config given its name.
@param string $id
@return bool | [
"Gets",
"a",
"definition",
"from",
"the",
"config",
"given",
"its",
"name",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/cache/classes/config.php#L382-L387 |
213,624 | moodle/moodle | cache/classes/config.php | cache_config.get_definitions_by_store | public function get_definitions_by_store($storename) {
$definitions = array();
// This function was accidentally made static at some stage in the past.
// It was converted to an instance method but to be backwards compatible
// we must step around this in code.
if (!isset($this)) {
$config = cache_config::instance();
} else {
$config = $this;
}
$stores = $config->get_all_stores();
if (!array_key_exists($storename, $stores)) {
// The store does not exist.
return false;
}
$defmappings = $config->get_definition_mappings();
// Create an associative array for the definition mappings.
$thedefmappings = array();
foreach ($defmappings as $defmapping) {
$thedefmappings[$defmapping['definition']] = $defmapping;
}
// Search for matches in default mappings.
$defs = $config->get_definitions();
foreach($config->get_mode_mappings() as $modemapping) {
if ($modemapping['store'] !== $storename) {
continue;
}
foreach($defs as $id => $definition) {
if ($definition['mode'] !== $modemapping['mode']) {
continue;
}
// Exclude custom definitions mapping: they will be managed few lines below.
if (array_key_exists($id, $thedefmappings)) {
continue;
}
$definitions[$id] = $definition;
}
}
// Search for matches in the custom definitions mapping
foreach ($defmappings as $defmapping) {
if ($defmapping['store'] !== $storename) {
continue;
}
$definition = $config->get_definition_by_id($defmapping['definition']);
if ($definition) {
$definitions[$defmapping['definition']] = $definition;
}
}
return $definitions;
} | php | public function get_definitions_by_store($storename) {
$definitions = array();
// This function was accidentally made static at some stage in the past.
// It was converted to an instance method but to be backwards compatible
// we must step around this in code.
if (!isset($this)) {
$config = cache_config::instance();
} else {
$config = $this;
}
$stores = $config->get_all_stores();
if (!array_key_exists($storename, $stores)) {
// The store does not exist.
return false;
}
$defmappings = $config->get_definition_mappings();
// Create an associative array for the definition mappings.
$thedefmappings = array();
foreach ($defmappings as $defmapping) {
$thedefmappings[$defmapping['definition']] = $defmapping;
}
// Search for matches in default mappings.
$defs = $config->get_definitions();
foreach($config->get_mode_mappings() as $modemapping) {
if ($modemapping['store'] !== $storename) {
continue;
}
foreach($defs as $id => $definition) {
if ($definition['mode'] !== $modemapping['mode']) {
continue;
}
// Exclude custom definitions mapping: they will be managed few lines below.
if (array_key_exists($id, $thedefmappings)) {
continue;
}
$definitions[$id] = $definition;
}
}
// Search for matches in the custom definitions mapping
foreach ($defmappings as $defmapping) {
if ($defmapping['store'] !== $storename) {
continue;
}
$definition = $config->get_definition_by_id($defmapping['definition']);
if ($definition) {
$definitions[$defmapping['definition']] = $definition;
}
}
return $definitions;
} | [
"public",
"function",
"get_definitions_by_store",
"(",
"$",
"storename",
")",
"{",
"$",
"definitions",
"=",
"array",
"(",
")",
";",
"// This function was accidentally made static at some stage in the past.",
"// It was converted to an instance method but to be backwards compatible",
"// we must step around this in code.",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
")",
")",
"{",
"$",
"config",
"=",
"cache_config",
"::",
"instance",
"(",
")",
";",
"}",
"else",
"{",
"$",
"config",
"=",
"$",
"this",
";",
"}",
"$",
"stores",
"=",
"$",
"config",
"->",
"get_all_stores",
"(",
")",
";",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"storename",
",",
"$",
"stores",
")",
")",
"{",
"// The store does not exist.",
"return",
"false",
";",
"}",
"$",
"defmappings",
"=",
"$",
"config",
"->",
"get_definition_mappings",
"(",
")",
";",
"// Create an associative array for the definition mappings.",
"$",
"thedefmappings",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"defmappings",
"as",
"$",
"defmapping",
")",
"{",
"$",
"thedefmappings",
"[",
"$",
"defmapping",
"[",
"'definition'",
"]",
"]",
"=",
"$",
"defmapping",
";",
"}",
"// Search for matches in default mappings.",
"$",
"defs",
"=",
"$",
"config",
"->",
"get_definitions",
"(",
")",
";",
"foreach",
"(",
"$",
"config",
"->",
"get_mode_mappings",
"(",
")",
"as",
"$",
"modemapping",
")",
"{",
"if",
"(",
"$",
"modemapping",
"[",
"'store'",
"]",
"!==",
"$",
"storename",
")",
"{",
"continue",
";",
"}",
"foreach",
"(",
"$",
"defs",
"as",
"$",
"id",
"=>",
"$",
"definition",
")",
"{",
"if",
"(",
"$",
"definition",
"[",
"'mode'",
"]",
"!==",
"$",
"modemapping",
"[",
"'mode'",
"]",
")",
"{",
"continue",
";",
"}",
"// Exclude custom definitions mapping: they will be managed few lines below.",
"if",
"(",
"array_key_exists",
"(",
"$",
"id",
",",
"$",
"thedefmappings",
")",
")",
"{",
"continue",
";",
"}",
"$",
"definitions",
"[",
"$",
"id",
"]",
"=",
"$",
"definition",
";",
"}",
"}",
"// Search for matches in the custom definitions mapping",
"foreach",
"(",
"$",
"defmappings",
"as",
"$",
"defmapping",
")",
"{",
"if",
"(",
"$",
"defmapping",
"[",
"'store'",
"]",
"!==",
"$",
"storename",
")",
"{",
"continue",
";",
"}",
"$",
"definition",
"=",
"$",
"config",
"->",
"get_definition_by_id",
"(",
"$",
"defmapping",
"[",
"'definition'",
"]",
")",
";",
"if",
"(",
"$",
"definition",
")",
"{",
"$",
"definitions",
"[",
"$",
"defmapping",
"[",
"'definition'",
"]",
"]",
"=",
"$",
"definition",
";",
"}",
"}",
"return",
"$",
"definitions",
";",
"}"
] | Returns the definitions mapped into the given store name.
@param string $storename
@return array Associative array of definitions, id=>definition | [
"Returns",
"the",
"definitions",
"mapped",
"into",
"the",
"given",
"store",
"name",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/cache/classes/config.php#L404-L459 |
213,625 | moodle/moodle | cache/classes/config.php | cache_config.get_stores | public function get_stores($mode, $requirements = 0) {
$stores = array();
foreach ($this->configstores as $name => $store) {
// If the mode is supported and all of the requirements are provided features.
if (($store['modes'] & $mode) && ($store['features'] & $requirements) === $requirements) {
$stores[$name] = $store;
}
}
return $stores;
} | php | public function get_stores($mode, $requirements = 0) {
$stores = array();
foreach ($this->configstores as $name => $store) {
// If the mode is supported and all of the requirements are provided features.
if (($store['modes'] & $mode) && ($store['features'] & $requirements) === $requirements) {
$stores[$name] = $store;
}
}
return $stores;
} | [
"public",
"function",
"get_stores",
"(",
"$",
"mode",
",",
"$",
"requirements",
"=",
"0",
")",
"{",
"$",
"stores",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"configstores",
"as",
"$",
"name",
"=>",
"$",
"store",
")",
"{",
"// If the mode is supported and all of the requirements are provided features.",
"if",
"(",
"(",
"$",
"store",
"[",
"'modes'",
"]",
"&",
"$",
"mode",
")",
"&&",
"(",
"$",
"store",
"[",
"'features'",
"]",
"&",
"$",
"requirements",
")",
"===",
"$",
"requirements",
")",
"{",
"$",
"stores",
"[",
"$",
"name",
"]",
"=",
"$",
"store",
";",
"}",
"}",
"return",
"$",
"stores",
";",
"}"
] | Returns all of the stores that are suitable for the given mode and requirements.
@param int $mode One of cache_store::MODE_*
@param int $requirements The requirements of the cache as a binary flag
@return array An array of suitable stores. | [
"Returns",
"all",
"of",
"the",
"stores",
"that",
"are",
"suitable",
"for",
"the",
"given",
"mode",
"and",
"requirements",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/cache/classes/config.php#L468-L477 |
213,626 | moodle/moodle | cache/classes/config.php | cache_config.get_stores_for_definition | public function get_stores_for_definition(cache_definition $definition) {
// Check if MUC has been disabled.
$factory = cache_factory::instance();
if ($factory->stores_disabled()) {
// Yip its been disabled.
// To facilitate this we are going to always return an empty array of stores to use.
// This will force all cache instances to use the cachestore_dummy.
// MUC will still be used essentially so that code using it will still continue to function but because no cache stores
// are being used interaction with MUC will be purely based around a static var.
return array();
}
$availablestores = $this->get_stores($definition->get_mode(), $definition->get_requirements_bin());
$stores = array();
$id = $definition->get_id();
// Now get any mappings and give them priority.
foreach ($this->configdefinitionmappings as $mapping) {
if ($mapping['definition'] !== $id) {
continue;
}
$storename = $mapping['store'];
if (!array_key_exists($storename, $availablestores)) {
continue;
}
if (array_key_exists($storename, $stores)) {
$store = $stores[$storename];
unset($stores[$storename]);
$stores[$storename] = $store;
} else {
$stores[$storename] = $availablestores[$storename];
}
}
if (empty($stores) && !$definition->is_for_mappings_only()) {
$mode = $definition->get_mode();
// Load the default stores.
foreach ($this->configmodemappings as $mapping) {
if ($mapping['mode'] === $mode && array_key_exists($mapping['store'], $availablestores)) {
$store = $availablestores[$mapping['store']];
if (empty($store['mappingsonly'])) {
$stores[$mapping['store']] = $store;
}
}
}
}
return $stores;
} | php | public function get_stores_for_definition(cache_definition $definition) {
// Check if MUC has been disabled.
$factory = cache_factory::instance();
if ($factory->stores_disabled()) {
// Yip its been disabled.
// To facilitate this we are going to always return an empty array of stores to use.
// This will force all cache instances to use the cachestore_dummy.
// MUC will still be used essentially so that code using it will still continue to function but because no cache stores
// are being used interaction with MUC will be purely based around a static var.
return array();
}
$availablestores = $this->get_stores($definition->get_mode(), $definition->get_requirements_bin());
$stores = array();
$id = $definition->get_id();
// Now get any mappings and give them priority.
foreach ($this->configdefinitionmappings as $mapping) {
if ($mapping['definition'] !== $id) {
continue;
}
$storename = $mapping['store'];
if (!array_key_exists($storename, $availablestores)) {
continue;
}
if (array_key_exists($storename, $stores)) {
$store = $stores[$storename];
unset($stores[$storename]);
$stores[$storename] = $store;
} else {
$stores[$storename] = $availablestores[$storename];
}
}
if (empty($stores) && !$definition->is_for_mappings_only()) {
$mode = $definition->get_mode();
// Load the default stores.
foreach ($this->configmodemappings as $mapping) {
if ($mapping['mode'] === $mode && array_key_exists($mapping['store'], $availablestores)) {
$store = $availablestores[$mapping['store']];
if (empty($store['mappingsonly'])) {
$stores[$mapping['store']] = $store;
}
}
}
}
return $stores;
} | [
"public",
"function",
"get_stores_for_definition",
"(",
"cache_definition",
"$",
"definition",
")",
"{",
"// Check if MUC has been disabled.",
"$",
"factory",
"=",
"cache_factory",
"::",
"instance",
"(",
")",
";",
"if",
"(",
"$",
"factory",
"->",
"stores_disabled",
"(",
")",
")",
"{",
"// Yip its been disabled.",
"// To facilitate this we are going to always return an empty array of stores to use.",
"// This will force all cache instances to use the cachestore_dummy.",
"// MUC will still be used essentially so that code using it will still continue to function but because no cache stores",
"// are being used interaction with MUC will be purely based around a static var.",
"return",
"array",
"(",
")",
";",
"}",
"$",
"availablestores",
"=",
"$",
"this",
"->",
"get_stores",
"(",
"$",
"definition",
"->",
"get_mode",
"(",
")",
",",
"$",
"definition",
"->",
"get_requirements_bin",
"(",
")",
")",
";",
"$",
"stores",
"=",
"array",
"(",
")",
";",
"$",
"id",
"=",
"$",
"definition",
"->",
"get_id",
"(",
")",
";",
"// Now get any mappings and give them priority.",
"foreach",
"(",
"$",
"this",
"->",
"configdefinitionmappings",
"as",
"$",
"mapping",
")",
"{",
"if",
"(",
"$",
"mapping",
"[",
"'definition'",
"]",
"!==",
"$",
"id",
")",
"{",
"continue",
";",
"}",
"$",
"storename",
"=",
"$",
"mapping",
"[",
"'store'",
"]",
";",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"storename",
",",
"$",
"availablestores",
")",
")",
"{",
"continue",
";",
"}",
"if",
"(",
"array_key_exists",
"(",
"$",
"storename",
",",
"$",
"stores",
")",
")",
"{",
"$",
"store",
"=",
"$",
"stores",
"[",
"$",
"storename",
"]",
";",
"unset",
"(",
"$",
"stores",
"[",
"$",
"storename",
"]",
")",
";",
"$",
"stores",
"[",
"$",
"storename",
"]",
"=",
"$",
"store",
";",
"}",
"else",
"{",
"$",
"stores",
"[",
"$",
"storename",
"]",
"=",
"$",
"availablestores",
"[",
"$",
"storename",
"]",
";",
"}",
"}",
"if",
"(",
"empty",
"(",
"$",
"stores",
")",
"&&",
"!",
"$",
"definition",
"->",
"is_for_mappings_only",
"(",
")",
")",
"{",
"$",
"mode",
"=",
"$",
"definition",
"->",
"get_mode",
"(",
")",
";",
"// Load the default stores.",
"foreach",
"(",
"$",
"this",
"->",
"configmodemappings",
"as",
"$",
"mapping",
")",
"{",
"if",
"(",
"$",
"mapping",
"[",
"'mode'",
"]",
"===",
"$",
"mode",
"&&",
"array_key_exists",
"(",
"$",
"mapping",
"[",
"'store'",
"]",
",",
"$",
"availablestores",
")",
")",
"{",
"$",
"store",
"=",
"$",
"availablestores",
"[",
"$",
"mapping",
"[",
"'store'",
"]",
"]",
";",
"if",
"(",
"empty",
"(",
"$",
"store",
"[",
"'mappingsonly'",
"]",
")",
")",
"{",
"$",
"stores",
"[",
"$",
"mapping",
"[",
"'store'",
"]",
"]",
"=",
"$",
"store",
";",
"}",
"}",
"}",
"}",
"return",
"$",
"stores",
";",
"}"
] | Gets all of the stores that are to be used for the given definition.
@param cache_definition $definition
@return array | [
"Gets",
"all",
"of",
"the",
"stores",
"that",
"are",
"to",
"be",
"used",
"for",
"the",
"given",
"definition",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/cache/classes/config.php#L485-L533 |
213,627 | moodle/moodle | cache/classes/config.php | cache_config.get_lock_for_store | public function get_lock_for_store($storename) {
if (array_key_exists($storename, $this->configstores)) {
if (array_key_exists($this->configstores[$storename]['lock'], $this->configlocks)) {
$lock = $this->configstores[$storename]['lock'];
return $this->configlocks[$lock];
}
}
return $this->get_default_lock();
} | php | public function get_lock_for_store($storename) {
if (array_key_exists($storename, $this->configstores)) {
if (array_key_exists($this->configstores[$storename]['lock'], $this->configlocks)) {
$lock = $this->configstores[$storename]['lock'];
return $this->configlocks[$lock];
}
}
return $this->get_default_lock();
} | [
"public",
"function",
"get_lock_for_store",
"(",
"$",
"storename",
")",
"{",
"if",
"(",
"array_key_exists",
"(",
"$",
"storename",
",",
"$",
"this",
"->",
"configstores",
")",
")",
"{",
"if",
"(",
"array_key_exists",
"(",
"$",
"this",
"->",
"configstores",
"[",
"$",
"storename",
"]",
"[",
"'lock'",
"]",
",",
"$",
"this",
"->",
"configlocks",
")",
")",
"{",
"$",
"lock",
"=",
"$",
"this",
"->",
"configstores",
"[",
"$",
"storename",
"]",
"[",
"'lock'",
"]",
";",
"return",
"$",
"this",
"->",
"configlocks",
"[",
"$",
"lock",
"]",
";",
"}",
"}",
"return",
"$",
"this",
"->",
"get_default_lock",
"(",
")",
";",
"}"
] | Returns the lock store configuration to use with a given store.
@param string $storename
@return array
@throws cache_exception | [
"Returns",
"the",
"lock",
"store",
"configuration",
"to",
"use",
"with",
"a",
"given",
"store",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/cache/classes/config.php#L573-L581 |
213,628 | moodle/moodle | message/output/popup/message_output_popup.php | message_output_popup.send_message | public function send_message($eventdata) {
global $DB;
// Prevent users from getting popup notifications from themselves (happens with forum notifications).
if ($eventdata->userfrom->id != $eventdata->userto->id && $eventdata->notification) {
if (!$DB->record_exists('message_popup_notifications', ['notificationid' => $eventdata->savedmessageid])) {
$record = new stdClass();
$record->notificationid = $eventdata->savedmessageid;
$DB->insert_record('message_popup_notifications', $record);
}
}
return true;
} | php | public function send_message($eventdata) {
global $DB;
// Prevent users from getting popup notifications from themselves (happens with forum notifications).
if ($eventdata->userfrom->id != $eventdata->userto->id && $eventdata->notification) {
if (!$DB->record_exists('message_popup_notifications', ['notificationid' => $eventdata->savedmessageid])) {
$record = new stdClass();
$record->notificationid = $eventdata->savedmessageid;
$DB->insert_record('message_popup_notifications', $record);
}
}
return true;
} | [
"public",
"function",
"send_message",
"(",
"$",
"eventdata",
")",
"{",
"global",
"$",
"DB",
";",
"// Prevent users from getting popup notifications from themselves (happens with forum notifications).",
"if",
"(",
"$",
"eventdata",
"->",
"userfrom",
"->",
"id",
"!=",
"$",
"eventdata",
"->",
"userto",
"->",
"id",
"&&",
"$",
"eventdata",
"->",
"notification",
")",
"{",
"if",
"(",
"!",
"$",
"DB",
"->",
"record_exists",
"(",
"'message_popup_notifications'",
",",
"[",
"'notificationid'",
"=>",
"$",
"eventdata",
"->",
"savedmessageid",
"]",
")",
")",
"{",
"$",
"record",
"=",
"new",
"stdClass",
"(",
")",
";",
"$",
"record",
"->",
"notificationid",
"=",
"$",
"eventdata",
"->",
"savedmessageid",
";",
"$",
"DB",
"->",
"insert_record",
"(",
"'message_popup_notifications'",
",",
"$",
"record",
")",
";",
"}",
"}",
"return",
"true",
";",
"}"
] | Adds notifications to the 'message_popup_notifications' table if applicable.
The reason for this is because we may not want to show all notifications in the notification popover. This
can happen if the popup processor was disabled when the notification was sent. If the processor is disabled this
function is never called so the notification will never be added to the 'message_popup_notifications' table.
Essentially this table is used to filter what notifications to display from the 'notifications' table.
@param object $eventdata the event data submitted by the message sender plus $eventdata->savedmessageid
@return true if ok, false if error | [
"Adds",
"notifications",
"to",
"the",
"message_popup_notifications",
"table",
"if",
"applicable",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/message/output/popup/message_output_popup.php#L48-L62 |
213,629 | moodle/moodle | lib/jabber/XMPP/Log.php | XMPPHP_Log.log | public function log($msg, $runlevel = self::LEVEL_INFO) {
$time = time();
#$this->data[] = array($this->runlevel, $msg, $time);
if($this->printout and $runlevel <= $this->runlevel) {
$this->writeLine($msg, $runlevel, $time);
}
} | php | public function log($msg, $runlevel = self::LEVEL_INFO) {
$time = time();
#$this->data[] = array($this->runlevel, $msg, $time);
if($this->printout and $runlevel <= $this->runlevel) {
$this->writeLine($msg, $runlevel, $time);
}
} | [
"public",
"function",
"log",
"(",
"$",
"msg",
",",
"$",
"runlevel",
"=",
"self",
"::",
"LEVEL_INFO",
")",
"{",
"$",
"time",
"=",
"time",
"(",
")",
";",
"#$this->data[] = array($this->runlevel, $msg, $time);",
"if",
"(",
"$",
"this",
"->",
"printout",
"and",
"$",
"runlevel",
"<=",
"$",
"this",
"->",
"runlevel",
")",
"{",
"$",
"this",
"->",
"writeLine",
"(",
"$",
"msg",
",",
"$",
"runlevel",
",",
"$",
"time",
")",
";",
"}",
"}"
] | Add a message to the log data array
If printout in this instance is set to true, directly output the message
@param string $msg
@param integer $runlevel | [
"Add",
"a",
"message",
"to",
"the",
"log",
"data",
"array",
"If",
"printout",
"in",
"this",
"instance",
"is",
"set",
"to",
"true",
"directly",
"output",
"the",
"message"
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/jabber/XMPP/Log.php#L85-L91 |
213,630 | moodle/moodle | auth/cas/CAS/CAS/Request/AbstractRequest.php | CAS_Request_AbstractRequest.addCookie | public function addCookie ($name, $value)
{
if ($this->_sent) {
throw new CAS_OutOfSequenceException(
'Request has already been sent cannot '.__METHOD__
);
}
$this->cookies[$name] = $value;
} | php | public function addCookie ($name, $value)
{
if ($this->_sent) {
throw new CAS_OutOfSequenceException(
'Request has already been sent cannot '.__METHOD__
);
}
$this->cookies[$name] = $value;
} | [
"public",
"function",
"addCookie",
"(",
"$",
"name",
",",
"$",
"value",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"_sent",
")",
"{",
"throw",
"new",
"CAS_OutOfSequenceException",
"(",
"'Request has already been sent cannot '",
".",
"__METHOD__",
")",
";",
"}",
"$",
"this",
"->",
"cookies",
"[",
"$",
"name",
"]",
"=",
"$",
"value",
";",
"}"
] | Add a cookie to the request.
@param string $name Name of entry
@param string $value value of entry
@return void
@throws CAS_OutOfSequenceException If called after the Request has been sent. | [
"Add",
"a",
"cookie",
"to",
"the",
"request",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/auth/cas/CAS/CAS/Request/AbstractRequest.php#L88-L97 |
213,631 | moodle/moodle | auth/cas/CAS/CAS/Request/AbstractRequest.php | CAS_Request_AbstractRequest.addHeaders | public function addHeaders (array $headers)
{
if ($this->_sent) {
throw new CAS_OutOfSequenceException(
'Request has already been sent cannot '.__METHOD__
);
}
$this->headers = array_merge($this->headers, $headers);
} | php | public function addHeaders (array $headers)
{
if ($this->_sent) {
throw new CAS_OutOfSequenceException(
'Request has already been sent cannot '.__METHOD__
);
}
$this->headers = array_merge($this->headers, $headers);
} | [
"public",
"function",
"addHeaders",
"(",
"array",
"$",
"headers",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"_sent",
")",
"{",
"throw",
"new",
"CAS_OutOfSequenceException",
"(",
"'Request has already been sent cannot '",
".",
"__METHOD__",
")",
";",
"}",
"$",
"this",
"->",
"headers",
"=",
"array_merge",
"(",
"$",
"this",
"->",
"headers",
",",
"$",
"headers",
")",
";",
"}"
] | Add an array of header strings to the request.
@param array $headers headers to add
@return void
@throws CAS_OutOfSequenceException If called after the Request has been sent. | [
"Add",
"an",
"array",
"of",
"header",
"strings",
"to",
"the",
"request",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/auth/cas/CAS/CAS/Request/AbstractRequest.php#L147-L156 |
213,632 | moodle/moodle | auth/cas/CAS/CAS/Request/AbstractRequest.php | CAS_Request_AbstractRequest.setPostBody | public function setPostBody ($body)
{
if ($this->_sent) {
throw new CAS_OutOfSequenceException(
'Request has already been sent cannot '.__METHOD__
);
}
if (!$this->isPost) {
throw new CAS_OutOfSequenceException(
'Cannot add a POST body to a GET request, use makePost() first.'
);
}
$this->postBody = $body;
} | php | public function setPostBody ($body)
{
if ($this->_sent) {
throw new CAS_OutOfSequenceException(
'Request has already been sent cannot '.__METHOD__
);
}
if (!$this->isPost) {
throw new CAS_OutOfSequenceException(
'Cannot add a POST body to a GET request, use makePost() first.'
);
}
$this->postBody = $body;
} | [
"public",
"function",
"setPostBody",
"(",
"$",
"body",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"_sent",
")",
"{",
"throw",
"new",
"CAS_OutOfSequenceException",
"(",
"'Request has already been sent cannot '",
".",
"__METHOD__",
")",
";",
"}",
"if",
"(",
"!",
"$",
"this",
"->",
"isPost",
")",
"{",
"throw",
"new",
"CAS_OutOfSequenceException",
"(",
"'Cannot add a POST body to a GET request, use makePost() first.'",
")",
";",
"}",
"$",
"this",
"->",
"postBody",
"=",
"$",
"body",
";",
"}"
] | Add a POST body to the request
@param string $body body to add
@return void
@throws CAS_OutOfSequenceException If called after the Request has been sent. | [
"Add",
"a",
"POST",
"body",
"to",
"the",
"request"
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/auth/cas/CAS/CAS/Request/AbstractRequest.php#L183-L197 |
213,633 | moodle/moodle | auth/cas/CAS/CAS/Request/AbstractRequest.php | CAS_Request_AbstractRequest.setSslCaCert | public function setSslCaCert ($caCertPath,$validate_cn=true)
{
if ($this->_sent) {
throw new CAS_OutOfSequenceException(
'Request has already been sent cannot '.__METHOD__
);
}
$this->caCertPath = $caCertPath;
$this->validateCN = $validate_cn;
} | php | public function setSslCaCert ($caCertPath,$validate_cn=true)
{
if ($this->_sent) {
throw new CAS_OutOfSequenceException(
'Request has already been sent cannot '.__METHOD__
);
}
$this->caCertPath = $caCertPath;
$this->validateCN = $validate_cn;
} | [
"public",
"function",
"setSslCaCert",
"(",
"$",
"caCertPath",
",",
"$",
"validate_cn",
"=",
"true",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"_sent",
")",
"{",
"throw",
"new",
"CAS_OutOfSequenceException",
"(",
"'Request has already been sent cannot '",
".",
"__METHOD__",
")",
";",
"}",
"$",
"this",
"->",
"caCertPath",
"=",
"$",
"caCertPath",
";",
"$",
"this",
"->",
"validateCN",
"=",
"$",
"validate_cn",
";",
"}"
] | Specify the path to an SSL CA certificate to validate the server with.
@param string $caCertPath path to cert
@param bool $validate_cn valdiate CN of certificate
@return void
@throws CAS_OutOfSequenceException If called after the Request has been sent. | [
"Specify",
"the",
"path",
"to",
"an",
"SSL",
"CA",
"certificate",
"to",
"validate",
"the",
"server",
"with",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/auth/cas/CAS/CAS/Request/AbstractRequest.php#L208-L217 |
213,634 | moodle/moodle | auth/cas/CAS/CAS/Request/AbstractRequest.php | CAS_Request_AbstractRequest.getResponseStatusCode | public function getResponseStatusCode ()
{
if (!$this->_sent) {
throw new CAS_OutOfSequenceException(
'Request has not been sent yet. Cannot '.__METHOD__
);
}
if (!preg_match(
'/HTTP\/[0-9.]+\s+([0-9]+)\s*(.*)/',
$this->_responseHeaders[0], $matches
)
) {
throw new CAS_Request_Exception(
'Bad response, no status code was found in the first line.'
);
}
return intval($matches[1]);
} | php | public function getResponseStatusCode ()
{
if (!$this->_sent) {
throw new CAS_OutOfSequenceException(
'Request has not been sent yet. Cannot '.__METHOD__
);
}
if (!preg_match(
'/HTTP\/[0-9.]+\s+([0-9]+)\s*(.*)/',
$this->_responseHeaders[0], $matches
)
) {
throw new CAS_Request_Exception(
'Bad response, no status code was found in the first line.'
);
}
return intval($matches[1]);
} | [
"public",
"function",
"getResponseStatusCode",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"_sent",
")",
"{",
"throw",
"new",
"CAS_OutOfSequenceException",
"(",
"'Request has not been sent yet. Cannot '",
".",
"__METHOD__",
")",
";",
"}",
"if",
"(",
"!",
"preg_match",
"(",
"'/HTTP\\/[0-9.]+\\s+([0-9]+)\\s*(.*)/'",
",",
"$",
"this",
"->",
"_responseHeaders",
"[",
"0",
"]",
",",
"$",
"matches",
")",
")",
"{",
"throw",
"new",
"CAS_Request_Exception",
"(",
"'Bad response, no status code was found in the first line.'",
")",
";",
"}",
"return",
"intval",
"(",
"$",
"matches",
"[",
"1",
"]",
")",
";",
"}"
] | Answer HTTP status code of the response
@return int
@throws CAS_OutOfSequenceException If called before the Request has been sent. | [
"Answer",
"HTTP",
"status",
"code",
"of",
"the",
"response"
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/auth/cas/CAS/CAS/Request/AbstractRequest.php#L326-L345 |
213,635 | moodle/moodle | enrol/meta/classes/observer.php | enrol_meta_observer.user_enrolment_created | public static function user_enrolment_created(\core\event\user_enrolment_created $event) {
if (!enrol_is_enabled('meta')) {
// No more enrolments for disabled plugins.
return true;
}
if ($event->other['enrol'] === 'meta') {
// Prevent circular dependencies - we can not sync meta enrolments recursively.
return true;
}
self::sync_course_instances($event->courseid, $event->relateduserid);
return true;
} | php | public static function user_enrolment_created(\core\event\user_enrolment_created $event) {
if (!enrol_is_enabled('meta')) {
// No more enrolments for disabled plugins.
return true;
}
if ($event->other['enrol'] === 'meta') {
// Prevent circular dependencies - we can not sync meta enrolments recursively.
return true;
}
self::sync_course_instances($event->courseid, $event->relateduserid);
return true;
} | [
"public",
"static",
"function",
"user_enrolment_created",
"(",
"\\",
"core",
"\\",
"event",
"\\",
"user_enrolment_created",
"$",
"event",
")",
"{",
"if",
"(",
"!",
"enrol_is_enabled",
"(",
"'meta'",
")",
")",
"{",
"// No more enrolments for disabled plugins.",
"return",
"true",
";",
"}",
"if",
"(",
"$",
"event",
"->",
"other",
"[",
"'enrol'",
"]",
"===",
"'meta'",
")",
"{",
"// Prevent circular dependencies - we can not sync meta enrolments recursively.",
"return",
"true",
";",
"}",
"self",
"::",
"sync_course_instances",
"(",
"$",
"event",
"->",
"courseid",
",",
"$",
"event",
"->",
"relateduserid",
")",
";",
"return",
"true",
";",
"}"
] | Triggered via user_enrolment_created event.
@param \core\event\user_enrolment_created $event
@return bool true on success. | [
"Triggered",
"via",
"user_enrolment_created",
"event",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/enrol/meta/classes/observer.php#L44-L57 |
213,636 | moodle/moodle | enrol/meta/classes/observer.php | enrol_meta_observer.role_unassigned | public static function role_unassigned(\core\event\role_unassigned $event) {
if (!enrol_is_enabled('meta')) {
// All roles are removed via cron automatically.
return true;
}
// Prevent circular dependencies - we can not sync meta roles recursively.
if ($event->other['component'] === 'enrol_meta') {
return true;
}
// Only course level roles are interesting.
if (!$parentcontext = context::instance_by_id($event->contextid, IGNORE_MISSING)) {
return true;
}
if ($parentcontext->contextlevel != CONTEXT_COURSE) {
return true;
}
self::sync_course_instances($parentcontext->instanceid, $event->relateduserid);
return true;
} | php | public static function role_unassigned(\core\event\role_unassigned $event) {
if (!enrol_is_enabled('meta')) {
// All roles are removed via cron automatically.
return true;
}
// Prevent circular dependencies - we can not sync meta roles recursively.
if ($event->other['component'] === 'enrol_meta') {
return true;
}
// Only course level roles are interesting.
if (!$parentcontext = context::instance_by_id($event->contextid, IGNORE_MISSING)) {
return true;
}
if ($parentcontext->contextlevel != CONTEXT_COURSE) {
return true;
}
self::sync_course_instances($parentcontext->instanceid, $event->relateduserid);
return true;
} | [
"public",
"static",
"function",
"role_unassigned",
"(",
"\\",
"core",
"\\",
"event",
"\\",
"role_unassigned",
"$",
"event",
")",
"{",
"if",
"(",
"!",
"enrol_is_enabled",
"(",
"'meta'",
")",
")",
"{",
"// All roles are removed via cron automatically.",
"return",
"true",
";",
"}",
"// Prevent circular dependencies - we can not sync meta roles recursively.",
"if",
"(",
"$",
"event",
"->",
"other",
"[",
"'component'",
"]",
"===",
"'enrol_meta'",
")",
"{",
"return",
"true",
";",
"}",
"// Only course level roles are interesting.",
"if",
"(",
"!",
"$",
"parentcontext",
"=",
"context",
"::",
"instance_by_id",
"(",
"$",
"event",
"->",
"contextid",
",",
"IGNORE_MISSING",
")",
")",
"{",
"return",
"true",
";",
"}",
"if",
"(",
"$",
"parentcontext",
"->",
"contextlevel",
"!=",
"CONTEXT_COURSE",
")",
"{",
"return",
"true",
";",
"}",
"self",
"::",
"sync_course_instances",
"(",
"$",
"parentcontext",
"->",
"instanceid",
",",
"$",
"event",
"->",
"relateduserid",
")",
";",
"return",
"true",
";",
"}"
] | Triggered via role_unassigned event.
@param \core\event\role_unassigned $event
@return bool true on success | [
"Triggered",
"via",
"role_unassigned",
"event",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/enrol/meta/classes/observer.php#L138-L160 |
213,637 | moodle/moodle | enrol/meta/classes/observer.php | enrol_meta_observer.course_deleted | public static function course_deleted(\core\event\course_deleted $event) {
global $DB;
if (!enrol_is_enabled('meta')) {
// This is slow, let enrol_meta_sync() deal with disabled plugin.
return true;
}
// Does anything want to sync with this parent?
if (!$enrols = $DB->get_records('enrol', array('customint1' => $event->objectid, 'enrol' => 'meta'),
'courseid ASC, id ASC')) {
return true;
}
$plugin = enrol_get_plugin('meta');
$unenrolaction = $plugin->get_config('unenrolaction', ENROL_EXT_REMOVED_SUSPENDNOROLES);
if ($unenrolaction == ENROL_EXT_REMOVED_UNENROL) {
// Simple, just delete this instance which purges all enrolments,
// admins were warned that this is risky setting!
foreach ($enrols as $enrol) {
$plugin->delete_instance($enrol);
}
return true;
}
foreach ($enrols as $enrol) {
if ($unenrolaction == ENROL_EXT_REMOVED_SUSPEND or $unenrolaction == ENROL_EXT_REMOVED_SUSPENDNOROLES) {
// This makes all enrolments suspended very quickly.
$plugin->update_status($enrol, ENROL_INSTANCE_DISABLED);
}
if ($unenrolaction == ENROL_EXT_REMOVED_SUSPENDNOROLES) {
$context = context_course::instance($enrol->courseid);
role_unassign_all(array('contextid'=>$context->id, 'component'=>'enrol_meta', 'itemid'=>$enrol->id));
}
}
return true;
} | php | public static function course_deleted(\core\event\course_deleted $event) {
global $DB;
if (!enrol_is_enabled('meta')) {
// This is slow, let enrol_meta_sync() deal with disabled plugin.
return true;
}
// Does anything want to sync with this parent?
if (!$enrols = $DB->get_records('enrol', array('customint1' => $event->objectid, 'enrol' => 'meta'),
'courseid ASC, id ASC')) {
return true;
}
$plugin = enrol_get_plugin('meta');
$unenrolaction = $plugin->get_config('unenrolaction', ENROL_EXT_REMOVED_SUSPENDNOROLES);
if ($unenrolaction == ENROL_EXT_REMOVED_UNENROL) {
// Simple, just delete this instance which purges all enrolments,
// admins were warned that this is risky setting!
foreach ($enrols as $enrol) {
$plugin->delete_instance($enrol);
}
return true;
}
foreach ($enrols as $enrol) {
if ($unenrolaction == ENROL_EXT_REMOVED_SUSPEND or $unenrolaction == ENROL_EXT_REMOVED_SUSPENDNOROLES) {
// This makes all enrolments suspended very quickly.
$plugin->update_status($enrol, ENROL_INSTANCE_DISABLED);
}
if ($unenrolaction == ENROL_EXT_REMOVED_SUSPENDNOROLES) {
$context = context_course::instance($enrol->courseid);
role_unassign_all(array('contextid'=>$context->id, 'component'=>'enrol_meta', 'itemid'=>$enrol->id));
}
}
return true;
} | [
"public",
"static",
"function",
"course_deleted",
"(",
"\\",
"core",
"\\",
"event",
"\\",
"course_deleted",
"$",
"event",
")",
"{",
"global",
"$",
"DB",
";",
"if",
"(",
"!",
"enrol_is_enabled",
"(",
"'meta'",
")",
")",
"{",
"// This is slow, let enrol_meta_sync() deal with disabled plugin.",
"return",
"true",
";",
"}",
"// Does anything want to sync with this parent?",
"if",
"(",
"!",
"$",
"enrols",
"=",
"$",
"DB",
"->",
"get_records",
"(",
"'enrol'",
",",
"array",
"(",
"'customint1'",
"=>",
"$",
"event",
"->",
"objectid",
",",
"'enrol'",
"=>",
"'meta'",
")",
",",
"'courseid ASC, id ASC'",
")",
")",
"{",
"return",
"true",
";",
"}",
"$",
"plugin",
"=",
"enrol_get_plugin",
"(",
"'meta'",
")",
";",
"$",
"unenrolaction",
"=",
"$",
"plugin",
"->",
"get_config",
"(",
"'unenrolaction'",
",",
"ENROL_EXT_REMOVED_SUSPENDNOROLES",
")",
";",
"if",
"(",
"$",
"unenrolaction",
"==",
"ENROL_EXT_REMOVED_UNENROL",
")",
"{",
"// Simple, just delete this instance which purges all enrolments,",
"// admins were warned that this is risky setting!",
"foreach",
"(",
"$",
"enrols",
"as",
"$",
"enrol",
")",
"{",
"$",
"plugin",
"->",
"delete_instance",
"(",
"$",
"enrol",
")",
";",
"}",
"return",
"true",
";",
"}",
"foreach",
"(",
"$",
"enrols",
"as",
"$",
"enrol",
")",
"{",
"if",
"(",
"$",
"unenrolaction",
"==",
"ENROL_EXT_REMOVED_SUSPEND",
"or",
"$",
"unenrolaction",
"==",
"ENROL_EXT_REMOVED_SUSPENDNOROLES",
")",
"{",
"// This makes all enrolments suspended very quickly.",
"$",
"plugin",
"->",
"update_status",
"(",
"$",
"enrol",
",",
"ENROL_INSTANCE_DISABLED",
")",
";",
"}",
"if",
"(",
"$",
"unenrolaction",
"==",
"ENROL_EXT_REMOVED_SUSPENDNOROLES",
")",
"{",
"$",
"context",
"=",
"context_course",
"::",
"instance",
"(",
"$",
"enrol",
"->",
"courseid",
")",
";",
"role_unassign_all",
"(",
"array",
"(",
"'contextid'",
"=>",
"$",
"context",
"->",
"id",
",",
"'component'",
"=>",
"'enrol_meta'",
",",
"'itemid'",
"=>",
"$",
"enrol",
"->",
"id",
")",
")",
";",
"}",
"}",
"return",
"true",
";",
"}"
] | Triggered via course_deleted event.
@param \core\event\course_deleted $event
@return bool true on success | [
"Triggered",
"via",
"course_deleted",
"event",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/enrol/meta/classes/observer.php#L168-L206 |
213,638 | moodle/moodle | enrol/meta/classes/observer.php | enrol_meta_observer.enrol_instance_updated | public static function enrol_instance_updated(\core\event\enrol_instance_updated $event) {
global $DB;
if (!enrol_is_enabled('meta')) {
// This is slow, let enrol_meta_sync() deal with disabled plugin.
return true;
}
// Does anything want to sync with this parent?
$affectedcourses = $DB->get_fieldset_sql('SELECT DISTINCT courseid FROM {enrol} '.
'WHERE customint1 = ? AND enrol = ?',
array($event->courseid, 'meta'));
foreach ($affectedcourses as $courseid) {
enrol_meta_sync($courseid);
}
return true;
} | php | public static function enrol_instance_updated(\core\event\enrol_instance_updated $event) {
global $DB;
if (!enrol_is_enabled('meta')) {
// This is slow, let enrol_meta_sync() deal with disabled plugin.
return true;
}
// Does anything want to sync with this parent?
$affectedcourses = $DB->get_fieldset_sql('SELECT DISTINCT courseid FROM {enrol} '.
'WHERE customint1 = ? AND enrol = ?',
array($event->courseid, 'meta'));
foreach ($affectedcourses as $courseid) {
enrol_meta_sync($courseid);
}
return true;
} | [
"public",
"static",
"function",
"enrol_instance_updated",
"(",
"\\",
"core",
"\\",
"event",
"\\",
"enrol_instance_updated",
"$",
"event",
")",
"{",
"global",
"$",
"DB",
";",
"if",
"(",
"!",
"enrol_is_enabled",
"(",
"'meta'",
")",
")",
"{",
"// This is slow, let enrol_meta_sync() deal with disabled plugin.",
"return",
"true",
";",
"}",
"// Does anything want to sync with this parent?",
"$",
"affectedcourses",
"=",
"$",
"DB",
"->",
"get_fieldset_sql",
"(",
"'SELECT DISTINCT courseid FROM {enrol} '",
".",
"'WHERE customint1 = ? AND enrol = ?'",
",",
"array",
"(",
"$",
"event",
"->",
"courseid",
",",
"'meta'",
")",
")",
";",
"foreach",
"(",
"$",
"affectedcourses",
"as",
"$",
"courseid",
")",
"{",
"enrol_meta_sync",
"(",
"$",
"courseid",
")",
";",
"}",
"return",
"true",
";",
"}"
] | Triggered via enrol_instance_updated event.
@param \core\event\enrol_instance_updated $event
@return boolean | [
"Triggered",
"via",
"enrol_instance_updated",
"event",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/enrol/meta/classes/observer.php#L214-L232 |
213,639 | moodle/moodle | badges/criteria/award_criteria_overall.php | award_criteria_overall.review | public function review($userid, $filtered = false) {
global $DB;
$sql = "SELECT bc.*, bcm.critid, bcm.userid, bcm.datemet
FROM {badge_criteria} bc
LEFT JOIN {badge_criteria_met} bcm
ON bc.id = bcm.critid AND bcm.userid = :userid
WHERE bc.badgeid = :badgeid
AND bc.criteriatype != :criteriatype ";
$params = array(
'userid' => $userid,
'badgeid' => $this->badgeid,
'criteriatype' => BADGE_CRITERIA_TYPE_OVERALL
);
$criteria = $DB->get_records_sql($sql, $params);
$overall = false;
foreach ($criteria as $crit) {
if ($this->method == BADGE_CRITERIA_AGGREGATION_ALL) {
if ($crit->datemet === null) {
return false;
} else {
$overall = true;
continue;
}
} else {
if ($crit->datemet === null) {
$overall = false;
continue;
} else {
return true;
}
}
}
return $overall;
} | php | public function review($userid, $filtered = false) {
global $DB;
$sql = "SELECT bc.*, bcm.critid, bcm.userid, bcm.datemet
FROM {badge_criteria} bc
LEFT JOIN {badge_criteria_met} bcm
ON bc.id = bcm.critid AND bcm.userid = :userid
WHERE bc.badgeid = :badgeid
AND bc.criteriatype != :criteriatype ";
$params = array(
'userid' => $userid,
'badgeid' => $this->badgeid,
'criteriatype' => BADGE_CRITERIA_TYPE_OVERALL
);
$criteria = $DB->get_records_sql($sql, $params);
$overall = false;
foreach ($criteria as $crit) {
if ($this->method == BADGE_CRITERIA_AGGREGATION_ALL) {
if ($crit->datemet === null) {
return false;
} else {
$overall = true;
continue;
}
} else {
if ($crit->datemet === null) {
$overall = false;
continue;
} else {
return true;
}
}
}
return $overall;
} | [
"public",
"function",
"review",
"(",
"$",
"userid",
",",
"$",
"filtered",
"=",
"false",
")",
"{",
"global",
"$",
"DB",
";",
"$",
"sql",
"=",
"\"SELECT bc.*, bcm.critid, bcm.userid, bcm.datemet\n FROM {badge_criteria} bc\n LEFT JOIN {badge_criteria_met} bcm\n ON bc.id = bcm.critid AND bcm.userid = :userid\n WHERE bc.badgeid = :badgeid\n AND bc.criteriatype != :criteriatype \"",
";",
"$",
"params",
"=",
"array",
"(",
"'userid'",
"=>",
"$",
"userid",
",",
"'badgeid'",
"=>",
"$",
"this",
"->",
"badgeid",
",",
"'criteriatype'",
"=>",
"BADGE_CRITERIA_TYPE_OVERALL",
")",
";",
"$",
"criteria",
"=",
"$",
"DB",
"->",
"get_records_sql",
"(",
"$",
"sql",
",",
"$",
"params",
")",
";",
"$",
"overall",
"=",
"false",
";",
"foreach",
"(",
"$",
"criteria",
"as",
"$",
"crit",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"method",
"==",
"BADGE_CRITERIA_AGGREGATION_ALL",
")",
"{",
"if",
"(",
"$",
"crit",
"->",
"datemet",
"===",
"null",
")",
"{",
"return",
"false",
";",
"}",
"else",
"{",
"$",
"overall",
"=",
"true",
";",
"continue",
";",
"}",
"}",
"else",
"{",
"if",
"(",
"$",
"crit",
"->",
"datemet",
"===",
"null",
")",
"{",
"$",
"overall",
"=",
"false",
";",
"continue",
";",
"}",
"else",
"{",
"return",
"true",
";",
"}",
"}",
"}",
"return",
"$",
"overall",
";",
"}"
] | Review this criteria and decide if it has been completed
Overall criteria review should be called only from other criteria handlers.
@param int $userid User whose criteria completion needs to be reviewed.
@param bool $filtered An additional parameter indicating that user list
has been reduced and some expensive checks can be skipped.
@return bool Whether criteria is complete | [
"Review",
"this",
"criteria",
"and",
"decide",
"if",
"it",
"has",
"been",
"completed",
"Overall",
"criteria",
"review",
"should",
"be",
"called",
"only",
"from",
"other",
"criteria",
"handlers",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/badges/criteria/award_criteria_overall.php#L106-L143 |
213,640 | moodle/moodle | badges/criteria/award_criteria_overall.php | award_criteria_overall.save | public function save($params = array()) {
global $DB;
// Sort out criteria description.
// If it is coming from the form editor, it is an array of (text, format).
$description = '';
$descriptionformat = FORMAT_HTML;
if (isset($params['description']['text'])) {
$description = $params['description']['text'];
$descriptionformat = $params['description']['format'];
} else if (isset($params['description'])) {
$description = $params['description'];
}
$fordb = new stdClass();
$fordb->criteriatype = $this->criteriatype;
$fordb->badgeid = $this->badgeid;
$fordb->description = $description;
$fordb->descriptionformat = $descriptionformat;
if ($this->id !== 0) {
$fordb->id = $this->id;
$DB->update_record('badge_criteria', $fordb);
} else {
// New record in DB, set aggregation to ALL by default.
$fordb->method = BADGE_CRITERIA_AGGREGATION_ALL;
$DB->insert_record('badge_criteria', $fordb);
}
} | php | public function save($params = array()) {
global $DB;
// Sort out criteria description.
// If it is coming from the form editor, it is an array of (text, format).
$description = '';
$descriptionformat = FORMAT_HTML;
if (isset($params['description']['text'])) {
$description = $params['description']['text'];
$descriptionformat = $params['description']['format'];
} else if (isset($params['description'])) {
$description = $params['description'];
}
$fordb = new stdClass();
$fordb->criteriatype = $this->criteriatype;
$fordb->badgeid = $this->badgeid;
$fordb->description = $description;
$fordb->descriptionformat = $descriptionformat;
if ($this->id !== 0) {
$fordb->id = $this->id;
$DB->update_record('badge_criteria', $fordb);
} else {
// New record in DB, set aggregation to ALL by default.
$fordb->method = BADGE_CRITERIA_AGGREGATION_ALL;
$DB->insert_record('badge_criteria', $fordb);
}
} | [
"public",
"function",
"save",
"(",
"$",
"params",
"=",
"array",
"(",
")",
")",
"{",
"global",
"$",
"DB",
";",
"// Sort out criteria description.",
"// If it is coming from the form editor, it is an array of (text, format).",
"$",
"description",
"=",
"''",
";",
"$",
"descriptionformat",
"=",
"FORMAT_HTML",
";",
"if",
"(",
"isset",
"(",
"$",
"params",
"[",
"'description'",
"]",
"[",
"'text'",
"]",
")",
")",
"{",
"$",
"description",
"=",
"$",
"params",
"[",
"'description'",
"]",
"[",
"'text'",
"]",
";",
"$",
"descriptionformat",
"=",
"$",
"params",
"[",
"'description'",
"]",
"[",
"'format'",
"]",
";",
"}",
"else",
"if",
"(",
"isset",
"(",
"$",
"params",
"[",
"'description'",
"]",
")",
")",
"{",
"$",
"description",
"=",
"$",
"params",
"[",
"'description'",
"]",
";",
"}",
"$",
"fordb",
"=",
"new",
"stdClass",
"(",
")",
";",
"$",
"fordb",
"->",
"criteriatype",
"=",
"$",
"this",
"->",
"criteriatype",
";",
"$",
"fordb",
"->",
"badgeid",
"=",
"$",
"this",
"->",
"badgeid",
";",
"$",
"fordb",
"->",
"description",
"=",
"$",
"description",
";",
"$",
"fordb",
"->",
"descriptionformat",
"=",
"$",
"descriptionformat",
";",
"if",
"(",
"$",
"this",
"->",
"id",
"!==",
"0",
")",
"{",
"$",
"fordb",
"->",
"id",
"=",
"$",
"this",
"->",
"id",
";",
"$",
"DB",
"->",
"update_record",
"(",
"'badge_criteria'",
",",
"$",
"fordb",
")",
";",
"}",
"else",
"{",
"// New record in DB, set aggregation to ALL by default.",
"$",
"fordb",
"->",
"method",
"=",
"BADGE_CRITERIA_AGGREGATION_ALL",
";",
"$",
"DB",
"->",
"insert_record",
"(",
"'badge_criteria'",
",",
"$",
"fordb",
")",
";",
"}",
"}"
] | Saves overall badge criteria description.
@param array $params Values from the form or any other array. | [
"Saves",
"overall",
"badge",
"criteria",
"description",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/badges/criteria/award_criteria_overall.php#L176-L203 |
213,641 | moodle/moodle | lib/classes/external/exporter.php | exporter.get_format_parameters | final protected function get_format_parameters($property) {
$parameters = [
'component' => null,
'filearea' => null,
'itemid' => null,
'options' => [],
'striplinks' => true,
];
$candidate = 'get_format_parameters_for_' . $property;
if (method_exists($this, $candidate)) {
$parameters = array_merge($parameters, $this->{$candidate}());
}
if (!isset($parameters['context'])) {
if (!isset($this->related['context']) || !($this->related['context'] instanceof context)) {
throw new coding_exception("Unknown context to use for formatting the property '$property' in the " .
"exporter '" . get_class($this) . "'. You either need to add 'context' to your related objects, " .
"or create the method '$candidate' and return the context from there.");
}
$parameters['context'] = $this->related['context'];
} else if (!($parameters['context'] instanceof context)) {
throw new coding_exception("The context given to format the property '$property' in the exporter '" .
get_class($this) . "' is invalid.");
}
return $parameters;
} | php | final protected function get_format_parameters($property) {
$parameters = [
'component' => null,
'filearea' => null,
'itemid' => null,
'options' => [],
'striplinks' => true,
];
$candidate = 'get_format_parameters_for_' . $property;
if (method_exists($this, $candidate)) {
$parameters = array_merge($parameters, $this->{$candidate}());
}
if (!isset($parameters['context'])) {
if (!isset($this->related['context']) || !($this->related['context'] instanceof context)) {
throw new coding_exception("Unknown context to use for formatting the property '$property' in the " .
"exporter '" . get_class($this) . "'. You either need to add 'context' to your related objects, " .
"or create the method '$candidate' and return the context from there.");
}
$parameters['context'] = $this->related['context'];
} else if (!($parameters['context'] instanceof context)) {
throw new coding_exception("The context given to format the property '$property' in the exporter '" .
get_class($this) . "' is invalid.");
}
return $parameters;
} | [
"final",
"protected",
"function",
"get_format_parameters",
"(",
"$",
"property",
")",
"{",
"$",
"parameters",
"=",
"[",
"'component'",
"=>",
"null",
",",
"'filearea'",
"=>",
"null",
",",
"'itemid'",
"=>",
"null",
",",
"'options'",
"=>",
"[",
"]",
",",
"'striplinks'",
"=>",
"true",
",",
"]",
";",
"$",
"candidate",
"=",
"'get_format_parameters_for_'",
".",
"$",
"property",
";",
"if",
"(",
"method_exists",
"(",
"$",
"this",
",",
"$",
"candidate",
")",
")",
"{",
"$",
"parameters",
"=",
"array_merge",
"(",
"$",
"parameters",
",",
"$",
"this",
"->",
"{",
"$",
"candidate",
"}",
"(",
")",
")",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"parameters",
"[",
"'context'",
"]",
")",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"related",
"[",
"'context'",
"]",
")",
"||",
"!",
"(",
"$",
"this",
"->",
"related",
"[",
"'context'",
"]",
"instanceof",
"context",
")",
")",
"{",
"throw",
"new",
"coding_exception",
"(",
"\"Unknown context to use for formatting the property '$property' in the \"",
".",
"\"exporter '\"",
".",
"get_class",
"(",
"$",
"this",
")",
".",
"\"'. You either need to add 'context' to your related objects, \"",
".",
"\"or create the method '$candidate' and return the context from there.\"",
")",
";",
"}",
"$",
"parameters",
"[",
"'context'",
"]",
"=",
"$",
"this",
"->",
"related",
"[",
"'context'",
"]",
";",
"}",
"else",
"if",
"(",
"!",
"(",
"$",
"parameters",
"[",
"'context'",
"]",
"instanceof",
"context",
")",
")",
"{",
"throw",
"new",
"coding_exception",
"(",
"\"The context given to format the property '$property' in the exporter '\"",
".",
"get_class",
"(",
"$",
"this",
")",
".",
"\"' is invalid.\"",
")",
";",
"}",
"return",
"$",
"parameters",
";",
"}"
] | Get the format parameters.
This method returns the parameters to use with the functions external_format_text(), and
external_format_string(). To override the default parameters, you can define a protected method
called 'get_format_parameters_for_<propertyName>'. For example, 'get_format_parameters_for_description',
if your property is 'description'.
Your method must return an array containing any of the following keys:
- context: The context to use. Defaults to $this->related['context'] if defined, else throws an exception.
- component: The component to use with external_format_text(). Defaults to null.
- filearea: The filearea to use with external_format_text(). Defaults to null.
- itemid: The itemid to use with external_format_text(). Defaults to null.
- options: An array of options accepted by external_format_text() or external_format_string(). Defaults to [].
- striplinks: Whether to strip the links with external_format_string(). Defaults to true.
@param string $property The property to get the parameters for.
@return array | [
"Get",
"the",
"format",
"parameters",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/external/exporter.php#L203-L231 |
213,642 | moodle/moodle | lib/classes/external/exporter.php | exporter.format_properties | final public static function format_properties($properties) {
foreach ($properties as $property => $definition) {
// Ensures that null is set to its default.
if (!isset($definition['null'])) {
$properties[$property]['null'] = NULL_NOT_ALLOWED;
}
if (!isset($definition['description'])) {
$properties[$property]['description'] = $property;
}
// If an array is provided, it may be a nested array that is unformatted so rinse and repeat.
if (is_array($definition['type'])) {
$properties[$property]['type'] = static::format_properties($definition['type']);
}
}
return $properties;
} | php | final public static function format_properties($properties) {
foreach ($properties as $property => $definition) {
// Ensures that null is set to its default.
if (!isset($definition['null'])) {
$properties[$property]['null'] = NULL_NOT_ALLOWED;
}
if (!isset($definition['description'])) {
$properties[$property]['description'] = $property;
}
// If an array is provided, it may be a nested array that is unformatted so rinse and repeat.
if (is_array($definition['type'])) {
$properties[$property]['type'] = static::format_properties($definition['type']);
}
}
return $properties;
} | [
"final",
"public",
"static",
"function",
"format_properties",
"(",
"$",
"properties",
")",
"{",
"foreach",
"(",
"$",
"properties",
"as",
"$",
"property",
"=>",
"$",
"definition",
")",
"{",
"// Ensures that null is set to its default.",
"if",
"(",
"!",
"isset",
"(",
"$",
"definition",
"[",
"'null'",
"]",
")",
")",
"{",
"$",
"properties",
"[",
"$",
"property",
"]",
"[",
"'null'",
"]",
"=",
"NULL_NOT_ALLOWED",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"definition",
"[",
"'description'",
"]",
")",
")",
"{",
"$",
"properties",
"[",
"$",
"property",
"]",
"[",
"'description'",
"]",
"=",
"$",
"property",
";",
"}",
"// If an array is provided, it may be a nested array that is unformatted so rinse and repeat.",
"if",
"(",
"is_array",
"(",
"$",
"definition",
"[",
"'type'",
"]",
")",
")",
"{",
"$",
"properties",
"[",
"$",
"property",
"]",
"[",
"'type'",
"]",
"=",
"static",
"::",
"format_properties",
"(",
"$",
"definition",
"[",
"'type'",
"]",
")",
";",
"}",
"}",
"return",
"$",
"properties",
";",
"}"
] | Recursively formats a given property definition with the default fields required.
@param array $properties List of properties to format
@return array Formatted array | [
"Recursively",
"formats",
"a",
"given",
"property",
"definition",
"with",
"the",
"default",
"fields",
"required",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/external/exporter.php#L275-L291 |
213,643 | moodle/moodle | lib/classes/external/exporter.php | exporter.get_context_structure | final protected static function get_context_structure() {
return array(
'contextid' => new external_value(PARAM_INT, 'The context id', VALUE_OPTIONAL),
'contextlevel' => new external_value(PARAM_ALPHA, 'The context level', VALUE_OPTIONAL),
'instanceid' => new external_value(PARAM_INT, 'The Instance id', VALUE_OPTIONAL),
);
} | php | final protected static function get_context_structure() {
return array(
'contextid' => new external_value(PARAM_INT, 'The context id', VALUE_OPTIONAL),
'contextlevel' => new external_value(PARAM_ALPHA, 'The context level', VALUE_OPTIONAL),
'instanceid' => new external_value(PARAM_INT, 'The Instance id', VALUE_OPTIONAL),
);
} | [
"final",
"protected",
"static",
"function",
"get_context_structure",
"(",
")",
"{",
"return",
"array",
"(",
"'contextid'",
"=>",
"new",
"external_value",
"(",
"PARAM_INT",
",",
"'The context id'",
",",
"VALUE_OPTIONAL",
")",
",",
"'contextlevel'",
"=>",
"new",
"external_value",
"(",
"PARAM_ALPHA",
",",
"'The context level'",
",",
"VALUE_OPTIONAL",
")",
",",
"'instanceid'",
"=>",
"new",
"external_value",
"(",
"PARAM_INT",
",",
"'The Instance id'",
",",
"VALUE_OPTIONAL",
")",
",",
")",
";",
"}"
] | Get the context structure.
@return external_single_structure | [
"Get",
"the",
"context",
"structure",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/external/exporter.php#L396-L402 |
213,644 | moodle/moodle | lib/classes/external/exporter.php | exporter.get_format_field | final protected static function get_format_field($definitions, $property) {
$formatproperty = $property . 'format';
if (($definitions[$property]['type'] == PARAM_RAW || $definitions[$property]['type'] == PARAM_CLEANHTML)
&& isset($definitions[$formatproperty])
&& $definitions[$formatproperty]['type'] == PARAM_INT) {
return $formatproperty;
}
return false;
} | php | final protected static function get_format_field($definitions, $property) {
$formatproperty = $property . 'format';
if (($definitions[$property]['type'] == PARAM_RAW || $definitions[$property]['type'] == PARAM_CLEANHTML)
&& isset($definitions[$formatproperty])
&& $definitions[$formatproperty]['type'] == PARAM_INT) {
return $formatproperty;
}
return false;
} | [
"final",
"protected",
"static",
"function",
"get_format_field",
"(",
"$",
"definitions",
",",
"$",
"property",
")",
"{",
"$",
"formatproperty",
"=",
"$",
"property",
".",
"'format'",
";",
"if",
"(",
"(",
"$",
"definitions",
"[",
"$",
"property",
"]",
"[",
"'type'",
"]",
"==",
"PARAM_RAW",
"||",
"$",
"definitions",
"[",
"$",
"property",
"]",
"[",
"'type'",
"]",
"==",
"PARAM_CLEANHTML",
")",
"&&",
"isset",
"(",
"$",
"definitions",
"[",
"$",
"formatproperty",
"]",
")",
"&&",
"$",
"definitions",
"[",
"$",
"formatproperty",
"]",
"[",
"'type'",
"]",
"==",
"PARAM_INT",
")",
"{",
"return",
"$",
"formatproperty",
";",
"}",
"return",
"false",
";",
"}"
] | Get the format field name.
@param array $definitions List of properties definitions.
@param string $property The name of the property that may have a format field.
@return bool|string False, or the name of the format property. | [
"Get",
"the",
"format",
"field",
"name",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/external/exporter.php#L411-L419 |
213,645 | moodle/moodle | lib/classes/external/exporter.php | exporter.get_format_structure | final protected static function get_format_structure($property, $definition, $required = VALUE_REQUIRED) {
if (array_key_exists('default', $definition)) {
$required = VALUE_DEFAULT;
}
return new external_format_value($property, $required);
} | php | final protected static function get_format_structure($property, $definition, $required = VALUE_REQUIRED) {
if (array_key_exists('default', $definition)) {
$required = VALUE_DEFAULT;
}
return new external_format_value($property, $required);
} | [
"final",
"protected",
"static",
"function",
"get_format_structure",
"(",
"$",
"property",
",",
"$",
"definition",
",",
"$",
"required",
"=",
"VALUE_REQUIRED",
")",
"{",
"if",
"(",
"array_key_exists",
"(",
"'default'",
",",
"$",
"definition",
")",
")",
"{",
"$",
"required",
"=",
"VALUE_DEFAULT",
";",
"}",
"return",
"new",
"external_format_value",
"(",
"$",
"property",
",",
"$",
"required",
")",
";",
"}"
] | Get the format structure.
@param string $property The name of the property on which the format applies.
@param array $definition The definition of the format property.
@param int $required Constant VALUE_*.
@return external_format_value | [
"Get",
"the",
"format",
"structure",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/external/exporter.php#L429-L434 |
213,646 | moodle/moodle | lib/classes/external/exporter.php | exporter.get_create_structure | final public static function get_create_structure() {
$properties = self::properties_definition();
$returns = array();
foreach ($properties as $property => $definition) {
if ($property == 'id') {
// The can not be set on create.
continue;
} else if (isset($returns[$property]) && substr($property, -6) === 'format') {
// We've already treated the format.
continue;
}
$required = VALUE_REQUIRED;
$default = null;
// We cannot use isset here because we want to detect nulls.
if (array_key_exists('default', $definition)) {
$required = VALUE_DEFAULT;
$default = $definition['default'];
}
// Magically treat the contextid fields.
if ($property == 'contextid') {
if (isset($properties['context'])) {
throw new coding_exception('There cannot be a context and a contextid column');
}
$returns += self::get_context_structure();
} else {
$returns[$property] = new external_value($definition['type'], $definition['description'], $required, $default,
$definition['null']);
// Magically treat the format properties.
if ($formatproperty = self::get_format_field($properties, $property)) {
if (isset($returns[$formatproperty])) {
throw new coding_exception('The format for \'' . $property . '\' is already defined.');
}
$returns[$formatproperty] = self::get_format_structure($property,
$properties[$formatproperty], VALUE_REQUIRED);
}
}
}
return new external_single_structure($returns);
} | php | final public static function get_create_structure() {
$properties = self::properties_definition();
$returns = array();
foreach ($properties as $property => $definition) {
if ($property == 'id') {
// The can not be set on create.
continue;
} else if (isset($returns[$property]) && substr($property, -6) === 'format') {
// We've already treated the format.
continue;
}
$required = VALUE_REQUIRED;
$default = null;
// We cannot use isset here because we want to detect nulls.
if (array_key_exists('default', $definition)) {
$required = VALUE_DEFAULT;
$default = $definition['default'];
}
// Magically treat the contextid fields.
if ($property == 'contextid') {
if (isset($properties['context'])) {
throw new coding_exception('There cannot be a context and a contextid column');
}
$returns += self::get_context_structure();
} else {
$returns[$property] = new external_value($definition['type'], $definition['description'], $required, $default,
$definition['null']);
// Magically treat the format properties.
if ($formatproperty = self::get_format_field($properties, $property)) {
if (isset($returns[$formatproperty])) {
throw new coding_exception('The format for \'' . $property . '\' is already defined.');
}
$returns[$formatproperty] = self::get_format_structure($property,
$properties[$formatproperty], VALUE_REQUIRED);
}
}
}
return new external_single_structure($returns);
} | [
"final",
"public",
"static",
"function",
"get_create_structure",
"(",
")",
"{",
"$",
"properties",
"=",
"self",
"::",
"properties_definition",
"(",
")",
";",
"$",
"returns",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"properties",
"as",
"$",
"property",
"=>",
"$",
"definition",
")",
"{",
"if",
"(",
"$",
"property",
"==",
"'id'",
")",
"{",
"// The can not be set on create.",
"continue",
";",
"}",
"else",
"if",
"(",
"isset",
"(",
"$",
"returns",
"[",
"$",
"property",
"]",
")",
"&&",
"substr",
"(",
"$",
"property",
",",
"-",
"6",
")",
"===",
"'format'",
")",
"{",
"// We've already treated the format.",
"continue",
";",
"}",
"$",
"required",
"=",
"VALUE_REQUIRED",
";",
"$",
"default",
"=",
"null",
";",
"// We cannot use isset here because we want to detect nulls.",
"if",
"(",
"array_key_exists",
"(",
"'default'",
",",
"$",
"definition",
")",
")",
"{",
"$",
"required",
"=",
"VALUE_DEFAULT",
";",
"$",
"default",
"=",
"$",
"definition",
"[",
"'default'",
"]",
";",
"}",
"// Magically treat the contextid fields.",
"if",
"(",
"$",
"property",
"==",
"'contextid'",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"properties",
"[",
"'context'",
"]",
")",
")",
"{",
"throw",
"new",
"coding_exception",
"(",
"'There cannot be a context and a contextid column'",
")",
";",
"}",
"$",
"returns",
"+=",
"self",
"::",
"get_context_structure",
"(",
")",
";",
"}",
"else",
"{",
"$",
"returns",
"[",
"$",
"property",
"]",
"=",
"new",
"external_value",
"(",
"$",
"definition",
"[",
"'type'",
"]",
",",
"$",
"definition",
"[",
"'description'",
"]",
",",
"$",
"required",
",",
"$",
"default",
",",
"$",
"definition",
"[",
"'null'",
"]",
")",
";",
"// Magically treat the format properties.",
"if",
"(",
"$",
"formatproperty",
"=",
"self",
"::",
"get_format_field",
"(",
"$",
"properties",
",",
"$",
"property",
")",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"returns",
"[",
"$",
"formatproperty",
"]",
")",
")",
"{",
"throw",
"new",
"coding_exception",
"(",
"'The format for \\''",
".",
"$",
"property",
".",
"'\\' is already defined.'",
")",
";",
"}",
"$",
"returns",
"[",
"$",
"formatproperty",
"]",
"=",
"self",
"::",
"get_format_structure",
"(",
"$",
"property",
",",
"$",
"properties",
"[",
"$",
"formatproperty",
"]",
",",
"VALUE_REQUIRED",
")",
";",
"}",
"}",
"}",
"return",
"new",
"external_single_structure",
"(",
"$",
"returns",
")",
";",
"}"
] | Returns the create structure.
@return external_single_structure | [
"Returns",
"the",
"create",
"structure",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/external/exporter.php#L441-L487 |
213,647 | moodle/moodle | lib/classes/external/exporter.php | exporter.get_update_structure | final public static function get_update_structure() {
$properties = self::properties_definition();
$returns = array();
foreach ($properties as $property => $definition) {
if (isset($returns[$property]) && substr($property, -6) === 'format') {
// We've already treated the format.
continue;
}
$default = null;
$required = VALUE_OPTIONAL;
if ($property == 'id') {
$required = VALUE_REQUIRED;
}
// Magically treat the contextid fields.
if ($property == 'contextid') {
if (isset($properties['context'])) {
throw new coding_exception('There cannot be a context and a contextid column');
}
$returns += self::get_context_structure();
} else {
$returns[$property] = new external_value($definition['type'], $definition['description'], $required, $default,
$definition['null']);
// Magically treat the format properties.
if ($formatproperty = self::get_format_field($properties, $property)) {
if (isset($returns[$formatproperty])) {
throw new coding_exception('The format for \'' . $property . '\' is already defined.');
}
$returns[$formatproperty] = self::get_format_structure($property,
$properties[$formatproperty], VALUE_OPTIONAL);
}
}
}
return new external_single_structure($returns);
} | php | final public static function get_update_structure() {
$properties = self::properties_definition();
$returns = array();
foreach ($properties as $property => $definition) {
if (isset($returns[$property]) && substr($property, -6) === 'format') {
// We've already treated the format.
continue;
}
$default = null;
$required = VALUE_OPTIONAL;
if ($property == 'id') {
$required = VALUE_REQUIRED;
}
// Magically treat the contextid fields.
if ($property == 'contextid') {
if (isset($properties['context'])) {
throw new coding_exception('There cannot be a context and a contextid column');
}
$returns += self::get_context_structure();
} else {
$returns[$property] = new external_value($definition['type'], $definition['description'], $required, $default,
$definition['null']);
// Magically treat the format properties.
if ($formatproperty = self::get_format_field($properties, $property)) {
if (isset($returns[$formatproperty])) {
throw new coding_exception('The format for \'' . $property . '\' is already defined.');
}
$returns[$formatproperty] = self::get_format_structure($property,
$properties[$formatproperty], VALUE_OPTIONAL);
}
}
}
return new external_single_structure($returns);
} | [
"final",
"public",
"static",
"function",
"get_update_structure",
"(",
")",
"{",
"$",
"properties",
"=",
"self",
"::",
"properties_definition",
"(",
")",
";",
"$",
"returns",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"properties",
"as",
"$",
"property",
"=>",
"$",
"definition",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"returns",
"[",
"$",
"property",
"]",
")",
"&&",
"substr",
"(",
"$",
"property",
",",
"-",
"6",
")",
"===",
"'format'",
")",
"{",
"// We've already treated the format.",
"continue",
";",
"}",
"$",
"default",
"=",
"null",
";",
"$",
"required",
"=",
"VALUE_OPTIONAL",
";",
"if",
"(",
"$",
"property",
"==",
"'id'",
")",
"{",
"$",
"required",
"=",
"VALUE_REQUIRED",
";",
"}",
"// Magically treat the contextid fields.",
"if",
"(",
"$",
"property",
"==",
"'contextid'",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"properties",
"[",
"'context'",
"]",
")",
")",
"{",
"throw",
"new",
"coding_exception",
"(",
"'There cannot be a context and a contextid column'",
")",
";",
"}",
"$",
"returns",
"+=",
"self",
"::",
"get_context_structure",
"(",
")",
";",
"}",
"else",
"{",
"$",
"returns",
"[",
"$",
"property",
"]",
"=",
"new",
"external_value",
"(",
"$",
"definition",
"[",
"'type'",
"]",
",",
"$",
"definition",
"[",
"'description'",
"]",
",",
"$",
"required",
",",
"$",
"default",
",",
"$",
"definition",
"[",
"'null'",
"]",
")",
";",
"// Magically treat the format properties.",
"if",
"(",
"$",
"formatproperty",
"=",
"self",
"::",
"get_format_field",
"(",
"$",
"properties",
",",
"$",
"property",
")",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"returns",
"[",
"$",
"formatproperty",
"]",
")",
")",
"{",
"throw",
"new",
"coding_exception",
"(",
"'The format for \\''",
".",
"$",
"property",
".",
"'\\' is already defined.'",
")",
";",
"}",
"$",
"returns",
"[",
"$",
"formatproperty",
"]",
"=",
"self",
"::",
"get_format_structure",
"(",
"$",
"property",
",",
"$",
"properties",
"[",
"$",
"formatproperty",
"]",
",",
"VALUE_OPTIONAL",
")",
";",
"}",
"}",
"}",
"return",
"new",
"external_single_structure",
"(",
"$",
"returns",
")",
";",
"}"
] | Returns the update structure.
This structure can never be included at the top level for an external function signature
because it contains optional parameters.
@return external_single_structure | [
"Returns",
"the",
"update",
"structure",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/external/exporter.php#L565-L604 |
213,648 | moodle/moodle | mod/scorm/report/graphs/classes/report.php | report.get_data | protected function get_data($scoid, $allowedlist = []) {
global $DB;
$data = array_fill(0, self::BANDS, 0);
if (empty($allowedlist)) {
return $data;
}
list($usql, $params) = $DB->get_in_or_equal($allowedlist);
$params[] = $scoid;
// Construct the SQL.
$sql = "SELECT DISTINCT " . $DB->sql_concat('st.userid', '\'#\'', 'COALESCE(st.attempt, 0)') . " AS uniqueid,
st.userid AS userid,
st.scormid AS scormid,
st.attempt AS attempt,
st.scoid AS scoid
FROM {scorm_scoes_track} st
WHERE st.userid $usql AND st.scoid = ?";
$attempts = $DB->get_records_sql($sql, $params);
$usergrades = [];
foreach ($attempts as $attempt) {
if ($trackdata = scorm_get_tracks($scoid, $attempt->userid, $attempt->attempt)) {
if (isset($trackdata->score_raw)) {
$score = (int) $trackdata->score_raw;
if (empty($trackdata->score_min)) {
$minmark = 0;
} else {
$minmark = $trackdata->score_min;
}
// TODO MDL-55004: Get this value from elsewhere?
if (empty($trackdata->score_max)) {
$maxmark = 100;
} else {
$maxmark = $trackdata->score_max;
}
$range = ($maxmark - $minmark);
if (empty($range)) {
continue;
}
$percent = round((($score * 100) / $range), 2);
if (empty($usergrades[$attempt->userid]) || !isset($usergrades[$attempt->userid])
|| ($percent > $usergrades[$attempt->userid]) || ($usergrades[$attempt->userid] === '*')) {
$usergrades[$attempt->userid] = $percent;
}
unset($percent);
} else {
// User has made an attempt but either SCO was not able to record the score or something else is broken in SCO.
if (!isset($usergrades[$attempt->userid])) {
$usergrades[$attempt->userid] = '*';
}
}
}
}
// Recording all users who attempted the SCO, but resulting data was invalid.
foreach ($usergrades as $userpercent) {
if ($userpercent === '*') {
$data[0]++;
} else {
$gradeband = floor($userpercent / self::BANDWIDTH);
if ($gradeband != (self::BANDS - 1)) {
$gradeband++;
}
$data[$gradeband]++;
}
}
return $data;
} | php | protected function get_data($scoid, $allowedlist = []) {
global $DB;
$data = array_fill(0, self::BANDS, 0);
if (empty($allowedlist)) {
return $data;
}
list($usql, $params) = $DB->get_in_or_equal($allowedlist);
$params[] = $scoid;
// Construct the SQL.
$sql = "SELECT DISTINCT " . $DB->sql_concat('st.userid', '\'#\'', 'COALESCE(st.attempt, 0)') . " AS uniqueid,
st.userid AS userid,
st.scormid AS scormid,
st.attempt AS attempt,
st.scoid AS scoid
FROM {scorm_scoes_track} st
WHERE st.userid $usql AND st.scoid = ?";
$attempts = $DB->get_records_sql($sql, $params);
$usergrades = [];
foreach ($attempts as $attempt) {
if ($trackdata = scorm_get_tracks($scoid, $attempt->userid, $attempt->attempt)) {
if (isset($trackdata->score_raw)) {
$score = (int) $trackdata->score_raw;
if (empty($trackdata->score_min)) {
$minmark = 0;
} else {
$minmark = $trackdata->score_min;
}
// TODO MDL-55004: Get this value from elsewhere?
if (empty($trackdata->score_max)) {
$maxmark = 100;
} else {
$maxmark = $trackdata->score_max;
}
$range = ($maxmark - $minmark);
if (empty($range)) {
continue;
}
$percent = round((($score * 100) / $range), 2);
if (empty($usergrades[$attempt->userid]) || !isset($usergrades[$attempt->userid])
|| ($percent > $usergrades[$attempt->userid]) || ($usergrades[$attempt->userid] === '*')) {
$usergrades[$attempt->userid] = $percent;
}
unset($percent);
} else {
// User has made an attempt but either SCO was not able to record the score or something else is broken in SCO.
if (!isset($usergrades[$attempt->userid])) {
$usergrades[$attempt->userid] = '*';
}
}
}
}
// Recording all users who attempted the SCO, but resulting data was invalid.
foreach ($usergrades as $userpercent) {
if ($userpercent === '*') {
$data[0]++;
} else {
$gradeband = floor($userpercent / self::BANDWIDTH);
if ($gradeband != (self::BANDS - 1)) {
$gradeband++;
}
$data[$gradeband]++;
}
}
return $data;
} | [
"protected",
"function",
"get_data",
"(",
"$",
"scoid",
",",
"$",
"allowedlist",
"=",
"[",
"]",
")",
"{",
"global",
"$",
"DB",
";",
"$",
"data",
"=",
"array_fill",
"(",
"0",
",",
"self",
"::",
"BANDS",
",",
"0",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"allowedlist",
")",
")",
"{",
"return",
"$",
"data",
";",
"}",
"list",
"(",
"$",
"usql",
",",
"$",
"params",
")",
"=",
"$",
"DB",
"->",
"get_in_or_equal",
"(",
"$",
"allowedlist",
")",
";",
"$",
"params",
"[",
"]",
"=",
"$",
"scoid",
";",
"// Construct the SQL.",
"$",
"sql",
"=",
"\"SELECT DISTINCT \"",
".",
"$",
"DB",
"->",
"sql_concat",
"(",
"'st.userid'",
",",
"'\\'#\\''",
",",
"'COALESCE(st.attempt, 0)'",
")",
".",
"\" AS uniqueid,\n st.userid AS userid,\n st.scormid AS scormid,\n st.attempt AS attempt,\n st.scoid AS scoid\n FROM {scorm_scoes_track} st\n WHERE st.userid $usql AND st.scoid = ?\"",
";",
"$",
"attempts",
"=",
"$",
"DB",
"->",
"get_records_sql",
"(",
"$",
"sql",
",",
"$",
"params",
")",
";",
"$",
"usergrades",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"attempts",
"as",
"$",
"attempt",
")",
"{",
"if",
"(",
"$",
"trackdata",
"=",
"scorm_get_tracks",
"(",
"$",
"scoid",
",",
"$",
"attempt",
"->",
"userid",
",",
"$",
"attempt",
"->",
"attempt",
")",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"trackdata",
"->",
"score_raw",
")",
")",
"{",
"$",
"score",
"=",
"(",
"int",
")",
"$",
"trackdata",
"->",
"score_raw",
";",
"if",
"(",
"empty",
"(",
"$",
"trackdata",
"->",
"score_min",
")",
")",
"{",
"$",
"minmark",
"=",
"0",
";",
"}",
"else",
"{",
"$",
"minmark",
"=",
"$",
"trackdata",
"->",
"score_min",
";",
"}",
"// TODO MDL-55004: Get this value from elsewhere?",
"if",
"(",
"empty",
"(",
"$",
"trackdata",
"->",
"score_max",
")",
")",
"{",
"$",
"maxmark",
"=",
"100",
";",
"}",
"else",
"{",
"$",
"maxmark",
"=",
"$",
"trackdata",
"->",
"score_max",
";",
"}",
"$",
"range",
"=",
"(",
"$",
"maxmark",
"-",
"$",
"minmark",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"range",
")",
")",
"{",
"continue",
";",
"}",
"$",
"percent",
"=",
"round",
"(",
"(",
"(",
"$",
"score",
"*",
"100",
")",
"/",
"$",
"range",
")",
",",
"2",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"usergrades",
"[",
"$",
"attempt",
"->",
"userid",
"]",
")",
"||",
"!",
"isset",
"(",
"$",
"usergrades",
"[",
"$",
"attempt",
"->",
"userid",
"]",
")",
"||",
"(",
"$",
"percent",
">",
"$",
"usergrades",
"[",
"$",
"attempt",
"->",
"userid",
"]",
")",
"||",
"(",
"$",
"usergrades",
"[",
"$",
"attempt",
"->",
"userid",
"]",
"===",
"'*'",
")",
")",
"{",
"$",
"usergrades",
"[",
"$",
"attempt",
"->",
"userid",
"]",
"=",
"$",
"percent",
";",
"}",
"unset",
"(",
"$",
"percent",
")",
";",
"}",
"else",
"{",
"// User has made an attempt but either SCO was not able to record the score or something else is broken in SCO.",
"if",
"(",
"!",
"isset",
"(",
"$",
"usergrades",
"[",
"$",
"attempt",
"->",
"userid",
"]",
")",
")",
"{",
"$",
"usergrades",
"[",
"$",
"attempt",
"->",
"userid",
"]",
"=",
"'*'",
";",
"}",
"}",
"}",
"}",
"// Recording all users who attempted the SCO, but resulting data was invalid.",
"foreach",
"(",
"$",
"usergrades",
"as",
"$",
"userpercent",
")",
"{",
"if",
"(",
"$",
"userpercent",
"===",
"'*'",
")",
"{",
"$",
"data",
"[",
"0",
"]",
"++",
";",
"}",
"else",
"{",
"$",
"gradeband",
"=",
"floor",
"(",
"$",
"userpercent",
"/",
"self",
"::",
"BANDWIDTH",
")",
";",
"if",
"(",
"$",
"gradeband",
"!=",
"(",
"self",
"::",
"BANDS",
"-",
"1",
")",
")",
"{",
"$",
"gradeband",
"++",
";",
"}",
"$",
"data",
"[",
"$",
"gradeband",
"]",
"++",
";",
"}",
"}",
"return",
"$",
"data",
";",
"}"
] | Get the data for the report.
@param int $scoid The sco ID.
@param array $allowedlist The list of user IDs allowed to be displayed.
@return array of data indexed per bar. | [
"Get",
"the",
"data",
"for",
"the",
"report",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/scorm/report/graphs/classes/report.php#L56-L125 |
213,649 | moodle/moodle | mod/scorm/report/graphs/classes/report.php | report.display | public function display($scorm, $cm, $course, $download) {
global $DB, $OUTPUT, $PAGE;
$contextmodule = context_module::instance($cm->id);
if ($groupmode = groups_get_activity_groupmode($cm)) { // Groups are being used.
groups_print_activity_menu($cm, new moodle_url($PAGE->url));
}
// Find out current restriction.
$group = groups_get_activity_group($cm, true);
if (empty($group)) {
// All users who can attempt scoes.
$students = get_users_by_capability($contextmodule, 'mod/scorm:savetrack', 'u.id' , '', '', '', '', '', false);
$allowedlist = empty($students) ? array() : array_keys($students);
} else {
// All users who can attempt scoes and who are in the currently selected group.
$groupstudents = get_users_by_capability($contextmodule, 'mod/scorm:savetrack', 'u.id', '', '', '', $group, '', false);
$allowedlist = empty($groupstudents) ? array() : array_keys($groupstudents);
}
// Labels.
$labels = [get_string('invaliddata', 'scormreport_graphs')];
for ($i = 1; $i <= self::BANDS - 1; $i++) {
$labels[] = ($i - 1) * self::BANDWIDTH . ' - ' . $i * self::BANDWIDTH;
}
if ($scoes = $DB->get_records('scorm_scoes', array("scorm" => $scorm->id), 'sortorder, id')) {
foreach ($scoes as $sco) {
if ($sco->launch != '') {
$data = $this->get_data($sco->id, $allowedlist);
$series = new chart_series($sco->title, $data);
$chart = new chart_bar();
$chart->set_labels($labels);
$chart->add_series($series);
$chart->get_xaxis(0, true)->set_label(get_string('percent', 'scormreport_graphs'));
$yaxis = $chart->get_yaxis(0, true);
$yaxis->set_label(get_string('participants', 'scormreport_graphs'));
$yaxis->set_stepsize(max(1, round(max($data) / 10)));
echo $OUTPUT->heading($sco->title, 3);
echo $OUTPUT->render($chart);
}
}
}
} | php | public function display($scorm, $cm, $course, $download) {
global $DB, $OUTPUT, $PAGE;
$contextmodule = context_module::instance($cm->id);
if ($groupmode = groups_get_activity_groupmode($cm)) { // Groups are being used.
groups_print_activity_menu($cm, new moodle_url($PAGE->url));
}
// Find out current restriction.
$group = groups_get_activity_group($cm, true);
if (empty($group)) {
// All users who can attempt scoes.
$students = get_users_by_capability($contextmodule, 'mod/scorm:savetrack', 'u.id' , '', '', '', '', '', false);
$allowedlist = empty($students) ? array() : array_keys($students);
} else {
// All users who can attempt scoes and who are in the currently selected group.
$groupstudents = get_users_by_capability($contextmodule, 'mod/scorm:savetrack', 'u.id', '', '', '', $group, '', false);
$allowedlist = empty($groupstudents) ? array() : array_keys($groupstudents);
}
// Labels.
$labels = [get_string('invaliddata', 'scormreport_graphs')];
for ($i = 1; $i <= self::BANDS - 1; $i++) {
$labels[] = ($i - 1) * self::BANDWIDTH . ' - ' . $i * self::BANDWIDTH;
}
if ($scoes = $DB->get_records('scorm_scoes', array("scorm" => $scorm->id), 'sortorder, id')) {
foreach ($scoes as $sco) {
if ($sco->launch != '') {
$data = $this->get_data($sco->id, $allowedlist);
$series = new chart_series($sco->title, $data);
$chart = new chart_bar();
$chart->set_labels($labels);
$chart->add_series($series);
$chart->get_xaxis(0, true)->set_label(get_string('percent', 'scormreport_graphs'));
$yaxis = $chart->get_yaxis(0, true);
$yaxis->set_label(get_string('participants', 'scormreport_graphs'));
$yaxis->set_stepsize(max(1, round(max($data) / 10)));
echo $OUTPUT->heading($sco->title, 3);
echo $OUTPUT->render($chart);
}
}
}
} | [
"public",
"function",
"display",
"(",
"$",
"scorm",
",",
"$",
"cm",
",",
"$",
"course",
",",
"$",
"download",
")",
"{",
"global",
"$",
"DB",
",",
"$",
"OUTPUT",
",",
"$",
"PAGE",
";",
"$",
"contextmodule",
"=",
"context_module",
"::",
"instance",
"(",
"$",
"cm",
"->",
"id",
")",
";",
"if",
"(",
"$",
"groupmode",
"=",
"groups_get_activity_groupmode",
"(",
"$",
"cm",
")",
")",
"{",
"// Groups are being used.",
"groups_print_activity_menu",
"(",
"$",
"cm",
",",
"new",
"moodle_url",
"(",
"$",
"PAGE",
"->",
"url",
")",
")",
";",
"}",
"// Find out current restriction.",
"$",
"group",
"=",
"groups_get_activity_group",
"(",
"$",
"cm",
",",
"true",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"group",
")",
")",
"{",
"// All users who can attempt scoes.",
"$",
"students",
"=",
"get_users_by_capability",
"(",
"$",
"contextmodule",
",",
"'mod/scorm:savetrack'",
",",
"'u.id'",
",",
"''",
",",
"''",
",",
"''",
",",
"''",
",",
"''",
",",
"false",
")",
";",
"$",
"allowedlist",
"=",
"empty",
"(",
"$",
"students",
")",
"?",
"array",
"(",
")",
":",
"array_keys",
"(",
"$",
"students",
")",
";",
"}",
"else",
"{",
"// All users who can attempt scoes and who are in the currently selected group.",
"$",
"groupstudents",
"=",
"get_users_by_capability",
"(",
"$",
"contextmodule",
",",
"'mod/scorm:savetrack'",
",",
"'u.id'",
",",
"''",
",",
"''",
",",
"''",
",",
"$",
"group",
",",
"''",
",",
"false",
")",
";",
"$",
"allowedlist",
"=",
"empty",
"(",
"$",
"groupstudents",
")",
"?",
"array",
"(",
")",
":",
"array_keys",
"(",
"$",
"groupstudents",
")",
";",
"}",
"// Labels.",
"$",
"labels",
"=",
"[",
"get_string",
"(",
"'invaliddata'",
",",
"'scormreport_graphs'",
")",
"]",
";",
"for",
"(",
"$",
"i",
"=",
"1",
";",
"$",
"i",
"<=",
"self",
"::",
"BANDS",
"-",
"1",
";",
"$",
"i",
"++",
")",
"{",
"$",
"labels",
"[",
"]",
"=",
"(",
"$",
"i",
"-",
"1",
")",
"*",
"self",
"::",
"BANDWIDTH",
".",
"' - '",
".",
"$",
"i",
"*",
"self",
"::",
"BANDWIDTH",
";",
"}",
"if",
"(",
"$",
"scoes",
"=",
"$",
"DB",
"->",
"get_records",
"(",
"'scorm_scoes'",
",",
"array",
"(",
"\"scorm\"",
"=>",
"$",
"scorm",
"->",
"id",
")",
",",
"'sortorder, id'",
")",
")",
"{",
"foreach",
"(",
"$",
"scoes",
"as",
"$",
"sco",
")",
"{",
"if",
"(",
"$",
"sco",
"->",
"launch",
"!=",
"''",
")",
"{",
"$",
"data",
"=",
"$",
"this",
"->",
"get_data",
"(",
"$",
"sco",
"->",
"id",
",",
"$",
"allowedlist",
")",
";",
"$",
"series",
"=",
"new",
"chart_series",
"(",
"$",
"sco",
"->",
"title",
",",
"$",
"data",
")",
";",
"$",
"chart",
"=",
"new",
"chart_bar",
"(",
")",
";",
"$",
"chart",
"->",
"set_labels",
"(",
"$",
"labels",
")",
";",
"$",
"chart",
"->",
"add_series",
"(",
"$",
"series",
")",
";",
"$",
"chart",
"->",
"get_xaxis",
"(",
"0",
",",
"true",
")",
"->",
"set_label",
"(",
"get_string",
"(",
"'percent'",
",",
"'scormreport_graphs'",
")",
")",
";",
"$",
"yaxis",
"=",
"$",
"chart",
"->",
"get_yaxis",
"(",
"0",
",",
"true",
")",
";",
"$",
"yaxis",
"->",
"set_label",
"(",
"get_string",
"(",
"'participants'",
",",
"'scormreport_graphs'",
")",
")",
";",
"$",
"yaxis",
"->",
"set_stepsize",
"(",
"max",
"(",
"1",
",",
"round",
"(",
"max",
"(",
"$",
"data",
")",
"/",
"10",
")",
")",
")",
";",
"echo",
"$",
"OUTPUT",
"->",
"heading",
"(",
"$",
"sco",
"->",
"title",
",",
"3",
")",
";",
"echo",
"$",
"OUTPUT",
"->",
"render",
"(",
"$",
"chart",
")",
";",
"}",
"}",
"}",
"}"
] | Displays the full report.
@param \stdClass $scorm full SCORM object
@param \stdClass $cm - full course_module object
@param \stdClass $course - full course object
@param string $download - type of download being requested
@return void | [
"Displays",
"the",
"full",
"report",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/scorm/report/graphs/classes/report.php#L136-L183 |
213,650 | moodle/moodle | group/externallib.php | core_group_external.get_groups | public static function get_groups($groupids) {
$params = self::validate_parameters(self::get_groups_parameters(), array('groupids'=>$groupids));
$groups = array();
foreach ($params['groupids'] as $groupid) {
// validate params
$group = groups_get_group($groupid, 'id, courseid, name, idnumber, description, descriptionformat, enrolmentkey', MUST_EXIST);
// now security checks
$context = context_course::instance($group->courseid, IGNORE_MISSING);
try {
self::validate_context($context);
} catch (Exception $e) {
$exceptionparam = new stdClass();
$exceptionparam->message = $e->getMessage();
$exceptionparam->courseid = $group->courseid;
throw new moodle_exception('errorcoursecontextnotvalid' , 'webservice', '', $exceptionparam);
}
require_capability('moodle/course:managegroups', $context);
list($group->description, $group->descriptionformat) =
external_format_text($group->description, $group->descriptionformat,
$context->id, 'group', 'description', $group->id);
$groups[] = (array)$group;
}
return $groups;
} | php | public static function get_groups($groupids) {
$params = self::validate_parameters(self::get_groups_parameters(), array('groupids'=>$groupids));
$groups = array();
foreach ($params['groupids'] as $groupid) {
// validate params
$group = groups_get_group($groupid, 'id, courseid, name, idnumber, description, descriptionformat, enrolmentkey', MUST_EXIST);
// now security checks
$context = context_course::instance($group->courseid, IGNORE_MISSING);
try {
self::validate_context($context);
} catch (Exception $e) {
$exceptionparam = new stdClass();
$exceptionparam->message = $e->getMessage();
$exceptionparam->courseid = $group->courseid;
throw new moodle_exception('errorcoursecontextnotvalid' , 'webservice', '', $exceptionparam);
}
require_capability('moodle/course:managegroups', $context);
list($group->description, $group->descriptionformat) =
external_format_text($group->description, $group->descriptionformat,
$context->id, 'group', 'description', $group->id);
$groups[] = (array)$group;
}
return $groups;
} | [
"public",
"static",
"function",
"get_groups",
"(",
"$",
"groupids",
")",
"{",
"$",
"params",
"=",
"self",
"::",
"validate_parameters",
"(",
"self",
"::",
"get_groups_parameters",
"(",
")",
",",
"array",
"(",
"'groupids'",
"=>",
"$",
"groupids",
")",
")",
";",
"$",
"groups",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"params",
"[",
"'groupids'",
"]",
"as",
"$",
"groupid",
")",
"{",
"// validate params",
"$",
"group",
"=",
"groups_get_group",
"(",
"$",
"groupid",
",",
"'id, courseid, name, idnumber, description, descriptionformat, enrolmentkey'",
",",
"MUST_EXIST",
")",
";",
"// now security checks",
"$",
"context",
"=",
"context_course",
"::",
"instance",
"(",
"$",
"group",
"->",
"courseid",
",",
"IGNORE_MISSING",
")",
";",
"try",
"{",
"self",
"::",
"validate_context",
"(",
"$",
"context",
")",
";",
"}",
"catch",
"(",
"Exception",
"$",
"e",
")",
"{",
"$",
"exceptionparam",
"=",
"new",
"stdClass",
"(",
")",
";",
"$",
"exceptionparam",
"->",
"message",
"=",
"$",
"e",
"->",
"getMessage",
"(",
")",
";",
"$",
"exceptionparam",
"->",
"courseid",
"=",
"$",
"group",
"->",
"courseid",
";",
"throw",
"new",
"moodle_exception",
"(",
"'errorcoursecontextnotvalid'",
",",
"'webservice'",
",",
"''",
",",
"$",
"exceptionparam",
")",
";",
"}",
"require_capability",
"(",
"'moodle/course:managegroups'",
",",
"$",
"context",
")",
";",
"list",
"(",
"$",
"group",
"->",
"description",
",",
"$",
"group",
"->",
"descriptionformat",
")",
"=",
"external_format_text",
"(",
"$",
"group",
"->",
"description",
",",
"$",
"group",
"->",
"descriptionformat",
",",
"$",
"context",
"->",
"id",
",",
"'group'",
",",
"'description'",
",",
"$",
"group",
"->",
"id",
")",
";",
"$",
"groups",
"[",
"]",
"=",
"(",
"array",
")",
"$",
"group",
";",
"}",
"return",
"$",
"groups",
";",
"}"
] | Get groups definition specified by ids
@param array $groupids arrays of group ids
@return array of group objects (id, courseid, name, enrolmentkey)
@since Moodle 2.2 | [
"Get",
"groups",
"definition",
"specified",
"by",
"ids"
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/group/externallib.php#L170-L198 |
213,651 | moodle/moodle | group/externallib.php | core_group_external.get_course_groups | public static function get_course_groups($courseid) {
$params = self::validate_parameters(self::get_course_groups_parameters(), array('courseid'=>$courseid));
// now security checks
$context = context_course::instance($params['courseid'], IGNORE_MISSING);
try {
self::validate_context($context);
} catch (Exception $e) {
$exceptionparam = new stdClass();
$exceptionparam->message = $e->getMessage();
$exceptionparam->courseid = $params['courseid'];
throw new moodle_exception('errorcoursecontextnotvalid' , 'webservice', '', $exceptionparam);
}
require_capability('moodle/course:managegroups', $context);
$gs = groups_get_all_groups($params['courseid'], 0, 0,
'g.id, g.courseid, g.name, g.idnumber, g.description, g.descriptionformat, g.enrolmentkey');
$groups = array();
foreach ($gs as $group) {
list($group->description, $group->descriptionformat) =
external_format_text($group->description, $group->descriptionformat,
$context->id, 'group', 'description', $group->id);
$groups[] = (array)$group;
}
return $groups;
} | php | public static function get_course_groups($courseid) {
$params = self::validate_parameters(self::get_course_groups_parameters(), array('courseid'=>$courseid));
// now security checks
$context = context_course::instance($params['courseid'], IGNORE_MISSING);
try {
self::validate_context($context);
} catch (Exception $e) {
$exceptionparam = new stdClass();
$exceptionparam->message = $e->getMessage();
$exceptionparam->courseid = $params['courseid'];
throw new moodle_exception('errorcoursecontextnotvalid' , 'webservice', '', $exceptionparam);
}
require_capability('moodle/course:managegroups', $context);
$gs = groups_get_all_groups($params['courseid'], 0, 0,
'g.id, g.courseid, g.name, g.idnumber, g.description, g.descriptionformat, g.enrolmentkey');
$groups = array();
foreach ($gs as $group) {
list($group->description, $group->descriptionformat) =
external_format_text($group->description, $group->descriptionformat,
$context->id, 'group', 'description', $group->id);
$groups[] = (array)$group;
}
return $groups;
} | [
"public",
"static",
"function",
"get_course_groups",
"(",
"$",
"courseid",
")",
"{",
"$",
"params",
"=",
"self",
"::",
"validate_parameters",
"(",
"self",
"::",
"get_course_groups_parameters",
"(",
")",
",",
"array",
"(",
"'courseid'",
"=>",
"$",
"courseid",
")",
")",
";",
"// now security checks",
"$",
"context",
"=",
"context_course",
"::",
"instance",
"(",
"$",
"params",
"[",
"'courseid'",
"]",
",",
"IGNORE_MISSING",
")",
";",
"try",
"{",
"self",
"::",
"validate_context",
"(",
"$",
"context",
")",
";",
"}",
"catch",
"(",
"Exception",
"$",
"e",
")",
"{",
"$",
"exceptionparam",
"=",
"new",
"stdClass",
"(",
")",
";",
"$",
"exceptionparam",
"->",
"message",
"=",
"$",
"e",
"->",
"getMessage",
"(",
")",
";",
"$",
"exceptionparam",
"->",
"courseid",
"=",
"$",
"params",
"[",
"'courseid'",
"]",
";",
"throw",
"new",
"moodle_exception",
"(",
"'errorcoursecontextnotvalid'",
",",
"'webservice'",
",",
"''",
",",
"$",
"exceptionparam",
")",
";",
"}",
"require_capability",
"(",
"'moodle/course:managegroups'",
",",
"$",
"context",
")",
";",
"$",
"gs",
"=",
"groups_get_all_groups",
"(",
"$",
"params",
"[",
"'courseid'",
"]",
",",
"0",
",",
"0",
",",
"'g.id, g.courseid, g.name, g.idnumber, g.description, g.descriptionformat, g.enrolmentkey'",
")",
";",
"$",
"groups",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"gs",
"as",
"$",
"group",
")",
"{",
"list",
"(",
"$",
"group",
"->",
"description",
",",
"$",
"group",
"->",
"descriptionformat",
")",
"=",
"external_format_text",
"(",
"$",
"group",
"->",
"description",
",",
"$",
"group",
"->",
"descriptionformat",
",",
"$",
"context",
"->",
"id",
",",
"'group'",
",",
"'description'",
",",
"$",
"group",
"->",
"id",
")",
";",
"$",
"groups",
"[",
"]",
"=",
"(",
"array",
")",
"$",
"group",
";",
"}",
"return",
"$",
"groups",
";",
"}"
] | Get all groups in the specified course
@param int $courseid id of course
@return array of group objects (id, courseid, name, enrolmentkey)
@since Moodle 2.2 | [
"Get",
"all",
"groups",
"in",
"the",
"specified",
"course"
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/group/externallib.php#L243-L270 |
213,652 | moodle/moodle | group/externallib.php | core_group_external.get_group_members | public static function get_group_members($groupids) {
$members = array();
$params = self::validate_parameters(self::get_group_members_parameters(), array('groupids'=>$groupids));
foreach ($params['groupids'] as $groupid) {
// validate params
$group = groups_get_group($groupid, 'id, courseid, name, enrolmentkey', MUST_EXIST);
// now security checks
$context = context_course::instance($group->courseid, IGNORE_MISSING);
try {
self::validate_context($context);
} catch (Exception $e) {
$exceptionparam = new stdClass();
$exceptionparam->message = $e->getMessage();
$exceptionparam->courseid = $group->courseid;
throw new moodle_exception('errorcoursecontextnotvalid' , 'webservice', '', $exceptionparam);
}
require_capability('moodle/course:managegroups', $context);
$groupmembers = groups_get_members($group->id, 'u.id', 'lastname ASC, firstname ASC');
$members[] = array('groupid'=>$groupid, 'userids'=>array_keys($groupmembers));
}
return $members;
} | php | public static function get_group_members($groupids) {
$members = array();
$params = self::validate_parameters(self::get_group_members_parameters(), array('groupids'=>$groupids));
foreach ($params['groupids'] as $groupid) {
// validate params
$group = groups_get_group($groupid, 'id, courseid, name, enrolmentkey', MUST_EXIST);
// now security checks
$context = context_course::instance($group->courseid, IGNORE_MISSING);
try {
self::validate_context($context);
} catch (Exception $e) {
$exceptionparam = new stdClass();
$exceptionparam->message = $e->getMessage();
$exceptionparam->courseid = $group->courseid;
throw new moodle_exception('errorcoursecontextnotvalid' , 'webservice', '', $exceptionparam);
}
require_capability('moodle/course:managegroups', $context);
$groupmembers = groups_get_members($group->id, 'u.id', 'lastname ASC, firstname ASC');
$members[] = array('groupid'=>$groupid, 'userids'=>array_keys($groupmembers));
}
return $members;
} | [
"public",
"static",
"function",
"get_group_members",
"(",
"$",
"groupids",
")",
"{",
"$",
"members",
"=",
"array",
"(",
")",
";",
"$",
"params",
"=",
"self",
"::",
"validate_parameters",
"(",
"self",
"::",
"get_group_members_parameters",
"(",
")",
",",
"array",
"(",
"'groupids'",
"=>",
"$",
"groupids",
")",
")",
";",
"foreach",
"(",
"$",
"params",
"[",
"'groupids'",
"]",
"as",
"$",
"groupid",
")",
"{",
"// validate params",
"$",
"group",
"=",
"groups_get_group",
"(",
"$",
"groupid",
",",
"'id, courseid, name, enrolmentkey'",
",",
"MUST_EXIST",
")",
";",
"// now security checks",
"$",
"context",
"=",
"context_course",
"::",
"instance",
"(",
"$",
"group",
"->",
"courseid",
",",
"IGNORE_MISSING",
")",
";",
"try",
"{",
"self",
"::",
"validate_context",
"(",
"$",
"context",
")",
";",
"}",
"catch",
"(",
"Exception",
"$",
"e",
")",
"{",
"$",
"exceptionparam",
"=",
"new",
"stdClass",
"(",
")",
";",
"$",
"exceptionparam",
"->",
"message",
"=",
"$",
"e",
"->",
"getMessage",
"(",
")",
";",
"$",
"exceptionparam",
"->",
"courseid",
"=",
"$",
"group",
"->",
"courseid",
";",
"throw",
"new",
"moodle_exception",
"(",
"'errorcoursecontextnotvalid'",
",",
"'webservice'",
",",
"''",
",",
"$",
"exceptionparam",
")",
";",
"}",
"require_capability",
"(",
"'moodle/course:managegroups'",
",",
"$",
"context",
")",
";",
"$",
"groupmembers",
"=",
"groups_get_members",
"(",
"$",
"group",
"->",
"id",
",",
"'u.id'",
",",
"'lastname ASC, firstname ASC'",
")",
";",
"$",
"members",
"[",
"]",
"=",
"array",
"(",
"'groupid'",
"=>",
"$",
"groupid",
",",
"'userids'",
"=>",
"array_keys",
"(",
"$",
"groupmembers",
")",
")",
";",
"}",
"return",
"$",
"members",
";",
"}"
] | Return all members for a group
@param array $groupids array of group ids
@return array with group id keys containing arrays of user ids
@since Moodle 2.2 | [
"Return",
"all",
"members",
"for",
"a",
"group"
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/group/externallib.php#L380-L406 |
213,653 | moodle/moodle | group/externallib.php | core_group_external.add_group_members | public static function add_group_members($members) {
global $CFG, $DB;
require_once("$CFG->dirroot/group/lib.php");
$params = self::validate_parameters(self::add_group_members_parameters(), array('members'=>$members));
$transaction = $DB->start_delegated_transaction();
foreach ($params['members'] as $member) {
// validate params
$groupid = $member['groupid'];
$userid = $member['userid'];
$group = groups_get_group($groupid, '*', MUST_EXIST);
$user = $DB->get_record('user', array('id'=>$userid, 'deleted'=>0, 'mnethostid'=>$CFG->mnet_localhost_id), '*', MUST_EXIST);
// now security checks
$context = context_course::instance($group->courseid, IGNORE_MISSING);
try {
self::validate_context($context);
} catch (Exception $e) {
$exceptionparam = new stdClass();
$exceptionparam->message = $e->getMessage();
$exceptionparam->courseid = $group->courseid;
throw new moodle_exception('errorcoursecontextnotvalid' , 'webservice', '', $exceptionparam);
}
require_capability('moodle/course:managegroups', $context);
// now make sure user is enrolled in course - this is mandatory requirement,
// unfortunately this is slow
if (!is_enrolled($context, $userid)) {
throw new invalid_parameter_exception('Only enrolled users may be members of groups');
}
groups_add_member($group, $user);
}
$transaction->allow_commit();
} | php | public static function add_group_members($members) {
global $CFG, $DB;
require_once("$CFG->dirroot/group/lib.php");
$params = self::validate_parameters(self::add_group_members_parameters(), array('members'=>$members));
$transaction = $DB->start_delegated_transaction();
foreach ($params['members'] as $member) {
// validate params
$groupid = $member['groupid'];
$userid = $member['userid'];
$group = groups_get_group($groupid, '*', MUST_EXIST);
$user = $DB->get_record('user', array('id'=>$userid, 'deleted'=>0, 'mnethostid'=>$CFG->mnet_localhost_id), '*', MUST_EXIST);
// now security checks
$context = context_course::instance($group->courseid, IGNORE_MISSING);
try {
self::validate_context($context);
} catch (Exception $e) {
$exceptionparam = new stdClass();
$exceptionparam->message = $e->getMessage();
$exceptionparam->courseid = $group->courseid;
throw new moodle_exception('errorcoursecontextnotvalid' , 'webservice', '', $exceptionparam);
}
require_capability('moodle/course:managegroups', $context);
// now make sure user is enrolled in course - this is mandatory requirement,
// unfortunately this is slow
if (!is_enrolled($context, $userid)) {
throw new invalid_parameter_exception('Only enrolled users may be members of groups');
}
groups_add_member($group, $user);
}
$transaction->allow_commit();
} | [
"public",
"static",
"function",
"add_group_members",
"(",
"$",
"members",
")",
"{",
"global",
"$",
"CFG",
",",
"$",
"DB",
";",
"require_once",
"(",
"\"$CFG->dirroot/group/lib.php\"",
")",
";",
"$",
"params",
"=",
"self",
"::",
"validate_parameters",
"(",
"self",
"::",
"add_group_members_parameters",
"(",
")",
",",
"array",
"(",
"'members'",
"=>",
"$",
"members",
")",
")",
";",
"$",
"transaction",
"=",
"$",
"DB",
"->",
"start_delegated_transaction",
"(",
")",
";",
"foreach",
"(",
"$",
"params",
"[",
"'members'",
"]",
"as",
"$",
"member",
")",
"{",
"// validate params",
"$",
"groupid",
"=",
"$",
"member",
"[",
"'groupid'",
"]",
";",
"$",
"userid",
"=",
"$",
"member",
"[",
"'userid'",
"]",
";",
"$",
"group",
"=",
"groups_get_group",
"(",
"$",
"groupid",
",",
"'*'",
",",
"MUST_EXIST",
")",
";",
"$",
"user",
"=",
"$",
"DB",
"->",
"get_record",
"(",
"'user'",
",",
"array",
"(",
"'id'",
"=>",
"$",
"userid",
",",
"'deleted'",
"=>",
"0",
",",
"'mnethostid'",
"=>",
"$",
"CFG",
"->",
"mnet_localhost_id",
")",
",",
"'*'",
",",
"MUST_EXIST",
")",
";",
"// now security checks",
"$",
"context",
"=",
"context_course",
"::",
"instance",
"(",
"$",
"group",
"->",
"courseid",
",",
"IGNORE_MISSING",
")",
";",
"try",
"{",
"self",
"::",
"validate_context",
"(",
"$",
"context",
")",
";",
"}",
"catch",
"(",
"Exception",
"$",
"e",
")",
"{",
"$",
"exceptionparam",
"=",
"new",
"stdClass",
"(",
")",
";",
"$",
"exceptionparam",
"->",
"message",
"=",
"$",
"e",
"->",
"getMessage",
"(",
")",
";",
"$",
"exceptionparam",
"->",
"courseid",
"=",
"$",
"group",
"->",
"courseid",
";",
"throw",
"new",
"moodle_exception",
"(",
"'errorcoursecontextnotvalid'",
",",
"'webservice'",
",",
"''",
",",
"$",
"exceptionparam",
")",
";",
"}",
"require_capability",
"(",
"'moodle/course:managegroups'",
",",
"$",
"context",
")",
";",
"// now make sure user is enrolled in course - this is mandatory requirement,",
"// unfortunately this is slow",
"if",
"(",
"!",
"is_enrolled",
"(",
"$",
"context",
",",
"$",
"userid",
")",
")",
"{",
"throw",
"new",
"invalid_parameter_exception",
"(",
"'Only enrolled users may be members of groups'",
")",
";",
"}",
"groups_add_member",
"(",
"$",
"group",
",",
"$",
"user",
")",
";",
"}",
"$",
"transaction",
"->",
"allow_commit",
"(",
")",
";",
"}"
] | Add group members
@param array $members of arrays with keys userid, groupid
@since Moodle 2.2 | [
"Add",
"group",
"members"
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/group/externallib.php#L453-L490 |
213,654 | moodle/moodle | group/externallib.php | core_group_external.delete_group_members | public static function delete_group_members($members) {
global $CFG, $DB;
require_once("$CFG->dirroot/group/lib.php");
$params = self::validate_parameters(self::delete_group_members_parameters(), array('members'=>$members));
$transaction = $DB->start_delegated_transaction();
foreach ($params['members'] as $member) {
// validate params
$groupid = $member['groupid'];
$userid = $member['userid'];
$group = groups_get_group($groupid, '*', MUST_EXIST);
$user = $DB->get_record('user', array('id'=>$userid, 'deleted'=>0, 'mnethostid'=>$CFG->mnet_localhost_id), '*', MUST_EXIST);
// now security checks
$context = context_course::instance($group->courseid, IGNORE_MISSING);
try {
self::validate_context($context);
} catch (Exception $e) {
$exceptionparam = new stdClass();
$exceptionparam->message = $e->getMessage();
$exceptionparam->courseid = $group->courseid;
throw new moodle_exception('errorcoursecontextnotvalid' , 'webservice', '', $exceptionparam);
}
require_capability('moodle/course:managegroups', $context);
if (!groups_remove_member_allowed($group, $user)) {
throw new moodle_exception('errorremovenotpermitted', 'group', '', fullname($user));
}
groups_remove_member($group, $user);
}
$transaction->allow_commit();
} | php | public static function delete_group_members($members) {
global $CFG, $DB;
require_once("$CFG->dirroot/group/lib.php");
$params = self::validate_parameters(self::delete_group_members_parameters(), array('members'=>$members));
$transaction = $DB->start_delegated_transaction();
foreach ($params['members'] as $member) {
// validate params
$groupid = $member['groupid'];
$userid = $member['userid'];
$group = groups_get_group($groupid, '*', MUST_EXIST);
$user = $DB->get_record('user', array('id'=>$userid, 'deleted'=>0, 'mnethostid'=>$CFG->mnet_localhost_id), '*', MUST_EXIST);
// now security checks
$context = context_course::instance($group->courseid, IGNORE_MISSING);
try {
self::validate_context($context);
} catch (Exception $e) {
$exceptionparam = new stdClass();
$exceptionparam->message = $e->getMessage();
$exceptionparam->courseid = $group->courseid;
throw new moodle_exception('errorcoursecontextnotvalid' , 'webservice', '', $exceptionparam);
}
require_capability('moodle/course:managegroups', $context);
if (!groups_remove_member_allowed($group, $user)) {
throw new moodle_exception('errorremovenotpermitted', 'group', '', fullname($user));
}
groups_remove_member($group, $user);
}
$transaction->allow_commit();
} | [
"public",
"static",
"function",
"delete_group_members",
"(",
"$",
"members",
")",
"{",
"global",
"$",
"CFG",
",",
"$",
"DB",
";",
"require_once",
"(",
"\"$CFG->dirroot/group/lib.php\"",
")",
";",
"$",
"params",
"=",
"self",
"::",
"validate_parameters",
"(",
"self",
"::",
"delete_group_members_parameters",
"(",
")",
",",
"array",
"(",
"'members'",
"=>",
"$",
"members",
")",
")",
";",
"$",
"transaction",
"=",
"$",
"DB",
"->",
"start_delegated_transaction",
"(",
")",
";",
"foreach",
"(",
"$",
"params",
"[",
"'members'",
"]",
"as",
"$",
"member",
")",
"{",
"// validate params",
"$",
"groupid",
"=",
"$",
"member",
"[",
"'groupid'",
"]",
";",
"$",
"userid",
"=",
"$",
"member",
"[",
"'userid'",
"]",
";",
"$",
"group",
"=",
"groups_get_group",
"(",
"$",
"groupid",
",",
"'*'",
",",
"MUST_EXIST",
")",
";",
"$",
"user",
"=",
"$",
"DB",
"->",
"get_record",
"(",
"'user'",
",",
"array",
"(",
"'id'",
"=>",
"$",
"userid",
",",
"'deleted'",
"=>",
"0",
",",
"'mnethostid'",
"=>",
"$",
"CFG",
"->",
"mnet_localhost_id",
")",
",",
"'*'",
",",
"MUST_EXIST",
")",
";",
"// now security checks",
"$",
"context",
"=",
"context_course",
"::",
"instance",
"(",
"$",
"group",
"->",
"courseid",
",",
"IGNORE_MISSING",
")",
";",
"try",
"{",
"self",
"::",
"validate_context",
"(",
"$",
"context",
")",
";",
"}",
"catch",
"(",
"Exception",
"$",
"e",
")",
"{",
"$",
"exceptionparam",
"=",
"new",
"stdClass",
"(",
")",
";",
"$",
"exceptionparam",
"->",
"message",
"=",
"$",
"e",
"->",
"getMessage",
"(",
")",
";",
"$",
"exceptionparam",
"->",
"courseid",
"=",
"$",
"group",
"->",
"courseid",
";",
"throw",
"new",
"moodle_exception",
"(",
"'errorcoursecontextnotvalid'",
",",
"'webservice'",
",",
"''",
",",
"$",
"exceptionparam",
")",
";",
"}",
"require_capability",
"(",
"'moodle/course:managegroups'",
",",
"$",
"context",
")",
";",
"if",
"(",
"!",
"groups_remove_member_allowed",
"(",
"$",
"group",
",",
"$",
"user",
")",
")",
"{",
"throw",
"new",
"moodle_exception",
"(",
"'errorremovenotpermitted'",
",",
"'group'",
",",
"''",
",",
"fullname",
"(",
"$",
"user",
")",
")",
";",
"}",
"groups_remove_member",
"(",
"$",
"group",
",",
"$",
"user",
")",
";",
"}",
"$",
"transaction",
"->",
"allow_commit",
"(",
")",
";",
"}"
] | Delete group members
@param array $members of arrays with keys userid, groupid
@since Moodle 2.2 | [
"Delete",
"group",
"members"
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/group/externallib.php#L530-L565 |
213,655 | moodle/moodle | group/externallib.php | core_group_external.get_groupings | public static function get_groupings($groupingids, $returngroups = false) {
global $CFG, $DB;
require_once("$CFG->dirroot/group/lib.php");
require_once("$CFG->libdir/filelib.php");
$params = self::validate_parameters(self::get_groupings_parameters(),
array('groupingids' => $groupingids,
'returngroups' => $returngroups));
$groupings = array();
foreach ($params['groupingids'] as $groupingid) {
// Validate params.
$grouping = groups_get_grouping($groupingid, '*', MUST_EXIST);
// Now security checks.
$context = context_course::instance($grouping->courseid);
try {
self::validate_context($context);
} catch (Exception $e) {
$exceptionparam = new stdClass();
$exceptionparam->message = $e->getMessage();
$exceptionparam->courseid = $grouping->courseid;
throw new moodle_exception('errorcoursecontextnotvalid' , 'webservice', '', $exceptionparam);
}
require_capability('moodle/course:managegroups', $context);
list($grouping->description, $grouping->descriptionformat) =
external_format_text($grouping->description, $grouping->descriptionformat,
$context->id, 'grouping', 'description', $grouping->id);
$groupingarray = (array)$grouping;
if ($params['returngroups']) {
$grouprecords = $DB->get_records_sql("SELECT * FROM {groups} g INNER JOIN {groupings_groups} gg ".
"ON g.id = gg.groupid WHERE gg.groupingid = ? ".
"ORDER BY groupid", array($groupingid));
if ($grouprecords) {
$groups = array();
foreach ($grouprecords as $grouprecord) {
list($grouprecord->description, $grouprecord->descriptionformat) =
external_format_text($grouprecord->description, $grouprecord->descriptionformat,
$context->id, 'group', 'description', $grouprecord->groupid);
$groups[] = array('id' => $grouprecord->groupid,
'name' => $grouprecord->name,
'idnumber' => $grouprecord->idnumber,
'description' => $grouprecord->description,
'descriptionformat' => $grouprecord->descriptionformat,
'enrolmentkey' => $grouprecord->enrolmentkey,
'courseid' => $grouprecord->courseid
);
}
$groupingarray['groups'] = $groups;
}
}
$groupings[] = $groupingarray;
}
return $groupings;
} | php | public static function get_groupings($groupingids, $returngroups = false) {
global $CFG, $DB;
require_once("$CFG->dirroot/group/lib.php");
require_once("$CFG->libdir/filelib.php");
$params = self::validate_parameters(self::get_groupings_parameters(),
array('groupingids' => $groupingids,
'returngroups' => $returngroups));
$groupings = array();
foreach ($params['groupingids'] as $groupingid) {
// Validate params.
$grouping = groups_get_grouping($groupingid, '*', MUST_EXIST);
// Now security checks.
$context = context_course::instance($grouping->courseid);
try {
self::validate_context($context);
} catch (Exception $e) {
$exceptionparam = new stdClass();
$exceptionparam->message = $e->getMessage();
$exceptionparam->courseid = $grouping->courseid;
throw new moodle_exception('errorcoursecontextnotvalid' , 'webservice', '', $exceptionparam);
}
require_capability('moodle/course:managegroups', $context);
list($grouping->description, $grouping->descriptionformat) =
external_format_text($grouping->description, $grouping->descriptionformat,
$context->id, 'grouping', 'description', $grouping->id);
$groupingarray = (array)$grouping;
if ($params['returngroups']) {
$grouprecords = $DB->get_records_sql("SELECT * FROM {groups} g INNER JOIN {groupings_groups} gg ".
"ON g.id = gg.groupid WHERE gg.groupingid = ? ".
"ORDER BY groupid", array($groupingid));
if ($grouprecords) {
$groups = array();
foreach ($grouprecords as $grouprecord) {
list($grouprecord->description, $grouprecord->descriptionformat) =
external_format_text($grouprecord->description, $grouprecord->descriptionformat,
$context->id, 'group', 'description', $grouprecord->groupid);
$groups[] = array('id' => $grouprecord->groupid,
'name' => $grouprecord->name,
'idnumber' => $grouprecord->idnumber,
'description' => $grouprecord->description,
'descriptionformat' => $grouprecord->descriptionformat,
'enrolmentkey' => $grouprecord->enrolmentkey,
'courseid' => $grouprecord->courseid
);
}
$groupingarray['groups'] = $groups;
}
}
$groupings[] = $groupingarray;
}
return $groupings;
} | [
"public",
"static",
"function",
"get_groupings",
"(",
"$",
"groupingids",
",",
"$",
"returngroups",
"=",
"false",
")",
"{",
"global",
"$",
"CFG",
",",
"$",
"DB",
";",
"require_once",
"(",
"\"$CFG->dirroot/group/lib.php\"",
")",
";",
"require_once",
"(",
"\"$CFG->libdir/filelib.php\"",
")",
";",
"$",
"params",
"=",
"self",
"::",
"validate_parameters",
"(",
"self",
"::",
"get_groupings_parameters",
"(",
")",
",",
"array",
"(",
"'groupingids'",
"=>",
"$",
"groupingids",
",",
"'returngroups'",
"=>",
"$",
"returngroups",
")",
")",
";",
"$",
"groupings",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"params",
"[",
"'groupingids'",
"]",
"as",
"$",
"groupingid",
")",
"{",
"// Validate params.",
"$",
"grouping",
"=",
"groups_get_grouping",
"(",
"$",
"groupingid",
",",
"'*'",
",",
"MUST_EXIST",
")",
";",
"// Now security checks.",
"$",
"context",
"=",
"context_course",
"::",
"instance",
"(",
"$",
"grouping",
"->",
"courseid",
")",
";",
"try",
"{",
"self",
"::",
"validate_context",
"(",
"$",
"context",
")",
";",
"}",
"catch",
"(",
"Exception",
"$",
"e",
")",
"{",
"$",
"exceptionparam",
"=",
"new",
"stdClass",
"(",
")",
";",
"$",
"exceptionparam",
"->",
"message",
"=",
"$",
"e",
"->",
"getMessage",
"(",
")",
";",
"$",
"exceptionparam",
"->",
"courseid",
"=",
"$",
"grouping",
"->",
"courseid",
";",
"throw",
"new",
"moodle_exception",
"(",
"'errorcoursecontextnotvalid'",
",",
"'webservice'",
",",
"''",
",",
"$",
"exceptionparam",
")",
";",
"}",
"require_capability",
"(",
"'moodle/course:managegroups'",
",",
"$",
"context",
")",
";",
"list",
"(",
"$",
"grouping",
"->",
"description",
",",
"$",
"grouping",
"->",
"descriptionformat",
")",
"=",
"external_format_text",
"(",
"$",
"grouping",
"->",
"description",
",",
"$",
"grouping",
"->",
"descriptionformat",
",",
"$",
"context",
"->",
"id",
",",
"'grouping'",
",",
"'description'",
",",
"$",
"grouping",
"->",
"id",
")",
";",
"$",
"groupingarray",
"=",
"(",
"array",
")",
"$",
"grouping",
";",
"if",
"(",
"$",
"params",
"[",
"'returngroups'",
"]",
")",
"{",
"$",
"grouprecords",
"=",
"$",
"DB",
"->",
"get_records_sql",
"(",
"\"SELECT * FROM {groups} g INNER JOIN {groupings_groups} gg \"",
".",
"\"ON g.id = gg.groupid WHERE gg.groupingid = ? \"",
".",
"\"ORDER BY groupid\"",
",",
"array",
"(",
"$",
"groupingid",
")",
")",
";",
"if",
"(",
"$",
"grouprecords",
")",
"{",
"$",
"groups",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"grouprecords",
"as",
"$",
"grouprecord",
")",
"{",
"list",
"(",
"$",
"grouprecord",
"->",
"description",
",",
"$",
"grouprecord",
"->",
"descriptionformat",
")",
"=",
"external_format_text",
"(",
"$",
"grouprecord",
"->",
"description",
",",
"$",
"grouprecord",
"->",
"descriptionformat",
",",
"$",
"context",
"->",
"id",
",",
"'group'",
",",
"'description'",
",",
"$",
"grouprecord",
"->",
"groupid",
")",
";",
"$",
"groups",
"[",
"]",
"=",
"array",
"(",
"'id'",
"=>",
"$",
"grouprecord",
"->",
"groupid",
",",
"'name'",
"=>",
"$",
"grouprecord",
"->",
"name",
",",
"'idnumber'",
"=>",
"$",
"grouprecord",
"->",
"idnumber",
",",
"'description'",
"=>",
"$",
"grouprecord",
"->",
"description",
",",
"'descriptionformat'",
"=>",
"$",
"grouprecord",
"->",
"descriptionformat",
",",
"'enrolmentkey'",
"=>",
"$",
"grouprecord",
"->",
"enrolmentkey",
",",
"'courseid'",
"=>",
"$",
"grouprecord",
"->",
"courseid",
")",
";",
"}",
"$",
"groupingarray",
"[",
"'groups'",
"]",
"=",
"$",
"groups",
";",
"}",
"}",
"$",
"groupings",
"[",
"]",
"=",
"$",
"groupingarray",
";",
"}",
"return",
"$",
"groupings",
";",
"}"
] | Get groupings definition specified by ids
@param array $groupingids arrays of grouping ids
@param boolean $returngroups return the associated groups if true. The default is false.
@return array of grouping objects (id, courseid, name)
@since Moodle 2.3 | [
"Get",
"groupings",
"definition",
"specified",
"by",
"ids"
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/group/externallib.php#L789-L847 |
213,656 | moodle/moodle | group/externallib.php | core_group_external.get_course_groupings | public static function get_course_groupings($courseid) {
global $CFG;
require_once("$CFG->dirroot/group/lib.php");
require_once("$CFG->libdir/filelib.php");
$params = self::validate_parameters(self::get_course_groupings_parameters(), array('courseid'=>$courseid));
// Now security checks.
$context = context_course::instance($params['courseid']);
try {
self::validate_context($context);
} catch (Exception $e) {
$exceptionparam = new stdClass();
$exceptionparam->message = $e->getMessage();
$exceptionparam->courseid = $params['courseid'];
throw new moodle_exception('errorcoursecontextnotvalid' , 'webservice', '', $exceptionparam);
}
require_capability('moodle/course:managegroups', $context);
$gs = groups_get_all_groupings($params['courseid']);
$groupings = array();
foreach ($gs as $grouping) {
list($grouping->description, $grouping->descriptionformat) =
external_format_text($grouping->description, $grouping->descriptionformat,
$context->id, 'grouping', 'description', $grouping->id);
$groupings[] = (array)$grouping;
}
return $groupings;
} | php | public static function get_course_groupings($courseid) {
global $CFG;
require_once("$CFG->dirroot/group/lib.php");
require_once("$CFG->libdir/filelib.php");
$params = self::validate_parameters(self::get_course_groupings_parameters(), array('courseid'=>$courseid));
// Now security checks.
$context = context_course::instance($params['courseid']);
try {
self::validate_context($context);
} catch (Exception $e) {
$exceptionparam = new stdClass();
$exceptionparam->message = $e->getMessage();
$exceptionparam->courseid = $params['courseid'];
throw new moodle_exception('errorcoursecontextnotvalid' , 'webservice', '', $exceptionparam);
}
require_capability('moodle/course:managegroups', $context);
$gs = groups_get_all_groupings($params['courseid']);
$groupings = array();
foreach ($gs as $grouping) {
list($grouping->description, $grouping->descriptionformat) =
external_format_text($grouping->description, $grouping->descriptionformat,
$context->id, 'grouping', 'description', $grouping->id);
$groupings[] = (array)$grouping;
}
return $groupings;
} | [
"public",
"static",
"function",
"get_course_groupings",
"(",
"$",
"courseid",
")",
"{",
"global",
"$",
"CFG",
";",
"require_once",
"(",
"\"$CFG->dirroot/group/lib.php\"",
")",
";",
"require_once",
"(",
"\"$CFG->libdir/filelib.php\"",
")",
";",
"$",
"params",
"=",
"self",
"::",
"validate_parameters",
"(",
"self",
"::",
"get_course_groupings_parameters",
"(",
")",
",",
"array",
"(",
"'courseid'",
"=>",
"$",
"courseid",
")",
")",
";",
"// Now security checks.",
"$",
"context",
"=",
"context_course",
"::",
"instance",
"(",
"$",
"params",
"[",
"'courseid'",
"]",
")",
";",
"try",
"{",
"self",
"::",
"validate_context",
"(",
"$",
"context",
")",
";",
"}",
"catch",
"(",
"Exception",
"$",
"e",
")",
"{",
"$",
"exceptionparam",
"=",
"new",
"stdClass",
"(",
")",
";",
"$",
"exceptionparam",
"->",
"message",
"=",
"$",
"e",
"->",
"getMessage",
"(",
")",
";",
"$",
"exceptionparam",
"->",
"courseid",
"=",
"$",
"params",
"[",
"'courseid'",
"]",
";",
"throw",
"new",
"moodle_exception",
"(",
"'errorcoursecontextnotvalid'",
",",
"'webservice'",
",",
"''",
",",
"$",
"exceptionparam",
")",
";",
"}",
"require_capability",
"(",
"'moodle/course:managegroups'",
",",
"$",
"context",
")",
";",
"$",
"gs",
"=",
"groups_get_all_groupings",
"(",
"$",
"params",
"[",
"'courseid'",
"]",
")",
";",
"$",
"groupings",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"gs",
"as",
"$",
"grouping",
")",
"{",
"list",
"(",
"$",
"grouping",
"->",
"description",
",",
"$",
"grouping",
"->",
"descriptionformat",
")",
"=",
"external_format_text",
"(",
"$",
"grouping",
"->",
"description",
",",
"$",
"grouping",
"->",
"descriptionformat",
",",
"$",
"context",
"->",
"id",
",",
"'grouping'",
",",
"'description'",
",",
"$",
"grouping",
"->",
"id",
")",
";",
"$",
"groupings",
"[",
"]",
"=",
"(",
"array",
")",
"$",
"grouping",
";",
"}",
"return",
"$",
"groupings",
";",
"}"
] | Get all groupings in the specified course
@param int $courseid id of course
@return array of grouping objects (id, courseid, name, enrolmentkey)
@since Moodle 2.3 | [
"Get",
"all",
"groupings",
"in",
"the",
"specified",
"course"
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/group/externallib.php#L904-L935 |
213,657 | moodle/moodle | group/externallib.php | core_group_external.assign_grouping | public static function assign_grouping($assignments) {
global $CFG, $DB;
require_once("$CFG->dirroot/group/lib.php");
$params = self::validate_parameters(self::assign_grouping_parameters(), array('assignments'=>$assignments));
$transaction = $DB->start_delegated_transaction();
foreach ($params['assignments'] as $assignment) {
// Validate params.
$groupingid = $assignment['groupingid'];
$groupid = $assignment['groupid'];
$grouping = groups_get_grouping($groupingid, 'id, courseid', MUST_EXIST);
$group = groups_get_group($groupid, 'id, courseid', MUST_EXIST);
if ($DB->record_exists('groupings_groups', array('groupingid'=>$groupingid, 'groupid'=>$groupid))) {
// Continue silently if the group is yet assigned to the grouping.
continue;
}
// Now security checks.
$context = context_course::instance($grouping->courseid);
try {
self::validate_context($context);
} catch (Exception $e) {
$exceptionparam = new stdClass();
$exceptionparam->message = $e->getMessage();
$exceptionparam->courseid = $group->courseid;
throw new moodle_exception('errorcoursecontextnotvalid' , 'webservice', '', $exceptionparam);
}
require_capability('moodle/course:managegroups', $context);
groups_assign_grouping($groupingid, $groupid);
}
$transaction->allow_commit();
} | php | public static function assign_grouping($assignments) {
global $CFG, $DB;
require_once("$CFG->dirroot/group/lib.php");
$params = self::validate_parameters(self::assign_grouping_parameters(), array('assignments'=>$assignments));
$transaction = $DB->start_delegated_transaction();
foreach ($params['assignments'] as $assignment) {
// Validate params.
$groupingid = $assignment['groupingid'];
$groupid = $assignment['groupid'];
$grouping = groups_get_grouping($groupingid, 'id, courseid', MUST_EXIST);
$group = groups_get_group($groupid, 'id, courseid', MUST_EXIST);
if ($DB->record_exists('groupings_groups', array('groupingid'=>$groupingid, 'groupid'=>$groupid))) {
// Continue silently if the group is yet assigned to the grouping.
continue;
}
// Now security checks.
$context = context_course::instance($grouping->courseid);
try {
self::validate_context($context);
} catch (Exception $e) {
$exceptionparam = new stdClass();
$exceptionparam->message = $e->getMessage();
$exceptionparam->courseid = $group->courseid;
throw new moodle_exception('errorcoursecontextnotvalid' , 'webservice', '', $exceptionparam);
}
require_capability('moodle/course:managegroups', $context);
groups_assign_grouping($groupingid, $groupid);
}
$transaction->allow_commit();
} | [
"public",
"static",
"function",
"assign_grouping",
"(",
"$",
"assignments",
")",
"{",
"global",
"$",
"CFG",
",",
"$",
"DB",
";",
"require_once",
"(",
"\"$CFG->dirroot/group/lib.php\"",
")",
";",
"$",
"params",
"=",
"self",
"::",
"validate_parameters",
"(",
"self",
"::",
"assign_grouping_parameters",
"(",
")",
",",
"array",
"(",
"'assignments'",
"=>",
"$",
"assignments",
")",
")",
";",
"$",
"transaction",
"=",
"$",
"DB",
"->",
"start_delegated_transaction",
"(",
")",
";",
"foreach",
"(",
"$",
"params",
"[",
"'assignments'",
"]",
"as",
"$",
"assignment",
")",
"{",
"// Validate params.",
"$",
"groupingid",
"=",
"$",
"assignment",
"[",
"'groupingid'",
"]",
";",
"$",
"groupid",
"=",
"$",
"assignment",
"[",
"'groupid'",
"]",
";",
"$",
"grouping",
"=",
"groups_get_grouping",
"(",
"$",
"groupingid",
",",
"'id, courseid'",
",",
"MUST_EXIST",
")",
";",
"$",
"group",
"=",
"groups_get_group",
"(",
"$",
"groupid",
",",
"'id, courseid'",
",",
"MUST_EXIST",
")",
";",
"if",
"(",
"$",
"DB",
"->",
"record_exists",
"(",
"'groupings_groups'",
",",
"array",
"(",
"'groupingid'",
"=>",
"$",
"groupingid",
",",
"'groupid'",
"=>",
"$",
"groupid",
")",
")",
")",
"{",
"// Continue silently if the group is yet assigned to the grouping.",
"continue",
";",
"}",
"// Now security checks.",
"$",
"context",
"=",
"context_course",
"::",
"instance",
"(",
"$",
"grouping",
"->",
"courseid",
")",
";",
"try",
"{",
"self",
"::",
"validate_context",
"(",
"$",
"context",
")",
";",
"}",
"catch",
"(",
"Exception",
"$",
"e",
")",
"{",
"$",
"exceptionparam",
"=",
"new",
"stdClass",
"(",
")",
";",
"$",
"exceptionparam",
"->",
"message",
"=",
"$",
"e",
"->",
"getMessage",
"(",
")",
";",
"$",
"exceptionparam",
"->",
"courseid",
"=",
"$",
"group",
"->",
"courseid",
";",
"throw",
"new",
"moodle_exception",
"(",
"'errorcoursecontextnotvalid'",
",",
"'webservice'",
",",
"''",
",",
"$",
"exceptionparam",
")",
";",
"}",
"require_capability",
"(",
"'moodle/course:managegroups'",
",",
"$",
"context",
")",
";",
"groups_assign_grouping",
"(",
"$",
"groupingid",
",",
"$",
"groupid",
")",
";",
"}",
"$",
"transaction",
"->",
"allow_commit",
"(",
")",
";",
"}"
] | Assign a group to a grouping
@param array $assignments of arrays with keys groupid, groupingid
@return void
@since Moodle 2.3 | [
"Assign",
"a",
"group",
"to",
"a",
"grouping"
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/group/externallib.php#L1050-L1086 |
213,658 | moodle/moodle | group/externallib.php | core_group_external.unassign_grouping | public static function unassign_grouping($unassignments) {
global $CFG, $DB;
require_once("$CFG->dirroot/group/lib.php");
$params = self::validate_parameters(self::unassign_grouping_parameters(), array('unassignments'=>$unassignments));
$transaction = $DB->start_delegated_transaction();
foreach ($params['unassignments'] as $unassignment) {
// Validate params.
$groupingid = $unassignment['groupingid'];
$groupid = $unassignment['groupid'];
$grouping = groups_get_grouping($groupingid, 'id, courseid', MUST_EXIST);
$group = groups_get_group($groupid, 'id, courseid', MUST_EXIST);
if (!$DB->record_exists('groupings_groups', array('groupingid'=>$groupingid, 'groupid'=>$groupid))) {
// Continue silently if the group is not assigned to the grouping.
continue;
}
// Now security checks.
$context = context_course::instance($grouping->courseid);
try {
self::validate_context($context);
} catch (Exception $e) {
$exceptionparam = new stdClass();
$exceptionparam->message = $e->getMessage();
$exceptionparam->courseid = $group->courseid;
throw new moodle_exception('errorcoursecontextnotvalid' , 'webservice', '', $exceptionparam);
}
require_capability('moodle/course:managegroups', $context);
groups_unassign_grouping($groupingid, $groupid);
}
$transaction->allow_commit();
} | php | public static function unassign_grouping($unassignments) {
global $CFG, $DB;
require_once("$CFG->dirroot/group/lib.php");
$params = self::validate_parameters(self::unassign_grouping_parameters(), array('unassignments'=>$unassignments));
$transaction = $DB->start_delegated_transaction();
foreach ($params['unassignments'] as $unassignment) {
// Validate params.
$groupingid = $unassignment['groupingid'];
$groupid = $unassignment['groupid'];
$grouping = groups_get_grouping($groupingid, 'id, courseid', MUST_EXIST);
$group = groups_get_group($groupid, 'id, courseid', MUST_EXIST);
if (!$DB->record_exists('groupings_groups', array('groupingid'=>$groupingid, 'groupid'=>$groupid))) {
// Continue silently if the group is not assigned to the grouping.
continue;
}
// Now security checks.
$context = context_course::instance($grouping->courseid);
try {
self::validate_context($context);
} catch (Exception $e) {
$exceptionparam = new stdClass();
$exceptionparam->message = $e->getMessage();
$exceptionparam->courseid = $group->courseid;
throw new moodle_exception('errorcoursecontextnotvalid' , 'webservice', '', $exceptionparam);
}
require_capability('moodle/course:managegroups', $context);
groups_unassign_grouping($groupingid, $groupid);
}
$transaction->allow_commit();
} | [
"public",
"static",
"function",
"unassign_grouping",
"(",
"$",
"unassignments",
")",
"{",
"global",
"$",
"CFG",
",",
"$",
"DB",
";",
"require_once",
"(",
"\"$CFG->dirroot/group/lib.php\"",
")",
";",
"$",
"params",
"=",
"self",
"::",
"validate_parameters",
"(",
"self",
"::",
"unassign_grouping_parameters",
"(",
")",
",",
"array",
"(",
"'unassignments'",
"=>",
"$",
"unassignments",
")",
")",
";",
"$",
"transaction",
"=",
"$",
"DB",
"->",
"start_delegated_transaction",
"(",
")",
";",
"foreach",
"(",
"$",
"params",
"[",
"'unassignments'",
"]",
"as",
"$",
"unassignment",
")",
"{",
"// Validate params.",
"$",
"groupingid",
"=",
"$",
"unassignment",
"[",
"'groupingid'",
"]",
";",
"$",
"groupid",
"=",
"$",
"unassignment",
"[",
"'groupid'",
"]",
";",
"$",
"grouping",
"=",
"groups_get_grouping",
"(",
"$",
"groupingid",
",",
"'id, courseid'",
",",
"MUST_EXIST",
")",
";",
"$",
"group",
"=",
"groups_get_group",
"(",
"$",
"groupid",
",",
"'id, courseid'",
",",
"MUST_EXIST",
")",
";",
"if",
"(",
"!",
"$",
"DB",
"->",
"record_exists",
"(",
"'groupings_groups'",
",",
"array",
"(",
"'groupingid'",
"=>",
"$",
"groupingid",
",",
"'groupid'",
"=>",
"$",
"groupid",
")",
")",
")",
"{",
"// Continue silently if the group is not assigned to the grouping.",
"continue",
";",
"}",
"// Now security checks.",
"$",
"context",
"=",
"context_course",
"::",
"instance",
"(",
"$",
"grouping",
"->",
"courseid",
")",
";",
"try",
"{",
"self",
"::",
"validate_context",
"(",
"$",
"context",
")",
";",
"}",
"catch",
"(",
"Exception",
"$",
"e",
")",
"{",
"$",
"exceptionparam",
"=",
"new",
"stdClass",
"(",
")",
";",
"$",
"exceptionparam",
"->",
"message",
"=",
"$",
"e",
"->",
"getMessage",
"(",
")",
";",
"$",
"exceptionparam",
"->",
"courseid",
"=",
"$",
"group",
"->",
"courseid",
";",
"throw",
"new",
"moodle_exception",
"(",
"'errorcoursecontextnotvalid'",
",",
"'webservice'",
",",
"''",
",",
"$",
"exceptionparam",
")",
";",
"}",
"require_capability",
"(",
"'moodle/course:managegroups'",
",",
"$",
"context",
")",
";",
"groups_unassign_grouping",
"(",
"$",
"groupingid",
",",
"$",
"groupid",
")",
";",
"}",
"$",
"transaction",
"->",
"allow_commit",
"(",
")",
";",
"}"
] | Unassign a group from a grouping
@param array $unassignments of arrays with keys groupid, groupingid
@return void
@since Moodle 2.3 | [
"Unassign",
"a",
"group",
"from",
"a",
"grouping"
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/group/externallib.php#L1126-L1162 |
213,659 | moodle/moodle | group/externallib.php | core_group_external.get_course_user_groups | public static function get_course_user_groups($courseid = 0, $userid = 0, $groupingid = 0) {
global $USER;
// Warnings array, it can be empty at the end but is mandatory.
$warnings = array();
$params = array(
'courseid' => $courseid,
'userid' => $userid,
'groupingid' => $groupingid
);
$params = self::validate_parameters(self::get_course_user_groups_parameters(), $params);
$courseid = $params['courseid'];
$userid = $params['userid'];
$groupingid = $params['groupingid'];
// Validate user.
if (empty($userid)) {
$userid = $USER->id;
} else {
$user = core_user::get_user($userid, '*', MUST_EXIST);
core_user::require_active_user($user);
}
// Get courses.
if (empty($courseid)) {
$courses = enrol_get_users_courses($userid, true);
$checkenrolments = false; // No need to check enrolments here since they are my courses.
} else {
$courses = array($courseid => get_course($courseid));
$checkenrolments = true;
}
// Security checks.
list($courses, $warnings) = external_util::validate_courses(array_keys($courses), $courses, true);
$usergroups = array();
foreach ($courses as $course) {
// Check if we have permissions for retrieve the information.
if ($userid != $USER->id && !has_capability('moodle/course:managegroups', $course->context)) {
$warnings[] = array(
'item' => 'course',
'itemid' => $course->id,
'warningcode' => 'cannotmanagegroups',
'message' => "User $USER->id cannot manage groups in course $course->id",
);
continue;
}
// Check if the user being check is enrolled in the given course.
if ($checkenrolments && !is_enrolled($course->context, $userid)) {
// We return a warning because the function does not fail for not enrolled users.
$warnings[] = array(
'item' => 'course',
'itemid' => $course->id,
'warningcode' => 'notenrolled',
'message' => "User $userid is not enrolled in course $course->id",
);
}
$groups = groups_get_all_groups($course->id, $userid, $groupingid,
'g.id, g.name, g.description, g.descriptionformat, g.idnumber');
foreach ($groups as $group) {
list($group->description, $group->descriptionformat) =
external_format_text($group->description, $group->descriptionformat,
$course->context->id, 'group', 'description', $group->id);
$group->courseid = $course->id;
$usergroups[] = $group;
}
}
$results = array(
'groups' => $usergroups,
'warnings' => $warnings
);
return $results;
} | php | public static function get_course_user_groups($courseid = 0, $userid = 0, $groupingid = 0) {
global $USER;
// Warnings array, it can be empty at the end but is mandatory.
$warnings = array();
$params = array(
'courseid' => $courseid,
'userid' => $userid,
'groupingid' => $groupingid
);
$params = self::validate_parameters(self::get_course_user_groups_parameters(), $params);
$courseid = $params['courseid'];
$userid = $params['userid'];
$groupingid = $params['groupingid'];
// Validate user.
if (empty($userid)) {
$userid = $USER->id;
} else {
$user = core_user::get_user($userid, '*', MUST_EXIST);
core_user::require_active_user($user);
}
// Get courses.
if (empty($courseid)) {
$courses = enrol_get_users_courses($userid, true);
$checkenrolments = false; // No need to check enrolments here since they are my courses.
} else {
$courses = array($courseid => get_course($courseid));
$checkenrolments = true;
}
// Security checks.
list($courses, $warnings) = external_util::validate_courses(array_keys($courses), $courses, true);
$usergroups = array();
foreach ($courses as $course) {
// Check if we have permissions for retrieve the information.
if ($userid != $USER->id && !has_capability('moodle/course:managegroups', $course->context)) {
$warnings[] = array(
'item' => 'course',
'itemid' => $course->id,
'warningcode' => 'cannotmanagegroups',
'message' => "User $USER->id cannot manage groups in course $course->id",
);
continue;
}
// Check if the user being check is enrolled in the given course.
if ($checkenrolments && !is_enrolled($course->context, $userid)) {
// We return a warning because the function does not fail for not enrolled users.
$warnings[] = array(
'item' => 'course',
'itemid' => $course->id,
'warningcode' => 'notenrolled',
'message' => "User $userid is not enrolled in course $course->id",
);
}
$groups = groups_get_all_groups($course->id, $userid, $groupingid,
'g.id, g.name, g.description, g.descriptionformat, g.idnumber');
foreach ($groups as $group) {
list($group->description, $group->descriptionformat) =
external_format_text($group->description, $group->descriptionformat,
$course->context->id, 'group', 'description', $group->id);
$group->courseid = $course->id;
$usergroups[] = $group;
}
}
$results = array(
'groups' => $usergroups,
'warnings' => $warnings
);
return $results;
} | [
"public",
"static",
"function",
"get_course_user_groups",
"(",
"$",
"courseid",
"=",
"0",
",",
"$",
"userid",
"=",
"0",
",",
"$",
"groupingid",
"=",
"0",
")",
"{",
"global",
"$",
"USER",
";",
"// Warnings array, it can be empty at the end but is mandatory.",
"$",
"warnings",
"=",
"array",
"(",
")",
";",
"$",
"params",
"=",
"array",
"(",
"'courseid'",
"=>",
"$",
"courseid",
",",
"'userid'",
"=>",
"$",
"userid",
",",
"'groupingid'",
"=>",
"$",
"groupingid",
")",
";",
"$",
"params",
"=",
"self",
"::",
"validate_parameters",
"(",
"self",
"::",
"get_course_user_groups_parameters",
"(",
")",
",",
"$",
"params",
")",
";",
"$",
"courseid",
"=",
"$",
"params",
"[",
"'courseid'",
"]",
";",
"$",
"userid",
"=",
"$",
"params",
"[",
"'userid'",
"]",
";",
"$",
"groupingid",
"=",
"$",
"params",
"[",
"'groupingid'",
"]",
";",
"// Validate user.",
"if",
"(",
"empty",
"(",
"$",
"userid",
")",
")",
"{",
"$",
"userid",
"=",
"$",
"USER",
"->",
"id",
";",
"}",
"else",
"{",
"$",
"user",
"=",
"core_user",
"::",
"get_user",
"(",
"$",
"userid",
",",
"'*'",
",",
"MUST_EXIST",
")",
";",
"core_user",
"::",
"require_active_user",
"(",
"$",
"user",
")",
";",
"}",
"// Get courses.",
"if",
"(",
"empty",
"(",
"$",
"courseid",
")",
")",
"{",
"$",
"courses",
"=",
"enrol_get_users_courses",
"(",
"$",
"userid",
",",
"true",
")",
";",
"$",
"checkenrolments",
"=",
"false",
";",
"// No need to check enrolments here since they are my courses.",
"}",
"else",
"{",
"$",
"courses",
"=",
"array",
"(",
"$",
"courseid",
"=>",
"get_course",
"(",
"$",
"courseid",
")",
")",
";",
"$",
"checkenrolments",
"=",
"true",
";",
"}",
"// Security checks.",
"list",
"(",
"$",
"courses",
",",
"$",
"warnings",
")",
"=",
"external_util",
"::",
"validate_courses",
"(",
"array_keys",
"(",
"$",
"courses",
")",
",",
"$",
"courses",
",",
"true",
")",
";",
"$",
"usergroups",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"courses",
"as",
"$",
"course",
")",
"{",
"// Check if we have permissions for retrieve the information.",
"if",
"(",
"$",
"userid",
"!=",
"$",
"USER",
"->",
"id",
"&&",
"!",
"has_capability",
"(",
"'moodle/course:managegroups'",
",",
"$",
"course",
"->",
"context",
")",
")",
"{",
"$",
"warnings",
"[",
"]",
"=",
"array",
"(",
"'item'",
"=>",
"'course'",
",",
"'itemid'",
"=>",
"$",
"course",
"->",
"id",
",",
"'warningcode'",
"=>",
"'cannotmanagegroups'",
",",
"'message'",
"=>",
"\"User $USER->id cannot manage groups in course $course->id\"",
",",
")",
";",
"continue",
";",
"}",
"// Check if the user being check is enrolled in the given course.",
"if",
"(",
"$",
"checkenrolments",
"&&",
"!",
"is_enrolled",
"(",
"$",
"course",
"->",
"context",
",",
"$",
"userid",
")",
")",
"{",
"// We return a warning because the function does not fail for not enrolled users.",
"$",
"warnings",
"[",
"]",
"=",
"array",
"(",
"'item'",
"=>",
"'course'",
",",
"'itemid'",
"=>",
"$",
"course",
"->",
"id",
",",
"'warningcode'",
"=>",
"'notenrolled'",
",",
"'message'",
"=>",
"\"User $userid is not enrolled in course $course->id\"",
",",
")",
";",
"}",
"$",
"groups",
"=",
"groups_get_all_groups",
"(",
"$",
"course",
"->",
"id",
",",
"$",
"userid",
",",
"$",
"groupingid",
",",
"'g.id, g.name, g.description, g.descriptionformat, g.idnumber'",
")",
";",
"foreach",
"(",
"$",
"groups",
"as",
"$",
"group",
")",
"{",
"list",
"(",
"$",
"group",
"->",
"description",
",",
"$",
"group",
"->",
"descriptionformat",
")",
"=",
"external_format_text",
"(",
"$",
"group",
"->",
"description",
",",
"$",
"group",
"->",
"descriptionformat",
",",
"$",
"course",
"->",
"context",
"->",
"id",
",",
"'group'",
",",
"'description'",
",",
"$",
"group",
"->",
"id",
")",
";",
"$",
"group",
"->",
"courseid",
"=",
"$",
"course",
"->",
"id",
";",
"$",
"usergroups",
"[",
"]",
"=",
"$",
"group",
";",
"}",
"}",
"$",
"results",
"=",
"array",
"(",
"'groups'",
"=>",
"$",
"usergroups",
",",
"'warnings'",
"=>",
"$",
"warnings",
")",
";",
"return",
"$",
"results",
";",
"}"
] | Get all groups in the specified course for the specified user.
@throws moodle_exception
@param int $courseid id of course.
@param int $userid id of user.
@param int $groupingid optional returns only groups in the specified grouping.
@return array of group objects (id, name, description, format) and possible warnings.
@since Moodle 2.9 | [
"Get",
"all",
"groups",
"in",
"the",
"specified",
"course",
"for",
"the",
"specified",
"user",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/group/externallib.php#L1201-L1279 |
213,660 | moodle/moodle | group/externallib.php | core_group_external.group_description | public static function group_description() {
return new external_single_structure(
array(
'id' => new external_value(PARAM_INT, 'group record id'),
'name' => new external_value(PARAM_TEXT, 'multilang compatible name, course unique'),
'description' => new external_value(PARAM_RAW, 'group description text'),
'descriptionformat' => new external_format_value('description'),
'idnumber' => new external_value(PARAM_RAW, 'id number'),
'courseid' => new external_value(PARAM_INT, 'course id', VALUE_OPTIONAL),
)
);
} | php | public static function group_description() {
return new external_single_structure(
array(
'id' => new external_value(PARAM_INT, 'group record id'),
'name' => new external_value(PARAM_TEXT, 'multilang compatible name, course unique'),
'description' => new external_value(PARAM_RAW, 'group description text'),
'descriptionformat' => new external_format_value('description'),
'idnumber' => new external_value(PARAM_RAW, 'id number'),
'courseid' => new external_value(PARAM_INT, 'course id', VALUE_OPTIONAL),
)
);
} | [
"public",
"static",
"function",
"group_description",
"(",
")",
"{",
"return",
"new",
"external_single_structure",
"(",
"array",
"(",
"'id'",
"=>",
"new",
"external_value",
"(",
"PARAM_INT",
",",
"'group record id'",
")",
",",
"'name'",
"=>",
"new",
"external_value",
"(",
"PARAM_TEXT",
",",
"'multilang compatible name, course unique'",
")",
",",
"'description'",
"=>",
"new",
"external_value",
"(",
"PARAM_RAW",
",",
"'group description text'",
")",
",",
"'descriptionformat'",
"=>",
"new",
"external_format_value",
"(",
"'description'",
")",
",",
"'idnumber'",
"=>",
"new",
"external_value",
"(",
"PARAM_RAW",
",",
"'id number'",
")",
",",
"'courseid'",
"=>",
"new",
"external_value",
"(",
"PARAM_INT",
",",
"'course id'",
",",
"VALUE_OPTIONAL",
")",
",",
")",
")",
";",
"}"
] | Create group return value description.
@return external_single_structure The group description | [
"Create",
"group",
"return",
"value",
"description",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/group/externallib.php#L1301-L1312 |
213,661 | moodle/moodle | group/externallib.php | core_group_external.get_activity_allowed_groups | public static function get_activity_allowed_groups($cmid, $userid = 0) {
global $USER;
// Warnings array, it can be empty at the end but is mandatory.
$warnings = array();
$params = array(
'cmid' => $cmid,
'userid' => $userid
);
$params = self::validate_parameters(self::get_activity_allowed_groups_parameters(), $params);
$cmid = $params['cmid'];
$userid = $params['userid'];
$cm = get_coursemodule_from_id(null, $cmid, 0, false, MUST_EXIST);
// Security checks.
$context = context_module::instance($cm->id);
$coursecontext = context_course::instance($cm->course);
self::validate_context($context);
if (empty($userid)) {
$userid = $USER->id;
}
$user = core_user::get_user($userid, '*', MUST_EXIST);
core_user::require_active_user($user);
// Check if we have permissions for retrieve the information.
if ($user->id != $USER->id) {
if (!has_capability('moodle/course:managegroups', $context)) {
throw new moodle_exception('accessdenied', 'admin');
}
// Validate if the user is enrolled in the course.
$course = get_course($cm->course);
if (!can_access_course($course, $user, '', true)) {
// We return a warning because the function does not fail for not enrolled users.
$warning = array();
$warning['item'] = 'course';
$warning['itemid'] = $cm->course;
$warning['warningcode'] = '1';
$warning['message'] = "User $user->id cannot access course $cm->course";
$warnings[] = $warning;
}
}
$usergroups = array();
if (empty($warnings)) {
$groups = groups_get_activity_allowed_groups($cm, $user->id);
foreach ($groups as $group) {
list($group->description, $group->descriptionformat) =
external_format_text($group->description, $group->descriptionformat,
$coursecontext->id, 'group', 'description', $group->id);
$group->courseid = $cm->course;
$usergroups[] = $group;
}
}
$results = array(
'groups' => $usergroups,
'canaccessallgroups' => has_capability('moodle/site:accessallgroups', $context, $user),
'warnings' => $warnings
);
return $results;
} | php | public static function get_activity_allowed_groups($cmid, $userid = 0) {
global $USER;
// Warnings array, it can be empty at the end but is mandatory.
$warnings = array();
$params = array(
'cmid' => $cmid,
'userid' => $userid
);
$params = self::validate_parameters(self::get_activity_allowed_groups_parameters(), $params);
$cmid = $params['cmid'];
$userid = $params['userid'];
$cm = get_coursemodule_from_id(null, $cmid, 0, false, MUST_EXIST);
// Security checks.
$context = context_module::instance($cm->id);
$coursecontext = context_course::instance($cm->course);
self::validate_context($context);
if (empty($userid)) {
$userid = $USER->id;
}
$user = core_user::get_user($userid, '*', MUST_EXIST);
core_user::require_active_user($user);
// Check if we have permissions for retrieve the information.
if ($user->id != $USER->id) {
if (!has_capability('moodle/course:managegroups', $context)) {
throw new moodle_exception('accessdenied', 'admin');
}
// Validate if the user is enrolled in the course.
$course = get_course($cm->course);
if (!can_access_course($course, $user, '', true)) {
// We return a warning because the function does not fail for not enrolled users.
$warning = array();
$warning['item'] = 'course';
$warning['itemid'] = $cm->course;
$warning['warningcode'] = '1';
$warning['message'] = "User $user->id cannot access course $cm->course";
$warnings[] = $warning;
}
}
$usergroups = array();
if (empty($warnings)) {
$groups = groups_get_activity_allowed_groups($cm, $user->id);
foreach ($groups as $group) {
list($group->description, $group->descriptionformat) =
external_format_text($group->description, $group->descriptionformat,
$coursecontext->id, 'group', 'description', $group->id);
$group->courseid = $cm->course;
$usergroups[] = $group;
}
}
$results = array(
'groups' => $usergroups,
'canaccessallgroups' => has_capability('moodle/site:accessallgroups', $context, $user),
'warnings' => $warnings
);
return $results;
} | [
"public",
"static",
"function",
"get_activity_allowed_groups",
"(",
"$",
"cmid",
",",
"$",
"userid",
"=",
"0",
")",
"{",
"global",
"$",
"USER",
";",
"// Warnings array, it can be empty at the end but is mandatory.",
"$",
"warnings",
"=",
"array",
"(",
")",
";",
"$",
"params",
"=",
"array",
"(",
"'cmid'",
"=>",
"$",
"cmid",
",",
"'userid'",
"=>",
"$",
"userid",
")",
";",
"$",
"params",
"=",
"self",
"::",
"validate_parameters",
"(",
"self",
"::",
"get_activity_allowed_groups_parameters",
"(",
")",
",",
"$",
"params",
")",
";",
"$",
"cmid",
"=",
"$",
"params",
"[",
"'cmid'",
"]",
";",
"$",
"userid",
"=",
"$",
"params",
"[",
"'userid'",
"]",
";",
"$",
"cm",
"=",
"get_coursemodule_from_id",
"(",
"null",
",",
"$",
"cmid",
",",
"0",
",",
"false",
",",
"MUST_EXIST",
")",
";",
"// Security checks.",
"$",
"context",
"=",
"context_module",
"::",
"instance",
"(",
"$",
"cm",
"->",
"id",
")",
";",
"$",
"coursecontext",
"=",
"context_course",
"::",
"instance",
"(",
"$",
"cm",
"->",
"course",
")",
";",
"self",
"::",
"validate_context",
"(",
"$",
"context",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"userid",
")",
")",
"{",
"$",
"userid",
"=",
"$",
"USER",
"->",
"id",
";",
"}",
"$",
"user",
"=",
"core_user",
"::",
"get_user",
"(",
"$",
"userid",
",",
"'*'",
",",
"MUST_EXIST",
")",
";",
"core_user",
"::",
"require_active_user",
"(",
"$",
"user",
")",
";",
"// Check if we have permissions for retrieve the information.",
"if",
"(",
"$",
"user",
"->",
"id",
"!=",
"$",
"USER",
"->",
"id",
")",
"{",
"if",
"(",
"!",
"has_capability",
"(",
"'moodle/course:managegroups'",
",",
"$",
"context",
")",
")",
"{",
"throw",
"new",
"moodle_exception",
"(",
"'accessdenied'",
",",
"'admin'",
")",
";",
"}",
"// Validate if the user is enrolled in the course.",
"$",
"course",
"=",
"get_course",
"(",
"$",
"cm",
"->",
"course",
")",
";",
"if",
"(",
"!",
"can_access_course",
"(",
"$",
"course",
",",
"$",
"user",
",",
"''",
",",
"true",
")",
")",
"{",
"// We return a warning because the function does not fail for not enrolled users.",
"$",
"warning",
"=",
"array",
"(",
")",
";",
"$",
"warning",
"[",
"'item'",
"]",
"=",
"'course'",
";",
"$",
"warning",
"[",
"'itemid'",
"]",
"=",
"$",
"cm",
"->",
"course",
";",
"$",
"warning",
"[",
"'warningcode'",
"]",
"=",
"'1'",
";",
"$",
"warning",
"[",
"'message'",
"]",
"=",
"\"User $user->id cannot access course $cm->course\"",
";",
"$",
"warnings",
"[",
"]",
"=",
"$",
"warning",
";",
"}",
"}",
"$",
"usergroups",
"=",
"array",
"(",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"warnings",
")",
")",
"{",
"$",
"groups",
"=",
"groups_get_activity_allowed_groups",
"(",
"$",
"cm",
",",
"$",
"user",
"->",
"id",
")",
";",
"foreach",
"(",
"$",
"groups",
"as",
"$",
"group",
")",
"{",
"list",
"(",
"$",
"group",
"->",
"description",
",",
"$",
"group",
"->",
"descriptionformat",
")",
"=",
"external_format_text",
"(",
"$",
"group",
"->",
"description",
",",
"$",
"group",
"->",
"descriptionformat",
",",
"$",
"coursecontext",
"->",
"id",
",",
"'group'",
",",
"'description'",
",",
"$",
"group",
"->",
"id",
")",
";",
"$",
"group",
"->",
"courseid",
"=",
"$",
"cm",
"->",
"course",
";",
"$",
"usergroups",
"[",
"]",
"=",
"$",
"group",
";",
"}",
"}",
"$",
"results",
"=",
"array",
"(",
"'groups'",
"=>",
"$",
"usergroups",
",",
"'canaccessallgroups'",
"=>",
"has_capability",
"(",
"'moodle/site:accessallgroups'",
",",
"$",
"context",
",",
"$",
"user",
")",
",",
"'warnings'",
"=>",
"$",
"warnings",
")",
";",
"return",
"$",
"results",
";",
"}"
] | Gets a list of groups that the user is allowed to access within the specified activity.
@throws moodle_exception
@param int $cmid course module id
@param int $userid id of user.
@return array of group objects (id, name, description, format) and possible warnings.
@since Moodle 3.0 | [
"Gets",
"a",
"list",
"of",
"groups",
"that",
"the",
"user",
"is",
"allowed",
"to",
"access",
"within",
"the",
"specified",
"activity",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/group/externallib.php#L1338-L1404 |
213,662 | moodle/moodle | group/externallib.php | core_group_external.get_activity_groupmode | public static function get_activity_groupmode($cmid) {
global $USER;
// Warnings array, it can be empty at the end but is mandatory.
$warnings = array();
$params = array(
'cmid' => $cmid
);
$params = self::validate_parameters(self::get_activity_groupmode_parameters(), $params);
$cmid = $params['cmid'];
$cm = get_coursemodule_from_id(null, $cmid, 0, false, MUST_EXIST);
// Security checks.
$context = context_module::instance($cm->id);
self::validate_context($context);
$groupmode = groups_get_activity_groupmode($cm);
$results = array(
'groupmode' => $groupmode,
'warnings' => $warnings
);
return $results;
} | php | public static function get_activity_groupmode($cmid) {
global $USER;
// Warnings array, it can be empty at the end but is mandatory.
$warnings = array();
$params = array(
'cmid' => $cmid
);
$params = self::validate_parameters(self::get_activity_groupmode_parameters(), $params);
$cmid = $params['cmid'];
$cm = get_coursemodule_from_id(null, $cmid, 0, false, MUST_EXIST);
// Security checks.
$context = context_module::instance($cm->id);
self::validate_context($context);
$groupmode = groups_get_activity_groupmode($cm);
$results = array(
'groupmode' => $groupmode,
'warnings' => $warnings
);
return $results;
} | [
"public",
"static",
"function",
"get_activity_groupmode",
"(",
"$",
"cmid",
")",
"{",
"global",
"$",
"USER",
";",
"// Warnings array, it can be empty at the end but is mandatory.",
"$",
"warnings",
"=",
"array",
"(",
")",
";",
"$",
"params",
"=",
"array",
"(",
"'cmid'",
"=>",
"$",
"cmid",
")",
";",
"$",
"params",
"=",
"self",
"::",
"validate_parameters",
"(",
"self",
"::",
"get_activity_groupmode_parameters",
"(",
")",
",",
"$",
"params",
")",
";",
"$",
"cmid",
"=",
"$",
"params",
"[",
"'cmid'",
"]",
";",
"$",
"cm",
"=",
"get_coursemodule_from_id",
"(",
"null",
",",
"$",
"cmid",
",",
"0",
",",
"false",
",",
"MUST_EXIST",
")",
";",
"// Security checks.",
"$",
"context",
"=",
"context_module",
"::",
"instance",
"(",
"$",
"cm",
"->",
"id",
")",
";",
"self",
"::",
"validate_context",
"(",
"$",
"context",
")",
";",
"$",
"groupmode",
"=",
"groups_get_activity_groupmode",
"(",
"$",
"cm",
")",
";",
"$",
"results",
"=",
"array",
"(",
"'groupmode'",
"=>",
"$",
"groupmode",
",",
"'warnings'",
"=>",
"$",
"warnings",
")",
";",
"return",
"$",
"results",
";",
"}"
] | Returns effective groupmode used in a given activity.
@throws moodle_exception
@param int $cmid course module id.
@return array containing the group mode and possible warnings.
@since Moodle 3.0
@throws moodle_exception | [
"Returns",
"effective",
"groupmode",
"used",
"in",
"a",
"given",
"activity",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/group/externallib.php#L1446-L1471 |
213,663 | moodle/moodle | lib/horde/framework/Horde/Support/Backtrace.php | Horde_Support_Backtrace._createFromThrowable | protected function _createFromThrowable($e)
{
$this->backtrace = $e->getTrace();
if ($previous = $e->getPrevious()) {
$backtrace = new self($previous);
$this->backtrace = array_merge($backtrace->backtrace,
$this->backtrace);
}
} | php | protected function _createFromThrowable($e)
{
$this->backtrace = $e->getTrace();
if ($previous = $e->getPrevious()) {
$backtrace = new self($previous);
$this->backtrace = array_merge($backtrace->backtrace,
$this->backtrace);
}
} | [
"protected",
"function",
"_createFromThrowable",
"(",
"$",
"e",
")",
"{",
"$",
"this",
"->",
"backtrace",
"=",
"$",
"e",
"->",
"getTrace",
"(",
")",
";",
"if",
"(",
"$",
"previous",
"=",
"$",
"e",
"->",
"getPrevious",
"(",
")",
")",
"{",
"$",
"backtrace",
"=",
"new",
"self",
"(",
"$",
"previous",
")",
";",
"$",
"this",
"->",
"backtrace",
"=",
"array_merge",
"(",
"$",
"backtrace",
"->",
"backtrace",
",",
"$",
"this",
"->",
"backtrace",
")",
";",
"}",
"}"
] | Wraps an error object's backtrace.
@todo Merge with createFromThrowable with PHP 7.
@param Throwable $e The error to wrap. | [
"Wraps",
"an",
"error",
"object",
"s",
"backtrace",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/horde/framework/Horde/Support/Backtrace.php#L82-L90 |
213,664 | moodle/moodle | lib/horde/framework/Horde/Support/Backtrace.php | Horde_Support_Backtrace.getContext | public function getContext($nestingLevel)
{
if (!isset($this->backtrace[$nestingLevel])) {
throw new Horde_Exception('Unknown nesting level');
}
return $this->backtrace[$nestingLevel];
} | php | public function getContext($nestingLevel)
{
if (!isset($this->backtrace[$nestingLevel])) {
throw new Horde_Exception('Unknown nesting level');
}
return $this->backtrace[$nestingLevel];
} | [
"public",
"function",
"getContext",
"(",
"$",
"nestingLevel",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"backtrace",
"[",
"$",
"nestingLevel",
"]",
")",
")",
"{",
"throw",
"new",
"Horde_Exception",
"(",
"'Unknown nesting level'",
")",
";",
"}",
"return",
"$",
"this",
"->",
"backtrace",
"[",
"$",
"nestingLevel",
"]",
";",
"}"
] | Returns the context at a specific nesting level.
@param integer $nestingLevel 0 == current level, 1 == caller, and so on
@return array The requested context. | [
"Returns",
"the",
"context",
"at",
"a",
"specific",
"nesting",
"level",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/horde/framework/Horde/Support/Backtrace.php#L121-L127 |
213,665 | moodle/moodle | report/log/classes/table_log.php | report_log_table_log.get_user_fullname | protected function get_user_fullname($userid) {
global $DB;
if (empty($userid)) {
return false;
}
if (!empty($this->userfullnames[$userid])) {
return $this->userfullnames[$userid];
}
// We already looked for the user and it does not exist.
if ($this->userfullnames[$userid] === false) {
return false;
}
// If we reach that point new users logs have been generated since the last users db query.
list($usql, $uparams) = $DB->get_in_or_equal($userid);
$sql = "SELECT id," . get_all_user_name_fields(true) . " FROM {user} WHERE id " . $usql;
if (!$user = $DB->get_records_sql($sql, $uparams)) {
return false;
}
$this->userfullnames[$userid] = fullname($user);
return $this->userfullnames[$userid];
} | php | protected function get_user_fullname($userid) {
global $DB;
if (empty($userid)) {
return false;
}
if (!empty($this->userfullnames[$userid])) {
return $this->userfullnames[$userid];
}
// We already looked for the user and it does not exist.
if ($this->userfullnames[$userid] === false) {
return false;
}
// If we reach that point new users logs have been generated since the last users db query.
list($usql, $uparams) = $DB->get_in_or_equal($userid);
$sql = "SELECT id," . get_all_user_name_fields(true) . " FROM {user} WHERE id " . $usql;
if (!$user = $DB->get_records_sql($sql, $uparams)) {
return false;
}
$this->userfullnames[$userid] = fullname($user);
return $this->userfullnames[$userid];
} | [
"protected",
"function",
"get_user_fullname",
"(",
"$",
"userid",
")",
"{",
"global",
"$",
"DB",
";",
"if",
"(",
"empty",
"(",
"$",
"userid",
")",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"userfullnames",
"[",
"$",
"userid",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"userfullnames",
"[",
"$",
"userid",
"]",
";",
"}",
"// We already looked for the user and it does not exist.",
"if",
"(",
"$",
"this",
"->",
"userfullnames",
"[",
"$",
"userid",
"]",
"===",
"false",
")",
"{",
"return",
"false",
";",
"}",
"// If we reach that point new users logs have been generated since the last users db query.",
"list",
"(",
"$",
"usql",
",",
"$",
"uparams",
")",
"=",
"$",
"DB",
"->",
"get_in_or_equal",
"(",
"$",
"userid",
")",
";",
"$",
"sql",
"=",
"\"SELECT id,\"",
".",
"get_all_user_name_fields",
"(",
"true",
")",
".",
"\" FROM {user} WHERE id \"",
".",
"$",
"usql",
";",
"if",
"(",
"!",
"$",
"user",
"=",
"$",
"DB",
"->",
"get_records_sql",
"(",
"$",
"sql",
",",
"$",
"uparams",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
"this",
"->",
"userfullnames",
"[",
"$",
"userid",
"]",
"=",
"fullname",
"(",
"$",
"user",
")",
";",
"return",
"$",
"this",
"->",
"userfullnames",
"[",
"$",
"userid",
"]",
";",
"}"
] | Gets the user full name.
This function is useful because, in the unlikely case that the user is
not already loaded in $this->userfullnames it will fetch it from db.
@since Moodle 2.9
@param int $userid
@return string|false | [
"Gets",
"the",
"user",
"full",
"name",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/report/log/classes/table_log.php#L110-L135 |
213,666 | moodle/moodle | report/log/classes/table_log.php | report_log_table_log.col_time | public function col_time($event) {
if (empty($this->download)) {
$dateformat = get_string('strftimedatetime', 'core_langconfig');
} else {
$dateformat = get_string('strftimedatetimeshort', 'core_langconfig');
}
return userdate($event->timecreated, $dateformat);
} | php | public function col_time($event) {
if (empty($this->download)) {
$dateformat = get_string('strftimedatetime', 'core_langconfig');
} else {
$dateformat = get_string('strftimedatetimeshort', 'core_langconfig');
}
return userdate($event->timecreated, $dateformat);
} | [
"public",
"function",
"col_time",
"(",
"$",
"event",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"download",
")",
")",
"{",
"$",
"dateformat",
"=",
"get_string",
"(",
"'strftimedatetime'",
",",
"'core_langconfig'",
")",
";",
"}",
"else",
"{",
"$",
"dateformat",
"=",
"get_string",
"(",
"'strftimedatetimeshort'",
",",
"'core_langconfig'",
")",
";",
"}",
"return",
"userdate",
"(",
"$",
"event",
"->",
"timecreated",
",",
"$",
"dateformat",
")",
";",
"}"
] | Generate the time column.
@param stdClass $event event data.
@return string HTML for the time column | [
"Generate",
"the",
"time",
"column",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/report/log/classes/table_log.php#L143-L151 |
213,667 | moodle/moodle | report/log/classes/table_log.php | report_log_table_log.col_component | public function col_component($event) {
// Component.
$componentname = $event->component;
if (($event->component === 'core') || ($event->component === 'legacy')) {
return get_string('coresystem');
} else if (get_string_manager()->string_exists('pluginname', $event->component)) {
return get_string('pluginname', $event->component);
} else {
return $componentname;
}
} | php | public function col_component($event) {
// Component.
$componentname = $event->component;
if (($event->component === 'core') || ($event->component === 'legacy')) {
return get_string('coresystem');
} else if (get_string_manager()->string_exists('pluginname', $event->component)) {
return get_string('pluginname', $event->component);
} else {
return $componentname;
}
} | [
"public",
"function",
"col_component",
"(",
"$",
"event",
")",
"{",
"// Component.",
"$",
"componentname",
"=",
"$",
"event",
"->",
"component",
";",
"if",
"(",
"(",
"$",
"event",
"->",
"component",
"===",
"'core'",
")",
"||",
"(",
"$",
"event",
"->",
"component",
"===",
"'legacy'",
")",
")",
"{",
"return",
"get_string",
"(",
"'coresystem'",
")",
";",
"}",
"else",
"if",
"(",
"get_string_manager",
"(",
")",
"->",
"string_exists",
"(",
"'pluginname'",
",",
"$",
"event",
"->",
"component",
")",
")",
"{",
"return",
"get_string",
"(",
"'pluginname'",
",",
"$",
"event",
"->",
"component",
")",
";",
"}",
"else",
"{",
"return",
"$",
"componentname",
";",
"}",
"}"
] | Generate the component column.
@param stdClass $event event data.
@return string HTML for the component column | [
"Generate",
"the",
"component",
"column",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/report/log/classes/table_log.php#L256-L266 |
213,668 | moodle/moodle | report/log/classes/table_log.php | report_log_table_log.action_link | protected function action_link(moodle_url $url, $text, $name = 'popup') {
global $OUTPUT;
$link = new action_link($url, $text, new popup_action('click', $url, $name, array('height' => 440, 'width' => 700)));
return $OUTPUT->render($link);
} | php | protected function action_link(moodle_url $url, $text, $name = 'popup') {
global $OUTPUT;
$link = new action_link($url, $text, new popup_action('click', $url, $name, array('height' => 440, 'width' => 700)));
return $OUTPUT->render($link);
} | [
"protected",
"function",
"action_link",
"(",
"moodle_url",
"$",
"url",
",",
"$",
"text",
",",
"$",
"name",
"=",
"'popup'",
")",
"{",
"global",
"$",
"OUTPUT",
";",
"$",
"link",
"=",
"new",
"action_link",
"(",
"$",
"url",
",",
"$",
"text",
",",
"new",
"popup_action",
"(",
"'click'",
",",
"$",
"url",
",",
"$",
"name",
",",
"array",
"(",
"'height'",
"=>",
"440",
",",
"'width'",
"=>",
"700",
")",
")",
")",
";",
"return",
"$",
"OUTPUT",
"->",
"render",
"(",
"$",
"link",
")",
";",
"}"
] | Method to create a link with popup action.
@param moodle_url $url The url to open.
@param string $text Anchor text for the link.
@param string $name Name of the popup window.
@return string html to use. | [
"Method",
"to",
"create",
"a",
"link",
"with",
"popup",
"action",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/report/log/classes/table_log.php#L341-L345 |
213,669 | moodle/moodle | report/log/classes/table_log.php | report_log_table_log.get_action_sql | public function get_action_sql() {
global $DB;
// In new logs we have a field to pick, and in legacy try get this from action.
if ($this->filterparams->logreader instanceof logstore_legacy\log\store) {
$action = $this->get_legacy_crud_action($this->filterparams->action);
$firstletter = substr($action, 0, 1);
if ($firstletter == '-') {
$sql = $DB->sql_like('action', ':action', false, true, true);
$params['action'] = '%'.substr($action, 1).'%';
} else {
$sql = $DB->sql_like('action', ':action', false);
$params['action'] = '%'.$action.'%';
}
} else if (!empty($this->filterparams->action)) {
list($sql, $params) = $DB->get_in_or_equal(str_split($this->filterparams->action),
SQL_PARAMS_NAMED, 'crud');
$sql = "crud " . $sql;
} else {
// Add condition for all possible values of crud (to use db index).
list($sql, $params) = $DB->get_in_or_equal(array('c', 'r', 'u', 'd'),
SQL_PARAMS_NAMED, 'crud');
$sql = "crud ".$sql;
}
return array($sql, $params);
} | php | public function get_action_sql() {
global $DB;
// In new logs we have a field to pick, and in legacy try get this from action.
if ($this->filterparams->logreader instanceof logstore_legacy\log\store) {
$action = $this->get_legacy_crud_action($this->filterparams->action);
$firstletter = substr($action, 0, 1);
if ($firstletter == '-') {
$sql = $DB->sql_like('action', ':action', false, true, true);
$params['action'] = '%'.substr($action, 1).'%';
} else {
$sql = $DB->sql_like('action', ':action', false);
$params['action'] = '%'.$action.'%';
}
} else if (!empty($this->filterparams->action)) {
list($sql, $params) = $DB->get_in_or_equal(str_split($this->filterparams->action),
SQL_PARAMS_NAMED, 'crud');
$sql = "crud " . $sql;
} else {
// Add condition for all possible values of crud (to use db index).
list($sql, $params) = $DB->get_in_or_equal(array('c', 'r', 'u', 'd'),
SQL_PARAMS_NAMED, 'crud');
$sql = "crud ".$sql;
}
return array($sql, $params);
} | [
"public",
"function",
"get_action_sql",
"(",
")",
"{",
"global",
"$",
"DB",
";",
"// In new logs we have a field to pick, and in legacy try get this from action.",
"if",
"(",
"$",
"this",
"->",
"filterparams",
"->",
"logreader",
"instanceof",
"logstore_legacy",
"\\",
"log",
"\\",
"store",
")",
"{",
"$",
"action",
"=",
"$",
"this",
"->",
"get_legacy_crud_action",
"(",
"$",
"this",
"->",
"filterparams",
"->",
"action",
")",
";",
"$",
"firstletter",
"=",
"substr",
"(",
"$",
"action",
",",
"0",
",",
"1",
")",
";",
"if",
"(",
"$",
"firstletter",
"==",
"'-'",
")",
"{",
"$",
"sql",
"=",
"$",
"DB",
"->",
"sql_like",
"(",
"'action'",
",",
"':action'",
",",
"false",
",",
"true",
",",
"true",
")",
";",
"$",
"params",
"[",
"'action'",
"]",
"=",
"'%'",
".",
"substr",
"(",
"$",
"action",
",",
"1",
")",
".",
"'%'",
";",
"}",
"else",
"{",
"$",
"sql",
"=",
"$",
"DB",
"->",
"sql_like",
"(",
"'action'",
",",
"':action'",
",",
"false",
")",
";",
"$",
"params",
"[",
"'action'",
"]",
"=",
"'%'",
".",
"$",
"action",
".",
"'%'",
";",
"}",
"}",
"else",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"filterparams",
"->",
"action",
")",
")",
"{",
"list",
"(",
"$",
"sql",
",",
"$",
"params",
")",
"=",
"$",
"DB",
"->",
"get_in_or_equal",
"(",
"str_split",
"(",
"$",
"this",
"->",
"filterparams",
"->",
"action",
")",
",",
"SQL_PARAMS_NAMED",
",",
"'crud'",
")",
";",
"$",
"sql",
"=",
"\"crud \"",
".",
"$",
"sql",
";",
"}",
"else",
"{",
"// Add condition for all possible values of crud (to use db index).",
"list",
"(",
"$",
"sql",
",",
"$",
"params",
")",
"=",
"$",
"DB",
"->",
"get_in_or_equal",
"(",
"array",
"(",
"'c'",
",",
"'r'",
",",
"'u'",
",",
"'d'",
")",
",",
"SQL_PARAMS_NAMED",
",",
"'crud'",
")",
";",
"$",
"sql",
"=",
"\"crud \"",
".",
"$",
"sql",
";",
"}",
"return",
"array",
"(",
"$",
"sql",
",",
"$",
"params",
")",
";",
"}"
] | Helper function which is used by build logs to get action sql and param.
@return array sql and param for action. | [
"Helper",
"function",
"which",
"is",
"used",
"by",
"build",
"logs",
"to",
"get",
"action",
"sql",
"and",
"param",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/report/log/classes/table_log.php#L368-L393 |
213,670 | moodle/moodle | report/log/classes/table_log.php | report_log_table_log.get_cm_sql | public function get_cm_sql() {
$joins = array();
$params = array();
if ($this->filterparams->logreader instanceof logstore_legacy\log\store) {
// The legacy store doesn't support context level.
$joins[] = "cmid = :cmid";
$params['cmid'] = $this->filterparams->modid;
} else {
$joins[] = "contextinstanceid = :contextinstanceid";
$joins[] = "contextlevel = :contextmodule";
$params['contextinstanceid'] = $this->filterparams->modid;
$params['contextmodule'] = CONTEXT_MODULE;
}
$sql = implode(' AND ', $joins);
return array($sql, $params);
} | php | public function get_cm_sql() {
$joins = array();
$params = array();
if ($this->filterparams->logreader instanceof logstore_legacy\log\store) {
// The legacy store doesn't support context level.
$joins[] = "cmid = :cmid";
$params['cmid'] = $this->filterparams->modid;
} else {
$joins[] = "contextinstanceid = :contextinstanceid";
$joins[] = "contextlevel = :contextmodule";
$params['contextinstanceid'] = $this->filterparams->modid;
$params['contextmodule'] = CONTEXT_MODULE;
}
$sql = implode(' AND ', $joins);
return array($sql, $params);
} | [
"public",
"function",
"get_cm_sql",
"(",
")",
"{",
"$",
"joins",
"=",
"array",
"(",
")",
";",
"$",
"params",
"=",
"array",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"filterparams",
"->",
"logreader",
"instanceof",
"logstore_legacy",
"\\",
"log",
"\\",
"store",
")",
"{",
"// The legacy store doesn't support context level.",
"$",
"joins",
"[",
"]",
"=",
"\"cmid = :cmid\"",
";",
"$",
"params",
"[",
"'cmid'",
"]",
"=",
"$",
"this",
"->",
"filterparams",
"->",
"modid",
";",
"}",
"else",
"{",
"$",
"joins",
"[",
"]",
"=",
"\"contextinstanceid = :contextinstanceid\"",
";",
"$",
"joins",
"[",
"]",
"=",
"\"contextlevel = :contextmodule\"",
";",
"$",
"params",
"[",
"'contextinstanceid'",
"]",
"=",
"$",
"this",
"->",
"filterparams",
"->",
"modid",
";",
"$",
"params",
"[",
"'contextmodule'",
"]",
"=",
"CONTEXT_MODULE",
";",
"}",
"$",
"sql",
"=",
"implode",
"(",
"' AND '",
",",
"$",
"joins",
")",
";",
"return",
"array",
"(",
"$",
"sql",
",",
"$",
"params",
")",
";",
"}"
] | Helper function which is used by build logs to get course module sql and param.
@return array sql and param for action. | [
"Helper",
"function",
"which",
"is",
"used",
"by",
"build",
"logs",
"to",
"get",
"course",
"module",
"sql",
"and",
"param",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/report/log/classes/table_log.php#L400-L417 |
213,671 | moodle/moodle | report/log/classes/table_log.php | report_log_table_log.update_users_used | protected function update_users_used() {
global $DB;
$this->userfullnames = array();
$userids = array();
// For each event cache full username.
// Get list of userids which will be shown in log report.
foreach ($this->rawdata as $event) {
$logextra = $event->get_logextra();
if (!empty($event->userid) && empty($userids[$event->userid])) {
$userids[$event->userid] = $event->userid;
}
if (!empty($logextra['realuserid']) && empty($userids[$logextra['realuserid']])) {
$userids[$logextra['realuserid']] = $logextra['realuserid'];
}
if (!empty($event->relateduserid) && empty($userids[$event->relateduserid])) {
$userids[$event->relateduserid] = $event->relateduserid;
}
}
$this->rawdata->close();
// Get user fullname and put that in return list.
if (!empty($userids)) {
list($usql, $uparams) = $DB->get_in_or_equal($userids);
$users = $DB->get_records_sql("SELECT id," . get_all_user_name_fields(true) . " FROM {user} WHERE id " . $usql,
$uparams);
foreach ($users as $userid => $user) {
$this->userfullnames[$userid] = fullname($user);
unset($userids[$userid]);
}
// We fill the array with false values for the users that don't exist anymore
// in the database so we don't need to query the db again later.
foreach ($userids as $userid) {
$this->userfullnames[$userid] = false;
}
}
} | php | protected function update_users_used() {
global $DB;
$this->userfullnames = array();
$userids = array();
// For each event cache full username.
// Get list of userids which will be shown in log report.
foreach ($this->rawdata as $event) {
$logextra = $event->get_logextra();
if (!empty($event->userid) && empty($userids[$event->userid])) {
$userids[$event->userid] = $event->userid;
}
if (!empty($logextra['realuserid']) && empty($userids[$logextra['realuserid']])) {
$userids[$logextra['realuserid']] = $logextra['realuserid'];
}
if (!empty($event->relateduserid) && empty($userids[$event->relateduserid])) {
$userids[$event->relateduserid] = $event->relateduserid;
}
}
$this->rawdata->close();
// Get user fullname and put that in return list.
if (!empty($userids)) {
list($usql, $uparams) = $DB->get_in_or_equal($userids);
$users = $DB->get_records_sql("SELECT id," . get_all_user_name_fields(true) . " FROM {user} WHERE id " . $usql,
$uparams);
foreach ($users as $userid => $user) {
$this->userfullnames[$userid] = fullname($user);
unset($userids[$userid]);
}
// We fill the array with false values for the users that don't exist anymore
// in the database so we don't need to query the db again later.
foreach ($userids as $userid) {
$this->userfullnames[$userid] = false;
}
}
} | [
"protected",
"function",
"update_users_used",
"(",
")",
"{",
"global",
"$",
"DB",
";",
"$",
"this",
"->",
"userfullnames",
"=",
"array",
"(",
")",
";",
"$",
"userids",
"=",
"array",
"(",
")",
";",
"// For each event cache full username.",
"// Get list of userids which will be shown in log report.",
"foreach",
"(",
"$",
"this",
"->",
"rawdata",
"as",
"$",
"event",
")",
"{",
"$",
"logextra",
"=",
"$",
"event",
"->",
"get_logextra",
"(",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"event",
"->",
"userid",
")",
"&&",
"empty",
"(",
"$",
"userids",
"[",
"$",
"event",
"->",
"userid",
"]",
")",
")",
"{",
"$",
"userids",
"[",
"$",
"event",
"->",
"userid",
"]",
"=",
"$",
"event",
"->",
"userid",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"logextra",
"[",
"'realuserid'",
"]",
")",
"&&",
"empty",
"(",
"$",
"userids",
"[",
"$",
"logextra",
"[",
"'realuserid'",
"]",
"]",
")",
")",
"{",
"$",
"userids",
"[",
"$",
"logextra",
"[",
"'realuserid'",
"]",
"]",
"=",
"$",
"logextra",
"[",
"'realuserid'",
"]",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"event",
"->",
"relateduserid",
")",
"&&",
"empty",
"(",
"$",
"userids",
"[",
"$",
"event",
"->",
"relateduserid",
"]",
")",
")",
"{",
"$",
"userids",
"[",
"$",
"event",
"->",
"relateduserid",
"]",
"=",
"$",
"event",
"->",
"relateduserid",
";",
"}",
"}",
"$",
"this",
"->",
"rawdata",
"->",
"close",
"(",
")",
";",
"// Get user fullname and put that in return list.",
"if",
"(",
"!",
"empty",
"(",
"$",
"userids",
")",
")",
"{",
"list",
"(",
"$",
"usql",
",",
"$",
"uparams",
")",
"=",
"$",
"DB",
"->",
"get_in_or_equal",
"(",
"$",
"userids",
")",
";",
"$",
"users",
"=",
"$",
"DB",
"->",
"get_records_sql",
"(",
"\"SELECT id,\"",
".",
"get_all_user_name_fields",
"(",
"true",
")",
".",
"\" FROM {user} WHERE id \"",
".",
"$",
"usql",
",",
"$",
"uparams",
")",
";",
"foreach",
"(",
"$",
"users",
"as",
"$",
"userid",
"=>",
"$",
"user",
")",
"{",
"$",
"this",
"->",
"userfullnames",
"[",
"$",
"userid",
"]",
"=",
"fullname",
"(",
"$",
"user",
")",
";",
"unset",
"(",
"$",
"userids",
"[",
"$",
"userid",
"]",
")",
";",
"}",
"// We fill the array with false values for the users that don't exist anymore",
"// in the database so we don't need to query the db again later.",
"foreach",
"(",
"$",
"userids",
"as",
"$",
"userid",
")",
"{",
"$",
"this",
"->",
"userfullnames",
"[",
"$",
"userid",
"]",
"=",
"false",
";",
"}",
"}",
"}"
] | Helper function to create list of user fullnames shown in log report.
This will update $this->userfullnames array with userfullname,
which will be used to render logs in table.
@since Moodle 2.9
@return void | [
"Helper",
"function",
"to",
"create",
"list",
"of",
"user",
"fullnames",
"shown",
"in",
"log",
"report",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/report/log/classes/table_log.php#L560-L598 |
213,672 | moodle/moodle | repository/skydrive/microsoftliveapi.php | microsoft_skydrive.post | public function post($url, $params = '', $options = array()) {
return parent::post($url, format_postdata_for_curlcall($params), $options);
} | php | public function post($url, $params = '', $options = array()) {
return parent::post($url, format_postdata_for_curlcall($params), $options);
} | [
"public",
"function",
"post",
"(",
"$",
"url",
",",
"$",
"params",
"=",
"''",
",",
"$",
"options",
"=",
"array",
"(",
")",
")",
"{",
"return",
"parent",
"::",
"post",
"(",
"$",
"url",
",",
"format_postdata_for_curlcall",
"(",
"$",
"params",
")",
",",
"$",
"options",
")",
";",
"}"
] | Post request.
Overridden to convert the data to a string, else curl will set the wrong headers.
@param string $url The URL.
@param array|string $params The parameters.
@param array $options The options.
@return bool | [
"Post",
"request",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/repository/skydrive/microsoftliveapi.php#L89-L91 |
213,673 | moodle/moodle | repository/skydrive/microsoftliveapi.php | microsoft_skydrive.download_file | public function download_file($id, $path) {
$url = self::API."/${id}/content";
// Microsoft live redirects to the real download location..
$this->setopt(array('CURLOPT_FOLLOWLOCATION' => true, 'CURLOPT_MAXREDIRS' => 3));
$content = $this->get($url);
file_put_contents($path, $content);
return array('path'=>$path, 'url'=>$url);
} | php | public function download_file($id, $path) {
$url = self::API."/${id}/content";
// Microsoft live redirects to the real download location..
$this->setopt(array('CURLOPT_FOLLOWLOCATION' => true, 'CURLOPT_MAXREDIRS' => 3));
$content = $this->get($url);
file_put_contents($path, $content);
return array('path'=>$path, 'url'=>$url);
} | [
"public",
"function",
"download_file",
"(",
"$",
"id",
",",
"$",
"path",
")",
"{",
"$",
"url",
"=",
"self",
"::",
"API",
".",
"\"/${id}/content\"",
";",
"// Microsoft live redirects to the real download location..",
"$",
"this",
"->",
"setopt",
"(",
"array",
"(",
"'CURLOPT_FOLLOWLOCATION'",
"=>",
"true",
",",
"'CURLOPT_MAXREDIRS'",
"=>",
"3",
")",
")",
";",
"$",
"content",
"=",
"$",
"this",
"->",
"get",
"(",
"$",
"url",
")",
";",
"file_put_contents",
"(",
"$",
"path",
",",
"$",
"content",
")",
";",
"return",
"array",
"(",
"'path'",
"=>",
"$",
"path",
",",
"'url'",
"=>",
"$",
"url",
")",
";",
"}"
] | Downloads a file to a file from skydrive using authenticated request
@param string $id id of file
@param string $path path to save file to
@return array stucture for repository download_file | [
"Downloads",
"a",
"file",
"to",
"a",
"file",
"from",
"skydrive",
"using",
"authenticated",
"request"
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/repository/skydrive/microsoftliveapi.php#L100-L107 |
213,674 | moodle/moodle | repository/skydrive/microsoftliveapi.php | microsoft_skydrive.get_folder_name | public function get_folder_name($folderid) {
if (empty($folderid)) {
throw new coding_exception('Empty folderid passed to get_folder_name');
}
// Cache based on oauthtoken and folderid.
$cachekey = $this->folder_cache_key($folderid);
if ($foldername = $this->foldernamecache->get($cachekey)) {
return $foldername;
}
$url = self::API."/{$folderid}";
$ret = json_decode($this->get($url));
if (isset($ret->error)) {
$this->log_out();
return false;
}
$this->foldernamecache->set($cachekey, $ret->name);
return $ret->name;
} | php | public function get_folder_name($folderid) {
if (empty($folderid)) {
throw new coding_exception('Empty folderid passed to get_folder_name');
}
// Cache based on oauthtoken and folderid.
$cachekey = $this->folder_cache_key($folderid);
if ($foldername = $this->foldernamecache->get($cachekey)) {
return $foldername;
}
$url = self::API."/{$folderid}";
$ret = json_decode($this->get($url));
if (isset($ret->error)) {
$this->log_out();
return false;
}
$this->foldernamecache->set($cachekey, $ret->name);
return $ret->name;
} | [
"public",
"function",
"get_folder_name",
"(",
"$",
"folderid",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"folderid",
")",
")",
"{",
"throw",
"new",
"coding_exception",
"(",
"'Empty folderid passed to get_folder_name'",
")",
";",
"}",
"// Cache based on oauthtoken and folderid.",
"$",
"cachekey",
"=",
"$",
"this",
"->",
"folder_cache_key",
"(",
"$",
"folderid",
")",
";",
"if",
"(",
"$",
"foldername",
"=",
"$",
"this",
"->",
"foldernamecache",
"->",
"get",
"(",
"$",
"cachekey",
")",
")",
"{",
"return",
"$",
"foldername",
";",
"}",
"$",
"url",
"=",
"self",
"::",
"API",
".",
"\"/{$folderid}\"",
";",
"$",
"ret",
"=",
"json_decode",
"(",
"$",
"this",
"->",
"get",
"(",
"$",
"url",
")",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"ret",
"->",
"error",
")",
")",
"{",
"$",
"this",
"->",
"log_out",
"(",
")",
";",
"return",
"false",
";",
"}",
"$",
"this",
"->",
"foldernamecache",
"->",
"set",
"(",
"$",
"cachekey",
",",
"$",
"ret",
"->",
"name",
")",
";",
"return",
"$",
"ret",
"->",
"name",
";",
"}"
] | Returns a folder name property for a given folderid.
@param string $folderid the folder id which is passed
@return mixed folder name or false in case of error | [
"Returns",
"a",
"folder",
"name",
"property",
"for",
"a",
"given",
"folderid",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/repository/skydrive/microsoftliveapi.php#L115-L136 |
213,675 | moodle/moodle | mod/assign/submission/comments/classes/privacy/provider.php | provider.get_context_for_userid_within_submission | public static function get_context_for_userid_within_submission(int $userid, contextlist $contextlist) {
$sql = "SELECT contextid
FROM {comments}
WHERE component = :component
AND commentarea = :commentarea
AND userid = :userid";
$params = ['userid' => $userid, 'component' => 'assignsubmission_comments', 'commentarea' => 'submission_comments'];
$contextlist->add_from_sql($sql, $params);
} | php | public static function get_context_for_userid_within_submission(int $userid, contextlist $contextlist) {
$sql = "SELECT contextid
FROM {comments}
WHERE component = :component
AND commentarea = :commentarea
AND userid = :userid";
$params = ['userid' => $userid, 'component' => 'assignsubmission_comments', 'commentarea' => 'submission_comments'];
$contextlist->add_from_sql($sql, $params);
} | [
"public",
"static",
"function",
"get_context_for_userid_within_submission",
"(",
"int",
"$",
"userid",
",",
"contextlist",
"$",
"contextlist",
")",
"{",
"$",
"sql",
"=",
"\"SELECT contextid\n FROM {comments}\n WHERE component = :component\n AND commentarea = :commentarea\n AND userid = :userid\"",
";",
"$",
"params",
"=",
"[",
"'userid'",
"=>",
"$",
"userid",
",",
"'component'",
"=>",
"'assignsubmission_comments'",
",",
"'commentarea'",
"=>",
"'submission_comments'",
"]",
";",
"$",
"contextlist",
"->",
"add_from_sql",
"(",
"$",
"sql",
",",
"$",
"params",
")",
";",
"}"
] | It is possible to make a comment as a teacher without creating an entry in the submission table, so this is required
to find those entries.
@param int $userid The user ID that we are finding contexts for.
@param contextlist $contextlist A context list to add sql and params to for contexts. | [
"It",
"is",
"possible",
"to",
"make",
"a",
"comment",
"as",
"a",
"teacher",
"without",
"creating",
"an",
"entry",
"in",
"the",
"submission",
"table",
"so",
"this",
"is",
"required",
"to",
"find",
"those",
"entries",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/assign/submission/comments/classes/privacy/provider.php#L66-L74 |
213,676 | moodle/moodle | mod/assign/submission/comments/classes/privacy/provider.php | provider.get_student_user_ids | public static function get_student_user_ids(\mod_assign\privacy\useridlist $useridlist) {
$params = ['assignid' => $useridlist->get_assignid(), 'commentuserid' => $useridlist->get_teacherid(),
'commentuserid2' => $useridlist->get_teacherid()];
$sql = "SELECT DISTINCT c.userid AS id
FROM {comments} c
JOIN (SELECT c.itemid
FROM {comments} c
JOIN {assign_submission} s ON s.id = c.itemid AND s.assignment = :assignid
WHERE c.userid = :commentuserid) aa ON aa.itemid = c.itemid
WHERE c.userid NOT IN (:commentuserid2)";
$useridlist->add_from_sql($sql, $params);
} | php | public static function get_student_user_ids(\mod_assign\privacy\useridlist $useridlist) {
$params = ['assignid' => $useridlist->get_assignid(), 'commentuserid' => $useridlist->get_teacherid(),
'commentuserid2' => $useridlist->get_teacherid()];
$sql = "SELECT DISTINCT c.userid AS id
FROM {comments} c
JOIN (SELECT c.itemid
FROM {comments} c
JOIN {assign_submission} s ON s.id = c.itemid AND s.assignment = :assignid
WHERE c.userid = :commentuserid) aa ON aa.itemid = c.itemid
WHERE c.userid NOT IN (:commentuserid2)";
$useridlist->add_from_sql($sql, $params);
} | [
"public",
"static",
"function",
"get_student_user_ids",
"(",
"\\",
"mod_assign",
"\\",
"privacy",
"\\",
"useridlist",
"$",
"useridlist",
")",
"{",
"$",
"params",
"=",
"[",
"'assignid'",
"=>",
"$",
"useridlist",
"->",
"get_assignid",
"(",
")",
",",
"'commentuserid'",
"=>",
"$",
"useridlist",
"->",
"get_teacherid",
"(",
")",
",",
"'commentuserid2'",
"=>",
"$",
"useridlist",
"->",
"get_teacherid",
"(",
")",
"]",
";",
"$",
"sql",
"=",
"\"SELECT DISTINCT c.userid AS id\n FROM {comments} c\n JOIN (SELECT c.itemid\n FROM {comments} c\n JOIN {assign_submission} s ON s.id = c.itemid AND s.assignment = :assignid\n WHERE c.userid = :commentuserid) aa ON aa.itemid = c.itemid\n WHERE c.userid NOT IN (:commentuserid2)\"",
";",
"$",
"useridlist",
"->",
"add_from_sql",
"(",
"$",
"sql",
",",
"$",
"params",
")",
";",
"}"
] | Due to the fact that we can't rely on the queries in the mod_assign provider we have to add some additional sql.
@param \mod_assign\privacy\useridlist $useridlist An object for obtaining user IDs of students. | [
"Due",
"to",
"the",
"fact",
"that",
"we",
"can",
"t",
"rely",
"on",
"the",
"queries",
"in",
"the",
"mod_assign",
"provider",
"we",
"have",
"to",
"add",
"some",
"additional",
"sql",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/assign/submission/comments/classes/privacy/provider.php#L81-L92 |
213,677 | moodle/moodle | mod/assign/submission/comments/classes/privacy/provider.php | provider.get_userids_from_context | public static function get_userids_from_context(\core_privacy\local\request\userlist $userlist) {
$context = $userlist->get_context();
if ($context->contextlevel != CONTEXT_MODULE) {
return;
}
comments_provider::get_users_in_context_from_sql($userlist, 'c', 'assignsubmission_comments', 'submission_comments',
$context->id);
} | php | public static function get_userids_from_context(\core_privacy\local\request\userlist $userlist) {
$context = $userlist->get_context();
if ($context->contextlevel != CONTEXT_MODULE) {
return;
}
comments_provider::get_users_in_context_from_sql($userlist, 'c', 'assignsubmission_comments', 'submission_comments',
$context->id);
} | [
"public",
"static",
"function",
"get_userids_from_context",
"(",
"\\",
"core_privacy",
"\\",
"local",
"\\",
"request",
"\\",
"userlist",
"$",
"userlist",
")",
"{",
"$",
"context",
"=",
"$",
"userlist",
"->",
"get_context",
"(",
")",
";",
"if",
"(",
"$",
"context",
"->",
"contextlevel",
"!=",
"CONTEXT_MODULE",
")",
"{",
"return",
";",
"}",
"comments_provider",
"::",
"get_users_in_context_from_sql",
"(",
"$",
"userlist",
",",
"'c'",
",",
"'assignsubmission_comments'",
",",
"'submission_comments'",
",",
"$",
"context",
"->",
"id",
")",
";",
"}"
] | If you have tables that contain userids and you can generate entries in your tables without creating an
entry in the assign_submission table then please fill in this method.
@param \core_privacy\local\request\userlist $userlist The userlist object | [
"If",
"you",
"have",
"tables",
"that",
"contain",
"userids",
"and",
"you",
"can",
"generate",
"entries",
"in",
"your",
"tables",
"without",
"creating",
"an",
"entry",
"in",
"the",
"assign_submission",
"table",
"then",
"please",
"fill",
"in",
"this",
"method",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/assign/submission/comments/classes/privacy/provider.php#L100-L107 |
213,678 | moodle/moodle | course/classes/search/customfield.php | customfield.get_document_recordset | public function get_document_recordset($modifiedfrom = 0, \context $context = null) {
global $DB;
list ($contextjoin, $contextparams) = $this->get_course_level_context_restriction_sql($context, 'c', SQL_PARAMS_NAMED);
if ($contextjoin === null) {
return null;
}
$fields = course_handler::create()->get_fields();
if (!$fields) {
$fields = array();
}
list($fieldsql, $fieldparam) = $DB->get_in_or_equal(array_keys($fields), SQL_PARAMS_NAMED, 'fld', true, true);
// Restrict recordset to CONTEXT_COURSE (since we are implementing it to core_course\search).
$sql = "SELECT d.*
FROM {customfield_data} d
JOIN {course} c ON c.id = d.instanceid
JOIN {context} cnt ON cnt.instanceid = c.id
$contextjoin
WHERE d.timemodified >= :modifiedfrom
AND cnt.contextlevel = :contextlevel
AND d.fieldid $fieldsql
ORDER BY d.timemodified ASC";
return $DB->get_recordset_sql($sql , array_merge($contextparams,
['modifiedfrom' => $modifiedfrom, 'contextlevel' => CONTEXT_COURSE], $fieldparam));
} | php | public function get_document_recordset($modifiedfrom = 0, \context $context = null) {
global $DB;
list ($contextjoin, $contextparams) = $this->get_course_level_context_restriction_sql($context, 'c', SQL_PARAMS_NAMED);
if ($contextjoin === null) {
return null;
}
$fields = course_handler::create()->get_fields();
if (!$fields) {
$fields = array();
}
list($fieldsql, $fieldparam) = $DB->get_in_or_equal(array_keys($fields), SQL_PARAMS_NAMED, 'fld', true, true);
// Restrict recordset to CONTEXT_COURSE (since we are implementing it to core_course\search).
$sql = "SELECT d.*
FROM {customfield_data} d
JOIN {course} c ON c.id = d.instanceid
JOIN {context} cnt ON cnt.instanceid = c.id
$contextjoin
WHERE d.timemodified >= :modifiedfrom
AND cnt.contextlevel = :contextlevel
AND d.fieldid $fieldsql
ORDER BY d.timemodified ASC";
return $DB->get_recordset_sql($sql , array_merge($contextparams,
['modifiedfrom' => $modifiedfrom, 'contextlevel' => CONTEXT_COURSE], $fieldparam));
} | [
"public",
"function",
"get_document_recordset",
"(",
"$",
"modifiedfrom",
"=",
"0",
",",
"\\",
"context",
"$",
"context",
"=",
"null",
")",
"{",
"global",
"$",
"DB",
";",
"list",
"(",
"$",
"contextjoin",
",",
"$",
"contextparams",
")",
"=",
"$",
"this",
"->",
"get_course_level_context_restriction_sql",
"(",
"$",
"context",
",",
"'c'",
",",
"SQL_PARAMS_NAMED",
")",
";",
"if",
"(",
"$",
"contextjoin",
"===",
"null",
")",
"{",
"return",
"null",
";",
"}",
"$",
"fields",
"=",
"course_handler",
"::",
"create",
"(",
")",
"->",
"get_fields",
"(",
")",
";",
"if",
"(",
"!",
"$",
"fields",
")",
"{",
"$",
"fields",
"=",
"array",
"(",
")",
";",
"}",
"list",
"(",
"$",
"fieldsql",
",",
"$",
"fieldparam",
")",
"=",
"$",
"DB",
"->",
"get_in_or_equal",
"(",
"array_keys",
"(",
"$",
"fields",
")",
",",
"SQL_PARAMS_NAMED",
",",
"'fld'",
",",
"true",
",",
"true",
")",
";",
"// Restrict recordset to CONTEXT_COURSE (since we are implementing it to core_course\\search).",
"$",
"sql",
"=",
"\"SELECT d.*\n FROM {customfield_data} d\n JOIN {course} c ON c.id = d.instanceid\n JOIN {context} cnt ON cnt.instanceid = c.id\n $contextjoin\n WHERE d.timemodified >= :modifiedfrom\n AND cnt.contextlevel = :contextlevel\n AND d.fieldid $fieldsql\n ORDER BY d.timemodified ASC\"",
";",
"return",
"$",
"DB",
"->",
"get_recordset_sql",
"(",
"$",
"sql",
",",
"array_merge",
"(",
"$",
"contextparams",
",",
"[",
"'modifiedfrom'",
"=>",
"$",
"modifiedfrom",
",",
"'contextlevel'",
"=>",
"CONTEXT_COURSE",
"]",
",",
"$",
"fieldparam",
")",
")",
";",
"}"
] | Returns recordset containing required data for indexing
course custom fields.
@param int $modifiedfrom timestamp
@param \context|null $context Restriction context
@return \moodle_recordset|null Recordset or null if no change possible | [
"Returns",
"recordset",
"containing",
"required",
"data",
"for",
"indexing",
"course",
"custom",
"fields",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/course/classes/search/customfield.php#L57-L83 |
213,679 | moodle/moodle | availability/classes/frontend.php | frontend.include_all_javascript | public static function include_all_javascript($course, \cm_info $cm = null,
\section_info $section = null) {
global $PAGE;
// Prepare array of required YUI modules. It is bad for performance to
// make multiple yui_module calls, so we group all the plugin modules
// into a single call (the main init function will call init for each
// plugin).
$modules = array('moodle-core_availability-form', 'base', 'node',
'panel', 'moodle-core-notification-dialogue', 'json');
// Work out JS to include for all components.
$pluginmanager = \core_plugin_manager::instance();
$enabled = $pluginmanager->get_enabled_plugins('availability');
$componentparams = new \stdClass();
foreach ($enabled as $plugin => $info) {
// Create plugin front-end object.
$class = '\availability_' . $plugin . '\frontend';
$frontend = new $class();
// Add to array of required YUI modules.
$component = $frontend->get_component();
$modules[] = 'moodle-' . $component . '-form';
// Get parameters for this plugin.
$componentparams->{$plugin} = array($component,
$frontend->allow_add($course, $cm, $section),
$frontend->get_javascript_init_params($course, $cm, $section));
// Include strings for this plugin.
$identifiers = $frontend->get_javascript_strings();
$identifiers[] = 'title';
$identifiers[] = 'description';
$PAGE->requires->strings_for_js($identifiers, $component);
}
// Include all JS (in one call). The init function runs on DOM ready.
$PAGE->requires->yui_module($modules,
'M.core_availability.form.init', array($componentparams), null, true);
// Include main strings.
$PAGE->requires->strings_for_js(array('none', 'cancel', 'delete', 'choosedots'),
'moodle');
$PAGE->requires->strings_for_js(array('addrestriction', 'invalid',
'listheader_sign_before', 'listheader_sign_pos',
'listheader_sign_neg', 'listheader_single',
'listheader_multi_after', 'listheader_multi_before',
'listheader_multi_or', 'listheader_multi_and',
'unknowncondition', 'hide_verb', 'hidden_individual',
'show_verb', 'shown_individual', 'hidden_all', 'shown_all',
'condition_group', 'condition_group_info', 'and', 'or',
'label_multi', 'label_sign', 'setheading', 'itemheading',
'missingplugin'),
'availability');
} | php | public static function include_all_javascript($course, \cm_info $cm = null,
\section_info $section = null) {
global $PAGE;
// Prepare array of required YUI modules. It is bad for performance to
// make multiple yui_module calls, so we group all the plugin modules
// into a single call (the main init function will call init for each
// plugin).
$modules = array('moodle-core_availability-form', 'base', 'node',
'panel', 'moodle-core-notification-dialogue', 'json');
// Work out JS to include for all components.
$pluginmanager = \core_plugin_manager::instance();
$enabled = $pluginmanager->get_enabled_plugins('availability');
$componentparams = new \stdClass();
foreach ($enabled as $plugin => $info) {
// Create plugin front-end object.
$class = '\availability_' . $plugin . '\frontend';
$frontend = new $class();
// Add to array of required YUI modules.
$component = $frontend->get_component();
$modules[] = 'moodle-' . $component . '-form';
// Get parameters for this plugin.
$componentparams->{$plugin} = array($component,
$frontend->allow_add($course, $cm, $section),
$frontend->get_javascript_init_params($course, $cm, $section));
// Include strings for this plugin.
$identifiers = $frontend->get_javascript_strings();
$identifiers[] = 'title';
$identifiers[] = 'description';
$PAGE->requires->strings_for_js($identifiers, $component);
}
// Include all JS (in one call). The init function runs on DOM ready.
$PAGE->requires->yui_module($modules,
'M.core_availability.form.init', array($componentparams), null, true);
// Include main strings.
$PAGE->requires->strings_for_js(array('none', 'cancel', 'delete', 'choosedots'),
'moodle');
$PAGE->requires->strings_for_js(array('addrestriction', 'invalid',
'listheader_sign_before', 'listheader_sign_pos',
'listheader_sign_neg', 'listheader_single',
'listheader_multi_after', 'listheader_multi_before',
'listheader_multi_or', 'listheader_multi_and',
'unknowncondition', 'hide_verb', 'hidden_individual',
'show_verb', 'shown_individual', 'hidden_all', 'shown_all',
'condition_group', 'condition_group_info', 'and', 'or',
'label_multi', 'label_sign', 'setheading', 'itemheading',
'missingplugin'),
'availability');
} | [
"public",
"static",
"function",
"include_all_javascript",
"(",
"$",
"course",
",",
"\\",
"cm_info",
"$",
"cm",
"=",
"null",
",",
"\\",
"section_info",
"$",
"section",
"=",
"null",
")",
"{",
"global",
"$",
"PAGE",
";",
"// Prepare array of required YUI modules. It is bad for performance to",
"// make multiple yui_module calls, so we group all the plugin modules",
"// into a single call (the main init function will call init for each",
"// plugin).",
"$",
"modules",
"=",
"array",
"(",
"'moodle-core_availability-form'",
",",
"'base'",
",",
"'node'",
",",
"'panel'",
",",
"'moodle-core-notification-dialogue'",
",",
"'json'",
")",
";",
"// Work out JS to include for all components.",
"$",
"pluginmanager",
"=",
"\\",
"core_plugin_manager",
"::",
"instance",
"(",
")",
";",
"$",
"enabled",
"=",
"$",
"pluginmanager",
"->",
"get_enabled_plugins",
"(",
"'availability'",
")",
";",
"$",
"componentparams",
"=",
"new",
"\\",
"stdClass",
"(",
")",
";",
"foreach",
"(",
"$",
"enabled",
"as",
"$",
"plugin",
"=>",
"$",
"info",
")",
"{",
"// Create plugin front-end object.",
"$",
"class",
"=",
"'\\availability_'",
".",
"$",
"plugin",
".",
"'\\frontend'",
";",
"$",
"frontend",
"=",
"new",
"$",
"class",
"(",
")",
";",
"// Add to array of required YUI modules.",
"$",
"component",
"=",
"$",
"frontend",
"->",
"get_component",
"(",
")",
";",
"$",
"modules",
"[",
"]",
"=",
"'moodle-'",
".",
"$",
"component",
".",
"'-form'",
";",
"// Get parameters for this plugin.",
"$",
"componentparams",
"->",
"{",
"$",
"plugin",
"}",
"=",
"array",
"(",
"$",
"component",
",",
"$",
"frontend",
"->",
"allow_add",
"(",
"$",
"course",
",",
"$",
"cm",
",",
"$",
"section",
")",
",",
"$",
"frontend",
"->",
"get_javascript_init_params",
"(",
"$",
"course",
",",
"$",
"cm",
",",
"$",
"section",
")",
")",
";",
"// Include strings for this plugin.",
"$",
"identifiers",
"=",
"$",
"frontend",
"->",
"get_javascript_strings",
"(",
")",
";",
"$",
"identifiers",
"[",
"]",
"=",
"'title'",
";",
"$",
"identifiers",
"[",
"]",
"=",
"'description'",
";",
"$",
"PAGE",
"->",
"requires",
"->",
"strings_for_js",
"(",
"$",
"identifiers",
",",
"$",
"component",
")",
";",
"}",
"// Include all JS (in one call). The init function runs on DOM ready.",
"$",
"PAGE",
"->",
"requires",
"->",
"yui_module",
"(",
"$",
"modules",
",",
"'M.core_availability.form.init'",
",",
"array",
"(",
"$",
"componentparams",
")",
",",
"null",
",",
"true",
")",
";",
"// Include main strings.",
"$",
"PAGE",
"->",
"requires",
"->",
"strings_for_js",
"(",
"array",
"(",
"'none'",
",",
"'cancel'",
",",
"'delete'",
",",
"'choosedots'",
")",
",",
"'moodle'",
")",
";",
"$",
"PAGE",
"->",
"requires",
"->",
"strings_for_js",
"(",
"array",
"(",
"'addrestriction'",
",",
"'invalid'",
",",
"'listheader_sign_before'",
",",
"'listheader_sign_pos'",
",",
"'listheader_sign_neg'",
",",
"'listheader_single'",
",",
"'listheader_multi_after'",
",",
"'listheader_multi_before'",
",",
"'listheader_multi_or'",
",",
"'listheader_multi_and'",
",",
"'unknowncondition'",
",",
"'hide_verb'",
",",
"'hidden_individual'",
",",
"'show_verb'",
",",
"'shown_individual'",
",",
"'hidden_all'",
",",
"'shown_all'",
",",
"'condition_group'",
",",
"'condition_group_info'",
",",
"'and'",
",",
"'or'",
",",
"'label_multi'",
",",
"'label_sign'",
",",
"'setheading'",
",",
"'itemheading'",
",",
"'missingplugin'",
")",
",",
"'availability'",
")",
";",
"}"
] | Includes JavaScript for the main system and all plugins.
@param \stdClass $course Course object
@param \cm_info $cm Course-module currently being edited (null if none)
@param \section_info $section Section currently being edited (null if none) | [
"Includes",
"JavaScript",
"for",
"the",
"main",
"system",
"and",
"all",
"plugins",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/availability/classes/frontend.php#L102-L156 |
213,680 | moodle/moodle | availability/classes/frontend.php | frontend.report_validation_errors | public static function report_validation_errors(array $data, array &$errors) {
// Empty value is allowed!
if ($data['availabilityconditionsjson'] === '') {
return;
}
// Decode value.
$decoded = json_decode($data['availabilityconditionsjson']);
if (!$decoded) {
// This shouldn't be possible.
throw new \coding_exception('Invalid JSON from availabilityconditionsjson field');
}
if (!empty($decoded->errors)) {
$error = '';
foreach ($decoded->errors as $stringinfo) {
list ($component, $stringname) = explode(':', $stringinfo);
if ($error !== '') {
$error .= ' ';
}
$error .= get_string($stringname, $component);
}
$errors['availabilityconditionsjson'] = $error;
}
} | php | public static function report_validation_errors(array $data, array &$errors) {
// Empty value is allowed!
if ($data['availabilityconditionsjson'] === '') {
return;
}
// Decode value.
$decoded = json_decode($data['availabilityconditionsjson']);
if (!$decoded) {
// This shouldn't be possible.
throw new \coding_exception('Invalid JSON from availabilityconditionsjson field');
}
if (!empty($decoded->errors)) {
$error = '';
foreach ($decoded->errors as $stringinfo) {
list ($component, $stringname) = explode(':', $stringinfo);
if ($error !== '') {
$error .= ' ';
}
$error .= get_string($stringname, $component);
}
$errors['availabilityconditionsjson'] = $error;
}
} | [
"public",
"static",
"function",
"report_validation_errors",
"(",
"array",
"$",
"data",
",",
"array",
"&",
"$",
"errors",
")",
"{",
"// Empty value is allowed!",
"if",
"(",
"$",
"data",
"[",
"'availabilityconditionsjson'",
"]",
"===",
"''",
")",
"{",
"return",
";",
"}",
"// Decode value.",
"$",
"decoded",
"=",
"json_decode",
"(",
"$",
"data",
"[",
"'availabilityconditionsjson'",
"]",
")",
";",
"if",
"(",
"!",
"$",
"decoded",
")",
"{",
"// This shouldn't be possible.",
"throw",
"new",
"\\",
"coding_exception",
"(",
"'Invalid JSON from availabilityconditionsjson field'",
")",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"decoded",
"->",
"errors",
")",
")",
"{",
"$",
"error",
"=",
"''",
";",
"foreach",
"(",
"$",
"decoded",
"->",
"errors",
"as",
"$",
"stringinfo",
")",
"{",
"list",
"(",
"$",
"component",
",",
"$",
"stringname",
")",
"=",
"explode",
"(",
"':'",
",",
"$",
"stringinfo",
")",
";",
"if",
"(",
"$",
"error",
"!==",
"''",
")",
"{",
"$",
"error",
".=",
"' '",
";",
"}",
"$",
"error",
".=",
"get_string",
"(",
"$",
"stringname",
",",
"$",
"component",
")",
";",
"}",
"$",
"errors",
"[",
"'availabilityconditionsjson'",
"]",
"=",
"$",
"error",
";",
"}",
"}"
] | For use within forms, reports any validation errors from the availability
field.
@param array $data Form data fields
@param array $errors Error array | [
"For",
"use",
"within",
"forms",
"reports",
"any",
"validation",
"errors",
"from",
"the",
"availability",
"field",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/availability/classes/frontend.php#L165-L188 |
213,681 | moodle/moodle | availability/classes/frontend.php | frontend.convert_associative_array_for_js | protected static function convert_associative_array_for_js(array $inarray,
$keyname, $valuename) {
$result = array();
foreach ($inarray as $key => $value) {
$result[] = (object)array($keyname => $key, $valuename => $value);
}
return $result;
} | php | protected static function convert_associative_array_for_js(array $inarray,
$keyname, $valuename) {
$result = array();
foreach ($inarray as $key => $value) {
$result[] = (object)array($keyname => $key, $valuename => $value);
}
return $result;
} | [
"protected",
"static",
"function",
"convert_associative_array_for_js",
"(",
"array",
"$",
"inarray",
",",
"$",
"keyname",
",",
"$",
"valuename",
")",
"{",
"$",
"result",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"inarray",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"result",
"[",
"]",
"=",
"(",
"object",
")",
"array",
"(",
"$",
"keyname",
"=>",
"$",
"key",
",",
"$",
"valuename",
"=>",
"$",
"value",
")",
";",
"}",
"return",
"$",
"result",
";",
"}"
] | Converts an associative array into an array of objects with two fields.
This is necessary because JavaScript associative arrays/objects are not
ordered (at least officially according to the language specification).
@param array $inarray Associative array key => value
@param string $keyname Name to use for key in resulting array objects
@param string $valuename Name to use for value in resulting array objects
@return array Non-associative (numeric) array | [
"Converts",
"an",
"associative",
"array",
"into",
"an",
"array",
"of",
"objects",
"with",
"two",
"fields",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/availability/classes/frontend.php#L201-L208 |
213,682 | moodle/moodle | mod/assign/feedback/editpdf/classes/pdf.php | pdf.combine_pdfs | public function combine_pdfs($pdflist, $outfilename) {
raise_memory_limit(MEMORY_EXTRA);
$olddebug = error_reporting(0);
$this->setPageUnit('pt');
$this->setPrintHeader(false);
$this->setPrintFooter(false);
$this->scale = 72.0 / 100.0;
// Use font supporting the widest range of characters.
$this->SetFont($this->get_export_font_name(), '', 16.0 * $this->scale, '', true);
$this->SetTextColor(0, 0, 0);
$totalpagecount = 0;
foreach ($pdflist as $file) {
$pagecount = $this->setSourceFile($file);
$totalpagecount += $pagecount;
for ($i = 1; $i<=$pagecount; $i++) {
$this->create_page_from_source($i);
}
}
$this->save_pdf($outfilename);
error_reporting($olddebug);
return $totalpagecount;
} | php | public function combine_pdfs($pdflist, $outfilename) {
raise_memory_limit(MEMORY_EXTRA);
$olddebug = error_reporting(0);
$this->setPageUnit('pt');
$this->setPrintHeader(false);
$this->setPrintFooter(false);
$this->scale = 72.0 / 100.0;
// Use font supporting the widest range of characters.
$this->SetFont($this->get_export_font_name(), '', 16.0 * $this->scale, '', true);
$this->SetTextColor(0, 0, 0);
$totalpagecount = 0;
foreach ($pdflist as $file) {
$pagecount = $this->setSourceFile($file);
$totalpagecount += $pagecount;
for ($i = 1; $i<=$pagecount; $i++) {
$this->create_page_from_source($i);
}
}
$this->save_pdf($outfilename);
error_reporting($olddebug);
return $totalpagecount;
} | [
"public",
"function",
"combine_pdfs",
"(",
"$",
"pdflist",
",",
"$",
"outfilename",
")",
"{",
"raise_memory_limit",
"(",
"MEMORY_EXTRA",
")",
";",
"$",
"olddebug",
"=",
"error_reporting",
"(",
"0",
")",
";",
"$",
"this",
"->",
"setPageUnit",
"(",
"'pt'",
")",
";",
"$",
"this",
"->",
"setPrintHeader",
"(",
"false",
")",
";",
"$",
"this",
"->",
"setPrintFooter",
"(",
"false",
")",
";",
"$",
"this",
"->",
"scale",
"=",
"72.0",
"/",
"100.0",
";",
"// Use font supporting the widest range of characters.",
"$",
"this",
"->",
"SetFont",
"(",
"$",
"this",
"->",
"get_export_font_name",
"(",
")",
",",
"''",
",",
"16.0",
"*",
"$",
"this",
"->",
"scale",
",",
"''",
",",
"true",
")",
";",
"$",
"this",
"->",
"SetTextColor",
"(",
"0",
",",
"0",
",",
"0",
")",
";",
"$",
"totalpagecount",
"=",
"0",
";",
"foreach",
"(",
"$",
"pdflist",
"as",
"$",
"file",
")",
"{",
"$",
"pagecount",
"=",
"$",
"this",
"->",
"setSourceFile",
"(",
"$",
"file",
")",
";",
"$",
"totalpagecount",
"+=",
"$",
"pagecount",
";",
"for",
"(",
"$",
"i",
"=",
"1",
";",
"$",
"i",
"<=",
"$",
"pagecount",
";",
"$",
"i",
"++",
")",
"{",
"$",
"this",
"->",
"create_page_from_source",
"(",
"$",
"i",
")",
";",
"}",
"}",
"$",
"this",
"->",
"save_pdf",
"(",
"$",
"outfilename",
")",
";",
"error_reporting",
"(",
"$",
"olddebug",
")",
";",
"return",
"$",
"totalpagecount",
";",
"}"
] | Combine the given PDF files into a single PDF. Optionally add a coversheet and coversheet fields.
@param string[] $pdflist the filenames of the files to combine
@param string $outfilename the filename to write to
@return int the number of pages in the combined PDF | [
"Combine",
"the",
"given",
"PDF",
"files",
"into",
"a",
"single",
"PDF",
".",
"Optionally",
"add",
"a",
"coversheet",
"and",
"coversheet",
"fields",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/assign/feedback/editpdf/classes/pdf.php#L98-L125 |
213,683 | moodle/moodle | mod/assign/feedback/editpdf/classes/pdf.php | pdf.load_pdf | public function load_pdf($filename) {
raise_memory_limit(MEMORY_EXTRA);
$olddebug = error_reporting(0);
$this->setPageUnit('pt');
$this->scale = 72.0 / 100.0;
$this->SetFont($this->get_export_font_name(), '', 16.0 * $this->scale, '', true);
$this->SetFillColor(255, 255, 176);
$this->SetDrawColor(0, 0, 0);
$this->SetLineWidth(1.0 * $this->scale);
$this->SetTextColor(0, 0, 0);
$this->setPrintHeader(false);
$this->setPrintFooter(false);
$this->pagecount = $this->setSourceFile($filename);
$this->filename = $filename;
error_reporting($olddebug);
return $this->pagecount;
} | php | public function load_pdf($filename) {
raise_memory_limit(MEMORY_EXTRA);
$olddebug = error_reporting(0);
$this->setPageUnit('pt');
$this->scale = 72.0 / 100.0;
$this->SetFont($this->get_export_font_name(), '', 16.0 * $this->scale, '', true);
$this->SetFillColor(255, 255, 176);
$this->SetDrawColor(0, 0, 0);
$this->SetLineWidth(1.0 * $this->scale);
$this->SetTextColor(0, 0, 0);
$this->setPrintHeader(false);
$this->setPrintFooter(false);
$this->pagecount = $this->setSourceFile($filename);
$this->filename = $filename;
error_reporting($olddebug);
return $this->pagecount;
} | [
"public",
"function",
"load_pdf",
"(",
"$",
"filename",
")",
"{",
"raise_memory_limit",
"(",
"MEMORY_EXTRA",
")",
";",
"$",
"olddebug",
"=",
"error_reporting",
"(",
"0",
")",
";",
"$",
"this",
"->",
"setPageUnit",
"(",
"'pt'",
")",
";",
"$",
"this",
"->",
"scale",
"=",
"72.0",
"/",
"100.0",
";",
"$",
"this",
"->",
"SetFont",
"(",
"$",
"this",
"->",
"get_export_font_name",
"(",
")",
",",
"''",
",",
"16.0",
"*",
"$",
"this",
"->",
"scale",
",",
"''",
",",
"true",
")",
";",
"$",
"this",
"->",
"SetFillColor",
"(",
"255",
",",
"255",
",",
"176",
")",
";",
"$",
"this",
"->",
"SetDrawColor",
"(",
"0",
",",
"0",
",",
"0",
")",
";",
"$",
"this",
"->",
"SetLineWidth",
"(",
"1.0",
"*",
"$",
"this",
"->",
"scale",
")",
";",
"$",
"this",
"->",
"SetTextColor",
"(",
"0",
",",
"0",
",",
"0",
")",
";",
"$",
"this",
"->",
"setPrintHeader",
"(",
"false",
")",
";",
"$",
"this",
"->",
"setPrintFooter",
"(",
"false",
")",
";",
"$",
"this",
"->",
"pagecount",
"=",
"$",
"this",
"->",
"setSourceFile",
"(",
"$",
"filename",
")",
";",
"$",
"this",
"->",
"filename",
"=",
"$",
"filename",
";",
"error_reporting",
"(",
"$",
"olddebug",
")",
";",
"return",
"$",
"this",
"->",
"pagecount",
";",
"}"
] | Load the specified PDF and set the initial output configuration
Used when processing comments and outputting a new PDF
@param string $filename the path to the PDF to load
@return int the number of pages in the PDF | [
"Load",
"the",
"specified",
"PDF",
"and",
"set",
"the",
"initial",
"output",
"configuration",
"Used",
"when",
"processing",
"comments",
"and",
"outputting",
"a",
"new",
"PDF"
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/assign/feedback/editpdf/classes/pdf.php#L149-L167 |
213,684 | moodle/moodle | mod/assign/feedback/editpdf/classes/pdf.php | pdf.copy_page | public function copy_page() {
if (!$this->filename) {
return false;
}
if ($this->currentpage>=$this->pagecount) {
return false;
}
$this->currentpage++;
$this->create_page_from_source($this->currentpage);
return true;
} | php | public function copy_page() {
if (!$this->filename) {
return false;
}
if ($this->currentpage>=$this->pagecount) {
return false;
}
$this->currentpage++;
$this->create_page_from_source($this->currentpage);
return true;
} | [
"public",
"function",
"copy_page",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"filename",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"currentpage",
">=",
"$",
"this",
"->",
"pagecount",
")",
"{",
"return",
"false",
";",
"}",
"$",
"this",
"->",
"currentpage",
"++",
";",
"$",
"this",
"->",
"create_page_from_source",
"(",
"$",
"this",
"->",
"currentpage",
")",
";",
"return",
"true",
";",
"}"
] | Copy the next page from the source file and set it as the current page
@return bool true if successful | [
"Copy",
"the",
"next",
"page",
"from",
"the",
"source",
"file",
"and",
"set",
"it",
"as",
"the",
"current",
"page"
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/assign/feedback/editpdf/classes/pdf.php#L191-L201 |
213,685 | moodle/moodle | mod/assign/feedback/editpdf/classes/pdf.php | pdf.create_page_from_source | protected function create_page_from_source($pageno) {
// Get the size (and deduce the orientation) of the next page.
$template = $this->importPage($pageno);
$size = $this->getTemplateSize($template);
$orientation = 'P';
if ($size['w'] > $size['h']) {
$orientation = 'L';
}
// Create a page of the required size / orientation.
$this->AddPage($orientation, array($size['w'], $size['h']));
// Prevent new page creation when comments are at the bottom of a page.
$this->setPageOrientation($orientation, false, 0);
// Fill in the page with the original contents from the student.
$this->useTemplate($template);
} | php | protected function create_page_from_source($pageno) {
// Get the size (and deduce the orientation) of the next page.
$template = $this->importPage($pageno);
$size = $this->getTemplateSize($template);
$orientation = 'P';
if ($size['w'] > $size['h']) {
$orientation = 'L';
}
// Create a page of the required size / orientation.
$this->AddPage($orientation, array($size['w'], $size['h']));
// Prevent new page creation when comments are at the bottom of a page.
$this->setPageOrientation($orientation, false, 0);
// Fill in the page with the original contents from the student.
$this->useTemplate($template);
} | [
"protected",
"function",
"create_page_from_source",
"(",
"$",
"pageno",
")",
"{",
"// Get the size (and deduce the orientation) of the next page.",
"$",
"template",
"=",
"$",
"this",
"->",
"importPage",
"(",
"$",
"pageno",
")",
";",
"$",
"size",
"=",
"$",
"this",
"->",
"getTemplateSize",
"(",
"$",
"template",
")",
";",
"$",
"orientation",
"=",
"'P'",
";",
"if",
"(",
"$",
"size",
"[",
"'w'",
"]",
">",
"$",
"size",
"[",
"'h'",
"]",
")",
"{",
"$",
"orientation",
"=",
"'L'",
";",
"}",
"// Create a page of the required size / orientation.",
"$",
"this",
"->",
"AddPage",
"(",
"$",
"orientation",
",",
"array",
"(",
"$",
"size",
"[",
"'w'",
"]",
",",
"$",
"size",
"[",
"'h'",
"]",
")",
")",
";",
"// Prevent new page creation when comments are at the bottom of a page.",
"$",
"this",
"->",
"setPageOrientation",
"(",
"$",
"orientation",
",",
"false",
",",
"0",
")",
";",
"// Fill in the page with the original contents from the student.",
"$",
"this",
"->",
"useTemplate",
"(",
"$",
"template",
")",
";",
"}"
] | Create a page from a source PDF.
@param int $pageno | [
"Create",
"a",
"page",
"from",
"a",
"source",
"PDF",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/assign/feedback/editpdf/classes/pdf.php#L208-L222 |
213,686 | moodle/moodle | mod/assign/feedback/editpdf/classes/pdf.php | pdf.append_comments | public function append_comments($allcomments) {
if (!$this->filename) {
return false;
}
$this->SetFontSize(12 * $this->scale);
$this->SetMargins(100 * $this->scale, 120 * $this->scale, -1, true);
$this->SetAutoPageBreak(true, 100 * $this->scale);
$this->setHeaderFont(array($this->get_export_font_name(), '', 24 * $this->scale, '', true));
$this->setHeaderMargin(24 * $this->scale);
$this->setHeaderData('', 0, '', get_string('commentindex', 'assignfeedback_editpdf'));
// Add a new page to the document with an appropriate header.
$this->setPrintHeader(true);
$this->AddPage();
// Add the comments.
$commentlinks = array();
foreach ($allcomments as $pageno => $comments) {
foreach ($comments as $index => $comment) {
// Create a link to the current location, which will be added to the marker.
$commentlink = $this->AddLink();
$this->SetLink($commentlink, -1);
$commentlinks[$pageno][$index] = $commentlink;
// Also create a link back to the marker, which will be added here.
$markerlink = $this->AddLink();
$this->SetLink($markerlink, $comment->y * $this->scale, $pageno + 1);
$label = get_string('commentlabel', 'assignfeedback_editpdf', array('pnum' => $pageno + 1, 'cnum' => $index + 1));
$this->Cell(50 * $this->scale, 0, $label, 0, 0, '', false, $markerlink);
$this->MultiCell(0, 0, $comment->rawtext, 0, 'L');
$this->Ln(12 * $this->scale);
}
// Add an extra line break between pages.
$this->Ln(12 * $this->scale);
}
return $commentlinks;
} | php | public function append_comments($allcomments) {
if (!$this->filename) {
return false;
}
$this->SetFontSize(12 * $this->scale);
$this->SetMargins(100 * $this->scale, 120 * $this->scale, -1, true);
$this->SetAutoPageBreak(true, 100 * $this->scale);
$this->setHeaderFont(array($this->get_export_font_name(), '', 24 * $this->scale, '', true));
$this->setHeaderMargin(24 * $this->scale);
$this->setHeaderData('', 0, '', get_string('commentindex', 'assignfeedback_editpdf'));
// Add a new page to the document with an appropriate header.
$this->setPrintHeader(true);
$this->AddPage();
// Add the comments.
$commentlinks = array();
foreach ($allcomments as $pageno => $comments) {
foreach ($comments as $index => $comment) {
// Create a link to the current location, which will be added to the marker.
$commentlink = $this->AddLink();
$this->SetLink($commentlink, -1);
$commentlinks[$pageno][$index] = $commentlink;
// Also create a link back to the marker, which will be added here.
$markerlink = $this->AddLink();
$this->SetLink($markerlink, $comment->y * $this->scale, $pageno + 1);
$label = get_string('commentlabel', 'assignfeedback_editpdf', array('pnum' => $pageno + 1, 'cnum' => $index + 1));
$this->Cell(50 * $this->scale, 0, $label, 0, 0, '', false, $markerlink);
$this->MultiCell(0, 0, $comment->rawtext, 0, 'L');
$this->Ln(12 * $this->scale);
}
// Add an extra line break between pages.
$this->Ln(12 * $this->scale);
}
return $commentlinks;
} | [
"public",
"function",
"append_comments",
"(",
"$",
"allcomments",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"filename",
")",
"{",
"return",
"false",
";",
"}",
"$",
"this",
"->",
"SetFontSize",
"(",
"12",
"*",
"$",
"this",
"->",
"scale",
")",
";",
"$",
"this",
"->",
"SetMargins",
"(",
"100",
"*",
"$",
"this",
"->",
"scale",
",",
"120",
"*",
"$",
"this",
"->",
"scale",
",",
"-",
"1",
",",
"true",
")",
";",
"$",
"this",
"->",
"SetAutoPageBreak",
"(",
"true",
",",
"100",
"*",
"$",
"this",
"->",
"scale",
")",
";",
"$",
"this",
"->",
"setHeaderFont",
"(",
"array",
"(",
"$",
"this",
"->",
"get_export_font_name",
"(",
")",
",",
"''",
",",
"24",
"*",
"$",
"this",
"->",
"scale",
",",
"''",
",",
"true",
")",
")",
";",
"$",
"this",
"->",
"setHeaderMargin",
"(",
"24",
"*",
"$",
"this",
"->",
"scale",
")",
";",
"$",
"this",
"->",
"setHeaderData",
"(",
"''",
",",
"0",
",",
"''",
",",
"get_string",
"(",
"'commentindex'",
",",
"'assignfeedback_editpdf'",
")",
")",
";",
"// Add a new page to the document with an appropriate header.",
"$",
"this",
"->",
"setPrintHeader",
"(",
"true",
")",
";",
"$",
"this",
"->",
"AddPage",
"(",
")",
";",
"// Add the comments.",
"$",
"commentlinks",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"allcomments",
"as",
"$",
"pageno",
"=>",
"$",
"comments",
")",
"{",
"foreach",
"(",
"$",
"comments",
"as",
"$",
"index",
"=>",
"$",
"comment",
")",
"{",
"// Create a link to the current location, which will be added to the marker.",
"$",
"commentlink",
"=",
"$",
"this",
"->",
"AddLink",
"(",
")",
";",
"$",
"this",
"->",
"SetLink",
"(",
"$",
"commentlink",
",",
"-",
"1",
")",
";",
"$",
"commentlinks",
"[",
"$",
"pageno",
"]",
"[",
"$",
"index",
"]",
"=",
"$",
"commentlink",
";",
"// Also create a link back to the marker, which will be added here.",
"$",
"markerlink",
"=",
"$",
"this",
"->",
"AddLink",
"(",
")",
";",
"$",
"this",
"->",
"SetLink",
"(",
"$",
"markerlink",
",",
"$",
"comment",
"->",
"y",
"*",
"$",
"this",
"->",
"scale",
",",
"$",
"pageno",
"+",
"1",
")",
";",
"$",
"label",
"=",
"get_string",
"(",
"'commentlabel'",
",",
"'assignfeedback_editpdf'",
",",
"array",
"(",
"'pnum'",
"=>",
"$",
"pageno",
"+",
"1",
",",
"'cnum'",
"=>",
"$",
"index",
"+",
"1",
")",
")",
";",
"$",
"this",
"->",
"Cell",
"(",
"50",
"*",
"$",
"this",
"->",
"scale",
",",
"0",
",",
"$",
"label",
",",
"0",
",",
"0",
",",
"''",
",",
"false",
",",
"$",
"markerlink",
")",
";",
"$",
"this",
"->",
"MultiCell",
"(",
"0",
",",
"0",
",",
"$",
"comment",
"->",
"rawtext",
",",
"0",
",",
"'L'",
")",
";",
"$",
"this",
"->",
"Ln",
"(",
"12",
"*",
"$",
"this",
"->",
"scale",
")",
";",
"}",
"// Add an extra line break between pages.",
"$",
"this",
"->",
"Ln",
"(",
"12",
"*",
"$",
"this",
"->",
"scale",
")",
";",
"}",
"return",
"$",
"commentlinks",
";",
"}"
] | Append all comments to the end of the document.
@param array $allcomments All comments, indexed by page number (starting at 0).
@return array|bool An array of links to comments, or false. | [
"Append",
"all",
"comments",
"to",
"the",
"end",
"of",
"the",
"document",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/assign/feedback/editpdf/classes/pdf.php#L240-L277 |
213,687 | moodle/moodle | mod/assign/feedback/editpdf/classes/pdf.php | pdf.add_comment_marker | public function add_comment_marker($pageno, $index, $x, $y, $link, $colour = 'yellow') {
if (!$this->filename) {
return false;
}
$fill = '';
$fillopacity = 0.9;
switch ($colour) {
case 'red':
$fill = 'rgb(249, 181, 179)';
break;
case 'green':
$fill = 'rgb(214, 234, 178)';
break;
case 'blue':
$fill = 'rgb(203, 217, 237)';
break;
case 'white':
$fill = 'rgb(255, 255, 255)';
break;
case 'clear':
$fillopacity = 0;
break;
default: /* Yellow */
$fill = 'rgb(255, 236, 174)';
}
$marker = '@<svg xmlns="http://www.w3.org/2000/svg" viewBox="-0.5 -0.5 12 12" preserveAspectRatio="xMinYMin meet">' .
'<path d="M11 0H1C.4 0 0 .4 0 1v6c0 .6.4 1 1 1h1v4l4-4h5c.6 0 1-.4 1-1V1c0-.6-.4-1-1-1z" fill="' . $fill . '" ' .
'fill-opacity="' . $fillopacity . '" stroke="rgb(153, 153, 153)" stroke-width="0.5"/></svg>';
$label = get_string('commentlabel', 'assignfeedback_editpdf', array('pnum' => $pageno + 1, 'cnum' => $index + 1));
$x *= $this->scale;
$y *= $this->scale;
$size = 24 * $this->scale;
$this->SetDrawColor(51, 51, 51);
$this->SetFontSize(10 * $this->scale);
$this->setPage($pageno + 1);
// Add the marker image.
$this->ImageSVG($marker, $x - 0.5, $y - 0.5, $size, $size, $link);
// Add the label.
$this->MultiCell($size * 0.95, 0, $label, 0, 'C', false, 1, $x, $y, true, 0, false, true, $size * 0.60, 'M', true);
return true;
} | php | public function add_comment_marker($pageno, $index, $x, $y, $link, $colour = 'yellow') {
if (!$this->filename) {
return false;
}
$fill = '';
$fillopacity = 0.9;
switch ($colour) {
case 'red':
$fill = 'rgb(249, 181, 179)';
break;
case 'green':
$fill = 'rgb(214, 234, 178)';
break;
case 'blue':
$fill = 'rgb(203, 217, 237)';
break;
case 'white':
$fill = 'rgb(255, 255, 255)';
break;
case 'clear':
$fillopacity = 0;
break;
default: /* Yellow */
$fill = 'rgb(255, 236, 174)';
}
$marker = '@<svg xmlns="http://www.w3.org/2000/svg" viewBox="-0.5 -0.5 12 12" preserveAspectRatio="xMinYMin meet">' .
'<path d="M11 0H1C.4 0 0 .4 0 1v6c0 .6.4 1 1 1h1v4l4-4h5c.6 0 1-.4 1-1V1c0-.6-.4-1-1-1z" fill="' . $fill . '" ' .
'fill-opacity="' . $fillopacity . '" stroke="rgb(153, 153, 153)" stroke-width="0.5"/></svg>';
$label = get_string('commentlabel', 'assignfeedback_editpdf', array('pnum' => $pageno + 1, 'cnum' => $index + 1));
$x *= $this->scale;
$y *= $this->scale;
$size = 24 * $this->scale;
$this->SetDrawColor(51, 51, 51);
$this->SetFontSize(10 * $this->scale);
$this->setPage($pageno + 1);
// Add the marker image.
$this->ImageSVG($marker, $x - 0.5, $y - 0.5, $size, $size, $link);
// Add the label.
$this->MultiCell($size * 0.95, 0, $label, 0, 'C', false, 1, $x, $y, true, 0, false, true, $size * 0.60, 'M', true);
return true;
} | [
"public",
"function",
"add_comment_marker",
"(",
"$",
"pageno",
",",
"$",
"index",
",",
"$",
"x",
",",
"$",
"y",
",",
"$",
"link",
",",
"$",
"colour",
"=",
"'yellow'",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"filename",
")",
"{",
"return",
"false",
";",
"}",
"$",
"fill",
"=",
"''",
";",
"$",
"fillopacity",
"=",
"0.9",
";",
"switch",
"(",
"$",
"colour",
")",
"{",
"case",
"'red'",
":",
"$",
"fill",
"=",
"'rgb(249, 181, 179)'",
";",
"break",
";",
"case",
"'green'",
":",
"$",
"fill",
"=",
"'rgb(214, 234, 178)'",
";",
"break",
";",
"case",
"'blue'",
":",
"$",
"fill",
"=",
"'rgb(203, 217, 237)'",
";",
"break",
";",
"case",
"'white'",
":",
"$",
"fill",
"=",
"'rgb(255, 255, 255)'",
";",
"break",
";",
"case",
"'clear'",
":",
"$",
"fillopacity",
"=",
"0",
";",
"break",
";",
"default",
":",
"/* Yellow */",
"$",
"fill",
"=",
"'rgb(255, 236, 174)'",
";",
"}",
"$",
"marker",
"=",
"'@<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"-0.5 -0.5 12 12\" preserveAspectRatio=\"xMinYMin meet\">'",
".",
"'<path d=\"M11 0H1C.4 0 0 .4 0 1v6c0 .6.4 1 1 1h1v4l4-4h5c.6 0 1-.4 1-1V1c0-.6-.4-1-1-1z\" fill=\"'",
".",
"$",
"fill",
".",
"'\" '",
".",
"'fill-opacity=\"'",
".",
"$",
"fillopacity",
".",
"'\" stroke=\"rgb(153, 153, 153)\" stroke-width=\"0.5\"/></svg>'",
";",
"$",
"label",
"=",
"get_string",
"(",
"'commentlabel'",
",",
"'assignfeedback_editpdf'",
",",
"array",
"(",
"'pnum'",
"=>",
"$",
"pageno",
"+",
"1",
",",
"'cnum'",
"=>",
"$",
"index",
"+",
"1",
")",
")",
";",
"$",
"x",
"*=",
"$",
"this",
"->",
"scale",
";",
"$",
"y",
"*=",
"$",
"this",
"->",
"scale",
";",
"$",
"size",
"=",
"24",
"*",
"$",
"this",
"->",
"scale",
";",
"$",
"this",
"->",
"SetDrawColor",
"(",
"51",
",",
"51",
",",
"51",
")",
";",
"$",
"this",
"->",
"SetFontSize",
"(",
"10",
"*",
"$",
"this",
"->",
"scale",
")",
";",
"$",
"this",
"->",
"setPage",
"(",
"$",
"pageno",
"+",
"1",
")",
";",
"// Add the marker image.",
"$",
"this",
"->",
"ImageSVG",
"(",
"$",
"marker",
",",
"$",
"x",
"-",
"0.5",
",",
"$",
"y",
"-",
"0.5",
",",
"$",
"size",
",",
"$",
"size",
",",
"$",
"link",
")",
";",
"// Add the label.",
"$",
"this",
"->",
"MultiCell",
"(",
"$",
"size",
"*",
"0.95",
",",
"0",
",",
"$",
"label",
",",
"0",
",",
"'C'",
",",
"false",
",",
"1",
",",
"$",
"x",
",",
"$",
"y",
",",
"true",
",",
"0",
",",
"false",
",",
"true",
",",
"$",
"size",
"*",
"0.60",
",",
"'M'",
",",
"true",
")",
";",
"return",
"true",
";",
"}"
] | Add a comment marker to the specified page.
@param int $pageno The page number to add markers to (starting at 0).
@param int $index The comment index.
@param int $x The x-coordinate of the marker (in pixels).
@param int $y The y-coordinate of the marker (in pixels).
@param int $link The link identifier pointing to the full comment text.
@param string $colour The fill colour of the marker (red, yellow, green, blue, white, clear).
@return bool Success status. | [
"Add",
"a",
"comment",
"marker",
"to",
"the",
"specified",
"page",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/assign/feedback/editpdf/classes/pdf.php#L290-L335 |
213,688 | moodle/moodle | mod/assign/feedback/editpdf/classes/pdf.php | pdf.add_comment | public function add_comment($text, $x, $y, $width, $colour = 'yellow') {
if (!$this->filename) {
return false;
}
$this->SetDrawColor(51, 51, 51);
switch ($colour) {
case 'red':
$this->SetFillColor(249, 181, 179);
break;
case 'green':
$this->SetFillColor(214, 234, 178);
break;
case 'blue':
$this->SetFillColor(203, 217, 237);
break;
case 'white':
$this->SetFillColor(255, 255, 255);
break;
default: /* Yellow */
$this->SetFillColor(255, 236, 174);
break;
}
$x *= $this->scale;
$y *= $this->scale;
$width *= $this->scale;
$text = str_replace('<', '<', $text);
$text = str_replace('>', '>', $text);
// Draw the text with a border, but no background colour (using a background colour would cause the fill to
// appear behind any existing content on the page, hence the extra filled rectangle drawn below).
$this->MultiCell($width, 1.0, $text, 0, 'L', 0, 4, $x, $y); /* width, height, text, border, justify, fill, ln, x, y */
if ($colour != 'clear') {
$newy = $this->GetY();
// Now we know the final size of the comment, draw a rectangle with the background colour.
$this->Rect($x, $y, $width, $newy - $y, 'DF');
// Re-draw the text over the top of the background rectangle.
$this->MultiCell($width, 1.0, $text, 0, 'L', 0, 4, $x, $y); /* width, height, text, border, justify, fill, ln, x, y */
}
return true;
} | php | public function add_comment($text, $x, $y, $width, $colour = 'yellow') {
if (!$this->filename) {
return false;
}
$this->SetDrawColor(51, 51, 51);
switch ($colour) {
case 'red':
$this->SetFillColor(249, 181, 179);
break;
case 'green':
$this->SetFillColor(214, 234, 178);
break;
case 'blue':
$this->SetFillColor(203, 217, 237);
break;
case 'white':
$this->SetFillColor(255, 255, 255);
break;
default: /* Yellow */
$this->SetFillColor(255, 236, 174);
break;
}
$x *= $this->scale;
$y *= $this->scale;
$width *= $this->scale;
$text = str_replace('<', '<', $text);
$text = str_replace('>', '>', $text);
// Draw the text with a border, but no background colour (using a background colour would cause the fill to
// appear behind any existing content on the page, hence the extra filled rectangle drawn below).
$this->MultiCell($width, 1.0, $text, 0, 'L', 0, 4, $x, $y); /* width, height, text, border, justify, fill, ln, x, y */
if ($colour != 'clear') {
$newy = $this->GetY();
// Now we know the final size of the comment, draw a rectangle with the background colour.
$this->Rect($x, $y, $width, $newy - $y, 'DF');
// Re-draw the text over the top of the background rectangle.
$this->MultiCell($width, 1.0, $text, 0, 'L', 0, 4, $x, $y); /* width, height, text, border, justify, fill, ln, x, y */
}
return true;
} | [
"public",
"function",
"add_comment",
"(",
"$",
"text",
",",
"$",
"x",
",",
"$",
"y",
",",
"$",
"width",
",",
"$",
"colour",
"=",
"'yellow'",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"filename",
")",
"{",
"return",
"false",
";",
"}",
"$",
"this",
"->",
"SetDrawColor",
"(",
"51",
",",
"51",
",",
"51",
")",
";",
"switch",
"(",
"$",
"colour",
")",
"{",
"case",
"'red'",
":",
"$",
"this",
"->",
"SetFillColor",
"(",
"249",
",",
"181",
",",
"179",
")",
";",
"break",
";",
"case",
"'green'",
":",
"$",
"this",
"->",
"SetFillColor",
"(",
"214",
",",
"234",
",",
"178",
")",
";",
"break",
";",
"case",
"'blue'",
":",
"$",
"this",
"->",
"SetFillColor",
"(",
"203",
",",
"217",
",",
"237",
")",
";",
"break",
";",
"case",
"'white'",
":",
"$",
"this",
"->",
"SetFillColor",
"(",
"255",
",",
"255",
",",
"255",
")",
";",
"break",
";",
"default",
":",
"/* Yellow */",
"$",
"this",
"->",
"SetFillColor",
"(",
"255",
",",
"236",
",",
"174",
")",
";",
"break",
";",
"}",
"$",
"x",
"*=",
"$",
"this",
"->",
"scale",
";",
"$",
"y",
"*=",
"$",
"this",
"->",
"scale",
";",
"$",
"width",
"*=",
"$",
"this",
"->",
"scale",
";",
"$",
"text",
"=",
"str_replace",
"(",
"'<'",
",",
"'<'",
",",
"$",
"text",
")",
";",
"$",
"text",
"=",
"str_replace",
"(",
"'>'",
",",
"'>'",
",",
"$",
"text",
")",
";",
"// Draw the text with a border, but no background colour (using a background colour would cause the fill to",
"// appear behind any existing content on the page, hence the extra filled rectangle drawn below).",
"$",
"this",
"->",
"MultiCell",
"(",
"$",
"width",
",",
"1.0",
",",
"$",
"text",
",",
"0",
",",
"'L'",
",",
"0",
",",
"4",
",",
"$",
"x",
",",
"$",
"y",
")",
";",
"/* width, height, text, border, justify, fill, ln, x, y */",
"if",
"(",
"$",
"colour",
"!=",
"'clear'",
")",
"{",
"$",
"newy",
"=",
"$",
"this",
"->",
"GetY",
"(",
")",
";",
"// Now we know the final size of the comment, draw a rectangle with the background colour.",
"$",
"this",
"->",
"Rect",
"(",
"$",
"x",
",",
"$",
"y",
",",
"$",
"width",
",",
"$",
"newy",
"-",
"$",
"y",
",",
"'DF'",
")",
";",
"// Re-draw the text over the top of the background rectangle.",
"$",
"this",
"->",
"MultiCell",
"(",
"$",
"width",
",",
"1.0",
",",
"$",
"text",
",",
"0",
",",
"'L'",
",",
"0",
",",
"4",
",",
"$",
"x",
",",
"$",
"y",
")",
";",
"/* width, height, text, border, justify, fill, ln, x, y */",
"}",
"return",
"true",
";",
"}"
] | Add a comment to the current page
@param string $text the text of the comment
@param int $x the x-coordinate of the comment (in pixels)
@param int $y the y-coordinate of the comment (in pixels)
@param int $width the width of the comment (in pixels)
@param string $colour optional the background colour of the comment (red, yellow, green, blue, white, clear)
@return bool true if successful (always) | [
"Add",
"a",
"comment",
"to",
"the",
"current",
"page"
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/assign/feedback/editpdf/classes/pdf.php#L346-L385 |
213,689 | moodle/moodle | mod/assign/feedback/editpdf/classes/pdf.php | pdf.get_image | public function get_image($pageno) {
global $CFG;
if (!$this->filename) {
throw new \coding_exception('Attempting to generate a page image without first setting the PDF filename');
}
if (!$this->imagefolder) {
throw new \coding_exception('Attempting to generate a page image without first specifying the image output folder');
}
if (!is_dir($this->imagefolder)) {
throw new \coding_exception('The specified image output folder is not a valid folder');
}
$imagefile = $this->imagefolder . '/' . self::IMAGE_PAGE . $pageno . '.png';
$generate = true;
if (file_exists($imagefile)) {
if (filemtime($imagefile) > filemtime($this->filename)) {
// Make sure the image is newer than the PDF file.
$generate = false;
}
}
if ($generate) {
// Use ghostscript to generate an image of the specified page.
$gsexec = \escapeshellarg($CFG->pathtogs);
$imageres = \escapeshellarg(100);
$imagefilearg = \escapeshellarg($imagefile);
$filename = \escapeshellarg($this->filename);
$pagenoinc = \escapeshellarg($pageno + 1);
$command = "$gsexec -q -sDEVICE=png16m -dSAFER -dBATCH -dNOPAUSE -r$imageres -dFirstPage=$pagenoinc -dLastPage=$pagenoinc ".
"-dDOINTERPOLATE -dGraphicsAlphaBits=4 -dTextAlphaBits=4 -sOutputFile=$imagefilearg $filename";
$output = null;
$result = exec($command, $output);
if (!file_exists($imagefile)) {
$fullerror = '<pre>'.get_string('command', 'assignfeedback_editpdf')."\n";
$fullerror .= $command . "\n\n";
$fullerror .= get_string('result', 'assignfeedback_editpdf')."\n";
$fullerror .= htmlspecialchars($result) . "\n\n";
$fullerror .= get_string('output', 'assignfeedback_editpdf')."\n";
$fullerror .= htmlspecialchars(implode("\n", $output)) . '</pre>';
throw new \moodle_exception('errorgenerateimage', 'assignfeedback_editpdf', '', $fullerror);
}
}
return self::IMAGE_PAGE . $pageno . '.png';
} | php | public function get_image($pageno) {
global $CFG;
if (!$this->filename) {
throw new \coding_exception('Attempting to generate a page image without first setting the PDF filename');
}
if (!$this->imagefolder) {
throw new \coding_exception('Attempting to generate a page image without first specifying the image output folder');
}
if (!is_dir($this->imagefolder)) {
throw new \coding_exception('The specified image output folder is not a valid folder');
}
$imagefile = $this->imagefolder . '/' . self::IMAGE_PAGE . $pageno . '.png';
$generate = true;
if (file_exists($imagefile)) {
if (filemtime($imagefile) > filemtime($this->filename)) {
// Make sure the image is newer than the PDF file.
$generate = false;
}
}
if ($generate) {
// Use ghostscript to generate an image of the specified page.
$gsexec = \escapeshellarg($CFG->pathtogs);
$imageres = \escapeshellarg(100);
$imagefilearg = \escapeshellarg($imagefile);
$filename = \escapeshellarg($this->filename);
$pagenoinc = \escapeshellarg($pageno + 1);
$command = "$gsexec -q -sDEVICE=png16m -dSAFER -dBATCH -dNOPAUSE -r$imageres -dFirstPage=$pagenoinc -dLastPage=$pagenoinc ".
"-dDOINTERPOLATE -dGraphicsAlphaBits=4 -dTextAlphaBits=4 -sOutputFile=$imagefilearg $filename";
$output = null;
$result = exec($command, $output);
if (!file_exists($imagefile)) {
$fullerror = '<pre>'.get_string('command', 'assignfeedback_editpdf')."\n";
$fullerror .= $command . "\n\n";
$fullerror .= get_string('result', 'assignfeedback_editpdf')."\n";
$fullerror .= htmlspecialchars($result) . "\n\n";
$fullerror .= get_string('output', 'assignfeedback_editpdf')."\n";
$fullerror .= htmlspecialchars(implode("\n", $output)) . '</pre>';
throw new \moodle_exception('errorgenerateimage', 'assignfeedback_editpdf', '', $fullerror);
}
}
return self::IMAGE_PAGE . $pageno . '.png';
} | [
"public",
"function",
"get_image",
"(",
"$",
"pageno",
")",
"{",
"global",
"$",
"CFG",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"filename",
")",
"{",
"throw",
"new",
"\\",
"coding_exception",
"(",
"'Attempting to generate a page image without first setting the PDF filename'",
")",
";",
"}",
"if",
"(",
"!",
"$",
"this",
"->",
"imagefolder",
")",
"{",
"throw",
"new",
"\\",
"coding_exception",
"(",
"'Attempting to generate a page image without first specifying the image output folder'",
")",
";",
"}",
"if",
"(",
"!",
"is_dir",
"(",
"$",
"this",
"->",
"imagefolder",
")",
")",
"{",
"throw",
"new",
"\\",
"coding_exception",
"(",
"'The specified image output folder is not a valid folder'",
")",
";",
"}",
"$",
"imagefile",
"=",
"$",
"this",
"->",
"imagefolder",
".",
"'/'",
".",
"self",
"::",
"IMAGE_PAGE",
".",
"$",
"pageno",
".",
"'.png'",
";",
"$",
"generate",
"=",
"true",
";",
"if",
"(",
"file_exists",
"(",
"$",
"imagefile",
")",
")",
"{",
"if",
"(",
"filemtime",
"(",
"$",
"imagefile",
")",
">",
"filemtime",
"(",
"$",
"this",
"->",
"filename",
")",
")",
"{",
"// Make sure the image is newer than the PDF file.",
"$",
"generate",
"=",
"false",
";",
"}",
"}",
"if",
"(",
"$",
"generate",
")",
"{",
"// Use ghostscript to generate an image of the specified page.",
"$",
"gsexec",
"=",
"\\",
"escapeshellarg",
"(",
"$",
"CFG",
"->",
"pathtogs",
")",
";",
"$",
"imageres",
"=",
"\\",
"escapeshellarg",
"(",
"100",
")",
";",
"$",
"imagefilearg",
"=",
"\\",
"escapeshellarg",
"(",
"$",
"imagefile",
")",
";",
"$",
"filename",
"=",
"\\",
"escapeshellarg",
"(",
"$",
"this",
"->",
"filename",
")",
";",
"$",
"pagenoinc",
"=",
"\\",
"escapeshellarg",
"(",
"$",
"pageno",
"+",
"1",
")",
";",
"$",
"command",
"=",
"\"$gsexec -q -sDEVICE=png16m -dSAFER -dBATCH -dNOPAUSE -r$imageres -dFirstPage=$pagenoinc -dLastPage=$pagenoinc \"",
".",
"\"-dDOINTERPOLATE -dGraphicsAlphaBits=4 -dTextAlphaBits=4 -sOutputFile=$imagefilearg $filename\"",
";",
"$",
"output",
"=",
"null",
";",
"$",
"result",
"=",
"exec",
"(",
"$",
"command",
",",
"$",
"output",
")",
";",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"imagefile",
")",
")",
"{",
"$",
"fullerror",
"=",
"'<pre>'",
".",
"get_string",
"(",
"'command'",
",",
"'assignfeedback_editpdf'",
")",
".",
"\"\\n\"",
";",
"$",
"fullerror",
".=",
"$",
"command",
".",
"\"\\n\\n\"",
";",
"$",
"fullerror",
".=",
"get_string",
"(",
"'result'",
",",
"'assignfeedback_editpdf'",
")",
".",
"\"\\n\"",
";",
"$",
"fullerror",
".=",
"htmlspecialchars",
"(",
"$",
"result",
")",
".",
"\"\\n\\n\"",
";",
"$",
"fullerror",
".=",
"get_string",
"(",
"'output'",
",",
"'assignfeedback_editpdf'",
")",
".",
"\"\\n\"",
";",
"$",
"fullerror",
".=",
"htmlspecialchars",
"(",
"implode",
"(",
"\"\\n\"",
",",
"$",
"output",
")",
")",
".",
"'</pre>'",
";",
"throw",
"new",
"\\",
"moodle_exception",
"(",
"'errorgenerateimage'",
",",
"'assignfeedback_editpdf'",
",",
"''",
",",
"$",
"fullerror",
")",
";",
"}",
"}",
"return",
"self",
"::",
"IMAGE_PAGE",
".",
"$",
"pageno",
".",
"'.png'",
";",
"}"
] | Generate an image of the specified page in the PDF
@param int $pageno the page to generate the image of
@throws \moodle_exception
@throws \coding_exception
@return string the filename of the generated image | [
"Generate",
"an",
"image",
"of",
"the",
"specified",
"page",
"in",
"the",
"PDF"
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/assign/feedback/editpdf/classes/pdf.php#L540-L588 |
213,690 | moodle/moodle | mod/assign/feedback/editpdf/classes/pdf.php | pdf.get_error_image | public static function get_error_image($errorimagefolder, $pageno) {
global $CFG;
$errorfile = $CFG->dirroot . self::BLANK_PDF;
if (!file_exists($errorfile)) {
throw new \coding_exception("Blank PDF not found", "File path" . $errorfile);
}
$tmperrorimagefolder = make_request_directory();
$pdf = new pdf();
$pdf->set_pdf($errorfile);
$pdf->copy_page();
$pdf->add_comment(get_string('errorpdfpage', 'assignfeedback_editpdf'), 250, 300, 200, "red");
$generatedpdf = $tmperrorimagefolder . '/' . 'error.pdf';
$pdf->save_pdf($generatedpdf);
$pdf = new pdf();
$pdf->set_pdf($generatedpdf);
$pdf->set_image_folder($tmperrorimagefolder);
$image = $pdf->get_image(0);
$pdf->Close(); // PDF loaded and never saved/outputted needs to be closed.
$newimg = self::IMAGE_PAGE . $pageno . '.png';
copy($tmperrorimagefolder . '/' . $image, $errorimagefolder . '/' . $newimg);
return $newimg;
} | php | public static function get_error_image($errorimagefolder, $pageno) {
global $CFG;
$errorfile = $CFG->dirroot . self::BLANK_PDF;
if (!file_exists($errorfile)) {
throw new \coding_exception("Blank PDF not found", "File path" . $errorfile);
}
$tmperrorimagefolder = make_request_directory();
$pdf = new pdf();
$pdf->set_pdf($errorfile);
$pdf->copy_page();
$pdf->add_comment(get_string('errorpdfpage', 'assignfeedback_editpdf'), 250, 300, 200, "red");
$generatedpdf = $tmperrorimagefolder . '/' . 'error.pdf';
$pdf->save_pdf($generatedpdf);
$pdf = new pdf();
$pdf->set_pdf($generatedpdf);
$pdf->set_image_folder($tmperrorimagefolder);
$image = $pdf->get_image(0);
$pdf->Close(); // PDF loaded and never saved/outputted needs to be closed.
$newimg = self::IMAGE_PAGE . $pageno . '.png';
copy($tmperrorimagefolder . '/' . $image, $errorimagefolder . '/' . $newimg);
return $newimg;
} | [
"public",
"static",
"function",
"get_error_image",
"(",
"$",
"errorimagefolder",
",",
"$",
"pageno",
")",
"{",
"global",
"$",
"CFG",
";",
"$",
"errorfile",
"=",
"$",
"CFG",
"->",
"dirroot",
".",
"self",
"::",
"BLANK_PDF",
";",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"errorfile",
")",
")",
"{",
"throw",
"new",
"\\",
"coding_exception",
"(",
"\"Blank PDF not found\"",
",",
"\"File path\"",
".",
"$",
"errorfile",
")",
";",
"}",
"$",
"tmperrorimagefolder",
"=",
"make_request_directory",
"(",
")",
";",
"$",
"pdf",
"=",
"new",
"pdf",
"(",
")",
";",
"$",
"pdf",
"->",
"set_pdf",
"(",
"$",
"errorfile",
")",
";",
"$",
"pdf",
"->",
"copy_page",
"(",
")",
";",
"$",
"pdf",
"->",
"add_comment",
"(",
"get_string",
"(",
"'errorpdfpage'",
",",
"'assignfeedback_editpdf'",
")",
",",
"250",
",",
"300",
",",
"200",
",",
"\"red\"",
")",
";",
"$",
"generatedpdf",
"=",
"$",
"tmperrorimagefolder",
".",
"'/'",
".",
"'error.pdf'",
";",
"$",
"pdf",
"->",
"save_pdf",
"(",
"$",
"generatedpdf",
")",
";",
"$",
"pdf",
"=",
"new",
"pdf",
"(",
")",
";",
"$",
"pdf",
"->",
"set_pdf",
"(",
"$",
"generatedpdf",
")",
";",
"$",
"pdf",
"->",
"set_image_folder",
"(",
"$",
"tmperrorimagefolder",
")",
";",
"$",
"image",
"=",
"$",
"pdf",
"->",
"get_image",
"(",
"0",
")",
";",
"$",
"pdf",
"->",
"Close",
"(",
")",
";",
"// PDF loaded and never saved/outputted needs to be closed.",
"$",
"newimg",
"=",
"self",
"::",
"IMAGE_PAGE",
".",
"$",
"pageno",
".",
"'.png'",
";",
"copy",
"(",
"$",
"tmperrorimagefolder",
".",
"'/'",
".",
"$",
"image",
",",
"$",
"errorimagefolder",
".",
"'/'",
".",
"$",
"newimg",
")",
";",
"return",
"$",
"newimg",
";",
"}"
] | Generate an localised error image for the given pagenumber.
@param string $errorimagefolder path of the folder where error image needs to be created.
@param int $pageno page number for which error image needs to be created.
@return string File name
@throws \coding_exception | [
"Generate",
"an",
"localised",
"error",
"image",
"for",
"the",
"given",
"pagenumber",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/assign/feedback/editpdf/classes/pdf.php#L671-L697 |
213,691 | moodle/moodle | mod/assign/feedback/editpdf/classes/pdf.php | pdf.add_image_page | public function add_image_page($imagestoredfile) {
$imageinfo = $imagestoredfile->get_imageinfo();
$imagecontent = $imagestoredfile->get_content();
$this->currentpage++;
$template = $this->importPage($this->currentpage);
$size = $this->getTemplateSize($template);
if ($imageinfo["width"] > $imageinfo["height"]) {
if ($size['w'] < $size['h']) {
$temp = $size['w'];
$size['w'] = $size['h'];
$size['h'] = $temp;
}
$orientation = 'L';
} else if ($imageinfo["width"] < $imageinfo["height"]) {
if ($size['w'] > $size['h']) {
$temp = $size['w'];
$size['w'] = $size['h'];
$size['h'] = $temp;
}
$orientation = 'P';
} else {
$orientation = 'P';
}
$this->SetHeaderMargin(0);
$this->SetFooterMargin(0);
$this->SetMargins(0, 0, 0, true);
$this->setPrintFooter(false);
$this->setPrintHeader(false);
$this->AddPage($orientation, $size);
$this->SetAutoPageBreak(false, 0);
$this->Image('@' . $imagecontent, 0, 0, $size['w'], $size['h'],
'', '', '', false, null, '', false, false, 0);
} | php | public function add_image_page($imagestoredfile) {
$imageinfo = $imagestoredfile->get_imageinfo();
$imagecontent = $imagestoredfile->get_content();
$this->currentpage++;
$template = $this->importPage($this->currentpage);
$size = $this->getTemplateSize($template);
if ($imageinfo["width"] > $imageinfo["height"]) {
if ($size['w'] < $size['h']) {
$temp = $size['w'];
$size['w'] = $size['h'];
$size['h'] = $temp;
}
$orientation = 'L';
} else if ($imageinfo["width"] < $imageinfo["height"]) {
if ($size['w'] > $size['h']) {
$temp = $size['w'];
$size['w'] = $size['h'];
$size['h'] = $temp;
}
$orientation = 'P';
} else {
$orientation = 'P';
}
$this->SetHeaderMargin(0);
$this->SetFooterMargin(0);
$this->SetMargins(0, 0, 0, true);
$this->setPrintFooter(false);
$this->setPrintHeader(false);
$this->AddPage($orientation, $size);
$this->SetAutoPageBreak(false, 0);
$this->Image('@' . $imagecontent, 0, 0, $size['w'], $size['h'],
'', '', '', false, null, '', false, false, 0);
} | [
"public",
"function",
"add_image_page",
"(",
"$",
"imagestoredfile",
")",
"{",
"$",
"imageinfo",
"=",
"$",
"imagestoredfile",
"->",
"get_imageinfo",
"(",
")",
";",
"$",
"imagecontent",
"=",
"$",
"imagestoredfile",
"->",
"get_content",
"(",
")",
";",
"$",
"this",
"->",
"currentpage",
"++",
";",
"$",
"template",
"=",
"$",
"this",
"->",
"importPage",
"(",
"$",
"this",
"->",
"currentpage",
")",
";",
"$",
"size",
"=",
"$",
"this",
"->",
"getTemplateSize",
"(",
"$",
"template",
")",
";",
"if",
"(",
"$",
"imageinfo",
"[",
"\"width\"",
"]",
">",
"$",
"imageinfo",
"[",
"\"height\"",
"]",
")",
"{",
"if",
"(",
"$",
"size",
"[",
"'w'",
"]",
"<",
"$",
"size",
"[",
"'h'",
"]",
")",
"{",
"$",
"temp",
"=",
"$",
"size",
"[",
"'w'",
"]",
";",
"$",
"size",
"[",
"'w'",
"]",
"=",
"$",
"size",
"[",
"'h'",
"]",
";",
"$",
"size",
"[",
"'h'",
"]",
"=",
"$",
"temp",
";",
"}",
"$",
"orientation",
"=",
"'L'",
";",
"}",
"else",
"if",
"(",
"$",
"imageinfo",
"[",
"\"width\"",
"]",
"<",
"$",
"imageinfo",
"[",
"\"height\"",
"]",
")",
"{",
"if",
"(",
"$",
"size",
"[",
"'w'",
"]",
">",
"$",
"size",
"[",
"'h'",
"]",
")",
"{",
"$",
"temp",
"=",
"$",
"size",
"[",
"'w'",
"]",
";",
"$",
"size",
"[",
"'w'",
"]",
"=",
"$",
"size",
"[",
"'h'",
"]",
";",
"$",
"size",
"[",
"'h'",
"]",
"=",
"$",
"temp",
";",
"}",
"$",
"orientation",
"=",
"'P'",
";",
"}",
"else",
"{",
"$",
"orientation",
"=",
"'P'",
";",
"}",
"$",
"this",
"->",
"SetHeaderMargin",
"(",
"0",
")",
";",
"$",
"this",
"->",
"SetFooterMargin",
"(",
"0",
")",
";",
"$",
"this",
"->",
"SetMargins",
"(",
"0",
",",
"0",
",",
"0",
",",
"true",
")",
";",
"$",
"this",
"->",
"setPrintFooter",
"(",
"false",
")",
";",
"$",
"this",
"->",
"setPrintHeader",
"(",
"false",
")",
";",
"$",
"this",
"->",
"AddPage",
"(",
"$",
"orientation",
",",
"$",
"size",
")",
";",
"$",
"this",
"->",
"SetAutoPageBreak",
"(",
"false",
",",
"0",
")",
";",
"$",
"this",
"->",
"Image",
"(",
"'@'",
".",
"$",
"imagecontent",
",",
"0",
",",
"0",
",",
"$",
"size",
"[",
"'w'",
"]",
",",
"$",
"size",
"[",
"'h'",
"]",
",",
"''",
",",
"''",
",",
"''",
",",
"false",
",",
"null",
",",
"''",
",",
"false",
",",
"false",
",",
"0",
")",
";",
"}"
] | This function add an image file to PDF page.
@param \stored_file $imagestoredfile Image file to be added | [
"This",
"function",
"add",
"an",
"image",
"file",
"to",
"PDF",
"page",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/assign/feedback/editpdf/classes/pdf.php#L778-L812 |
213,692 | moodle/moodle | course/classes/deletecategory_form.php | core_course_deletecategory_form.validation | public function validation($data, $files) {
$errors = parent::validation($data, $files);
if (empty($data['fulldelete']) && empty($data['newparent'])) {
// When they have chosen the move option, they must specify a destination.
$errors['newparent'] = get_string('required');
}
if ($data['sure'] !== md5(serialize($this->coursecat))) {
$errors['categorylabel'] = get_string('categorymodifiedcancel');
}
return $errors;
} | php | public function validation($data, $files) {
$errors = parent::validation($data, $files);
if (empty($data['fulldelete']) && empty($data['newparent'])) {
// When they have chosen the move option, they must specify a destination.
$errors['newparent'] = get_string('required');
}
if ($data['sure'] !== md5(serialize($this->coursecat))) {
$errors['categorylabel'] = get_string('categorymodifiedcancel');
}
return $errors;
} | [
"public",
"function",
"validation",
"(",
"$",
"data",
",",
"$",
"files",
")",
"{",
"$",
"errors",
"=",
"parent",
"::",
"validation",
"(",
"$",
"data",
",",
"$",
"files",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"data",
"[",
"'fulldelete'",
"]",
")",
"&&",
"empty",
"(",
"$",
"data",
"[",
"'newparent'",
"]",
")",
")",
"{",
"// When they have chosen the move option, they must specify a destination.",
"$",
"errors",
"[",
"'newparent'",
"]",
"=",
"get_string",
"(",
"'required'",
")",
";",
"}",
"if",
"(",
"$",
"data",
"[",
"'sure'",
"]",
"!==",
"md5",
"(",
"serialize",
"(",
"$",
"this",
"->",
"coursecat",
")",
")",
")",
"{",
"$",
"errors",
"[",
"'categorylabel'",
"]",
"=",
"get_string",
"(",
"'categorymodifiedcancel'",
")",
";",
"}",
"return",
"$",
"errors",
";",
"}"
] | Perform some extra moodle validation.
@param array $data
@param array $files
@return array An array of errors. | [
"Perform",
"some",
"extra",
"moodle",
"validation",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/course/classes/deletecategory_form.php#L129-L141 |
213,693 | moodle/moodle | login/forgot_password_form.php | login_forgot_password_form.definition | function definition() {
global $USER;
$mform = $this->_form;
$mform->setDisableShortforms(true);
$mform->addElement('header', 'searchbyusername', get_string('searchbyusername'), '');
$purpose = user_edit_map_field_purpose($USER->id, 'username');
$mform->addElement('text', 'username', get_string('username'), 'size="20"' . $purpose);
$mform->setType('username', PARAM_RAW);
$submitlabel = get_string('search');
$mform->addElement('submit', 'submitbuttonusername', $submitlabel);
$mform->addElement('header', 'searchbyemail', get_string('searchbyemail'), '');
$purpose = user_edit_map_field_purpose($USER->id, 'email');
$mform->addElement('text', 'email', get_string('email'), 'maxlength="100" size="30"' . $purpose);
$mform->setType('email', PARAM_RAW_TRIMMED);
$submitlabel = get_string('search');
$mform->addElement('submit', 'submitbuttonemail', $submitlabel);
} | php | function definition() {
global $USER;
$mform = $this->_form;
$mform->setDisableShortforms(true);
$mform->addElement('header', 'searchbyusername', get_string('searchbyusername'), '');
$purpose = user_edit_map_field_purpose($USER->id, 'username');
$mform->addElement('text', 'username', get_string('username'), 'size="20"' . $purpose);
$mform->setType('username', PARAM_RAW);
$submitlabel = get_string('search');
$mform->addElement('submit', 'submitbuttonusername', $submitlabel);
$mform->addElement('header', 'searchbyemail', get_string('searchbyemail'), '');
$purpose = user_edit_map_field_purpose($USER->id, 'email');
$mform->addElement('text', 'email', get_string('email'), 'maxlength="100" size="30"' . $purpose);
$mform->setType('email', PARAM_RAW_TRIMMED);
$submitlabel = get_string('search');
$mform->addElement('submit', 'submitbuttonemail', $submitlabel);
} | [
"function",
"definition",
"(",
")",
"{",
"global",
"$",
"USER",
";",
"$",
"mform",
"=",
"$",
"this",
"->",
"_form",
";",
"$",
"mform",
"->",
"setDisableShortforms",
"(",
"true",
")",
";",
"$",
"mform",
"->",
"addElement",
"(",
"'header'",
",",
"'searchbyusername'",
",",
"get_string",
"(",
"'searchbyusername'",
")",
",",
"''",
")",
";",
"$",
"purpose",
"=",
"user_edit_map_field_purpose",
"(",
"$",
"USER",
"->",
"id",
",",
"'username'",
")",
";",
"$",
"mform",
"->",
"addElement",
"(",
"'text'",
",",
"'username'",
",",
"get_string",
"(",
"'username'",
")",
",",
"'size=\"20\"'",
".",
"$",
"purpose",
")",
";",
"$",
"mform",
"->",
"setType",
"(",
"'username'",
",",
"PARAM_RAW",
")",
";",
"$",
"submitlabel",
"=",
"get_string",
"(",
"'search'",
")",
";",
"$",
"mform",
"->",
"addElement",
"(",
"'submit'",
",",
"'submitbuttonusername'",
",",
"$",
"submitlabel",
")",
";",
"$",
"mform",
"->",
"addElement",
"(",
"'header'",
",",
"'searchbyemail'",
",",
"get_string",
"(",
"'searchbyemail'",
")",
",",
"''",
")",
";",
"$",
"purpose",
"=",
"user_edit_map_field_purpose",
"(",
"$",
"USER",
"->",
"id",
",",
"'email'",
")",
";",
"$",
"mform",
"->",
"addElement",
"(",
"'text'",
",",
"'email'",
",",
"get_string",
"(",
"'email'",
")",
",",
"'maxlength=\"100\" size=\"30\"'",
".",
"$",
"purpose",
")",
";",
"$",
"mform",
"->",
"setType",
"(",
"'email'",
",",
"PARAM_RAW_TRIMMED",
")",
";",
"$",
"submitlabel",
"=",
"get_string",
"(",
"'search'",
")",
";",
"$",
"mform",
"->",
"addElement",
"(",
"'submit'",
",",
"'submitbuttonemail'",
",",
"$",
"submitlabel",
")",
";",
"}"
] | Define the forgot password form. | [
"Define",
"the",
"forgot",
"password",
"form",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/login/forgot_password_form.php#L43-L66 |
213,694 | moodle/moodle | login/forgot_password_form.php | login_forgot_password_form.validation | function validation($data, $files) {
$errors = parent::validation($data, $files);
$errors += core_login_validate_forgot_password_data($data);
return $errors;
} | php | function validation($data, $files) {
$errors = parent::validation($data, $files);
$errors += core_login_validate_forgot_password_data($data);
return $errors;
} | [
"function",
"validation",
"(",
"$",
"data",
",",
"$",
"files",
")",
"{",
"$",
"errors",
"=",
"parent",
"::",
"validation",
"(",
"$",
"data",
",",
"$",
"files",
")",
";",
"$",
"errors",
"+=",
"core_login_validate_forgot_password_data",
"(",
"$",
"data",
")",
";",
"return",
"$",
"errors",
";",
"}"
] | Validate user input from the forgot password form.
@param array $data array of submitted form fields.
@param array $files submitted with the form.
@return array errors occuring during validation. | [
"Validate",
"user",
"input",
"from",
"the",
"forgot",
"password",
"form",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/login/forgot_password_form.php#L74-L80 |
213,695 | moodle/moodle | lib/form/duration.php | MoodleQuickForm_duration.get_units | public function get_units() {
if (is_null($this->_units)) {
$this->_units = array(
604800 => get_string('weeks'),
86400 => get_string('days'),
3600 => get_string('hours'),
60 => get_string('minutes'),
1 => get_string('seconds'),
);
}
return $this->_units;
} | php | public function get_units() {
if (is_null($this->_units)) {
$this->_units = array(
604800 => get_string('weeks'),
86400 => get_string('days'),
3600 => get_string('hours'),
60 => get_string('minutes'),
1 => get_string('seconds'),
);
}
return $this->_units;
} | [
"public",
"function",
"get_units",
"(",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"this",
"->",
"_units",
")",
")",
"{",
"$",
"this",
"->",
"_units",
"=",
"array",
"(",
"604800",
"=>",
"get_string",
"(",
"'weeks'",
")",
",",
"86400",
"=>",
"get_string",
"(",
"'days'",
")",
",",
"3600",
"=>",
"get_string",
"(",
"'hours'",
")",
",",
"60",
"=>",
"get_string",
"(",
"'minutes'",
")",
",",
"1",
"=>",
"get_string",
"(",
"'seconds'",
")",
",",
")",
";",
"}",
"return",
"$",
"this",
"->",
"_units",
";",
"}"
] | Returns time associative array of unit length.
@return array unit length in seconds => string unit name. | [
"Returns",
"time",
"associative",
"array",
"of",
"unit",
"length",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/form/duration.php#L102-L113 |
213,696 | moodle/moodle | lib/form/duration.php | MoodleQuickForm_duration._createElements | function _createElements() {
$attributes = $this->getAttributes();
if (is_null($attributes)) {
$attributes = array();
}
if (!isset($attributes['size'])) {
$attributes['size'] = 3;
}
$this->_elements = array();
// E_STRICT creating elements without forms is nasty because it internally uses $this
$number = $this->createFormElement('text', 'number', get_string('time', 'form'), $attributes, true);
$number->set_force_ltr(true);
$this->_elements[] = $number;
unset($attributes['size']);
$this->_elements[] = $this->createFormElement('select', 'timeunit', get_string('timeunit', 'form'), $this->get_units(), $attributes, true);
// If optional we add a checkbox which the user can use to turn if on
if($this->_options['optional']) {
$this->_elements[] = $this->createFormElement('checkbox', 'enabled', null, get_string('enable'), $this->getAttributes(), true);
}
foreach ($this->_elements as $element){
if (method_exists($element, 'setHiddenLabel')){
$element->setHiddenLabel(true);
}
}
} | php | function _createElements() {
$attributes = $this->getAttributes();
if (is_null($attributes)) {
$attributes = array();
}
if (!isset($attributes['size'])) {
$attributes['size'] = 3;
}
$this->_elements = array();
// E_STRICT creating elements without forms is nasty because it internally uses $this
$number = $this->createFormElement('text', 'number', get_string('time', 'form'), $attributes, true);
$number->set_force_ltr(true);
$this->_elements[] = $number;
unset($attributes['size']);
$this->_elements[] = $this->createFormElement('select', 'timeunit', get_string('timeunit', 'form'), $this->get_units(), $attributes, true);
// If optional we add a checkbox which the user can use to turn if on
if($this->_options['optional']) {
$this->_elements[] = $this->createFormElement('checkbox', 'enabled', null, get_string('enable'), $this->getAttributes(), true);
}
foreach ($this->_elements as $element){
if (method_exists($element, 'setHiddenLabel')){
$element->setHiddenLabel(true);
}
}
} | [
"function",
"_createElements",
"(",
")",
"{",
"$",
"attributes",
"=",
"$",
"this",
"->",
"getAttributes",
"(",
")",
";",
"if",
"(",
"is_null",
"(",
"$",
"attributes",
")",
")",
"{",
"$",
"attributes",
"=",
"array",
"(",
")",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"attributes",
"[",
"'size'",
"]",
")",
")",
"{",
"$",
"attributes",
"[",
"'size'",
"]",
"=",
"3",
";",
"}",
"$",
"this",
"->",
"_elements",
"=",
"array",
"(",
")",
";",
"// E_STRICT creating elements without forms is nasty because it internally uses $this",
"$",
"number",
"=",
"$",
"this",
"->",
"createFormElement",
"(",
"'text'",
",",
"'number'",
",",
"get_string",
"(",
"'time'",
",",
"'form'",
")",
",",
"$",
"attributes",
",",
"true",
")",
";",
"$",
"number",
"->",
"set_force_ltr",
"(",
"true",
")",
";",
"$",
"this",
"->",
"_elements",
"[",
"]",
"=",
"$",
"number",
";",
"unset",
"(",
"$",
"attributes",
"[",
"'size'",
"]",
")",
";",
"$",
"this",
"->",
"_elements",
"[",
"]",
"=",
"$",
"this",
"->",
"createFormElement",
"(",
"'select'",
",",
"'timeunit'",
",",
"get_string",
"(",
"'timeunit'",
",",
"'form'",
")",
",",
"$",
"this",
"->",
"get_units",
"(",
")",
",",
"$",
"attributes",
",",
"true",
")",
";",
"// If optional we add a checkbox which the user can use to turn if on",
"if",
"(",
"$",
"this",
"->",
"_options",
"[",
"'optional'",
"]",
")",
"{",
"$",
"this",
"->",
"_elements",
"[",
"]",
"=",
"$",
"this",
"->",
"createFormElement",
"(",
"'checkbox'",
",",
"'enabled'",
",",
"null",
",",
"get_string",
"(",
"'enable'",
")",
",",
"$",
"this",
"->",
"getAttributes",
"(",
")",
",",
"true",
")",
";",
"}",
"foreach",
"(",
"$",
"this",
"->",
"_elements",
"as",
"$",
"element",
")",
"{",
"if",
"(",
"method_exists",
"(",
"$",
"element",
",",
"'setHiddenLabel'",
")",
")",
"{",
"$",
"element",
"->",
"setHiddenLabel",
"(",
"true",
")",
";",
"}",
"}",
"}"
] | Override of standard quickforms method to create this element. | [
"Override",
"of",
"standard",
"quickforms",
"method",
"to",
"create",
"this",
"element",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/form/duration.php#L137-L161 |
213,697 | moodle/moodle | lib/form/duration.php | MoodleQuickForm_duration.toHtml | function toHtml() {
include_once('HTML/QuickForm/Renderer/Default.php');
$renderer = new HTML_QuickForm_Renderer_Default();
$renderer->setElementTemplate('{element}');
parent::accept($renderer);
return $renderer->toHtml();
} | php | function toHtml() {
include_once('HTML/QuickForm/Renderer/Default.php');
$renderer = new HTML_QuickForm_Renderer_Default();
$renderer->setElementTemplate('{element}');
parent::accept($renderer);
return $renderer->toHtml();
} | [
"function",
"toHtml",
"(",
")",
"{",
"include_once",
"(",
"'HTML/QuickForm/Renderer/Default.php'",
")",
";",
"$",
"renderer",
"=",
"new",
"HTML_QuickForm_Renderer_Default",
"(",
")",
";",
"$",
"renderer",
"->",
"setElementTemplate",
"(",
"'{element}'",
")",
";",
"parent",
"::",
"accept",
"(",
"$",
"renderer",
")",
";",
"return",
"$",
"renderer",
"->",
"toHtml",
"(",
")",
";",
"}"
] | Returns HTML for advchecbox form element.
@return string | [
"Returns",
"HTML",
"for",
"advchecbox",
"form",
"element",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/form/duration.php#L220-L226 |
213,698 | moodle/moodle | lib/form/duration.php | MoodleQuickForm_duration.exportValue | function exportValue(&$submitValues, $notused = false) {
// Get the values from all the child elements.
$valuearray = array();
foreach ($this->_elements as $element) {
$thisexport = $element->exportValue($submitValues[$this->getName()], true);
if (!is_null($thisexport)) {
$valuearray += $thisexport;
}
}
// Convert the value to an integer number of seconds.
if (empty($valuearray)) {
return null;
}
if ($this->_options['optional'] && empty($valuearray['enabled'])) {
return array($this->getName() => 0);
}
return array($this->getName() => $valuearray['number'] * $valuearray['timeunit']);
} | php | function exportValue(&$submitValues, $notused = false) {
// Get the values from all the child elements.
$valuearray = array();
foreach ($this->_elements as $element) {
$thisexport = $element->exportValue($submitValues[$this->getName()], true);
if (!is_null($thisexport)) {
$valuearray += $thisexport;
}
}
// Convert the value to an integer number of seconds.
if (empty($valuearray)) {
return null;
}
if ($this->_options['optional'] && empty($valuearray['enabled'])) {
return array($this->getName() => 0);
}
return array($this->getName() => $valuearray['number'] * $valuearray['timeunit']);
} | [
"function",
"exportValue",
"(",
"&",
"$",
"submitValues",
",",
"$",
"notused",
"=",
"false",
")",
"{",
"// Get the values from all the child elements.",
"$",
"valuearray",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"_elements",
"as",
"$",
"element",
")",
"{",
"$",
"thisexport",
"=",
"$",
"element",
"->",
"exportValue",
"(",
"$",
"submitValues",
"[",
"$",
"this",
"->",
"getName",
"(",
")",
"]",
",",
"true",
")",
";",
"if",
"(",
"!",
"is_null",
"(",
"$",
"thisexport",
")",
")",
"{",
"$",
"valuearray",
"+=",
"$",
"thisexport",
";",
"}",
"}",
"// Convert the value to an integer number of seconds.",
"if",
"(",
"empty",
"(",
"$",
"valuearray",
")",
")",
"{",
"return",
"null",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"_options",
"[",
"'optional'",
"]",
"&&",
"empty",
"(",
"$",
"valuearray",
"[",
"'enabled'",
"]",
")",
")",
"{",
"return",
"array",
"(",
"$",
"this",
"->",
"getName",
"(",
")",
"=>",
"0",
")",
";",
"}",
"return",
"array",
"(",
"$",
"this",
"->",
"getName",
"(",
")",
"=>",
"$",
"valuearray",
"[",
"'number'",
"]",
"*",
"$",
"valuearray",
"[",
"'timeunit'",
"]",
")",
";",
"}"
] | Output a timestamp. Give it the name of the group.
Override of standard quickforms method.
@param array $submitValues
@param bool $notused Not used.
@return array field name => value. The value is the time interval in seconds. | [
"Output",
"a",
"timestamp",
".",
"Give",
"it",
"the",
"name",
"of",
"the",
"group",
".",
"Override",
"of",
"standard",
"quickforms",
"method",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/form/duration.php#L247-L265 |
213,699 | moodle/moodle | mod/lesson/pagetypes/essay.php | lesson_page_type_essay.extract_useranswer | static public function extract_useranswer($useranswer) {
$essayinfo = unserialize($useranswer);
if (!isset($essayinfo->responseformat)) {
$essayinfo->response = text_to_html($essayinfo->response, false, false);
$essayinfo->responseformat = FORMAT_HTML;
}
return $essayinfo;
} | php | static public function extract_useranswer($useranswer) {
$essayinfo = unserialize($useranswer);
if (!isset($essayinfo->responseformat)) {
$essayinfo->response = text_to_html($essayinfo->response, false, false);
$essayinfo->responseformat = FORMAT_HTML;
}
return $essayinfo;
} | [
"static",
"public",
"function",
"extract_useranswer",
"(",
"$",
"useranswer",
")",
"{",
"$",
"essayinfo",
"=",
"unserialize",
"(",
"$",
"useranswer",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"essayinfo",
"->",
"responseformat",
")",
")",
"{",
"$",
"essayinfo",
"->",
"response",
"=",
"text_to_html",
"(",
"$",
"essayinfo",
"->",
"response",
",",
"false",
",",
"false",
")",
";",
"$",
"essayinfo",
"->",
"responseformat",
"=",
"FORMAT_HTML",
";",
"}",
"return",
"$",
"essayinfo",
";",
"}"
] | Unserialize attempt useranswer and add missing responseformat if needed
for compatibility with old records.
@param string $useranswer serialized object
@return object | [
"Unserialize",
"attempt",
"useranswer",
"and",
"add",
"missing",
"responseformat",
"if",
"needed",
"for",
"compatibility",
"with",
"old",
"records",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/lesson/pagetypes/essay.php#L58-L65 |
Subsets and Splits
Yii Code Samples
Gathers all records from test, train, and validation sets that contain the word 'yii', providing a basic filtered view of the dataset relevant to Yii-related content.