Browse Source

Use attendance-id instead of cmid in warning table.

MOODLE_32_STABLE
Dan Marsden 7 years ago
parent
commit
fe20e88964
  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

@ -421,5 +421,24 @@ function xmldb_attendance_upgrade($oldversion=0) {
// Attendance savepoint reached.
upgrade_mod_savepoint(true, 2016121319, 'attendance');
}
if ($oldversion < 2016121321) {
// 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, 2016121321, 'attendance');
}
return $result;
}

8
lib.php

@ -72,9 +72,9 @@ function att_add_default_statuses($attid) {
/**
* 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;
require_once($CFG->dirroot.'/mod/attendance/locallib.php');
@ -82,7 +82,7 @@ function attendance_add_default_warnings($cmid) {
array('idnumber' => 0), 'id');
foreach ($warnings as $n) {
$rec = $n;
$rec->idnumber = $cmid;
$rec->idnumber = $id;
$DB->insert_record('attendance_warning', $rec);
}
$warnings->close();
@ -103,7 +103,7 @@ function attendance_add_instance($attendance) {
att_add_default_statuses($attendance->id);
attendance_add_default_warnings($attendance->coursemodule);
attendance_add_default_warnings($attendance->id);
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 {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_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
JOIN (SELECT attendanceid, setnumber, MAX(grade) AS maxgrade
FROM {attendance_statuses}

2
version.php

@ -23,7 +23,7 @@
*/
defined('MOODLE_INTERNAL') || die();
$plugin->version = 2016121320;
$plugin->version = 2016121321;
$plugin->requires = 2016111800;
$plugin->release = '3.2.16';
$plugin->maturity = MATURITY_STABLE;

8
warnings.php

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

Loading…
Cancel
Save