Browse Source

Fixed #13: course reset for attendance activities now works.

MOODLE_23_STABLE
Artem Andreev 13 years ago
parent
commit
175cd46bb8
  1. 2
      lang/en/attforblock.php
  2. 2
      lang/ru/attforblock.php
  3. 68
      lib.php

2
lang/en/attforblock.php

@ -17,6 +17,7 @@ $string['addsession'] = 'Add session';
$string['allcourses'] = 'All courses'; $string['allcourses'] = 'All courses';
$string['all'] = 'All'; $string['all'] = 'All';
$string['allpast'] = 'All past'; $string['allpast'] = 'All past';
$string['attendancedata'] = 'Attendance data';
$string['attendanceforthecourse'] = 'Attendance for the course'; $string['attendanceforthecourse'] = 'Attendance for the course';
$string['attendancegrade'] = 'Attendance grade'; $string['attendancegrade'] = 'Attendance grade';
$string['attendancenotstarted'] = 'Attendance has not started yet for this course'; $string['attendancenotstarted'] = 'Attendance has not started yet for this course';
@ -158,6 +159,7 @@ $string['sortedgrid'] = 'Sorted grid';
$string['sortedlist'] = 'Sorted list'; $string['sortedlist'] = 'Sorted list';
$string['startofperiod'] = 'Start of period'; $string['startofperiod'] = 'Start of period';
$string['status'] = 'Status'; $string['status'] = 'Status';
$string['statuses'] = 'Statuses';
$string['statusdeleted'] = 'Status deleted'; $string['statusdeleted'] = 'Status deleted';
$string['strftimedm'] = '%d.%m'; $string['strftimedm'] = '%d.%m';
$string['strftimedmy'] = '%d.%m.%Y'; $string['strftimedmy'] = '%d.%m.%Y';

2
lang/ru/attforblock.php

@ -17,6 +17,7 @@ $string['addsession'] = 'Добавить занятие';
$string['all'] = 'Все'; $string['all'] = 'Все';
$string['allcourses'] = 'Все курсы'; $string['allcourses'] = 'Все курсы';
$string['allpast'] = 'Все прошедшие'; $string['allpast'] = 'Все прошедшие';
$string['attendancedata'] = 'Информация о посещаемости';
$string['attendanceforthecourse'] = 'Посещаемость для курса'; $string['attendanceforthecourse'] = 'Посещаемость для курса';
$string['attendancegrade'] = 'Оценка за посещаемость'; $string['attendancegrade'] = 'Оценка за посещаемость';
$string['attendancenotstarted'] = 'Пока нет отметок о посещаемости в данном курсе.'; $string['attendancenotstarted'] = 'Пока нет отметок о посещаемости в данном курсе.';
@ -145,6 +146,7 @@ $string['sortedgrid'] = 'Таблица';
$string['sortedlist'] = 'Список'; $string['sortedlist'] = 'Список';
$string['startofperiod'] = 'Начало периода'; $string['startofperiod'] = 'Начало периода';
$string['status'] = 'Статус'; $string['status'] = 'Статус';
$string['statuses'] = 'Статусы';
$string['statusdeleted'] = 'Статус удален'; $string['statusdeleted'] = 'Статус удален';
$string['strftimedm'] = '%d.%m'; $string['strftimedm'] = '%d.%m';
$string['strftimedmy'] = '%d.%m.%Y'; $string['strftimedmy'] = '%d.%m.%Y';

68
lib.php

@ -28,6 +28,17 @@ function attforblock_supports($feature) {
} }
} }
function att_add_default_statuses($attid) {
global $DB;
$statuses = $DB->get_records('attendance_statuses', array('attendanceid'=> 0), 'id');
foreach($statuses as $st) {
$rec = $st;
$rec->attendanceid = $attid;
$DB->insert_record('attendance_statuses', $rec);
}
}
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
@ -40,12 +51,7 @@ 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('attendanceid'=> 0), 'id'); att_add_default_statuses($attforblock->id);
foreach($statuses as $st) {
$rec = $st;
$rec->attendanceid = $attforblock->id;
$DB->insert_record('attendance_statuses', $rec);
}
attforblock_grade_item_update($attforblock); attforblock_grade_item_update($attforblock);
// attforblock_update_grades($attforblock); // attforblock_update_grades($attforblock);
@ -138,24 +144,50 @@ function attforblock_reset_course_form_defaults($course) {
function attforblock_reset_userdata($data) { function attforblock_reset_userdata($data) {
global $DB; global $DB;
$status = array();
$attids = array_keys($DB->get_records('attforblock', array('course'=> $data->courseid), '', 'id'));
if (!empty($data->reset_attendance_log)) { if (!empty($data->reset_attendance_log)) {
$sess = $DB->get_records('attendance_sessions', array('courseid'=> $data->courseid), '', 'id'); $sess = $DB->get_records_list('attendance_sessions', 'attendanceid', $attids, '', 'id');
$slist = implode(',', array_keys($sess)); if (!empty($sess)) {
$DB->delete_records_select('attendance_log', "sessionid IN ($slist)"); list($sql, $params) = $DB->get_in_or_equal(array_keys($sess));
$DB->set_field('attendance_sessions', 'lasttaken', 0, array('courseid' => $data->courseid)); $DB->delete_records_select('attendance_log', "sessionid $sql", $params);
list($sql, $params) = $DB->get_in_or_equal($attids);
$DB->set_field_select('attendance_sessions', 'lasttaken', 0, "attendanceid $sql", $params);
$status[] = array(
'component' => get_string('modulenameplural', 'attforblock'),
'item' => get_string('attendancedata', 'attforblock'),
'error' => false
);
}
} }
if (!empty($data->reset_attendance_statuses)) { if (!empty($data->reset_attendance_statuses)) {
$DB->delete_records('attendance_statuses', array('courseid'=> $data->courseid)); $DB->delete_records_list('attendance_statuses', 'attendanceid', $attids);
$statuses = $DB->get_records('attendance_statuses', array('courseid'=> 0), 'id'); foreach($attids as $attid) {
foreach($statuses as $stat) { att_add_default_statuses($attid);
$rec = $stat; }
$rec->courseid = $data->courseid;
$DB->insert_record('attendance_statuses', $rec); $status[] = array(
} 'component' => get_string('modulenameplural', 'attforblock'),
'item' => get_string('sessions', 'attforblock'),
'error' => false
);
} }
if (!empty($data->reset_attendance_sessions)) { if (!empty($data->reset_attendance_sessions)) {
$DB->delete_records('attendance_sessions', array('courseid'=> $data->courseid)); $DB->delete_records_list('attendance_sessions', 'attendanceid', $attids);
$status[] = array(
'component' => get_string('modulenameplural', 'attforblock'),
'item' => get_string('statuses', 'attforblock'),
'error' => false
);
} }
return $status;
} }
function attforblock_user_outline($course, $user, $mod, $attforblock) { function attforblock_user_outline($course, $user, $mod, $attforblock) {

Loading…
Cancel
Save