Browse Source

Added paging to reporting and taking attendance configable via module setting.

MOODLE_26_STABLE
Tim Lock 11 years ago
parent
commit
759c848b86
  1. 1
      export.php
  2. 1
      lang/en/attendance.php
  3. 29
      locallib.php
  4. 1
      manage.php
  5. 6
      renderables.php
  6. 62
      renderer.php
  7. 2
      report.php
  8. 44
      settings.php
  9. 2
      take.php

1
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)) {

1
lang/en/attendance.php

@ -130,6 +130,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';

29
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";
}
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)) {

1
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);

6
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);

62
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()))) {

2
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);

44
settings.php

@ -0,0 +1,44 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* 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));
}

2
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);

Loading…
Cancel
Save