Browse Source

Merge pull request #10 from tlock/master

Our improvements
MOODLE_26_STABLE
Dan Marsden 11 years ago
parent
commit
66b1e4b611
  1. 10
      add_form.php
  2. 1
      export.php
  3. 3
      lang/en/attendance.php
  4. 29
      locallib.php
  5. 1
      manage.php
  6. 6
      renderables.php
  7. 62
      renderer.php
  8. 2
      report.php
  9. 44
      settings.php
  10. 2
      take.php

10
add_form.php

@ -158,9 +158,19 @@ class mod_attendance_add_form extends moodleform {
public function validation($data, $files) { public function validation($data, $files) {
$errors = parent::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'])) { if ($data['sessiontype'] == attendance::SESSION_GROUP and empty($data['groups'])) {
$errors['groups'] = get_string('errorgroupsnotselected', 'attendance'); $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; return $errors;
} }

1
export.php

@ -55,6 +55,7 @@ if ($mform->is_submitted()) {
$pageparams = new att_page_with_filter_controls(); $pageparams = new att_page_with_filter_controls();
$pageparams->init($cm); $pageparams->init($cm);
$pageparams->page = 0;
$pageparams->group = $formdata->group; $pageparams->group = $formdata->group;
$pageparams->set_current_sesstype($formdata->group ? $formdata->group : att_page_with_filter_controls::SESSTYPE_ALL); $pageparams->set_current_sesstype($formdata->group ? $formdata->group : att_page_with_filter_controls::SESSTYPE_ALL);
if (isset($formdata->includeallsessions)) { if (isset($formdata->includeallsessions)) {

3
lang/en/attendance.php

@ -121,6 +121,7 @@ $string['identifyby'] = 'Identify student by';
$string['includeall'] = 'Select all sessions'; $string['includeall'] = 'Select all sessions';
$string['includenottaken'] = 'Include not taken sessions'; $string['includenottaken'] = 'Include not taken sessions';
$string['indetail'] = 'In detail...'; $string['indetail'] = 'In detail...';
$string['invalidsessionenddate'] = 'The session end date can not be earlier than the session start date';
$string['jumpto'] = 'Jump to'; $string['jumpto'] = 'Jump to';
$string['modulename'] = 'Attendance'; $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. $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.'; Reports are available for the entire class or individual students.';
$string['modulenameplural'] = 'Attendances'; $string['modulenameplural'] = 'Attendances';
$string['months'] = 'Months'; $string['months'] = 'Months';
$string['moreattendance'] = 'Attendance has been successfully taken for this page';
$string['myvariables'] = 'My Variables'; $string['myvariables'] = 'My Variables';
$string['newdate'] = 'New date'; $string['newdate'] = 'New date';
$string['newduration'] = 'New duration'; $string['newduration'] = 'New duration';
@ -152,6 +154,7 @@ $string['pluginname'] = 'Attendance';
$string['pluginadministration'] = 'Attendance administration'; $string['pluginadministration'] = 'Attendance administration';
$string['remarks'] = 'Remarks'; $string['remarks'] = 'Remarks';
$string['report'] = 'Report'; $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['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['resetstatuses'] = 'Reset statuses to default';
$string['restoredefaults'] = 'Restore defaults'; $string['restoredefaults'] = 'Restore defaults';

29
locallib.php

@ -887,13 +887,33 @@ class attendance {
$url = $this->url_take($params); $url = $this->url_take($params);
add_to_log($this->course->id, 'attendance', 'taken', $url, '', $this->cm->id); 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')); redirect($this->url_manage(), get_string('attendancesuccess', 'attendance'));
} }
/** /**
* MDL-27591 made this method obsolete. * MDL-27591 made this method obsolete.
*/ */
public function get_users($groupid = 0) { public function get_users($groupid = 0, $page = 1) {
global $DB; global $DB;
// Fields we need from the user table. // Fields we need from the user table.
@ -905,7 +925,14 @@ class attendance {
$orderby = "u.lastname ASC, u.firstname ASC"; $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); $users = get_enrolled_users($this->context, 'mod/attendance:canbelisted', $groupid, $userfields, $orderby);
}
// Add a flag to each user indicating whether their enrolment is active. // Add a flag to each user indicating whether their enrolment is active.
if (!empty($users)) { if (!empty($users)) {

1
manage.php

@ -31,6 +31,7 @@ $id = required_param('id', PARAM_INT);
$from = optional_param('from', null, PARAM_ALPHANUMEXT); $from = optional_param('from', null, PARAM_ALPHANUMEXT);
$pageparams->view = optional_param('view', null, PARAM_INT); $pageparams->view = optional_param('view', null, PARAM_INT);
$pageparams->curdate = optional_param('curdate', 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); $cm = get_coursemodule_from_id('attendance', $id, 0, false, MUST_EXIST);
$course = $DB->get_record('course', array('id' => $cm->course), '*', 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) { public function __construct(attendance $att) {
if ($att->pageparams->grouptype) { if ($att->pageparams->grouptype) {
$this->users = $att->get_users($att->pageparams->grouptype); $this->users = $att->get_users($att->pageparams->grouptype, $att->pageparams->page);
} else { } else {
$this->users = $att->get_users($att->pageparams->group); $this->users = $att->get_users($att->pageparams->group, $att->pageparams->page);
} }
$this->pageparams = $att->pageparams; $this->pageparams = $att->pageparams;
@ -458,7 +458,7 @@ class attendance_report_data implements renderable {
$this->perm = $att->perm; $this->perm = $att->perm;
$this->pageparams = $att->pageparams; $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); $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 = new html_table();
$filtertable->attributes['class'] = ' '; $filtertable->attributes['class'] = ' ';
$filtertable->width = '100%'; $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_sess_group_selector($fcontrols);
$filtertable->data[0][] = $this->render_curdate_controls($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); $filtertable->data[0][] = $this->render_view_controls($fcontrols);
$o = html_writer::table($filtertable); $o = html_writer::table($filtertable);
@ -91,6 +93,37 @@ class mod_attendance_renderer extends plugin_renderer_base {
return ''; 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) { protected function render_curdate_controls(attendance_filter_controls $fcontrols) {
global $CFG; global $CFG;
@ -280,7 +313,7 @@ class mod_attendance_renderer extends plugin_renderer_base {
} else { } else {
$table = $this->render_attendance_take_grid($takedata); $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( $params = array(
'type' => 'submit', 'type' => 'submit',
'value' => get_string('save', 'attendance')); '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) { private function construct_take_controls(attendance_take_data $takedata) {
$controls = ''; $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 if ($takedata->pageparams->grouptype == attendance::SESSION_COMMON and
($takedata->groupmode == VISIBLEGROUPS or ($takedata->groupmode == VISIBLEGROUPS or
($takedata->groupmode and $takedata->perm->can_access_all_groups()))) { ($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->curdate = optional_param('curdate', null, PARAM_INT);
$pageparams->group = optional_param('group', null, PARAM_INT); $pageparams->group = optional_param('group', null, PARAM_INT);
$pageparams->sort = optional_param('sort', 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); $cm = get_coursemodule_from_id('attendance', $id, 0, false, MUST_EXIST);
$course = $DB->get_record('course', array('id' => $cm->course), '*', 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->copyfrom = optional_param('copyfrom', null, PARAM_INT);
$pageparams->viewmode = optional_param('viewmode', null, PARAM_INT); $pageparams->viewmode = optional_param('viewmode', null, PARAM_INT);
$pageparams->gridcols = optional_param('gridcols', 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); $cm = get_coursemodule_from_id('attendance', $id, 0, false, MUST_EXIST);
$course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST); $course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST);

Loading…
Cancel
Save