mirror of
https://github.com/moodle/moodle.git
synced 2025-04-15 13:33:52 +02:00
MDL-81872 glossary: Fix coding style
This commit is contained in:
parent
2d595135b6
commit
4a02c6de5d
@ -2861,7 +2861,7 @@ function glossary_reset_userdata($data) {
|
||||
require_once($CFG->dirroot.'/rating/lib.php');
|
||||
|
||||
$componentstr = get_string('modulenameplural', 'glossary');
|
||||
$status = array();
|
||||
$status = [];
|
||||
|
||||
$allentriessql = "SELECT e.id
|
||||
FROM {glossary_entries} e
|
||||
@ -2872,7 +2872,7 @@ function glossary_reset_userdata($data) {
|
||||
FROM {glossary} g
|
||||
WHERE g.course = ?";
|
||||
|
||||
$params = array($data->courseid);
|
||||
$params = [$data->courseid];
|
||||
|
||||
$fs = get_file_storage();
|
||||
|
||||
@ -2881,7 +2881,7 @@ function glossary_reset_userdata($data) {
|
||||
$ratingdeloptions->component = 'mod_glossary';
|
||||
$ratingdeloptions->ratingarea = 'entry';
|
||||
|
||||
// delete entries if requested
|
||||
// Delete entries if requested.
|
||||
if (!empty($data->reset_glossary_all)
|
||||
or (!empty($data->reset_glossary_types) and in_array('main', $data->reset_glossary_types) and in_array('secondary', $data->reset_glossary_types))) {
|
||||
|
||||
@ -2890,7 +2890,7 @@ function glossary_reset_userdata($data) {
|
||||
$DB->delete_records_select('glossary_alias', "entryid IN ($allentriessql)", $params);
|
||||
$DB->delete_records_select('glossary_entries', "glossaryid IN ($allglossariessql)", $params);
|
||||
|
||||
// now get rid of all attachments
|
||||
// Now get rid of all attachments.
|
||||
if ($glossaries = $DB->get_records_sql($allglossariessql, $params)) {
|
||||
foreach ($glossaries as $glossaryid=>$unused) {
|
||||
if (!$cm = get_coursemodule_from_instance('glossary', $glossaryid)) {
|
||||
@ -2899,7 +2899,7 @@ function glossary_reset_userdata($data) {
|
||||
$context = context_module::instance($cm->id);
|
||||
$fs->delete_area_files($context->id, 'mod_glossary', 'attachment');
|
||||
|
||||
//delete ratings
|
||||
// Delete ratings.
|
||||
$ratingdeloptions->contextid = $context->id;
|
||||
$rm->delete_ratings($ratingdeloptions);
|
||||
|
||||
@ -2907,18 +2907,22 @@ function glossary_reset_userdata($data) {
|
||||
}
|
||||
}
|
||||
|
||||
// remove all grades from gradebook
|
||||
// Remove all grades from gradebook.
|
||||
if (empty($data->reset_gradebook_grades)) {
|
||||
glossary_reset_gradebook($data->courseid);
|
||||
}
|
||||
|
||||
$status[] = array('component'=>$componentstr, 'item'=>get_string('resetglossariesall', 'glossary'), 'error'=>false);
|
||||
$status[] = [
|
||||
'component' => $componentstr,
|
||||
'item' => get_string('resetglossariesall', 'glossary'),
|
||||
'error' => false,
|
||||
];
|
||||
|
||||
} else if (!empty($data->reset_glossary_types)) {
|
||||
$mainentriessql = "$allentriessql AND g.mainglossary=1";
|
||||
$secondaryentriessql = "$allentriessql AND g.mainglossary=0";
|
||||
$mainentriessql = "$allentriessql AND g.mainglossary=1";
|
||||
$secondaryentriessql = "$allentriessql AND g.mainglossary=0";
|
||||
|
||||
$mainglossariessql = "$allglossariessql AND g.mainglossary=1";
|
||||
$mainglossariessql = "$allglossariessql AND g.mainglossary=1";
|
||||
$secondaryglossariessql = "$allglossariessql AND g.mainglossary=0";
|
||||
|
||||
if (in_array('main', $data->reset_glossary_types)) {
|
||||
@ -2934,7 +2938,7 @@ function glossary_reset_userdata($data) {
|
||||
$context = context_module::instance($cm->id);
|
||||
$fs->delete_area_files($context->id, 'mod_glossary', 'attachment');
|
||||
|
||||
//delete ratings
|
||||
// Delete ratings.
|
||||
$ratingdeloptions->contextid = $context->id;
|
||||
$rm->delete_ratings($ratingdeloptions);
|
||||
|
||||
@ -2942,18 +2946,22 @@ function glossary_reset_userdata($data) {
|
||||
}
|
||||
}
|
||||
|
||||
// remove all grades from gradebook
|
||||
// Remove all grades from gradebook.
|
||||
if (empty($data->reset_gradebook_grades)) {
|
||||
glossary_reset_gradebook($data->courseid, 'main');
|
||||
}
|
||||
|
||||
$status[] = array('component'=>$componentstr, 'item'=>get_string('resetglossaries', 'glossary').': '.get_string('mainglossary', 'glossary'), 'error'=>false);
|
||||
$status[] = [
|
||||
'component' => $componentstr,
|
||||
'item' => get_string('resetglossaries', 'glossary').': '.get_string('mainglossary', 'glossary'),
|
||||
'error' => false,
|
||||
];
|
||||
|
||||
} else if (in_array('secondary', $data->reset_glossary_types)) {
|
||||
$params[] = 'glossary_entry';
|
||||
$DB->delete_records_select('comments', "itemid IN ($secondaryentriessql) AND commentarea=?", $params);
|
||||
$DB->delete_records_select('glossary_entries', "glossaryid IN ($secondaryglossariessql)", $params);
|
||||
// remove exported source flag from entries in main glossary
|
||||
// Remove exported source flag from entries in main glossary.
|
||||
$DB->execute("UPDATE {glossary_entries}
|
||||
SET sourceglossaryid=0
|
||||
WHERE glossaryid IN ($mainglossariessql)", $params);
|
||||
@ -2966,7 +2974,7 @@ function glossary_reset_userdata($data) {
|
||||
$context = context_module::instance($cm->id);
|
||||
$fs->delete_area_files($context->id, 'mod_glossary', 'attachment');
|
||||
|
||||
//delete ratings
|
||||
// Delete ratings.
|
||||
$ratingdeloptions->contextid = $context->id;
|
||||
$rm->delete_ratings($ratingdeloptions);
|
||||
|
||||
@ -2974,16 +2982,20 @@ function glossary_reset_userdata($data) {
|
||||
}
|
||||
}
|
||||
|
||||
// remove all grades from gradebook
|
||||
// Remove all grades from gradebook.
|
||||
if (empty($data->reset_gradebook_grades)) {
|
||||
glossary_reset_gradebook($data->courseid, 'secondary');
|
||||
}
|
||||
|
||||
$status[] = array('component'=>$componentstr, 'item'=>get_string('resetglossaries', 'glossary').': '.get_string('secondaryglossary', 'glossary'), 'error'=>false);
|
||||
$status[] = [
|
||||
'component' => $componentstr,
|
||||
'item' => get_string('resetglossaries', 'glossary').': '.get_string('secondaryglossary', 'glossary'),
|
||||
'error' => false,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
// remove entries by users not enrolled into course
|
||||
// Remove entries by users not enrolled into course.
|
||||
if (!empty($data->reset_glossary_notenrolled)) {
|
||||
$entriessql = "SELECT e.id, e.userid, e.glossaryid, u.id AS userexists, u.deleted AS userdeleted
|
||||
FROM {glossary_entries} e
|
||||
@ -2991,15 +3003,15 @@ function glossary_reset_userdata($data) {
|
||||
LEFT JOIN {user} u ON e.userid = u.id
|
||||
WHERE g.course = ? AND e.userid > 0";
|
||||
|
||||
$course_context = context_course::instance($data->courseid);
|
||||
$notenrolled = array();
|
||||
$coursecontext = context_course::instance($data->courseid);
|
||||
$notenrolled = [];
|
||||
$rs = $DB->get_recordset_sql($entriessql, $params);
|
||||
if ($rs->valid()) {
|
||||
foreach ($rs as $entry) {
|
||||
if (array_key_exists($entry->userid, $notenrolled) or !$entry->userexists or $entry->userdeleted
|
||||
or !is_enrolled($course_context , $entry->userid)) {
|
||||
$DB->delete_records('comments', array('commentarea'=>'glossary_entry', 'itemid'=>$entry->id));
|
||||
$DB->delete_records('glossary_entries', array('id'=>$entry->id));
|
||||
if (array_key_exists($entry->userid, $notenrolled) || !$entry->userexists || $entry->userdeleted
|
||||
|| !is_enrolled($coursecontext , $entry->userid)) {
|
||||
$DB->delete_records('comments', ['commentarea' => 'glossary_entry', 'itemid' => $entry->id]);
|
||||
$DB->delete_records('glossary_entries', ['id' => $entry->id]);
|
||||
|
||||
if ($cm = get_coursemodule_from_instance('glossary', $entry->glossaryid)) {
|
||||
$context = context_module::instance($cm->id);
|
||||
@ -3011,14 +3023,18 @@ function glossary_reset_userdata($data) {
|
||||
}
|
||||
}
|
||||
}
|
||||
$status[] = array('component'=>$componentstr, 'item'=>get_string('deletenotenrolled', 'glossary'), 'error'=>false);
|
||||
$status[] = [
|
||||
'component' => $componentstr,
|
||||
'item' => get_string('deletenotenrolled', 'glossary'),
|
||||
'error' => false,
|
||||
];
|
||||
}
|
||||
$rs->close();
|
||||
}
|
||||
|
||||
// remove all ratings
|
||||
// Remove all ratings.
|
||||
if (!empty($data->reset_glossary_ratings)) {
|
||||
//remove ratings
|
||||
// Remove ratings.
|
||||
if ($glossaries = $DB->get_records_sql($allglossariessql, $params)) {
|
||||
foreach ($glossaries as $glossaryid=>$unused) {
|
||||
if (!$cm = get_coursemodule_from_instance('glossary', $glossaryid)) {
|
||||
@ -3026,24 +3042,32 @@ function glossary_reset_userdata($data) {
|
||||
}
|
||||
$context = context_module::instance($cm->id);
|
||||
|
||||
//delete ratings
|
||||
// Delete ratings.
|
||||
$ratingdeloptions->contextid = $context->id;
|
||||
$rm->delete_ratings($ratingdeloptions);
|
||||
}
|
||||
}
|
||||
|
||||
// remove all grades from gradebook
|
||||
// Remove all grades from gradebook.
|
||||
if (empty($data->reset_gradebook_grades)) {
|
||||
glossary_reset_gradebook($data->courseid);
|
||||
}
|
||||
$status[] = array('component'=>$componentstr, 'item'=>get_string('deleteallratings'), 'error'=>false);
|
||||
$status[] = [
|
||||
'component' => $componentstr,
|
||||
'item' => get_string('deleteallratings'),
|
||||
'error' => false,
|
||||
];
|
||||
}
|
||||
|
||||
// remove comments
|
||||
// Remove comments.
|
||||
if (!empty($data->reset_glossary_comments)) {
|
||||
$params[] = 'glossary_entry';
|
||||
$DB->delete_records_select('comments', "itemid IN ($allentriessql) AND commentarea= ? ", $params);
|
||||
$status[] = array('component'=>$componentstr, 'item'=>get_string('deleteallcomments'), 'error'=>false);
|
||||
$status[] = [
|
||||
'component' => $componentstr,
|
||||
'item' => get_string('deleteallcomments'),
|
||||
'error' => false,
|
||||
];
|
||||
}
|
||||
|
||||
// Remove all the tags.
|
||||
@ -3059,15 +3083,23 @@ function glossary_reset_userdata($data) {
|
||||
}
|
||||
}
|
||||
|
||||
$status[] = array('component' => $componentstr, 'item' => get_string('tagsdeleted', 'glossary'), 'error' => false);
|
||||
$status[] = [
|
||||
'component' => $componentstr,
|
||||
'item' => get_string('tagsdeleted', 'glossary'),
|
||||
'error' => false,
|
||||
];
|
||||
}
|
||||
|
||||
/// updating dates - shift may be negative too
|
||||
// Updating dates - shift may be negative too.
|
||||
if ($data->timeshift) {
|
||||
// Any changes to the list of dates that needs to be rolled should be same during course restore and course reset.
|
||||
// See MDL-9367.
|
||||
shift_course_mod_dates('glossary', array('assesstimestart', 'assesstimefinish'), $data->timeshift, $data->courseid);
|
||||
$status[] = array('component'=>$componentstr, 'item'=>get_string('datechanged'), 'error'=>false);
|
||||
shift_course_mod_dates('glossary', ['assesstimestart', 'assesstimefinish'], $data->timeshift, $data->courseid);
|
||||
$status[] = [
|
||||
'component' => $componentstr,
|
||||
'item' => get_string('datechanged'),
|
||||
'error' => false,
|
||||
];
|
||||
}
|
||||
|
||||
return $status;
|
||||
|
Loading…
x
Reference in New Issue
Block a user