Browse Source

Use attendance-id instead of cmid in warning table.

MOODLE_34_STABLE
Dan Marsden 7 years ago
parent
commit
a9eb008211
  1. 19
      db/upgrade.php
  2. 8
      lib.php
  3. 2
      locallib.php
  4. 2
      version.php
  5. 8
      warnings.php

19
db/upgrade.php

@ -434,5 +434,24 @@ function xmldb_attendance_upgrade($oldversion=0) {
// Attendance savepoint reached. // Attendance savepoint reached.
upgrade_mod_savepoint(true, 2017071802, 'attendance'); upgrade_mod_savepoint(true, 2017071802, 'attendance');
} }
if ($oldversion < 2017082200) {
// Warnings idnumber field should use attendanceid instead of cmid.
$sql = "SELECT cm.id, cm.instance
FROM {course_modules} cm
JOIN {modules} md ON md.id = cm.module AND md.name = 'attendance'";
$idnumbers = $DB->get_records_sql_menu($sql);
$warnings = $DB->get_recordset('attendance_warning');
foreach ($warnings as $warning) {
if (!empty($warning->idnumber) && !empty($idnumbers[$warning->idnumber])) {
$warning->idnumber = $idnumbers[$warning->idnumber];
$DB->update_record("attendance_warning", $warning);
}
}
$warnings->close();
// Attendance savepoint reached.
upgrade_mod_savepoint(true, 2017082200, 'attendance');
}
return $result; return $result;
} }

8
lib.php

@ -72,9 +72,9 @@ function att_add_default_statuses($attid) {
/** /**
* Add default set of warnings to the new attendance. * Add default set of warnings to the new attendance.
* *
* @param int $attid - id of attendance instance. * @param int $id - id of attendance instance.
*/ */
function attendance_add_default_warnings($cmid) { function attendance_add_default_warnings($id) {
global $DB, $CFG; global $DB, $CFG;
require_once($CFG->dirroot.'/mod/attendance/locallib.php'); require_once($CFG->dirroot.'/mod/attendance/locallib.php');
@ -82,7 +82,7 @@ function attendance_add_default_warnings($cmid) {
array('idnumber' => 0), 'id'); array('idnumber' => 0), 'id');
foreach ($warnings as $n) { foreach ($warnings as $n) {
$rec = $n; $rec = $n;
$rec->idnumber = $cmid; $rec->idnumber = $id;
$DB->insert_record('attendance_warning', $rec); $DB->insert_record('attendance_warning', $rec);
} }
$warnings->close(); $warnings->close();
@ -103,7 +103,7 @@ function attendance_add_instance($attendance) {
att_add_default_statuses($attendance->id); att_add_default_statuses($attendance->id);
attendance_add_default_warnings($attendance->coursemodule); attendance_add_default_warnings($attendance->id);
attendance_grade_item_update($attendance); attendance_grade_item_update($attendance);

2
locallib.php

@ -755,7 +755,7 @@ function attendance_get_users_to_notify($courseids = array(), $orderby = '', $al
JOIN {attendance_log} atl ON (atl.sessionid = ats.id) JOIN {attendance_log} atl ON (atl.sessionid = ats.id)
JOIN {user} u ON (u.id = atl.studentid) JOIN {user} u ON (u.id = atl.studentid)
JOIN {attendance_statuses} stg ON (stg.id = atl.statusid AND stg.deleted = 0 AND stg.visible = 1) JOIN {attendance_statuses} stg ON (stg.id = atl.statusid AND stg.deleted = 0 AND stg.visible = 1)
JOIN {attendance_warning} n ON n.idnumber = cm.id JOIN {attendance_warning} n ON n.idnumber = a.id
LEFT JOIN {attendance_warning_done} ns ON ns.notifyid = n.id AND ns.userid = atl.studentid LEFT JOIN {attendance_warning_done} ns ON ns.notifyid = n.id AND ns.userid = atl.studentid
JOIN (SELECT attendanceid, setnumber, MAX(grade) AS maxgrade JOIN (SELECT attendanceid, setnumber, MAX(grade) AS maxgrade
FROM {attendance_statuses} FROM {attendance_statuses}

2
version.php

@ -23,7 +23,7 @@
*/ */
defined('MOODLE_INTERNAL') || die(); defined('MOODLE_INTERNAL') || die();
$plugin->version = 2017072100; $plugin->version = 2017082200;
$plugin->requires = 2017042100; $plugin->requires = 2017042100;
$plugin->release = '3.3.11'; $plugin->release = '3.3.11';
$plugin->maturity = MATURITY_ALPHA; $plugin->maturity = MATURITY_ALPHA;

8
warnings.php

@ -79,7 +79,7 @@ if ($data = $mform->get_data()) {
if (empty($id)) { if (empty($id)) {
$notify->idnumber = 0; $notify->idnumber = 0;
} else { } else {
$notify->idnumber = $cm->id; $notify->idnumber = $att->id;
} }
$notify->warningpercent = $data->warningpercent; $notify->warningpercent = $data->warningpercent;
@ -105,7 +105,7 @@ if ($data = $mform->get_data()) {
} else { } else {
$notify = $DB->get_record('attendance_warning', array('id' => $data->notid)); $notify = $DB->get_record('attendance_warning', array('id' => $data->notid));
if (!empty($id) && $data->idnumber != $id) { if (!empty($id) && $data->idnumber != $att->id) {
// Someone is trying to update a record for a different attendance. // Someone is trying to update a record for a different attendance.
print_error('invalidcoursemodule'); print_error('invalidcoursemodule');
} else { } else {
@ -146,7 +146,7 @@ if ($action == 'delete' && !empty($notid)) {
$params = array('id' => $notid); $params = array('id' => $notid);
if (!empty($id)) { if (!empty($id)) {
// Add id/level to array. // Add id/level to array.
$params['idnumber'] = $cm->id; $params['idnumber'] = $id;
} }
$DB->delete_records('attendance_warning', $params); $DB->delete_records('attendance_warning', $params);
echo $OUTPUT->notification(get_string('warningdeleted', 'mod_attendance'), 'success'); echo $OUTPUT->notification(get_string('warningdeleted', 'mod_attendance'), 'success');
@ -173,7 +173,7 @@ if ($action == 'update' && !empty($notid)) {
'warningpercent'); 'warningpercent');
} else { } else {
$existingnotifications = $DB->get_records('attendance_warning', $existingnotifications = $DB->get_records('attendance_warning',
array('idnumber' => $cm->id), array('idnumber' => $att->id),
'warningpercent'); 'warningpercent');
} }
if (!empty($existingnotifications)) { if (!empty($existingnotifications)) {

Loading…
Cancel
Save