Browse Source

Fixes #143 Include action to delete all hidden sections

MOODLE_29_STABLE
Antonio Carlos Mariani 9 years ago
committed by Dan Marsden
parent
commit
1f2842f206
  1. 7
      lang/en/attendance.php
  2. 19
      locallib.php
  3. 10
      renderer.php
  4. 23
      sessions.php

7
lang/en/attendance.php

@ -301,3 +301,10 @@ $string['lowgrade'] = 'Low grade';
$string['submitattendance'] = 'Submit attendance';
$string['attendancenotset'] = 'You must set your attendance';
$string['export'] = 'Export';
$string['points'] = 'Points';
$string['unknowngroup'] = 'Unknown group';
$string['notmember'] = 'not member';
$string['deletehiddensessions'] = 'Delete all hidden sessions';
$string['confirmdeletehiddensessions'] = 'Are you sure you want to delete {$a->count} sessions scheduled before the course start date ({$a->date})?';
$string['hiddensessionsdeleted'] = 'All hidden sessions were delete';

19
locallib.php

@ -276,6 +276,7 @@ class att_sessions_page_params {
const ACTION_DELETE = 3;
const ACTION_DELETE_SELECTED = 4;
const ACTION_CHANGE_DURATION = 5;
const ACTION_DELETE_HIDDEN = 6;
/** @var int view mode of taking attendance page*/
public $action;
@ -573,6 +574,24 @@ class attendance {
return $DB->count_records_select('attendance_sessions', $where, $params);
}
/**
* Returns the hidden sessions for this attendance
*
* Fetches data from {attendance_sessions}
*
* @return hidden sessions
*/
public function get_hidden_sessions() {
global $DB;
$where = "attendanceid = :aid AND sessdate < :csdate";
$params = array(
'aid' => $this->id,
'csdate'=> $this->course->startdate);
return $DB->get_records_select('attendance_sessions', $where, $params);
}
public function get_filtered_sessions() {
global $DB;

10
renderer.php

@ -283,6 +283,8 @@ class mod_attendance_renderer extends plugin_renderer_base {
}
protected function render_sess_manage_control(attendance_manage_data $sessdata) {
global $OUTPUT;
$table = new html_table();
$table->attributes['class'] = ' ';
$table->width = '100%';
@ -292,6 +294,14 @@ class mod_attendance_renderer extends plugin_renderer_base {
get_string('hiddensessions', 'attendance').': '.$sessdata->hiddensessionscount);
if (has_capability('mod/attendance:manageattendances', $sessdata->att->context)) {
if ($sessdata->hiddensessionscount > 0) {
$attributes = array(
'type' => 'submit',
'name' => 'deletehiddensessions',
'value' => get_string('deletehiddensessions', 'attendance'));
$table->data[1][] = html_writer::empty_tag('input', $attributes);
}
$options = array(
att_sessions_page_params::ACTION_DELETE_SELECTED => get_string('delete'),
att_sessions_page_params::ACTION_CHANGE_DURATION => get_string('changeduration', 'attendance'));

23
sessions.php

@ -33,6 +33,10 @@ $pageparams = new att_sessions_page_params();
$id = required_param('id', PARAM_INT);
$pageparams->action = required_param('action', PARAM_INT);
if (optional_param('deletehiddensessions', false, PARAM_TEXT)) {
$pageparams->action = att_sessions_page_params::ACTION_DELETE_HIDDEN;
}
if (empty($pageparams->action)) {
// The form on manage.php can submit with the "choose" option - this should be fixed in the long term,
// but in the meantime show a useful error and redirect when it occurs.
@ -175,6 +179,25 @@ switch ($att->pageparams->action) {
}
break;
case att_sessions_page_params::ACTION_DELETE_HIDDEN:
$confirm = optional_param('confirm', null, PARAM_INT);
if ($confirm && confirm_sesskey()) {
$sessions = $att->get_hidden_sessions();
$att->delete_sessions(array_keys($sessions));
redirect($att->url_manage(), get_string('hiddensessionsdeleted', 'attendance'));
}
$a = new stdClass();
$a->count = $att->get_hidden_sessions_count();
$a->date = userdate($course->startdate);
$message = get_string('confirmdeletehiddensessions', 'attendance', $a);
$params = array('action' => $att->pageparams->action, 'confirm' => 1, 'sesskey' => sesskey());
echo $OUTPUT->header();
echo $OUTPUT->heading(get_string('attendanceforthecourse', 'attendance').' :: ' .format_string($course->fullname));
echo $OUTPUT->confirm($message, $att->url_sessions($params), $att->url_manage());
echo $OUTPUT->footer();
exit;
}
$output = $PAGE->get_renderer('mod_attendance');

Loading…
Cancel
Save