Browse Source

Better attendaces deleting in attforblock_update_instance and attforblock_delete_course

MOODLE_23_STABLE
Artem Andreev 14 years ago
parent
commit
fdb4af1f2b
  1. 50
      lib.php

50
lib.php

@ -26,25 +26,6 @@ function attforblock_supports($feature) {
} }
} }
function attforblock_install() {
global $DB;
$result = true;
$arr = array('P' => 2, 'A' => 0, 'L' => 1, 'E' => 1);
foreach ($arr as $k => $v) {
unset($rec);
$rec->courseid = 0;
$rec->acronym = get_string($k.'acronym', 'attforblock');
$rec->description = get_string($k.'full', 'attforblock');
$rec->grade = $v;
$rec->visible = 1;
$rec->deleted = 0;
$result = $result && $DB->insert_record('attendance_statuses', $rec);
}
return $result;
}
function attforblock_add_instance($attforblock) { function attforblock_add_instance($attforblock) {
/// Given an object containing all the necessary data, /// Given an object containing all the necessary data,
/// (defined by the form in mod.html) this function /// (defined by the form in mod.html) this function
@ -57,10 +38,9 @@ function attforblock_add_instance($attforblock) {
$attforblock->id = $DB->insert_record('attforblock', $attforblock); $attforblock->id = $DB->insert_record('attforblock', $attforblock);
$statuses = $DB->get_records('attendance_statuses', array('courseid'=> 0), 'id'); $statuses = $DB->get_records('attendance_statuses', array('attendanceid'=> 0), 'id');
foreach($statuses as $st) { foreach($statuses as $st) {
$rec = $st; $rec = $st;
$rec->courseid = $attforblock->course;
$rec->attendanceid = $attforblock->id; $rec->attendanceid = $attforblock->id;
$DB->insert_record('attendance_statuses', $rec); $DB->insert_record('attendance_statuses', $rec);
} }
@ -92,19 +72,14 @@ function attforblock_update_instance($attforblock) {
function attforblock_delete_instance($id) { function attforblock_delete_instance($id) {
/// Given an ID of an instance of this module,
/// this function will permanently delete the instance
/// and any data that depends on it.
global $DB; global $DB;
if (! $attforblock = $DB->get_record('attforblock', array('id'=> $id))) { if (! $attforblock = $DB->get_record('attforblock', array('id'=> $id))) {
return false; return false;
} }
if ($sess = $DB->get_records('attendance_sessions', array('attendanceid'=> $id), '', 'id')) { if ($sessids = array_keys($DB->get_records('attendance_sessions', array('attendanceid'=> $id), '', 'id'))) {
$slist = implode(',', array_keys($sess)); $DB->delete_records_list('attendance_log', 'sessionid', $sessids);
$DB->delete_records_select('attendance_log', "sessionid IN ($slist)");
$DB->delete_records('attendance_sessions', array('attendanceid'=> $id)); $DB->delete_records('attendance_sessions', array('attendanceid'=> $id));
} }
$DB->delete_records('attendance_statuses', array('attendanceid'=> $id)); $DB->delete_records('attendance_statuses', array('attendanceid'=> $id));
@ -117,20 +92,17 @@ function attforblock_delete_instance($id) {
} }
function attforblock_delete_course($course, $feedback=true){ function attforblock_delete_course($course, $feedback=true){
global $DB; global $DB;
if ($sess = $DB->get_records('attendance_sessions', array('courseid'=> $course->id), '', 'id')) { $attids = array_keys($DB->get_records('attforblock', array('course'=> $course->id), '', 'id'));
$slist = implode(',', array_keys($sess)); $sessids = array_keys($DB->get_records_list('attendance_sessions', 'attendanceid', $attids, '', 'id'));
$DB->delete_records_select('attendance_log', "sessionid IN ($slist)"); if ($sessids)
$DB->delete_records('attendance_sessions', array('courseid'=> $course->id)); $DB->delete_records_list('attendance_log', 'sessionid', $sessids);
if ($attids) {
$DB->delete_records_list('attendance_statuses', 'attendanceid', $attids);
$DB->delete_records_list('attendance_sessions', 'attendanceid', $attids);
} }
$DB->delete_records('attendance_statuses', array('courseid'=> $course->id)); $DB->delete_records('attforblock', array('course'=> $course->id));
//Inform about changes performed if feedback is enabled
// if ($feedback) {
// notify(get_string('deletedefaults', 'lesson', $count));
// }
return true; return true;
} }

Loading…
Cancel
Save