diff --git a/add_form.php b/add_form.php index dabaeb1..6cec532 100644 --- a/add_form.php +++ b/add_form.php @@ -158,9 +158,19 @@ class mod_attendance_add_form extends moodleform { public function validation($data, $files) { $errors = parent::validation($data, $files); + if ($data['sessiondate'] != 0 && $data['sessionenddate'] != 0 && $data['sessionenddate'] < $data['sessiondate']) { + $errors['sessionenddate'] = get_string('invalidsessionenddate', 'attendance'); + } + if ($data['sessiontype'] == attendance::SESSION_GROUP and empty($data['groups'])) { $errors['groups'] = get_string('errorgroupsnotselected', 'attendance'); } + + $addmulti = isset($data['addmultiply'])? (int)$data['addmultiply'] : 0; + if (($addmulti != 0) && (!array_key_exists('sdays',$data) || empty($data['sdays']))) { + $data['sdays']= array(); + $errors['sdays'] = get_string('required', 'attendance'); + } return $errors; } diff --git a/export.php b/export.php index 57d7ebc..5d2d32f 100644 --- a/export.php +++ b/export.php @@ -55,6 +55,7 @@ if ($mform->is_submitted()) { $pageparams = new att_page_with_filter_controls(); $pageparams->init($cm); + $pageparams->page = 0; $pageparams->group = $formdata->group; $pageparams->set_current_sesstype($formdata->group ? $formdata->group : att_page_with_filter_controls::SESSTYPE_ALL); if (isset($formdata->includeallsessions)) { diff --git a/lang/en/attendance.php b/lang/en/attendance.php index 5dd803c..3ade055 100755 --- a/lang/en/attendance.php +++ b/lang/en/attendance.php @@ -121,6 +121,7 @@ $string['identifyby'] = 'Identify student by'; $string['includeall'] = 'Select all sessions'; $string['includenottaken'] = 'Include not taken sessions'; $string['indetail'] = 'In detail...'; +$string['invalidsessionenddate'] = 'The session end date can not be earlier than the session start date'; $string['jumpto'] = 'Jump to'; $string['modulename'] = 'Attendance'; $string['modulename_help'] = 'The attendance activity module enables a teacher to take attendance during class and students to view their own attendance record. @@ -130,6 +131,7 @@ The teacher can create multiple sessions and can mark the attendance status as " Reports are available for the entire class or individual students.'; $string['modulenameplural'] = 'Attendances'; $string['months'] = 'Months'; +$string['moreattendance'] = 'Attendance has been successfully taken for this page'; $string['myvariables'] = 'My Variables'; $string['newdate'] = 'New date'; $string['newduration'] = 'New duration'; @@ -152,6 +154,7 @@ $string['pluginname'] = 'Attendance'; $string['pluginadministration'] = 'Attendance administration'; $string['remarks'] = 'Remarks'; $string['report'] = 'Report'; +$string['required'] = 'Required*'; $string['resetdescription'] = 'Remember that deleting attendance data will erase information from database. You can just hide older sessions having changed start date of course!'; $string['resetstatuses'] = 'Reset statuses to default'; $string['restoredefaults'] = 'Restore defaults'; diff --git a/locallib.php b/locallib.php index 1975b0b..a772da0 100644 --- a/locallib.php +++ b/locallib.php @@ -887,13 +887,33 @@ class attendance { $url = $this->url_take($params); add_to_log($this->course->id, 'attendance', 'taken', $url, '', $this->cm->id); + $group = 0; + if ($this->pageparams->grouptype != attendance::SESSION_COMMON) { + $group = $this->pageparams->grouptype; + } else { + if ($this->pageparams->group) { + $group = $this->pageparams->group; + } + } + + $totalusers = count_enrolled_users(get_context_instance(CONTEXT_MODULE, $this->cm->id), 'mod/attendance:canbelisted', $group); + $usersperpage = $this->pageparams->perpage; + + if (!empty($this->pageparams->page) && $this->pageparams->page && $totalusers && $usersperpage) { + $numberofpages = ceil($totalusers / $usersperpage); + if ($this->pageparams->page < $numberofpages) { + $params['page'] = $this->pageparams->page + 1; + redirect($this->url_take($params), get_string('moreattendance', 'attendance')); + } + } + redirect($this->url_manage(), get_string('attendancesuccess', 'attendance')); } /** * MDL-27591 made this method obsolete. */ - public function get_users($groupid = 0) { + public function get_users($groupid = 0, $page = 1) { global $DB; // Fields we need from the user table. @@ -905,7 +925,14 @@ class attendance { $orderby = "u.lastname ASC, u.firstname ASC"; } - $users = get_enrolled_users($this->context, 'mod/attendance:canbelisted', $groupid, $userfields, $orderby); + if ($page) { + $totalusers = count_enrolled_users($this->context, 'mod/attendance:canbelisted', $groupid); + $usersperpage = $this->pageparams->perpage; + $startusers = ($page - 1) * $usersperpage; + $users = get_enrolled_users($this->context, 'mod/attendance:canbelisted', $groupid, $userfields, $orderby, $startusers, $usersperpage); + } else { + $users = get_enrolled_users($this->context, 'mod/attendance:canbelisted', $groupid, $userfields, $orderby); + } // Add a flag to each user indicating whether their enrolment is active. if (!empty($users)) { diff --git a/manage.php b/manage.php index 03a394c..0099d5e 100644 --- a/manage.php +++ b/manage.php @@ -31,6 +31,7 @@ $id = required_param('id', PARAM_INT); $from = optional_param('from', null, PARAM_ALPHANUMEXT); $pageparams->view = optional_param('view', null, PARAM_INT); $pageparams->curdate = optional_param('curdate', null, PARAM_INT); +$pageparams->perpage = get_config('attendance', 'resultsperpage'); $cm = get_coursemodule_from_id('attendance', $id, 0, false, MUST_EXIST); $course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST); diff --git a/renderables.php b/renderables.php index 4234bcd..af38c0f 100644 --- a/renderables.php +++ b/renderables.php @@ -265,9 +265,9 @@ class attendance_take_data implements renderable { public function __construct(attendance $att) { if ($att->pageparams->grouptype) { - $this->users = $att->get_users($att->pageparams->grouptype); + $this->users = $att->get_users($att->pageparams->grouptype, $att->pageparams->page); } else { - $this->users = $att->get_users($att->pageparams->group); + $this->users = $att->get_users($att->pageparams->group, $att->pageparams->page); } $this->pageparams = $att->pageparams; @@ -458,7 +458,7 @@ class attendance_report_data implements renderable { $this->perm = $att->perm; $this->pageparams = $att->pageparams; - $this->users = $att->get_users($att->pageparams->group); + $this->users = $att->get_users($att->pageparams->group, $att->pageparams->page); $this->groups = groups_get_all_groups($att->course->id); diff --git a/renderer.php b/renderer.php index 2b7dae2..5192f2a 100644 --- a/renderer.php +++ b/renderer.php @@ -57,12 +57,14 @@ class mod_attendance_renderer extends plugin_renderer_base { $filtertable = new html_table(); $filtertable->attributes['class'] = ' '; $filtertable->width = '100%'; - $filtertable->align = array('left', 'center', 'right'); + $filtertable->align = array('left', 'center', 'right', 'right'); $filtertable->data[0][] = $this->render_sess_group_selector($fcontrols); $filtertable->data[0][] = $this->render_curdate_controls($fcontrols); + $filtertable->data[0][] = $this->render_paging_controls($fcontrols); + $filtertable->data[0][] = $this->render_view_controls($fcontrols); $o = html_writer::table($filtertable); @@ -91,6 +93,37 @@ class mod_attendance_renderer extends plugin_renderer_base { return ''; } + protected function render_paging_controls(attendance_filter_controls $fcontrols) { + global $CFG; + + $paging_controls = ''; + + $group = 0; + if (!empty($fcontrols->pageparams->group)) { + $group = $fcontrols->pageparams->group; + } + + $totalusers = count_enrolled_users(get_context_instance(CONTEXT_MODULE, $fcontrols->cm->id), 'mod/attendance:canbelisted', $group); + $usersperpage = $fcontrols->pageparams->perpage; + if (empty($fcontrols->pageparams->page) || !$fcontrols->pageparams->page || !$totalusers || !$usersperpage) { + return $paging_controls; + } + + $numberofpages = ceil($totalusers / $usersperpage); + + if ($fcontrols->pageparams->page > 1) { + $paging_controls .= html_writer::link($fcontrols->url(array('curdate' => $fcontrols->nextcur, 'page' => $fcontrols->pageparams->page - 1)), + $this->output->larrow()); + } + $paging_controls .= html_writer::tag('span', "Page {$fcontrols->pageparams->page} of $numberofpages", array('class' => 'attbtn')); + if ($fcontrols->pageparams->page < $numberofpages) { + $paging_controls .= html_writer::link($fcontrols->url(array('curdate' => $fcontrols->nextcur, 'page' => $fcontrols->pageparams->page + 1)), + $this->output->rarrow()); + } + + return $paging_controls ; + } + protected function render_curdate_controls(attendance_filter_controls $fcontrols) { global $CFG; @@ -280,7 +313,7 @@ class mod_attendance_renderer extends plugin_renderer_base { } else { $table = $this->render_attendance_take_grid($takedata); } - $table .= html_writer::input_hidden_params($takedata->url(array('sesskey' => sesskey()))); + $table .= html_writer::input_hidden_params($takedata->url(array('sesskey' => sesskey(), 'page' => $takedata->pageparams->page))); $params = array( 'type' => 'submit', 'value' => get_string('save', 'attendance')); @@ -316,6 +349,31 @@ class mod_attendance_renderer extends plugin_renderer_base { private function construct_take_controls(attendance_take_data $takedata) { $controls = ''; + + $group = 0; + if ($takedata->pageparams->grouptype != attendance::SESSION_COMMON) { + $group = $takedata->pageparams->grouptype; + } else { + if ($takedata->pageparams->group) { + $group = $takedata->pageparams->group; + } + } + + $totalusers = count_enrolled_users(get_context_instance(CONTEXT_MODULE, $takedata->cm->id), 'mod/attendance:canbelisted', $group); + $usersperpage = $takedata->pageparams->perpage; + if (!empty($takedata->pageparams->page) && $takedata->pageparams->page && $totalusers && $usersperpage) { + $controls .= html_writer::empty_tag('br'); + $numberofpages = ceil($totalusers / $usersperpage); + + if ($takedata->pageparams->page > 1) { + $controls .= html_writer::link($takedata->url(array('page' => $takedata->pageparams->page - 1)), $this->output->larrow()); + } + $controls .= html_writer::tag('span', "Page {$takedata->pageparams->page} of $numberofpages", array('class' => 'attbtn')); + if ($takedata->pageparams->page < $numberofpages) { + $controls .= html_writer::link($takedata->url(array('page' => $takedata->pageparams->page + 1)), $this->output->rarrow()); + } + } + if ($takedata->pageparams->grouptype == attendance::SESSION_COMMON and ($takedata->groupmode == VISIBLEGROUPS or ($takedata->groupmode and $takedata->perm->can_access_all_groups()))) { diff --git a/report.php b/report.php index 032c4fd..8a4d4cf 100644 --- a/report.php +++ b/report.php @@ -33,6 +33,8 @@ $pageparams->view = optional_param('view', null, PARAM_INT); $pageparams->curdate = optional_param('curdate', null, PARAM_INT); $pageparams->group = optional_param('group', null, PARAM_INT); $pageparams->sort = optional_param('sort', null, PARAM_INT); +$pageparams->page = optional_param('page', 1, PARAM_INT); +$pageparams->perpage = get_config('attendance', 'resultsperpage'); $cm = get_coursemodule_from_id('attendance', $id, 0, false, MUST_EXIST); $course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST); diff --git a/settings.php b/settings.php new file mode 100644 index 0000000..66c5805 --- /dev/null +++ b/settings.php @@ -0,0 +1,44 @@ +. + +/** + * Attendance plugin settings + * + * @package mod_attendance + * @copyright 2013 Netspot, Tim Lock. + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +defined('MOODLE_INTERNAL') || die; + +if ($ADMIN->fulltree) { + require_once(dirname(__FILE__).'/lib.php'); + + // Paging options. + $options = array( + 0 => get_string('donotusepaging', 'attendance'), + 25 => 25, + 50 => 50, + 75 => 75, + 100 => 100, + 250 => 250, + 500 => 500, + 1000 => 1000, + ); + + $settings->add(new admin_setting_configselect('attendance/resultsperpage', + get_string('resultsperpage', 'attendance'), get_string('resultsperpage_desc', 'attendance'), 25, $options)); +} diff --git a/take.php b/take.php index d7c7ac0..4452927 100644 --- a/take.php +++ b/take.php @@ -34,6 +34,8 @@ $pageparams->sort = optional_param('sort', null, PARAM_INT); $pageparams->copyfrom = optional_param('copyfrom', null, PARAM_INT); $pageparams->viewmode = optional_param('viewmode', null, PARAM_INT); $pageparams->gridcols = optional_param('gridcols', null, PARAM_INT); +$pageparams->page = optional_param('page', 1, PARAM_INT); +$pageparams->perpage = get_config('attendance', 'resultsperpage'); $cm = get_coursemodule_from_id('attendance', $id, 0, false, MUST_EXIST); $course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST);