Browse Source

Convert locallib.php classes into proper auto-loading classes

MOODLE_29_STABLE
Dan Marsden 9 years ago
parent
commit
f5dd18fba9
  1. 2
      attendance.php
  2. 39
      classes/manage_page_params.php
  3. 6
      classes/notifyqueue.php
  4. 224
      classes/page_with_filter_controls.php
  5. 60
      classes/preferences_page_params.php
  6. 59
      classes/report_page_params.php
  7. 42
      classes/sessions_page_params.php
  8. 24
      classes/structure.php
  9. 92
      classes/take_page_params.php
  10. 55
      classes/view_page_params.php
  11. 2
      duration_form.php
  12. 4
      export.php
  13. 371
      locallib.php
  14. 2
      manage.php
  15. 12
      preferences.php
  16. 6
      renderables.php
  17. 45
      renderer.php
  18. 2
      report.php
  19. 22
      sessions.php
  20. 2
      take.php
  21. 4
      view.php

2
attendance.php

@ -26,7 +26,7 @@ require_once(dirname(__FILE__).'/../../config.php');
require_once(dirname(__FILE__).'/locallib.php'); require_once(dirname(__FILE__).'/locallib.php');
require_once(dirname(__FILE__).'/student_attendance_form.php'); require_once(dirname(__FILE__).'/student_attendance_form.php');
$pageparams = new att_sessions_page_params(); $pageparams = new mod_attendance_sessions_page_params();
// Check that the required parameters are present. // Check that the required parameters are present.
$id = required_param('sessid', PARAM_INT); $id = required_param('sessid', PARAM_INT);

39
classes/manage_page_params.php

@ -0,0 +1,39 @@
<?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/>.
/**
* Class definition for mod_attendance_manage_page_params
*
* @package mod_attendance
* @copyright 2016 Dan Marsden http://danmarsden.com
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
/**
* stores constants/data passed depending on view.
*
* @copyright 2016 Dan Marsden http://danmarsden.com
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class mod_attendance_manage_page_params extends mod_attendance_page_with_filter_controls {
public function __construct() {
$this->selectortype = mod_attendance_page_with_filter_controls::SELECTOR_SESS_TYPE;
}
public function get_significant_params() {
return array();
}
}

6
classes/notifyqueue.php

@ -24,6 +24,12 @@
defined('MOODLE_INTERNAL') || die(); defined('MOODLE_INTERNAL') || die();
/**
* Notify Queue class
*
* @copyright 2015 Antonio Carlos Mariani <antonio.c.mariani@gmail.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class mod_attendance_notifyqueue { class mod_attendance_notifyqueue {
/** /**

224
classes/page_with_filter_controls.php

@ -0,0 +1,224 @@
<?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/>.
/**
* Class definition for mod_attendance_page_with_filter_controls
*
* @package mod_attendance
* @copyright 2016 Dan Marsden http://danmarsden.com
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
/**
* base filter controls class - overridden by different views where needed.
*
* @copyright 2016 Dan Marsden http://danmarsden.com
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class mod_attendance_page_with_filter_controls {
const SELECTOR_NONE = 1;
const SELECTOR_GROUP = 2;
const SELECTOR_SESS_TYPE = 3;
const SESSTYPE_COMMON = 0;
const SESSTYPE_ALL = -1;
const SESSTYPE_NO_VALUE = -2;
/** @var int current view mode */
public $view;
/** @var int $view and $curdate specify displaed date range */
public $curdate;
/** @var int start date of displayed date range */
public $startdate;
/** @var int end date of displayed date range */
public $enddate;
public $selectortype = self::SELECTOR_NONE;
protected $defaultview = ATT_VIEW_WEEKS;
private $cm;
private $sessgroupslist;
private $sesstype;
public function init($cm) {
$this->cm = $cm;
$this->init_view();
$this->init_curdate();
$this->init_start_end_date();
}
private function init_view() {
global $SESSION;
if (isset($this->view)) {
$SESSION->attcurrentattview[$this->cm->course] = $this->view;
} else if (isset($SESSION->attcurrentattview[$this->cm->course])) {
$this->view = $SESSION->attcurrentattview[$this->cm->course];
} else {
$this->view = $this->defaultview;
}
}
private function init_curdate() {
global $SESSION;
if (isset($this->curdate)) {
$SESSION->attcurrentattdate[$this->cm->course] = $this->curdate;
} else if (isset($SESSION->attcurrentattdate[$this->cm->course])) {
$this->curdate = $SESSION->attcurrentattdate[$this->cm->course];
} else {
$this->curdate = time();
}
}
public function init_start_end_date() {
global $CFG;
// HOURSECS solves issue for weeks view with Daylight saving time and clocks adjusting by one hour backward.
$date = usergetdate($this->curdate + HOURSECS);
$mday = $date['mday'];
$wday = $date['wday'] - $CFG->calendar_startwday;
if ($wday < 0) {
$wday += 7;
}
$mon = $date['mon'];
$year = $date['year'];
switch ($this->view) {
case ATT_VIEW_DAYS:
$this->startdate = make_timestamp($year, $mon, $mday);
$this->enddate = make_timestamp($year, $mon, $mday + 1);
break;
case ATT_VIEW_WEEKS:
$this->startdate = make_timestamp($year, $mon, $mday - $wday);
$this->enddate = make_timestamp($year, $mon, $mday + 7 - $wday) - 1;
break;
case ATT_VIEW_MONTHS:
$this->startdate = make_timestamp($year, $mon);
$this->enddate = make_timestamp($year, $mon + 1);
break;
case ATT_VIEW_ALLPAST:
$this->startdate = 1;
$this->enddate = time();
break;
case ATT_VIEW_ALL:
$this->startdate = 0;
$this->enddate = 0;
break;
}
}
private function calc_sessgroupslist_sesstype() {
global $SESSION;
if (!array_key_exists('attsessiontype', $SESSION)) {
$SESSION->attsessiontype = array($this->cm->course => self::SESSTYPE_ALL);
} else if (!array_key_exists($this->cm->course, $SESSION->attsessiontype)) {
$SESSION->attsessiontype[$this->cm->course] = self::SESSTYPE_ALL;
}
$group = optional_param('group', self::SESSTYPE_NO_VALUE, PARAM_INT);
if ($this->selectortype == self::SELECTOR_SESS_TYPE) {
if ($group > self::SESSTYPE_NO_VALUE) {
$SESSION->attsessiontype[$this->cm->course] = $group;
if ($group > self::SESSTYPE_ALL) {
// Set activegroup in $SESSION.
groups_get_activity_group($this->cm, true);
} else {
// Reset activegroup in $SESSION.
unset($SESSION->activegroup[$this->cm->course][VISIBLEGROUPS][$this->cm->groupingid]);
unset($SESSION->activegroup[$this->cm->course]['aag'][$this->cm->groupingid]);
unset($SESSION->activegroup[$this->cm->course][SEPARATEGROUPS][$this->cm->groupingid]);
}
$this->sesstype = $group;
} else {
$this->sesstype = $SESSION->attsessiontype[$this->cm->course];
}
} else if ($this->selectortype == self::SELECTOR_GROUP) {
if ($group == 0) {
$SESSION->attsessiontype[$this->cm->course] = self::SESSTYPE_ALL;
$this->sesstype = self::SESSTYPE_ALL;
} else if ($group > 0) {
$SESSION->attsessiontype[$this->cm->course] = $group;
$this->sesstype = $group;
} else {
$this->sesstype = $SESSION->attsessiontype[$this->cm->course];
}
}
if (is_null($this->sessgroupslist)) {
$this->calc_sessgroupslist();
}
// For example, we set SESSTYPE_ALL but user can access only to limited set of groups.
if (!array_key_exists($this->sesstype, $this->sessgroupslist)) {
reset($this->sessgroupslist);
$this->sesstype = key($this->sessgroupslist);
}
}
private function calc_sessgroupslist() {
global $USER, $PAGE;
$this->sessgroupslist = array();
$groupmode = groups_get_activity_groupmode($this->cm);
if ($groupmode == NOGROUPS) {
return;
}
if ($groupmode == VISIBLEGROUPS or has_capability('moodle/site:accessallgroups', $PAGE->context)) {
$allowedgroups = groups_get_all_groups($this->cm->course, 0, $this->cm->groupingid);
} else {
$allowedgroups = groups_get_all_groups($this->cm->course, $USER->id, $this->cm->groupingid);
}
if ($allowedgroups) {
if ($groupmode == VISIBLEGROUPS or has_capability('moodle/site:accessallgroups', $PAGE->context)) {
$this->sessgroupslist[self::SESSTYPE_ALL] = get_string('all', 'attendance');
}
// Show Common groups always.
$this->sessgroupslist[self::SESSTYPE_COMMON] = get_string('commonsessions', 'attendance');
foreach ($allowedgroups as $group) {
$this->sessgroupslist[$group->id] = get_string('group') . ': ' . format_string($group->name);
}
}
}
public function get_sess_groups_list() {
if (is_null($this->sessgroupslist)) {
$this->calc_sessgroupslist_sesstype();
}
return $this->sessgroupslist;
}
public function get_current_sesstype() {
if (is_null($this->sesstype)) {
$this->calc_sessgroupslist_sesstype();
}
return $this->sesstype;
}
public function set_current_sesstype($sesstype) {
$this->sesstype = $sesstype;
}
}

