From 1f2842f2063d220360a3eda981395304eb2af877 Mon Sep 17 00:00:00 2001 From: Antonio Carlos Mariani Date: Sun, 23 Aug 2015 00:23:48 -0300 Subject: [PATCH] Fixes #143 Include action to delete all hidden sections --- lang/en/attendance.php | 7 +++++++ locallib.php | 19 +++++++++++++++++++ renderer.php | 10 ++++++++++ sessions.php | 23 +++++++++++++++++++++++ 4 files changed, 59 insertions(+) diff --git a/lang/en/attendance.php b/lang/en/attendance.php index 9299464..4375926 100644 --- a/lang/en/attendance.php +++ b/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'; diff --git a/locallib.php b/locallib.php index 44291b8..5bcdb49 100644 --- a/locallib.php +++ b/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; diff --git a/renderer.php b/renderer.php index 36134cf..9e34dad 100644 --- a/renderer.php +++ b/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')); diff --git a/sessions.php b/sessions.php index 3aa8e8c..2aac736 100644 --- a/sessions.php +++ b/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');