60
classes/preferences_page_params.php

@ -0,0 +1,60 @@
<?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/>.
/**
* Class definition for mod_attendance_preferences_page_params
*
* @package mod_attendance
* @copyright 2016 Dan Marsden http://danmarsden.com
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
/**
* base preferences page param class
*
* @copyright 2016 Dan Marsden http://danmarsden.com
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class mod_attendance_preferences_page_params {
const ACTION_ADD = 1;
const ACTION_DELETE = 2;
const ACTION_HIDE = 3;
const ACTION_SHOW = 4;
const ACTION_SAVE = 5;
/** @var int view mode of taking attendance page*/
public $action;
public $statusid;
public $statusset;
public function get_significant_params() {
$params = array();
if (isset($this->action)) {
$params['action'] = $this->action;
}
if (isset($this->statusid)) {
$params['statusid'] = $this->statusid;
}
if (isset($this->statusset)) {
$params['statusset'] = $this->statusset;
}
return $params;
}
}

59
classes/report_page_params.php

@ -0,0 +1,59 @@
<?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/>.
/**
* Class definition for mod_attendance_report_page_params
*
* @package mod_attendance
* @copyright 2016 Dan Marsden http://danmarsden.com
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
/**
* contains specific data/functions for report_page.
*
* @copyright 2016 Dan Marsden http://danmarsden.com
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class mod_attendance_report_page_params extends mod_attendance_page_with_filter_controls {
public $group;
public $sort;
public function __construct() {
$this->selectortype = self::SELECTOR_GROUP;
}
public function init($cm) {
parent::init($cm);
if (!isset($this->group)) {
$this->group = $this->get_current_sesstype() > 0 ? $this->get_current_sesstype() : 0;
}
if (!isset($this->sort)) {
$this->sort = ATT_SORT_LASTNAME;
}
}
public function get_significant_params() {
$params = array();
if ($this->sort != ATT_SORT_LASTNAME) {
$params['sort'] = $this->sort;
}
return $params;
}
}

42
classes/sessions_page_params.php

@ -0,0 +1,42 @@
<?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/>.
/**
* Class definition for mod_attendance_sessions_page_params
*
* @package mod_attendance
* @copyright 2016 Dan Marsden http://danmarsden.com
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
/**
* stores constants/data used by sessions page params.
*
* @copyright 2016 Dan Marsden http://danmarsden.com
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class mod_attendance_sessions_page_params {
const ACTION_ADD = 1;
const ACTION_UPDATE = 2;
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;
}

24
classes/structure.php

@ -14,6 +14,20 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Class definition for mod_attendance_structure
*
* @package mod_attendance
* @copyright 2016 Dan Marsden http://danmarsden.com
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
/**
* Main class with all Attendance related info.
*
* @copyright 2016 Dan Marsden http://danmarsden.com
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class mod_attendance_structure { class mod_attendance_structure {
const SESSION_COMMON = 0; const SESSION_COMMON = 0;
const SESSION_GROUP = 1; const SESSION_GROUP = 1;
@ -209,7 +223,7 @@ class mod_attendance_structure {
$where = "attendanceid = :aid AND sessdate >= :csdate"; $where = "attendanceid = :aid AND sessdate >= :csdate";
} }
if ($this->pageparams->get_current_sesstype() > att_page_with_filter_controls::SESSTYPE_ALL) { if ($this->pageparams->get_current_sesstype() > mod_attendance_page_with_filter_controls::SESSTYPE_ALL) {
$where .= " AND (groupid = :cgroup OR groupid = 0)"; $where .= " AND (groupid = :cgroup OR groupid = 0)";
} }
$params = array( $params = array(
@ -382,7 +396,7 @@ class mod_attendance_structure {
$event = \mod_attendance\event\session_updated::create(array( $event = \mod_attendance\event\session_updated::create(array(
'objectid' => $this->id, 'objectid' => $this->id,
'context' => $this->context, 'context' => $this->context,
'other' => array('info' => $info, 'sessionid' => $sessionid, 'action' => att_sessions_page_params::ACTION_UPDATE))); 'other' => array('info' => $info, 'sessionid' => $sessionid, 'action' => mod_attendance_sessions_page_params::ACTION_UPDATE)));
$event->add_record_snapshot('course_modules', $this->cm); $event->add_record_snapshot('course_modules', $this->cm);
$event->add_record_snapshot('attendance_sessions', $sess); $event->add_record_snapshot('attendance_sessions', $sess);
$event->trigger(); $event->trigger();
@ -391,8 +405,6 @@ class mod_attendance_structure {
/** /**
* Used to record attendance submitted by the student. * Used to record attendance submitted by the student.
* *
* @global type $DB
* @global type $USER
* @param type $mformdata * @param type $mformdata
* @return boolean * @return boolean
*/ */
@ -757,7 +769,6 @@ class mod_attendance_structure {
/** /**
* *
* @global type $DB
* @param type $userid * @param type $userid
* @param type $filters - An array things to filter by. For now only enddate is valid. * @param type $filters - An array things to filter by. For now only enddate is valid.
* @return type * @return type
@ -1020,7 +1031,6 @@ class mod_attendance_structure {
/** /**
* Remove a status variable from an attendance instance * Remove a status variable from an attendance instance
* *
* @global moodle_database $DB
* @param stdClass $status * @param stdClass $status
*/ */
public function remove_status($status) { public function remove_status($status) {
@ -1042,7 +1052,6 @@ class mod_attendance_structure {
/** /**
* Add an attendance status variable * Add an attendance status variable
* *
* @global moodle_database $DB
* @param string $acronym * @param string $acronym
* @param string $description * @param string $description
* @param int $grade * @param int $grade
@ -1078,7 +1087,6 @@ class mod_attendance_structure {
/** /**
* Update status variable for a particular Attendance module instance * Update status variable for a particular Attendance module instance
* *
* @global moodle_database $DB
* @param stdClass $status * @param stdClass $status
* @param string $acronym * @param string $acronym
* @param string $description * @param string $description

92
classes/take_page_params.php

@ -0,0 +1,92 @@
<?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/>.
/**
* Class definition for mod_attendance_take_page_params
*
* @package mod_attendance
* @copyright 2016 Dan Marsden http://danmarsden.com
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
/**
* contains functions/constants used by take attendance page.
*
* @copyright 2016 Dan Marsden http://danmarsden.com
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class mod_attendance_take_page_params {
const SORTED_LIST = 1;
const SORTED_GRID = 2;
const DEFAULT_VIEW_MODE = self::SORTED_LIST;
public $sessionid;
public $grouptype;
public $group;
public $sort;
public $copyfrom;
/** @var int view mode of taking attendance page*/
public $viewmode;
public $gridcols;
public function init() {
if (!isset($this->group)) {
$this->group = 0;
}
if (!isset($this->sort)) {
$this->sort = ATT_SORT_LASTNAME;
}
$this->init_view_mode();
$this->init_gridcols();
}
private function init_view_mode() {
if (isset($this->viewmode)) {
set_user_preference("attendance_take_view_mode", $this->viewmode);
} else {
$this->viewmode = get_user_preferences("attendance_take_view_mode", self::DEFAULT_VIEW_MODE);
}
}
private function init_gridcols() {
if (isset($this->gridcols)) {
set_user_preference("attendance_gridcolumns", $this->gridcols);
} else {
$this->gridcols = get_user_preferences("attendance_gridcolumns", 5);
}
}
public function get_significant_params() {
$params = array();
$params['sessionid'] = $this->sessionid;
$params['grouptype'] = $this->grouptype;
if ($this->group) {
$params['group'] = $this->group;
}
if ($this->sort != ATT_SORT_LASTNAME) {
$params['sort'] = $this->sort;
}
if (isset($this->copyfrom)) {
$params['copyfrom'] = $this->copyfrom;
}
return $params;
}
}

55
classes/view_page_params.php

@ -0,0 +1,55 @@
<?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/>.
/**
* Class definition for mod_attendance_view_page_params
*
* @package mod_attendance
* @copyright 2016 Dan Marsden http://danmarsden.com
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
/**
* contains functions/constants used by attendance view page.
*
* @copyright 2016 Dan Marsden http://danmarsden.com
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class mod_attendance_view_page_params extends mod_attendance_page_with_filter_controls {
const MODE_THIS_COURSE = 0;
const MODE_ALL_COURSES = 1;
public $studentid;
public $mode;
public function __construct() {
$this->defaultview = ATT_VIEW_MONTHS;
}
public function get_significant_params() {
$params = array();
if (isset($this->studentid)) {
$params['studentid'] = $this->studentid;
}
if ($this->mode != self::MODE_THIS_COURSE) {
$params['mode'] = $this->mode;
}
return $params;
}
}

2
duration_form.php

@ -61,7 +61,7 @@ class mod_attendance_duration_form extends moodleform {
$mform->setType('ids', PARAM_ALPHANUMEXT); $mform->setType('ids', PARAM_ALPHANUMEXT);
$mform->addElement('hidden', 'id', $cm->id); $mform->addElement('hidden', 'id', $cm->id);
$mform->setType('id', PARAM_INT); $mform->setType('id', PARAM_INT);
$mform->addElement('hidden', 'action', att_sessions_page_params::ACTION_CHANGE_DURATION); $mform->addElement('hidden', 'action', mod_attendance_sessions_page_params::ACTION_CHANGE_DURATION);
$mform->setType('action', PARAM_INT); $mform->setType('action', PARAM_INT);
$mform->setDefaults(array('durtime' => array('hours' => 0, 'minutes' => 0))); $mform->setDefaults(array('durtime' => array('hours' => 0, 'minutes' => 0)));

4
export.php

@ -53,11 +53,11 @@ $mform = new mod_attendance_export_form($att->url_export(), $formparams);
if ($formdata = $mform->get_data()) { if ($formdata = $mform->get_data()) {
$pageparams = new att_page_with_filter_controls(); $pageparams = new mod_attendance_page_with_filter_controls();
$pageparams->init($cm); $pageparams->init($cm);
$pageparams->page = 0; $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 : mod_attendance_page_with_filter_controls::SESSTYPE_ALL);
if (isset($formdata->includeallsessions)) { if (isset($formdata->includeallsessions)) {
if (isset($formdata->includenottaken)) { if (isset($formdata->includenottaken)) {
$pageparams->view = ATT_VIEW_ALL; $pageparams->view = ATT_VIEW_ALL;

371
locallib.php

@ -24,7 +24,6 @@
defined('MOODLE_INTERNAL') || die(); defined('MOODLE_INTERNAL') || die();
global $CFG;
require_once($CFG->libdir . '/gradelib.php'); require_once($CFG->libdir . '/gradelib.php');
require_once(dirname(__FILE__).'/renderhelpers.php'); require_once(dirname(__FILE__).'/renderhelpers.php');
@ -38,376 +37,6 @@ define('ATT_VIEW_NOTPRESENT', 6);
define('ATT_SORT_LASTNAME', 1); define('ATT_SORT_LASTNAME', 1);
define('ATT_SORT_FIRSTNAME', 2); define('ATT_SORT_FIRSTNAME', 2);
class att_page_with_filter_controls {
const SELECTOR_NONE = 1;
const SELECTOR_GROUP = 2;
const SELECTOR_SESS_TYPE = 3;
const SESSTYPE_COMMON = 0;
const SESSTYPE_ALL = -1;
const SESSTYPE_NO_VALUE = -2;
/** @var int current view mode */
public $view;
/** @var int $view and $curdate specify displaed date range */
public $curdate;
/** @var int start date of displayed date range */
public $startdate;
/** @var int end date of displayed date range */
public $enddate;
public $selectortype = self::SELECTOR_NONE;
protected $defaultview = ATT_VIEW_WEEKS;
private $cm;
private $sessgroupslist;
private $sesstype;
public function init($cm) {
$this->cm = $cm;
$this->init_view();
$this->init_curdate();
$this->init_start_end_date();
}
private function init_view() {
global $SESSION;
if (isset($this->view)) {
$SESSION->attcurrentattview[$this->cm->course] = $this->view;
} else if (isset($SESSION->attcurrentattview[$this->cm->course])) {
$this->view = $SESSION->attcurrentattview[$this->cm->course];
} else {
$this->view = $this->defaultview;
}
}
private function init_curdate() {
global $SESSION;
if (isset($this->curdate)) {
$SESSION->attcurrentattdate[$this->cm->course] = $this->curdate;
} else if (isset($SESSION->attcurrentattdate[$this->cm->course])) {
$this->curdate = $SESSION->attcurrentattdate[$this->cm->course];
} else {
$this->curdate = time();
}
}
public function init_start_end_date() {
global $CFG;
// HOURSECS solves issue for weeks view with Daylight saving time and clocks adjusting by one hour backward.
$date = usergetdate($this->curdate + HOURSECS);
$mday = $date['mday'];
$wday = $date['wday'] - $CFG->calendar_startwday;
if ($wday < 0) {
$wday += 7;
}
$mon = $date['mon'];
$year = $date['year'];
switch ($this->view) {
case ATT_VIEW_DAYS:
$this->startdate = make_timestamp($year, $mon, $mday);
$this->enddate = make_timestamp($year, $mon, $mday + 1);
break;
case ATT_VIEW_WEEKS:
$this->startdate = make_timestamp($year, $mon, $mday - $wday);
$this->enddate = make_timestamp($year, $mon, $mday + 7 - $wday) - 1;
break;
case ATT_VIEW_MONTHS:
$this->startdate = make_timestamp($year, $mon);
$this->enddate = make_timestamp($year, $mon + 1);
break;
case ATT_VIEW_ALLPAST:
$this->startdate = 1;
$this->enddate = time();
break;
case ATT_VIEW_ALL:
$this->startdate = 0;
$this->enddate = 0;
break;
}
}
private function calc_sessgroupslist_sesstype() {
global $SESSION;
if (!array_key_exists('attsessiontype', $SESSION)) {
$SESSION->attsessiontype = array($this->cm->course => self::SESSTYPE_ALL);
} else if (!array_key_exists($this->cm->course, $SESSION->attsessiontype)) {
$SESSION->attsessiontype[$this->cm->course] = self::SESSTYPE_ALL;
}
$group = optional_param('group', self::SESSTYPE_NO_VALUE, PARAM_INT);
if ($this->selectortype == self::SELECTOR_SESS_TYPE) {
if ($group > self::SESSTYPE_NO_VALUE) {
$SESSION->attsessiontype[$this->cm->course] = $group;
if ($group > self::SESSTYPE_ALL) {
// Set activegroup in $SESSION.
groups_get_activity_group($this->cm, true);
} else {
// Reset activegroup in $SESSION.
unset($SESSION->activegroup[$this->cm->course][VISIBLEGROUPS][$this->cm->groupingid]);
unset($SESSION->activegroup[$this->cm->course]['aag'][$this->cm->groupingid]);
unset($SESSION->activegroup[$this->cm->course][SEPARATEGROUPS][$this->cm->groupingid]);
}
$this->sesstype = $group;
} else {
$this->sesstype = $SESSION->attsessiontype[$this->cm->course];
}
} else if ($this->selectortype == self::SELECTOR_GROUP) {
if ($group == 0) {
$SESSION->attsessiontype[$this->cm->course] = self::SESSTYPE_ALL;
$this->sesstype = self::SESSTYPE_ALL;
} else if ($group > 0) {
$SESSION->attsessiontype[$this->cm->course] = $group;
$this->sesstype = $group;
} else {
$this->sesstype = $SESSION->attsessiontype[$this->cm->course];
}
}
if (is_null($this->sessgroupslist)) {
$this->calc_sessgroupslist();
}
// For example, we set SESSTYPE_ALL but user can access only to limited set of groups.
if (!array_key_exists($this->sesstype, $this->sessgroupslist)) {
reset($this->sessgroupslist);
$this->sesstype = key($this->sessgroupslist);
}
}
private function calc_sessgroupslist() {
global $USER, $PAGE;
$this->sessgroupslist = array();
$groupmode = groups_get_activity_groupmode($this->cm);
if ($groupmode == NOGROUPS) {
return;
}
if ($groupmode == VISIBLEGROUPS or has_capability('moodle/site:accessallgroups', $PAGE->context)) {
$allowedgroups = groups_get_all_groups($this->cm->course, 0, $this->cm->groupingid);
} else {
$allowedgroups = groups_get_all_groups($this->cm->course, $USER->id, $this->cm->groupingid);
}
if ($allowedgroups) {
if ($groupmode == VISIBLEGROUPS or has_capability('moodle/site:accessallgroups', $PAGE->context)) {
$this->sessgroupslist[self::SESSTYPE_ALL] = get_string('all', 'attendance');
}
// Show Common groups always.
$this->sessgroupslist[self::SESSTYPE_COMMON] = get_string('commonsessions', 'attendance');
foreach ($allowedgroups as $group) {
$this->sessgroupslist[$group->id] = get_string('group') . ': ' . format_string($group->name);
}
}
}
public function get_sess_groups_list() {
if (is_null($this->sessgroupslist)) {
$this->calc_sessgroupslist_sesstype();
}
return $this->sessgroupslist;
}
public function get_current_sesstype() {
if (is_null($this->sesstype)) {
$this->calc_sessgroupslist_sesstype();
}
return $this->sesstype;
}
public function set_current_sesstype($sesstype) {
$this->sesstype = $sesstype;
}
}
class att_view_page_params extends att_page_with_filter_controls {
const MODE_THIS_COURSE = 0;
const MODE_ALL_COURSES = 1;
public $studentid;
public $mode;
public function __construct() {
$this->defaultview = ATT_VIEW_MONTHS;
}
public function get_significant_params() {
$params = array();
if (isset($this->studentid)) {
$params['studentid'] = $this->studentid;
}
if ($this->mode != self::MODE_THIS_COURSE) {
$params['mode'] = $this->mode;
}
return $params;
}
}
class att_manage_page_params extends att_page_with_filter_controls {
public function __construct() {
$this->selectortype = att_page_with_filter_controls::SELECTOR_SESS_TYPE;
}
public function get_significant_params() {
return array();
}
}
class att_sessions_page_params {
const ACTION_ADD = 1;
const ACTION_UPDATE = 2;
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;
}
class att_take_page_params {
const SORTED_LIST = 1;
const SORTED_GRID = 2;
const DEFAULT_VIEW_MODE = self::SORTED_LIST;
public $sessionid;
public $grouptype;
public $group;
public $sort;
public $copyfrom;
/** @var int view mode of taking attendance page*/
public $viewmode;
public $gridcols;
public function init() {
if (!isset($this->group)) {
$this->group = 0;
}
if (!isset($this->sort)) {
$this->sort = ATT_SORT_LASTNAME;
}
$this->init_view_mode();
$this->init_gridcols();
}
private function init_view_mode() {
if (isset($this->viewmode)) {
set_user_preference("attendance_take_view_mode", $this->viewmode);
} else {
$this->viewmode = get_user_preferences("attendance_take_view_mode", self::DEFAULT_VIEW_MODE);
}
}
private function init_gridcols() {
if (isset($this->gridcols)) {
set_user_preference("attendance_gridcolumns", $this->gridcols);
} else {
$this->gridcols = get_user_preferences("attendance_gridcolumns", 5);
}
}
public function get_significant_params() {
$params = array();
$params['sessionid'] = $this->sessionid;
$params['grouptype'] = $this->grouptype;
if ($this->group) {
$params['group'] = $this->group;
}
if ($this->sort != ATT_SORT_LASTNAME) {
$params['sort'] = $this->sort;
}
if (isset($this->copyfrom)) {
$params['copyfrom'] = $this->copyfrom;
}
return $params;
}
}
class att_report_page_params extends att_page_with_filter_controls {
public $group;
public $sort;
public function __construct() {
$this->selectortype = self::SELECTOR_GROUP;
}
public function init($cm) {
parent::init($cm);
if (!isset($this->group)) {
$this->group = $this->get_current_sesstype() > 0 ? $this->get_current_sesstype() : 0;
}
if (!isset($this->sort)) {
$this->sort = ATT_SORT_LASTNAME;
}
}
public function get_significant_params() {
$params = array();
if ($this->sort != ATT_SORT_LASTNAME) {
$params['sort'] = $this->sort;
}
return $params;
}
}
class att_preferences_page_params {
const ACTION_ADD = 1;
const ACTION_DELETE = 2;
const ACTION_HIDE = 3;
const ACTION_SHOW = 4;
const ACTION_SAVE = 5;
/** @var int view mode of taking attendance page*/
public $action;
public $statusid;
public $statusset;
public function get_significant_params() {
$params = array();
if (isset($this->action)) {
$params['action'] = $this->action;
}
if (isset($this->statusid)) {
$params['statusid'] = $this->statusid;
}
if (isset($this->statusset)) {
$params['statusset'] = $this->statusset;
}
return $params;
}
}
function att_get_statuses($attid, $onlyvisible=true, $statusset = -1) { function att_get_statuses($attid, $onlyvisible=true, $statusset = -1) {
global $DB; global $DB;

2
manage.php

@ -25,7 +25,7 @@
require_once(dirname(__FILE__).'/../../config.php'); require_once(dirname(__FILE__).'/../../config.php');
require_once(dirname(__FILE__).'/locallib.php'); require_once(dirname(__FILE__).'/locallib.php');
$pageparams = new att_manage_page_params(); $pageparams = new mod_attendance_manage_page_params();
$id = required_param('id', PARAM_INT); $id = required_param('id', PARAM_INT);
$from = optional_param('from', null, PARAM_ALPHANUMEXT); $from = optional_param('from', null, PARAM_ALPHANUMEXT);

12
preferences.php

@ -25,7 +25,7 @@
require_once(dirname(__FILE__).'/../../config.php'); require_once(dirname(__FILE__).'/../../config.php');
require_once(dirname(__FILE__).'/locallib.php'); require_once(dirname(__FILE__).'/locallib.php');
$pageparams = new att_preferences_page_params(); $pageparams = new mod_attendance_preferences_page_params();
$id = required_param('id', PARAM_INT); $id = required_param('id', PARAM_INT);
$pageparams->action = optional_param('action', null, PARAM_INT); $pageparams->action = optional_param('action', null, PARAM_INT);
@ -64,7 +64,7 @@ if (!empty($att->pageparams->action)) {
} }
switch ($att->pageparams->action) { switch ($att->pageparams->action) {
case att_preferences_page_params::ACTION_ADD: case mod_attendance_preferences_page_params::ACTION_ADD:
$newacronym = optional_param('newacronym', null, PARAM_TEXT); $newacronym = optional_param('newacronym', null, PARAM_TEXT);
$newdescription = optional_param('newdescription', null, PARAM_TEXT); $newdescription = optional_param('newdescription', null, PARAM_TEXT);
$newgrade = optional_param('newgrade', 0, PARAM_RAW); $newgrade = optional_param('newgrade', 0, PARAM_RAW);
@ -75,7 +75,7 @@ switch ($att->pageparams->action) {
$maxstatusset = $pageparams->statusset; // Make sure the new maximum is shown without a page refresh. $maxstatusset = $pageparams->statusset; // Make sure the new maximum is shown without a page refresh.
} }
break; break;
case att_preferences_page_params::ACTION_DELETE: case mod_attendance_preferences_page_params::ACTION_DELETE:
if (attendance_has_logs_for_status($att->pageparams->statusid)) { if (attendance_has_logs_for_status($att->pageparams->statusid)) {
print_error('cantdeletestatus', 'attendance', "attsettings.php?id=$id"); print_error('cantdeletestatus', 'attendance', "attsettings.php?id=$id");
} }
@ -99,17 +99,17 @@ switch ($att->pageparams->action) {
echo $OUTPUT->confirm($message, $att->url_preferences($params), $att->url_preferences()); echo $OUTPUT->confirm($message, $att->url_preferences($params), $att->url_preferences());
echo $OUTPUT->footer(); echo $OUTPUT->footer();
exit; exit;
case att_preferences_page_params::ACTION_HIDE: case mod_attendance_preferences_page_params::ACTION_HIDE:
$statuses = $att->get_statuses(false); $statuses = $att->get_statuses(false);
$status = $statuses[$att->pageparams->statusid]; $status = $statuses[$att->pageparams->statusid];
$att->update_status($status, null, null, null, 0); $att->update_status($status, null, null, null, 0);
break; break;
case att_preferences_page_params::ACTION_SHOW: case mod_attendance_preferences_page_params::ACTION_SHOW:
$statuses = $att->get_statuses(false); $statuses = $att->get_statuses(false);
$status = $statuses[$att->pageparams->statusid]; $status = $statuses[$att->pageparams->statusid];
$att->update_status($status, null, null, null, 1); $att->update_status($status, null, null, null, 1);
break; break;
case att_preferences_page_params::ACTION_SAVE: case mod_attendance_preferences_page_params::ACTION_SAVE:
$acronym = required_param_array('acronym', PARAM_TEXT); $acronym = required_param_array('acronym', PARAM_TEXT);
$description = required_param_array('description', PARAM_TEXT); $description = required_param_array('description', PARAM_TEXT);
$grade = required_param_array('grade', PARAM_RAW); $grade = required_param_array('grade', PARAM_RAW);

6
renderables.php

@ -80,7 +80,7 @@ class attendance_tabs implements renderable {
if (has_capability('mod/attendance:manageattendances', $context)) { if (has_capability('mod/attendance:manageattendances', $context)) {
$toprow[] = new tabobject(self::TAB_ADD, $toprow[] = new tabobject(self::TAB_ADD,
$this->att->url_sessions()->out(true, array('action' => att_sessions_page_params::ACTION_ADD)), $this->att->url_sessions()->out(true, array('action' => mod_attendance_sessions_page_params::ACTION_ADD)),
get_string('addsession', 'attendance')); get_string('addsession', 'attendance'));
} }
if (has_capability('mod/attendance:viewreports', $context)) { if (has_capability('mod/attendance:viewreports', $context)) {
@ -103,7 +103,7 @@ class attendance_tabs implements renderable {
} }
if ($this->currenttab == self::TAB_UPDATE && has_capability('mod/attendance:manageattendances', $context)) { if ($this->currenttab == self::TAB_UPDATE && has_capability('mod/attendance:manageattendances', $context)) {
$toprow[] = new tabobject(self::TAB_UPDATE, $toprow[] = new tabobject(self::TAB_UPDATE,
$this->att->url_sessions()->out(true, array('action' => att_sessions_page_params::ACTION_UPDATE)), $this->att->url_sessions()->out(true, array('action' => mod_attendance_sessions_page_params::ACTION_UPDATE)),
get_string('changesession', 'attendance')); get_string('changesession', 'attendance'));
} }
@ -370,7 +370,7 @@ class attendance_user_data implements renderable {
$this->decimalpoints = $CFG->grade_decimalpoints; $this->decimalpoints = $CFG->grade_decimalpoints;
} }
if ($this->pageparams->mode == att_view_page_params::MODE_THIS_COURSE) { if ($this->pageparams->mode == mod_attendance_view_page_params::MODE_THIS_COURSE) {
$this->statuses = $att->get_statuses(true, true); $this->statuses = $att->get_statuses(true, true);
$this->stat = $att->get_user_stat($userid); $this->stat = $att->get_user_stat($userid);

45
renderer.php

@ -75,7 +75,7 @@ class mod_attendance_renderer extends plugin_renderer_base {
protected function render_sess_group_selector(attendance_filter_controls $fcontrols) { protected function render_sess_group_selector(attendance_filter_controls $fcontrols) {
switch ($fcontrols->pageparams->selectortype) { switch ($fcontrols->pageparams->selectortype) {
case att_page_with_filter_controls::SELECTOR_SESS_TYPE: case mod_attendance_page_with_filter_controls::SELECTOR_SESS_TYPE:
$sessgroups = $fcontrols->get_sess_groups_list(); $sessgroups = $fcontrols->get_sess_groups_list();
if ($sessgroups) { if ($sessgroups) {
$select = new single_select($fcontrols->url(), 'group', $sessgroups, $select = new single_select($fcontrols->url(), 'group', $sessgroups,
@ -86,7 +86,7 @@ class mod_attendance_renderer extends plugin_renderer_base {
return html_writer::tag('div', $output, array('class' => 'groupselector')); return html_writer::tag('div', $output, array('class' => 'groupselector'));
} }
break; break;
case att_page_with_filter_controls::SELECTOR_GROUP: case mod_attendance_page_with_filter_controls::SELECTOR_GROUP:
return groups_print_activity_menu($fcontrols->cm, $fcontrols->url(), true); return groups_print_activity_menu($fcontrols->cm, $fcontrols->url(), true);
} }
@ -278,11 +278,11 @@ class mod_attendance_renderer extends plugin_renderer_base {
} }
if (has_capability('mod/attendance:manageattendances', $sessdata->att->context)) { if (has_capability('mod/attendance:manageattendances', $sessdata->att->context)) {
$url = $sessdata->url_sessions($sess->id, att_sessions_page_params::ACTION_UPDATE); $url = $sessdata->url_sessions($sess->id, mod_attendance_sessions_page_params::ACTION_UPDATE);
$title = get_string('editsession', 'attendance'); $title = get_string('editsession', 'attendance');
$actions .= $this->output->action_icon($url, new pix_icon('t/edit', $title)); $actions .= $this->output->action_icon($url, new pix_icon('t/edit', $title));
$url = $sessdata->url_sessions($sess->id, att_sessions_page_params::ACTION_DELETE); $url = $sessdata->url_sessions($sess->id, mod_attendance_sessions_page_params::ACTION_DELETE);
$title = get_string('deletesession', 'attendance'); $title = get_string('deletesession', 'attendance');
$actions .= $this->output->action_icon($url, new pix_icon('t/delete', $title)); $actions .= $this->output->action_icon($url, new pix_icon('t/delete', $title));
} }
@ -310,9 +310,8 @@ class mod_attendance_renderer extends plugin_renderer_base {
$table->data[1][] = html_writer::empty_tag('input', $attributes); $table->data[1][] = html_writer::empty_tag('input', $attributes);
} }
$options = array( $options = array(mod_attendance_sessions_page_params::ACTION_DELETE_SELECTED => get_string('delete'),
att_sessions_page_params::ACTION_DELETE_SELECTED => get_string('delete'), mod_attendance_sessions_page_params::ACTION_CHANGE_DURATION => get_string('changeduration', 'attendance'));
att_sessions_page_params::ACTION_CHANGE_DURATION => get_string('changeduration', 'attendance'));
$controls = html_writer::select($options, 'action'); $controls = html_writer::select($options, 'action');
$attributes = array( $attributes = array(
@ -331,7 +330,7 @@ class mod_attendance_renderer extends plugin_renderer_base {
protected function render_attendance_take_data(attendance_take_data $takedata) { protected function render_attendance_take_data(attendance_take_data $takedata) {
$controls = $this->render_attendance_take_controls($takedata); $controls = $this->render_attendance_take_controls($takedata);
if ($takedata->pageparams->viewmode == att_take_page_params::SORTED_LIST) { if ($takedata->pageparams->viewmode == mod_attendance_take_page_params::SORTED_LIST) {
$table = $this->render_attendance_take_list($takedata); $table = $this->render_attendance_take_list($takedata);
} else { } else {
$table = $this->render_attendance_take_grid($takedata); $table = $this->render_attendance_take_grid($takedata);
@ -443,14 +442,14 @@ class mod_attendance_renderer extends plugin_renderer_base {
$controls .= html_writer::empty_tag('br'); $controls .= html_writer::empty_tag('br');
$options = array( $options = array(
att_take_page_params::SORTED_LIST => get_string('sortedlist', 'attendance'), mod_attendance_take_page_params::SORTED_LIST => get_string('sortedlist', 'attendance'),
att_take_page_params::SORTED_GRID => get_string('sortedgrid', 'attendance')); mod_attendance_take_page_params::SORTED_GRID => get_string('sortedgrid', 'attendance'));
$select = new single_select($takedata->url(), 'viewmode', $options, $takedata->pageparams->viewmode, null); $select = new single_select($takedata->url(), 'viewmode', $options, $takedata->pageparams->viewmode, null);
$select->set_label(get_string('viewmode', 'attendance')); $select->set_label(get_string('viewmode', 'attendance'));
$select->class = 'singleselect inline'; $select->class = 'singleselect inline';
$controls .= $this->output->render($select); $controls .= $this->output->render($select);
if ($takedata->pageparams->viewmode == att_take_page_params::SORTED_LIST) { if ($takedata->pageparams->viewmode == mod_attendance_take_page_params::SORTED_LIST) {
$options = array( $options = array(
0 => get_string('donotusepaging', 'attendance'), 0 => get_string('donotusepaging', 'attendance'),
get_config('attendance', 'resultsperpage') => get_config('attendance', 'resultsperpage')); get_config('attendance', 'resultsperpage') => get_config('attendance', 'resultsperpage'));
@ -459,7 +458,7 @@ class mod_attendance_renderer extends plugin_renderer_base {
$controls .= $this->output->render($select); $controls .= $this->output->render($select);
} }
if ($takedata->pageparams->viewmode == att_take_page_params::SORTED_GRID) { if ($takedata->pageparams->viewmode == mod_attendance_take_page_params::SORTED_GRID) {
$options = array (1 => '1 '.get_string('column', 'attendance'), '2 '.get_string('columns', 'attendance'), $options = array (1 => '1 '.get_string('column', 'attendance'), '2 '.get_string('columns', 'attendance'),
'3 '.get_string('columns', 'attendance'), '4 '.get_string('columns', 'attendance'), '3 '.get_string('columns', 'attendance'), '4 '.get_string('columns', 'attendance'),
'5 '.get_string('columns', 'attendance'), '6 '.get_string('columns', 'attendance'), '5 '.get_string('columns', 'attendance'), '6 '.get_string('columns', 'attendance'),
@ -663,7 +662,7 @@ class mod_attendance_renderer extends plugin_renderer_base {
$input = html_writer::empty_tag('input', $params); $input = html_writer::empty_tag('input', $params);
if ($takedata->pageparams->viewmode == att_take_page_params::SORTED_GRID) { if ($takedata->pageparams->viewmode == mod_attendance_take_page_params::SORTED_GRID) {
$input = html_writer::tag('nobr', $input . $st->acronym); $input = html_writer::tag('nobr', $input . $st->acronym);
} }
@ -707,14 +706,14 @@ class mod_attendance_renderer extends plugin_renderer_base {
protected function render_user_report_tabs(attendance_user_data $userdata) { protected function render_user_report_tabs(attendance_user_data $userdata) {
$tabs = array(); $tabs = array();
$tabs[] = new tabobject(att_view_page_params::MODE_THIS_COURSE, $tabs[] = new tabobject(mod_attendance_view_page_params::MODE_THIS_COURSE,
$userdata->url()->out(true, array('mode' => att_view_page_params::MODE_THIS_COURSE)), $userdata->url()->out(true, array('mode' => mod_attendance_view_page_params::MODE_THIS_COURSE)),
get_string('thiscourse', 'attendance')); get_string('thiscourse', 'attendance'));
// Skip the 'all courses' tab for 'temporary' users. // Skip the 'all courses' tab for 'temporary' users.
if ($userdata->user->type == 'standard') { if ($userdata->user->type == 'standard') {
$tabs[] = new tabobject(att_view_page_params::MODE_ALL_COURSES, $tabs[] = new tabobject(mod_attendance_view_page_params::MODE_ALL_COURSES,
$userdata->url()->out(true, array('mode' => att_view_page_params::MODE_ALL_COURSES)), $userdata->url()->out(true, array('mode' => mod_attendance_view_page_params::MODE_ALL_COURSES)),
get_string('allcourses', 'attendance')); get_string('allcourses', 'attendance'));
} }
@ -724,7 +723,7 @@ class mod_attendance_renderer extends plugin_renderer_base {
private function construct_user_data(attendance_user_data $userdata) { private function construct_user_data(attendance_user_data $userdata) {
$o = html_writer::tag('h2', fullname($userdata->user)); $o = html_writer::tag('h2', fullname($userdata->user));
if ($userdata->pageparams->mode == att_view_page_params::MODE_THIS_COURSE) { if ($userdata->pageparams->mode == mod_attendance_view_page_params::MODE_THIS_COURSE) {
$o .= html_writer::empty_tag('hr'); $o .= html_writer::empty_tag('hr');
$o .= construct_user_data_stat($userdata->stat, $userdata->statuses, $o .= construct_user_data_stat($userdata->stat, $userdata->statuses,
@ -1027,7 +1026,7 @@ class mod_attendance_renderer extends plugin_renderer_base {
$table->data[$i][] = $this->construct_text_input('newdescription', 30, 30); $table->data[$i][] = $this->construct_text_input('newdescription', 30, 30);
$table->data[$i][] = $this->construct_text_input('newgrade', 4, 4); $table->data[$i][] = $this->construct_text_input('newgrade', 4, 4);
$table->data[$i][] = $this->construct_preferences_button(get_string('add', 'attendance'), $table->data[$i][] = $this->construct_preferences_button(get_string('add', 'attendance'),
att_preferences_page_params::ACTION_ADD); mod_attendance_preferences_page_params::ACTION_ADD);
$o = html_writer::tag('h1', get_string('myvariables', 'attendance')); $o = html_writer::tag('h1', get_string('myvariables', 'attendance'));
$o .= html_writer::table($table); $o .= html_writer::table($table);
@ -1035,7 +1034,7 @@ class mod_attendance_renderer extends plugin_renderer_base {
// We should probably rewrite this to use mforms but for now add sesskey. // We should probably rewrite this to use mforms but for now add sesskey.
$o .= html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'sesskey', 'value' => sesskey()))."\n"; $o .= html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'sesskey', 'value' => sesskey()))."\n";
$o .= $this->construct_preferences_button(get_string('update', 'attendance'), att_preferences_page_params::ACTION_SAVE); $o .= $this->construct_preferences_button(get_string('update', 'attendance'), mod_attendance_preferences_page_params::ACTION_SAVE);
$o = html_writer::tag('form', $o, array('id' => 'preferencesform', 'method' => 'post', $o = html_writer::tag('form', $o, array('id' => 'preferencesform', 'method' => 'post',
'action' => $prefdata->url(array(), false)->out_omit_querystring())); 'action' => $prefdata->url(array(), false)->out_omit_querystring()));
$o = $this->output->container($o, 'generalbox attwidth'); $o = $this->output->container($o, 'generalbox attwidth');
@ -1058,18 +1057,18 @@ class mod_attendance_renderer extends plugin_renderer_base {
$params = array('sesskey' => sesskey(), $params = array('sesskey' => sesskey(),
'statusid' => $st->id); 'statusid' => $st->id);
if ($st->visible) { if ($st->visible) {
$params['action'] = att_preferences_page_params::ACTION_HIDE; $params['action'] = mod_attendance_preferences_page_params::ACTION_HIDE;
$showhideicon = $OUTPUT->action_icon( $showhideicon = $OUTPUT->action_icon(
$prefdata->url($params), $prefdata->url($params),
new pix_icon("t/hide", get_string('hide'))); new pix_icon("t/hide", get_string('hide')));
} else { } else {
$params['action'] = att_preferences_page_params::ACTION_SHOW; $params['action'] = mod_attendance_preferences_page_params::ACTION_SHOW;
$showhideicon = $OUTPUT->action_icon( $showhideicon = $OUTPUT->action_icon(
$prefdata->url($params), $prefdata->url($params),
new pix_icon("t/show", get_string('show'))); new pix_icon("t/show", get_string('show')));
} }
if (!$st->haslogs) { if (!$st->haslogs) {
$params['action'] = att_preferences_page_params::ACTION_DELETE; $params['action'] = mod_attendance_preferences_page_params::ACTION_DELETE;
$deleteicon = $OUTPUT->action_icon( $deleteicon = $OUTPUT->action_icon(
$prefdata->url($params), $prefdata->url($params),
new pix_icon("t/delete", get_string('delete'))); new pix_icon("t/delete", get_string('delete')));

2
report.php

@ -25,7 +25,7 @@
require_once(dirname(__FILE__).'/../../config.php'); require_once(dirname(__FILE__).'/../../config.php');
require_once(dirname(__FILE__).'/locallib.php'); require_once(dirname(__FILE__).'/locallib.php');
$pageparams = new att_report_page_params(); $pageparams = new mod_attendance_report_page_params();
$id = required_param('id', PARAM_INT); $id = required_param('id', PARAM_INT);
$from = optional_param('from', null, PARAM_ACTION); $from = optional_param('from', null, PARAM_ACTION);

22
sessions.php

@ -28,13 +28,13 @@ require_once(dirname(__FILE__).'/add_form.php');
require_once(dirname(__FILE__).'/update_form.php'); require_once(dirname(__FILE__).'/update_form.php');
require_once(dirname(__FILE__).'/duration_form.php'); require_once(dirname(__FILE__).'/duration_form.php');
$pageparams = new att_sessions_page_params(); $pageparams = new mod_attendance_sessions_page_params();
$id = required_param('id', PARAM_INT); $id = required_param('id', PARAM_INT);
$pageparams->action = required_param('action', PARAM_INT); $pageparams->action = required_param('action', PARAM_INT);
if (optional_param('deletehiddensessions', false, PARAM_TEXT)) { if (optional_param('deletehiddensessions', false, PARAM_TEXT)) {
$pageparams->action = att_sessions_page_params::ACTION_DELETE_HIDDEN; $pageparams->action = mod_attendance_sessions_page_params::ACTION_DELETE_HIDDEN;
} }
if (empty($pageparams->action)) { if (empty($pageparams->action)) {
@ -65,8 +65,8 @@ $PAGE->navbar->add($att->name);
$currenttab = attendance_tabs::TAB_ADD; $currenttab = attendance_tabs::TAB_ADD;
$formparams = array('course' => $course, 'cm' => $cm, 'modcontext' => $context, 'att' => $att); $formparams = array('course' => $course, 'cm' => $cm, 'modcontext' => $context, 'att' => $att);
switch ($att->pageparams->action) { switch ($att->pageparams->action) {
case att_sessions_page_params::ACTION_ADD: case mod_attendance_sessions_page_params::ACTION_ADD:
$url = $att->url_sessions(array('action' => att_sessions_page_params::ACTION_ADD)); $url = $att->url_sessions(array('action' => mod_attendance_sessions_page_params::ACTION_ADD));
$mform = new mod_attendance_add_form($url, $formparams); $mform = new mod_attendance_add_form($url, $formparams);
if ($mform->is_cancelled()) { if ($mform->is_cancelled()) {
@ -88,10 +88,10 @@ switch ($att->pageparams->action) {
redirect($att->url_manage()); redirect($att->url_manage());
} }
break; break;
case att_sessions_page_params::ACTION_UPDATE: case mod_attendance_sessions_page_params::ACTION_UPDATE:
$sessionid = required_param('sessionid', PARAM_INT); $sessionid = required_param('sessionid', PARAM_INT);
$url = $att->url_sessions(array('action' => att_sessions_page_params::ACTION_UPDATE, 'sessionid' => $sessionid)); $url = $att->url_sessions(array('action' => mod_attendance_sessions_page_params::ACTION_UPDATE, 'sessionid' => $sessionid));
$formparams['sessionid'] = $sessionid; $formparams['sessionid'] = $sessionid;
$mform = new mod_attendance_update_form($url, $formparams); $mform = new mod_attendance_update_form($url, $formparams);
@ -107,7 +107,7 @@ switch ($att->pageparams->action) {
} }
$currenttab = attendance_tabs::TAB_UPDATE; $currenttab = attendance_tabs::TAB_UPDATE;
break; break;
case att_sessions_page_params::ACTION_DELETE: case mod_attendance_sessions_page_params::ACTION_DELETE:
$sessionid = required_param('sessionid', PARAM_INT); $sessionid = required_param('sessionid', PARAM_INT);
$confirm = optional_param('confirm', null, PARAM_INT); $confirm = optional_param('confirm', null, PARAM_INT);
@ -134,7 +134,7 @@ switch ($att->pageparams->action) {
echo $OUTPUT->confirm($message, $att->url_sessions($params), $att->url_manage()); echo $OUTPUT->confirm($message, $att->url_sessions($params), $att->url_manage());
echo $OUTPUT->footer(); echo $OUTPUT->footer();
exit; exit;
case att_sessions_page_params::ACTION_DELETE_SELECTED: case mod_attendance_sessions_page_params::ACTION_DELETE_SELECTED:
$confirm = optional_param('confirm', null, PARAM_INT); $confirm = optional_param('confirm', null, PARAM_INT);
if (isset($confirm) && confirm_sesskey()) { if (isset($confirm) && confirm_sesskey()) {
@ -171,13 +171,13 @@ switch ($att->pageparams->action) {
echo $OUTPUT->confirm($message, $att->url_sessions($params), $att->url_manage()); echo $OUTPUT->confirm($message, $att->url_sessions($params), $att->url_manage());
echo $OUTPUT->footer(); echo $OUTPUT->footer();
exit; exit;
case att_sessions_page_params::ACTION_CHANGE_DURATION: case mod_attendance_sessions_page_params::ACTION_CHANGE_DURATION:
$sessid = optional_param_array('sessid', '', PARAM_SEQUENCE); $sessid = optional_param_array('sessid', '', PARAM_SEQUENCE);
$ids = optional_param('ids', '', PARAM_ALPHANUMEXT); $ids = optional_param('ids', '', PARAM_ALPHANUMEXT);
$slist = !empty($sessid) ? implode('_', $sessid) : ''; $slist = !empty($sessid) ? implode('_', $sessid) : '';
$url = $att->url_sessions(array('action' => att_sessions_page_params::ACTION_CHANGE_DURATION)); $url = $att->url_sessions(array('action' => mod_attendance_sessions_page_params::ACTION_CHANGE_DURATION));
$formparams['ids'] = $slist; $formparams['ids'] = $slist;
$mform = new mod_attendance_duration_form($url, $formparams); $mform = new mod_attendance_duration_form($url, $formparams);
@ -197,7 +197,7 @@ switch ($att->pageparams->action) {
} }
break; break;
case att_sessions_page_params::ACTION_DELETE_HIDDEN: case mod_attendance_sessions_page_params::ACTION_DELETE_HIDDEN:
$confirm = optional_param('confirm', null, PARAM_INT); $confirm = optional_param('confirm', null, PARAM_INT);
if ($confirm && confirm_sesskey()) { if ($confirm && confirm_sesskey()) {
$sessions = $att->get_hidden_sessions(); $sessions = $att->get_hidden_sessions();

2
take.php

@ -25,7 +25,7 @@
require_once(dirname(__FILE__).'/../../config.php'); require_once(dirname(__FILE__).'/../../config.php');
require_once(dirname(__FILE__).'/locallib.php'); require_once(dirname(__FILE__).'/locallib.php');
$pageparams = new att_take_page_params(); $pageparams = new mod_attendance_take_page_params();
$id = required_param('id', PARAM_INT); $id = required_param('id', PARAM_INT);
$pageparams->sessionid = required_param('sessionid', PARAM_INT); $pageparams->sessionid = required_param('sessionid', PARAM_INT);

4
view.php

@ -26,11 +26,11 @@
require_once(dirname(__FILE__).'/../../config.php'); require_once(dirname(__FILE__).'/../../config.php');
require_once(dirname(__FILE__).'/locallib.php'); require_once(dirname(__FILE__).'/locallib.php');
$pageparams = new att_view_page_params(); $pageparams = new mod_attendance_view_page_params();
$id = required_param('id', PARAM_INT); $id = required_param('id', PARAM_INT);
$pageparams->studentid = optional_param('studentid', null, PARAM_INT); $pageparams->studentid = optional_param('studentid', null, PARAM_INT);
$pageparams->mode = optional_param('mode', att_view_page_params::MODE_THIS_COURSE, PARAM_INT); $pageparams->mode = optional_param('mode', mod_attendance_view_page_params::MODE_THIS_COURSE, PARAM_INT);
$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);

Loading…
Cancel
Save