Browse Source

rename attforblock module to attendance - also includes upgrade script to rename old attforblock tables.

MOODLE_23_STABLE
Dan Marsden 12 years ago
parent
commit
8a1d4654e9
  1. 2
      README.md
  2. 58
      add_form.php
  3. 22
      backup/moodle2/backup_attforblock_activity_task.class.php
  4. 2
      backup/moodle2/backup_attforblock_settingslib.php
  5. 20
      backup/moodle2/backup_attforblock_stepslib.php
  6. 18
      backup/moodle2/restore_attforblock_activity_task.class.php
  7. 50
      backup/moodle2/restore_attforblock_stepslib.php
  8. 10
      calendar.js
  9. 18
      db/access.php
  10. 8
      db/install.php
  11. 8
      db/install.xml
  12. 300
      db/upgrade.php
  13. 10
      duration_form.php
  14. 26
      export.php
  15. 20
      export_form.php
  16. 4
      index.php
  17. 21
      lang/en/attendance.php
  18. 192
      lib.php
  19. 138
      locallib.php
  20. 24
      manage.php
  21. 8
      mod_form.php
  22. 6
      module.js
  23. 32
      preferences.php
  24. 58
      renderables.php
  25. 190
      renderer.php
  26. 36
      renderhelpers.php
  27. 24
      report.php
  28. 50
      sessions.php
  29. 62
      styles.css
  30. 20
      take.php
  31. 20
      update_form.php
  32. 12
      version.php
  33. 14
      view.php

2
README.md

@ -16,6 +16,6 @@ INSTALLATION
========== ==========
The attendance module follows standard installation procedure. The attendance module follows standard installation procedure.
1. Create folder <path to your moodle dir>/mod/attforblock. 1. Create folder <path to your moodle dir>/mod/attendance.
2. Extract files from folder inside archive to created folder. 2. Extract files from folder inside archive to created folder.
3. Visit page Home ► Site administration ► Notifications to complete installation. 3. Visit page Home ► Site administration ► Notifications to complete installation.

58
add_form.php

@ -24,7 +24,7 @@
require_once($CFG->libdir.'/formslib.php'); require_once($CFG->libdir.'/formslib.php');
class mod_attforblock_add_form extends moodleform { class mod_attendance_add_form extends moodleform {
public function definition() { public function definition() {
@ -35,31 +35,31 @@ class mod_attforblock_add_form extends moodleform {
$cm = $this->_customdata['cm']; $cm = $this->_customdata['cm'];
$modcontext = $this->_customdata['modcontext']; $modcontext = $this->_customdata['modcontext'];
$mform->addElement('header', 'general', get_string('addsession', 'attforblock')); $mform->addElement('header', 'general', get_string('addsession', 'attendance'));
$groupmode = groups_get_activity_groupmode($cm); $groupmode = groups_get_activity_groupmode($cm);
switch ($groupmode) { switch ($groupmode) {
case NOGROUPS: case NOGROUPS:
$mform->addElement('static', 'sessiontypedescription', get_string('sessiontype', 'attforblock'), $mform->addElement('static', 'sessiontypedescription', get_string('sessiontype', 'attendance'),
get_string('commonsession', 'attforblock')); get_string('commonsession', 'attendance'));
$mform->addHelpButton('sessiontypedescription', 'sessiontype', 'attforblock'); $mform->addHelpButton('sessiontypedescription', 'sessiontype', 'attendance');
$mform->addElement('hidden', 'sessiontype', attforblock::SESSION_COMMON); $mform->addElement('hidden', 'sessiontype', attendance::SESSION_COMMON);
break; break;
case SEPARATEGROUPS: case SEPARATEGROUPS:
$mform->addElement('static', 'sessiontypedescription', get_string('sessiontype', 'attforblock'), $mform->addElement('static', 'sessiontypedescription', get_string('sessiontype', 'attendance'),
get_string('groupsession', 'attforblock')); get_string('groupsession', 'attendance'));
$mform->addHelpButton('sessiontypedescription', 'sessiontype', 'attforblock'); $mform->addHelpButton('sessiontypedescription', 'sessiontype', 'attendance');
$mform->addElement('hidden', 'sessiontype', attforblock::SESSION_GROUP); $mform->addElement('hidden', 'sessiontype', attendance::SESSION_GROUP);
break; break;
case VISIBLEGROUPS: case VISIBLEGROUPS:
$radio=array(); $radio=array();
$radio[] = &$mform->createElement('radio', 'sessiontype', '', $radio[] = &$mform->createElement('radio', 'sessiontype', '',
get_string('commonsession', 'attforblock'), attforblock::SESSION_COMMON); get_string('commonsession', 'attendance'), attendance::SESSION_COMMON);
$radio[] = &$mform->createElement('radio', 'sessiontype', '', $radio[] = &$mform->createElement('radio', 'sessiontype', '',
get_string('groupsession', 'attforblock'), attforblock::SESSION_GROUP); get_string('groupsession', 'attendance'), attendance::SESSION_GROUP);
$mform->addGroup($radio, 'sessiontype', get_string('sessiontype', 'attforblock'), ' ', false); $mform->addGroup($radio, 'sessiontype', get_string('sessiontype', 'attendance'), ' ', false);
$mform->addHelpButton('sessiontype', 'sessiontype', 'attforblock'); $mform->addHelpButton('sessiontype', 'sessiontype', 'attendance');
$mform->setDefault('sessiontype', attforblock::SESSION_COMMON); $mform->setDefault('sessiontype', attendance::SESSION_COMMON);
break; break;
} }
if ($groupmode == SEPARATEGROUPS or $groupmode == VISIBLEGROUPS) { if ($groupmode == SEPARATEGROUPS or $groupmode == VISIBLEGROUPS) {
@ -75,21 +75,21 @@ class mod_attforblock_add_form extends moodleform {
} }
$select = &$mform->addElement('select', 'groups', get_string('groups', 'group'), $selectgroups); $select = &$mform->addElement('select', 'groups', get_string('groups', 'group'), $selectgroups);
$select->setMultiple(true); $select->setMultiple(true);
$mform->disabledIf('groups', 'sessiontype', 'neq', attforblock::SESSION_GROUP); $mform->disabledIf('groups', 'sessiontype', 'neq', attendance::SESSION_GROUP);
} else { } else {
$mform->updateElementAttr($radio, array('disabled'=>'disabled')); $mform->updateElementAttr($radio, array('disabled'=>'disabled'));
$mform->addElement('static', 'groups', get_string('groups', 'group'), $mform->addElement('static', 'groups', get_string('groups', 'group'),
get_string('nogroups', 'attforblock')); get_string('nogroups', 'attendance'));
if ($groupmode == SEPARATEGROUPS) { if ($groupmode == SEPARATEGROUPS) {
return; return;
} }
} }
} }
$mform->addElement('checkbox', 'addmultiply', '', get_string('createmultiplesessions', 'attforblock')); $mform->addElement('checkbox', 'addmultiply', '', get_string('createmultiplesessions', 'attendance'));
$mform->addHelpButton('addmultiply', 'createmultiplesessions', 'attforblock'); $mform->addHelpButton('addmultiply', 'createmultiplesessions', 'attendance');
$mform->addElement('date_time_selector', 'sessiondate', get_string('sessiondate', 'attforblock')); $mform->addElement('date_time_selector', 'sessiondate', get_string('sessiondate', 'attendance'));
for ($i=0; $i<=23; $i++) { for ($i=0; $i<=23; $i++) {
$hours[$i] = sprintf("%02d", $i); $hours[$i] = sprintf("%02d", $i);
@ -100,9 +100,9 @@ class mod_attforblock_add_form extends moodleform {
$durtime = array(); $durtime = array();
$durtime[] =& $mform->createElement('select', 'hours', get_string('hour', 'form'), $hours, false, true); $durtime[] =& $mform->createElement('select', 'hours', get_string('hour', 'form'), $hours, false, true);
$durtime[] =& $mform->createElement('select', 'minutes', get_string('minute', 'form'), $minutes, false, true); $durtime[] =& $mform->createElement('select', 'minutes', get_string('minute', 'form'), $minutes, false, true);
$mform->addGroup($durtime, 'durtime', get_string('duration', 'attforblock'), array(' '), true); $mform->addGroup($durtime, 'durtime', get_string('duration', 'attendance'), array(' '), true);
$mform->addElement('date_selector', 'sessionenddate', get_string('sessionenddate', 'attforblock')); $mform->addElement('date_selector', 'sessionenddate', get_string('sessionenddate', 'attendance'));
$mform->disabledIf('sessionenddate', 'addmultiply', 'notchecked'); $mform->disabledIf('sessionenddate', 'addmultiply', 'notchecked');
$sdays = array(); $sdays = array();
@ -118,29 +118,29 @@ class mod_attforblock_add_form extends moodleform {
if ($CFG->calendar_startwday !== '0') { // Week start from sunday. if ($CFG->calendar_startwday !== '0') { // Week start from sunday.
$sdays[] =& $mform->createElement('checkbox', 'Sun', '', get_string('sunday', 'calendar')); $sdays[] =& $mform->createElement('checkbox', 'Sun', '', get_string('sunday', 'calendar'));
} }
$mform->addGroup($sdays, 'sdays', get_string('sessiondays', 'attforblock'), array(' '), true); $mform->addGroup($sdays, 'sdays', get_string('sessiondays', 'attendance'), array(' '), true);
$mform->disabledIf('sdays', 'addmultiply', 'notchecked'); $mform->disabledIf('sdays', 'addmultiply', 'notchecked');
$period = array(1=>1, 2, 3, 4, 5, 6, 7, 8); $period = array(1=>1, 2, 3, 4, 5, 6, 7, 8);
$periodgroup = array(); $periodgroup = array();
$periodgroup[] =& $mform->createElement('select', 'period', '', $period, false, true); $periodgroup[] =& $mform->createElement('select', 'period', '', $period, false, true);
$periodgroup[] =& $mform->createElement('static', 'perioddesc', '', get_string('week', 'attforblock')); $periodgroup[] =& $mform->createElement('static', 'perioddesc', '', get_string('week', 'attendance'));
$mform->addGroup($periodgroup, 'periodgroup', get_string('period', 'attforblock'), array(' '), false); $mform->addGroup($periodgroup, 'periodgroup', get_string('period', 'attendance'), array(' '), false);
$mform->disabledIf('periodgroup', 'addmultiply', 'notchecked'); $mform->disabledIf('periodgroup', 'addmultiply', 'notchecked');
$mform->addElement('editor', 'sdescription', get_string('description', 'attforblock'), $mform->addElement('editor', 'sdescription', get_string('description', 'attendance'),
null, array('maxfiles'=>EDITOR_UNLIMITED_FILES, 'noclean'=>true, 'context'=>$modcontext)); null, array('maxfiles'=>EDITOR_UNLIMITED_FILES, 'noclean'=>true, 'context'=>$modcontext));
$mform->setType('sdescription', PARAM_RAW); $mform->setType('sdescription', PARAM_RAW);
$submit_string = get_string('addsession', 'attforblock'); $submit_string = get_string('addsession', 'attendance');
$this->add_action_buttons(false, $submit_string); $this->add_action_buttons(false, $submit_string);
} }
public function validation($data, $files) { public function validation($data, $files) {
$errors = parent::validation($data, $files); $errors = parent::validation($data, $files);
if ($data['sessiontype'] == attforblock::SESSION_GROUP and empty($data['groups'])) { if ($data['sessiontype'] == attendance::SESSION_GROUP and empty($data['groups'])) {
$errors['groups'] = get_string('errorgroupsnotselected', 'attforblock'); $errors['groups'] = get_string('errorgroupsnotselected', 'attendance');
} }
return $errors; return $errors;
} }

22
backup/moodle2/backup_attforblock_activity_task.class.php

@ -15,23 +15,23 @@
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/** /**
* Class {@link backup_attforblock_activity_task} definition * Class {@link backup_attendance_activity_task} definition
* *
* @package mod * @package mod
* @subpackage attforblock * @subpackage attendance
* @copyright 2011 Artem Andreev <andreev.artem@gmail.com> * @copyright 2011 Artem Andreev <andreev.artem@gmail.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/ */
defined('MOODLE_INTERNAL') || die(); defined('MOODLE_INTERNAL') || die();
require_once($CFG->dirroot . '/mod/attforblock/backup/moodle2/backup_attforblock_settingslib.php'); require_once($CFG->dirroot . '/mod/attendance/backup/moodle2/backup_attendance_settingslib.php');
require_once($CFG->dirroot . '/mod/attforblock/backup/moodle2/backup_attforblock_stepslib.php'); require_once($CFG->dirroot . '/mod/attendance/backup/moodle2/backup_attendance_stepslib.php');
/** /**
* Provides all the settings and steps to perform one complete backup of attforblock activity * Provides all the settings and steps to perform one complete backup of attendance activity
*/ */
class backup_attforblock_activity_task extends backup_activity_task { class backup_attendance_activity_task extends backup_activity_task {
/** /**
* Define (add) particular settings this activity can have * Define (add) particular settings this activity can have
@ -43,7 +43,7 @@ class backup_attforblock_activity_task extends backup_activity_task {
* Define (add) particular steps this activity can have * Define (add) particular steps this activity can have
*/ */
protected function define_my_steps() { protected function define_my_steps() {
$this->add_step(new backup_attforblock_activity_structure_step('attforblock_structure', 'attforblock.xml')); $this->add_step(new backup_attendance_activity_structure_step('attendance_structure', 'attendance.xml'));
} }
/** /**
@ -55,12 +55,12 @@ class backup_attforblock_activity_task extends backup_activity_task {
$base = preg_quote($CFG->wwwroot, "/"); $base = preg_quote($CFG->wwwroot, "/");
// Link to attforblock view by moduleid. // Link to attendance view by moduleid.
$search = "/(" . $base . "\/mod\/attforblock\/view.php\?id\=)([0-9]+)/"; $search = "/(" . $base . "\/mod\/attendance\/view.php\?id\=)([0-9]+)/";
$content= preg_replace($search, '$@ATTFORBLOCKVIEWBYID*$2@$', $content); $content= preg_replace($search, '$@ATTFORBLOCKVIEWBYID*$2@$', $content);
// Link to attforblock view by moduleid and studentid. // Link to attendance view by moduleid and studentid.
$search = "/(" . $base . "\/mod\/attforblock\/view.php\?id\=)([0-9]+)\&studentid\=([0-9]+)/"; $search = "/(" . $base . "\/mod\/attendance\/view.php\?id\=)([0-9]+)\&studentid\=([0-9]+)/";
$content= preg_replace($search, '$@ATTFORBLOCKVIEWBYIDSTUD*$2*$3@$', $content); $content= preg_replace($search, '$@ATTFORBLOCKVIEWBYIDSTUD*$2*$3@$', $content);
return $content; return $content;

2
backup/moodle2/backup_attforblock_settingslib.php

@ -16,7 +16,7 @@
/** /**
* @package mod * @package mod
* @subpackage attforblock * @subpackage attendance
* @copyright 2011 Artem Andreev <andreev.artem@gmail.com> * @copyright 2011 Artem Andreev <andreev.artem@gmail.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/ */

20
backup/moodle2/backup_attforblock_stepslib.php

@ -15,10 +15,10 @@
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/** /**
* Defines all the backup steps that will be used by {@link backup_attforblock_activity_task} * Defines all the backup steps that will be used by {@link backup_attendance_activity_task}
* *
* @package mod * @package mod
* @subpackage attforblock * @subpackage attendance
* @copyright 2011 Artem Andreev <andreev.artem@gmail.com> * @copyright 2011 Artem Andreev <andreev.artem@gmail.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/ */
@ -26,9 +26,9 @@
defined('MOODLE_INTERNAL') || die(); defined('MOODLE_INTERNAL') || die();
/** /**
* Defines the complete attforblock structure for backup, with file and id annotations * Defines the complete attendance structure for backup, with file and id annotations
*/ */
class backup_attforblock_activity_structure_step extends backup_activity_structure_step { class backup_attendance_activity_structure_step extends backup_activity_structure_step {
protected function define_structure() { protected function define_structure() {
@ -36,7 +36,7 @@ class backup_attforblock_activity_structure_step extends backup_activity_structu
$userinfo = $this->get_setting_value('userinfo'); $userinfo = $this->get_setting_value('userinfo');
// XML nodes declaration - non-user data. // XML nodes declaration - non-user data.
$attforblock = new backup_nested_element('attforblock', array('id'), array( $attendance = new backup_nested_element('attendance', array('id'), array(
'name', 'grade')); 'name', 'grade'));
$statuses = new backup_nested_element('statuses'); $statuses = new backup_nested_element('statuses');
@ -55,10 +55,10 @@ class backup_attforblock_activity_structure_step extends backup_activity_structu
'timetaken', 'takenby', 'remarks')); 'timetaken', 'takenby', 'remarks'));
// Build the tree in the order needed for restore. // Build the tree in the order needed for restore.
$attforblock->add_child($statuses); $attendance->add_child($statuses);
$statuses->add_child($status); $statuses->add_child($status);
$attforblock->add_child($sessions); $attendance->add_child($sessions);
$sessions->add_child($session); $sessions->add_child($session);
$session->add_child($logs); $session->add_child($logs);
@ -66,7 +66,7 @@ class backup_attforblock_activity_structure_step extends backup_activity_structu
// Data sources - non-user data. // Data sources - non-user data.
$attforblock->set_source_table('attforblock', array('id' => backup::VAR_ACTIVITYID)); $attendance->set_source_table('attendance', array('id' => backup::VAR_ACTIVITYID));
$status->set_source_table('attendance_statuses', array('attendanceid' => backup::VAR_PARENTID)); $status->set_source_table('attendance_statuses', array('attendanceid' => backup::VAR_PARENTID));
@ -84,9 +84,9 @@ class backup_attforblock_activity_structure_step extends backup_activity_structu
$log->annotate_ids('user', 'takenby'); $log->annotate_ids('user', 'takenby');
// File annotations. // File annotations.
$session->annotate_files('mod_attforblock', 'session', 'id'); $session->annotate_files('mod_attendance', 'session', 'id');
// Return the root element (workshop), wrapped into standard activity structure. // Return the root element (workshop), wrapped into standard activity structure.
return $this->prepare_activity_structure($attforblock); return $this->prepare_activity_structure($attendance);
} }
} }

18
backup/moodle2/restore_attforblock_activity_task.class.php

@ -16,20 +16,20 @@
/** /**
* @package mod * @package mod
* @subpackage attforblock * @subpackage attendance
* @copyright 2011 Artem Andreev <andreev.artem@gmail.com> * @copyright 2011 Artem Andreev <andreev.artem@gmail.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/ */
defined('MOODLE_INTERNAL') || die(); defined('MOODLE_INTERNAL') || die();
require_once($CFG->dirroot . '/mod/attforblock/backup/moodle2/restore_attforblock_stepslib.php'); require_once($CFG->dirroot . '/mod/attendance/backup/moodle2/restore_attendance_stepslib.php');
/** /**
* attforblock restore task that provides all the settings and steps to perform one * attendance restore task that provides all the settings and steps to perform one
* complete restore of the activity * complete restore of the activity
*/ */
class restore_attforblock_activity_task extends restore_activity_task { class restore_attendance_activity_task extends restore_activity_task {
/** /**
* Define (add) particular settings this activity can have * Define (add) particular settings this activity can have
@ -41,7 +41,7 @@ class restore_attforblock_activity_task extends restore_activity_task {
* Define (add) particular steps this activity can have * Define (add) particular steps this activity can have
*/ */
protected function define_my_steps() { protected function define_my_steps() {
$this->add_step(new restore_attforblock_activity_structure_step('attforblock_structure', 'attforblock.xml')); $this->add_step(new restore_attendance_activity_structure_step('attendance_structure', 'attendance.xml'));
} }
/** /**
@ -52,7 +52,7 @@ class restore_attforblock_activity_task extends restore_activity_task {
$contents = array(); $contents = array();
$contents[] = new restore_decode_content('attendance_sessions', $contents[] = new restore_decode_content('attendance_sessions',
array('description'), 'attforblock_session'); array('description'), 'attendance_session');
return $contents; return $contents;
} }
@ -65,9 +65,9 @@ class restore_attforblock_activity_task extends restore_activity_task {
$rules = array(); $rules = array();
$rules[] = new restore_decode_rule('ATTFORBLOCKVIEWBYID', $rules[] = new restore_decode_rule('ATTFORBLOCKVIEWBYID',
'/mod/attforblock/view.php?id=$1', 'course_module'); '/mod/attendance/view.php?id=$1', 'course_module');
$rules[] = new restore_decode_rule('ATTFORBLOCKVIEWBYIDSTUD', $rules[] = new restore_decode_rule('ATTFORBLOCKVIEWBYIDSTUD',
'/mod/attforblock/view.php?id=$1&studentid=$2', array('course_module', 'user')); '/mod/attendance/view.php?id=$1&studentid=$2', array('course_module', 'user'));
return $rules; return $rules;
@ -76,7 +76,7 @@ class restore_attforblock_activity_task extends restore_activity_task {
/** /**
* Define the restore log rules that will be applied * Define the restore log rules that will be applied
* by the {@link restore_logs_processor} when restoring * by the {@link restore_logs_processor} when restoring
* attforblock logs. It must return one array * attendance logs. It must return one array
* of {@link restore_log_rule} objects * of {@link restore_log_rule} objects
*/ */
static public function define_restore_log_rules() { static public function define_restore_log_rules() {

50
backup/moodle2/restore_attforblock_stepslib.php

@ -16,7 +16,7 @@
/** /**
* @package mod * @package mod
* @subpackage attforblock * @subpackage attendance
* @copyright 2011 Artem Andreev <andreev.artem@gmail.com> * @copyright 2011 Artem Andreev <andreev.artem@gmail.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/ */
@ -24,13 +24,13 @@
defined('MOODLE_INTERNAL') || die(); defined('MOODLE_INTERNAL') || die();
/** /**
* Define all the restore steps that will be used by the restore_attforblock_activity_task * Define all the restore steps that will be used by the restore_attendance_activity_task
*/ */
/** /**
* Structure step to restore one attforblock activity * Structure step to restore one attendance activity
*/ */
class restore_attforblock_activity_structure_step extends restore_activity_structure_step { class restore_attendance_activity_structure_step extends restore_activity_structure_step {
protected function define_structure() { protected function define_structure() {
@ -39,13 +39,13 @@ class restore_attforblock_activity_structure_step extends restore_activity_struc
$userinfo = $this->get_setting_value('userinfo'); // Are we including userinfo? $userinfo = $this->get_setting_value('userinfo'); // Are we including userinfo?
// XML interesting paths - non-user data. // XML interesting paths - non-user data.
$paths[] = new restore_path_element('attforblock', '/activity/attforblock'); $paths[] = new restore_path_element('attendance', '/activity/attendance');
$paths[] = new restore_path_element('attforblock_status', $paths[] = new restore_path_element('attendance_status',
'/activity/attforblock/statuses/status'); '/activity/attendance/statuses/status');
$paths[] = new restore_path_element('attforblock_session', $paths[] = new restore_path_element('attendance_session',
'/activity/attforblock/sessions/session'); '/activity/attendance/sessions/session');
// End here if no-user data has been selected. // End here if no-user data has been selected.
if (!$userinfo) { if (!$userinfo) {
@ -53,45 +53,45 @@ class restore_attforblock_activity_structure_step extends restore_activity_struc
} }
// XML interesting paths - user data. // XML interesting paths - user data.
$paths[] = new restore_path_element('attforblock_log', $paths[] = new restore_path_element('attendance_log',
'/activity/attforblock/sessions/session/logs/log'); '/activity/attendance/sessions/session/logs/log');
// Return the paths wrapped into standard activity structure. // Return the paths wrapped into standard activity structure.
return $this->prepare_activity_structure($paths); return $this->prepare_activity_structure($paths);
} }
protected function process_attforblock($data) { protected function process_attendance($data) {
global $DB; global $DB;
$data = (object)$data; $data = (object)$data;
$oldid = $data->id; $oldid = $data->id;
$data->course = $this->get_courseid(); $data->course = $this->get_courseid();
// Insert the attforblock record. // Insert the attendance record.
$newitemid = $DB->insert_record('attforblock', $data); $newitemid = $DB->insert_record('attendance', $data);
// Immediately after inserting "activity" record, call this. // Immediately after inserting "activity" record, call this.
$this->apply_activity_instance($newitemid); $this->apply_activity_instance($newitemid);
} }
protected function process_attforblock_status($data) { protected function process_attendance_status($data) {
global $DB; global $DB;
$data = (object)$data; $data = (object)$data;
$oldid = $data->id; $oldid = $data->id;
$data->attendanceid = $this->get_new_parentid('attforblock'); $data->attendanceid = $this->get_new_parentid('attendance');
$newitemid = $DB->insert_record('attendance_statuses', $data); $newitemid = $DB->insert_record('attendance_statuses', $data);
$this->set_mapping('attforblock_status', $oldid, $newitemid); $this->set_mapping('attendance_status', $oldid, $newitemid);
} }
protected function process_attforblock_session($data) { protected function process_attendance_session($data) {
global $DB; global $DB;
$data = (object)$data; $data = (object)$data;
$oldid = $data->id; $oldid = $data->id;
$data->attendanceid = $this->get_new_parentid('attforblock'); $data->attendanceid = $this->get_new_parentid('attendance');
$data->groupid = $this->get_mappingid('group', $data->groupid); $data->groupid = $this->get_mappingid('group', $data->groupid);
$data->sessdate = $this->apply_date_offset($data->sessdate); $data->sessdate = $this->apply_date_offset($data->sessdate);
$data->lasttaken = $this->apply_date_offset($data->lasttaken); $data->lasttaken = $this->apply_date_offset($data->lasttaken);
@ -99,21 +99,21 @@ class restore_attforblock_activity_structure_step extends restore_activity_struc
$data->timemodified = $this->apply_date_offset($data->timemodified); $data->timemodified = $this->apply_date_offset($data->timemodified);
$newitemid = $DB->insert_record('attendance_sessions', $data); $newitemid = $DB->insert_record('attendance_sessions', $data);
$this->set_mapping('attforblock_session', $oldid, $newitemid, true); $this->set_mapping('attendance_session', $oldid, $newitemid, true);
} }
protected function process_attforblock_log($data) { protected function process_attendance_log($data) {
global $DB; global $DB;
$data = (object)$data; $data = (object)$data;
$oldid = $data->id; $oldid = $data->id;
$data->sessionid = $this->get_mappingid('attforblock_session', $data->sessionid); $data->sessionid = $this->get_mappingid('attendance_session', $data->sessionid);
$data->studentid = $this->get_mappingid('user', $data->studentid); $data->studentid = $this->get_mappingid('user', $data->studentid);
$data->statusid = $this->get_mappingid('attforblock_status', $data->statusid); $data->statusid = $this->get_mappingid('attendance_status', $data->statusid);
$statusset = explode(',', $data->statusset); $statusset = explode(',', $data->statusset);
foreach ($statusset as $st) { foreach ($statusset as $st) {
$st = $this->get_mappingid('attforblock_status', $st); $st = $this->get_mappingid('attendance_status', $st);
} }
$data->statusset = implode(',', $statusset); $data->statusset = implode(',', $statusset);
$data->timetaken = $this->apply_date_offset($data->timetaken); $data->timetaken = $this->apply_date_offset($data->timetaken);
@ -123,6 +123,6 @@ class restore_attforblock_activity_structure_step extends restore_activity_struc
} }
protected function after_execute() { protected function after_execute() {
$this->add_related_files('mod_attforblock', 'session', 'attforblock_session'); $this->add_related_files('mod_attendance', 'session', 'attendance_session');
} }
} }

10
calendar.js

@ -37,7 +37,7 @@ YUI().use('yui2-container', 'yui2-calendar', function(Y) {
dialog = new YAHOO.widget.Dialog("attcalendarcontainer", { dialog = new YAHOO.widget.Dialog("attcalendarcontainer", {
visible:false, visible:false,
context:["show", "tl", "bl"], context:["show", "tl", "bl"],
buttons:[{text: M.str.attforblock.caltoday, handler: resetHandler, isDefault:true}, {text: M.str.attforblock.calclose, handler: closeHandler}], buttons:[{text: M.str.attendance.caltoday, handler: resetHandler, isDefault:true}, {text: M.str.attendance.calclose, handler: closeHandler}],
draggable:false, draggable:false,
close:false close:false
}); });
@ -63,10 +63,10 @@ YUI().use('yui2-container', 'yui2-calendar', function(Y) {
hide_blank_weeks:true // Enable, to demonstrate how we handle changing height, using changeContent hide_blank_weeks:true // Enable, to demonstrate how we handle changing height, using changeContent
}); });
calendar.cfg.setProperty("start_weekday", M.attforblock.cal_start_weekday); calendar.cfg.setProperty("start_weekday", M.attendance.cal_start_weekday);
calendar.cfg.setProperty("MONTHS_LONG", M.attforblock.cal_months); calendar.cfg.setProperty("MONTHS_LONG", M.attendance.cal_months);
calendar.cfg.setProperty("WEEKDAYS_SHORT", M.attforblock.cal_week_days); calendar.cfg.setProperty("WEEKDAYS_SHORT", M.attendance.cal_week_days);
calendar.select(new Date(M.attforblock.cal_cur_date*1000)); calendar.select(new Date(M.attendance.cal_cur_date*1000));
calendar.render(); calendar.render();
calendar.selectEvent.subscribe(function() { calendar.selectEvent.subscribe(function() {

18
db/access.php

@ -47,7 +47,7 @@
$capabilities = array( $capabilities = array(
'mod/attforblock:view' => array( 'mod/attendance:view' => array(
'captype' => 'read', 'captype' => 'read',
'contextlevel' => CONTEXT_MODULE, 'contextlevel' => CONTEXT_MODULE,
'archetypes' => array( 'archetypes' => array(
@ -58,7 +58,7 @@ $capabilities = array(
) )
), ),
'mod/attforblock:addinstance' => array( 'mod/attendance:addinstance' => array(
'riskbitmask' => RISK_XSS, 'riskbitmask' => RISK_XSS,
'captype' => 'write', 'captype' => 'write',
'contextlevel' => CONTEXT_COURSE, 'contextlevel' => CONTEXT_COURSE,
@ -69,7 +69,7 @@ $capabilities = array(
'clonepermissionsfrom' => 'moodle/course:manageactivities' 'clonepermissionsfrom' => 'moodle/course:manageactivities'
), ),
'mod/attforblock:viewreports' => array( 'mod/attendance:viewreports' => array(
'riskbitmask' => RISK_PERSONAL, 'riskbitmask' => RISK_PERSONAL,
'captype' => 'read', 'captype' => 'read',
'contextlevel' => CONTEXT_MODULE, 'contextlevel' => CONTEXT_MODULE,
@ -80,7 +80,7 @@ $capabilities = array(
) )
), ),
'mod/attforblock:takeattendances' => array( 'mod/attendance:takeattendances' => array(
'riskbitmask' => RISK_DATALOSS, 'riskbitmask' => RISK_DATALOSS,
'captype' => 'write', 'captype' => 'write',
'contextlevel' => CONTEXT_MODULE, 'contextlevel' => CONTEXT_MODULE,
@ -91,7 +91,7 @@ $capabilities = array(
) )
), ),
'mod/attforblock:changeattendances' => array( 'mod/attendance:changeattendances' => array(
'riskbitmask' => RISK_DATALOSS, 'riskbitmask' => RISK_DATALOSS,
'captype' => 'write', 'captype' => 'write',
'contextlevel' => CONTEXT_MODULE, 'contextlevel' => CONTEXT_MODULE,
@ -102,7 +102,7 @@ $capabilities = array(
) )
), ),
'mod/attforblock:manageattendances' => array( 'mod/attendance:manageattendances' => array(
'riskbitmask' => RISK_CONFIG, 'riskbitmask' => RISK_CONFIG,
'captype' => 'write', 'captype' => 'write',
'contextlevel' => CONTEXT_MODULE, 'contextlevel' => CONTEXT_MODULE,
@ -112,7 +112,7 @@ $capabilities = array(
) )
), ),
'mod/attforblock:changepreferences' => array( 'mod/attendance:changepreferences' => array(
'riskbitmask' => RISK_CONFIG, 'riskbitmask' => RISK_CONFIG,
'captype' => 'write', 'captype' => 'write',
'contextlevel' => CONTEXT_MODULE, 'contextlevel' => CONTEXT_MODULE,
@ -122,7 +122,7 @@ $capabilities = array(
) )
), ),
'mod/attforblock:export' => array( 'mod/attendance:export' => array(
'riskbitmask' => RISK_PERSONAL, 'riskbitmask' => RISK_PERSONAL,
'captype' => 'read', 'captype' => 'read',
'contextlevel' => CONTEXT_MODULE, 'contextlevel' => CONTEXT_MODULE,
@ -133,7 +133,7 @@ $capabilities = array(
), ),
'mod/attforblock:canbelisted' => array( 'mod/attendance:canbelisted' => array(
'riskbitmask' => RISK_PERSONAL, 'riskbitmask' => RISK_PERSONAL,
'captype' => 'read', 'captype' => 'read',
'contextlevel' => CONTEXT_MODULE, 'contextlevel' => CONTEXT_MODULE,

8
db/install.php

@ -20,7 +20,7 @@
* lib.php/modulename_install() post installation hook and partially defaults.php * lib.php/modulename_install() post installation hook and partially defaults.php
* *
* @package mod * @package mod
* @subpackage attforblock * @subpackage attendance
* @copyright 2011 Artem Andreev <andreev.artem@gmail.com> * @copyright 2011 Artem Andreev <andreev.artem@gmail.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/ */
@ -28,7 +28,7 @@
/** /**
* Post installation procedure * Post installation procedure
*/ */
function xmldb_attforblock_install() { function xmldb_attendance_install() {
global $DB; global $DB;
$result = true; $result = true;
@ -36,8 +36,8 @@ function xmldb_attforblock_install() {
foreach ($arr as $k => $v) { foreach ($arr as $k => $v) {
$rec = new stdClass; $rec = new stdClass;
$rec->attendanceid = 0; $rec->attendanceid = 0;
$rec->acronym = get_string($k.'acronym', 'attforblock'); $rec->acronym = get_string($k.'acronym', 'attendance');
$rec->description = get_string($k.'full', 'attforblock'); $rec->description = get_string($k.'full', 'attendance');
$rec->grade = $v; $rec->grade = $v;
$rec->visible = 1; $rec->visible = 1;
$rec->deleted = 0; $rec->deleted = 0;

8
db/install.xml

@ -1,10 +1,10 @@
<?xml version="1.0" encoding="UTF-8" ?> <?xml version="1.0" encoding="UTF-8" ?>
<XMLDB PATH="mod/attforblock/db" VERSION="20090112" COMMENT="XMLDB file for Moodle mod/attforblock" <XMLDB PATH="mod/attendance/db" VERSION="20090112" COMMENT="XMLDB file for Moodle mod/attendance"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="../../../lib/xmldb/xmldb.xsd" xsi:noNamespaceSchemaLocation="../../../lib/xmldb/xmldb.xsd"
> >
<TABLES> <TABLES>
<TABLE NAME="attforblock" COMMENT="Module for support Attendances" NEXT="attendance_sessions"> <TABLE NAME="attendance" COMMENT="Module for support Attendances" NEXT="attendance_sessions">
<FIELDS> <FIELDS>
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="true" COMMENT="id of the table, please edit me" NEXT="course"/> <FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="true" COMMENT="id of the table, please edit me" NEXT="course"/>
<FIELD NAME="course" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="id" NEXT="name"/> <FIELD NAME="course" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="id" NEXT="name"/>
@ -12,13 +12,13 @@
<FIELD NAME="grade" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="false" DEFAULT="100" SEQUENCE="false" COMMENT="This is maximum grade for instance" PREVIOUS="name"/> <FIELD NAME="grade" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="false" DEFAULT="100" SEQUENCE="false" COMMENT="This is maximum grade for instance" PREVIOUS="name"/>
</FIELDS> </FIELDS>
<KEYS> <KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id" COMMENT="Primary key for attforblock"/> <KEY NAME="primary" TYPE="primary" FIELDS="id" COMMENT="Primary key for attendance"/>
</KEYS> </KEYS>
<INDEXES> <INDEXES>
<INDEX NAME="course" UNIQUE="false" FIELDS="course"/> <INDEX NAME="course" UNIQUE="false" FIELDS="course"/>
</INDEXES> </INDEXES>
</TABLE> </TABLE>
<TABLE NAME="attendance_sessions" COMMENT="attendance_sessions table retrofitted from MySQL" PREVIOUS="attforblock" NEXT="attendance_log"> <TABLE NAME="attendance_sessions" COMMENT="attendance_sessions table retrofitted from MySQL" PREVIOUS="attendance" NEXT="attendance_log">
<FIELDS> <FIELDS>
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="true" NEXT="attendanceid"/> <FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="true" NEXT="attendanceid"/>
<FIELD NAME="attendanceid" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="id" NEXT="groupid"/> <FIELD NAME="attendanceid" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="id" NEXT="groupid"/>

300
db/upgrade.php

@ -15,309 +15,15 @@
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
// This file keeps track of upgrades to // This file keeps track of upgrades to
// the attforblock module. // the attendance module.
function xmldb_attforblock_upgrade($oldversion=0) { function xmldb_attendance_upgrade($oldversion=0) {
global $CFG, $THEME, $DB; global $CFG, $THEME, $DB;
$dbman = $DB->get_manager(); // Loads ddl manager and xmldb classes. $dbman = $DB->get_manager(); // Loads ddl manager and xmldb classes.
$result = true; $result = true;
if ($oldversion < 2008021904) { // New version in version.php. // UPGRADES from attforblock are only supported for sites that are running attforblock version 2012120700
global $USER;
if ($sessions = $DB->get_records('attendance_sessions', array('takenby'=> 0))) {
foreach ($sessions as $sess) {
if ($DB->count_records('attendance_log', array('attsid'=> $sess->id)) > 0) {
$sess->takenby = $USER->id;
$sess->timetaken = $sess->timemodified ? $sess->timemodified : time();
$sess->description = addslashes($sess->description);
$result = $DB->update_record('attendance_sessions', $sess) and $result;
}
}
}
upgrade_mod_savepoint(true, 2008021904, 'attforblock');
}
if ($oldversion < 2008102401) {
$table = new xmldb_table('attforblock');
$field = new xmldb_field('grade');
$field->set_attributes(XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '100', 'name');
$dbman->add_field($table, $field);
$table = new xmldb_table('attendance_sessions');
$field = new xmldb_field('courseid');
$field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'id');
$dbman->change_field_unsigned($table, $field);
$field = new xmldb_field('sessdate');
$field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'creator');
$dbman->change_field_unsigned($table, $field);
$field = new xmldb_field('duration');
$field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'sessdate');
$dbman->add_field($table, $field);
$field = new xmldb_field('timetaken');
$field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'takenby');
$dbman->change_field_unsigned($table, $field);
$dbman->rename_field($table, $field, 'lasttaken');
$field = new xmldb_field('takenby');
$field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'lasttaken');
$dbman->change_field_unsigned($table, $field);
$dbman->rename_field($table, $field, 'lasttakenby');
$field = new xmldb_field('timemodified');
$field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, 'lasttaken');
$dbman->change_field_unsigned($table, $field);
$table = new xmldb_table('attendance_log');
$field = new xmldb_field('attsid');
$field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'id');
$dbman->change_field_unsigned($table, $field);
$field = new xmldb_field('studentid');
$field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'attsid');
$dbman->change_field_unsigned($table, $field);
$field = new xmldb_field('statusid');
$field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'status');
$dbman->add_field($table, $field);
$field = new xmldb_field('statusset');
$field->set_attributes(XMLDB_TYPE_CHAR, '100', null, null, null, null, 'statusid');
$dbman->add_field($table, $field);
$field = new xmldb_field('timetaken');
$field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'statusid');
$dbman->add_field($table, $field);
$field = new xmldb_field('takenby');
$field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'timetaken');
$dbman->add_field($table, $field);
// Indexes.
$index = new xmldb_index('statusid');
$index->set_attributes(XMLDB_INDEX_NOTUNIQUE, array('statusid'));
$dbman->add_index($table, $index);
$index = new xmldb_index('attsid');
$index->set_attributes(XMLDB_INDEX_NOTUNIQUE, array('attsid'));
$dbman->drop_index($table, $index);
$field = new xmldb_field('attsid'); // Rename field.
$field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'id');
$dbman->rename_field($table, $field, 'sessionid');
$index = new xmldb_index('sessionid');
$index->set_attributes(XMLDB_INDEX_NOTUNIQUE, array('sessionid'));
$dbman->add_index($table, $index);
$table = new xmldb_table('attendance_settings');
$field = new xmldb_field('courseid');
$field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'id');
$dbman->change_field_unsigned($table, $field);
$field = new xmldb_field('visible');
$field->set_attributes(XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '1', 'grade');
$dbman->add_field($table, $field);
$field = new xmldb_field('deleted');
$field->set_attributes(XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'visible');
$dbman->add_field($table, $field);
// Indexes.
$index = new xmldb_index('visible');
$index->set_attributes(XMLDB_INDEX_NOTUNIQUE, array('visible'));
$dbman->add_index($table, $index);
$index = new xmldb_index('deleted');
$index->set_attributes(XMLDB_INDEX_NOTUNIQUE, array('deleted'));
$dbman->add_index($table, $index);
$dbman->rename_table($table, 'attendance_statuses');
upgrade_mod_savepoint(true, 2008102401, 'attforblock');
}
if ($oldversion < 2008102406) {
if ($courses = $DB->get_records_sql("SELECT courseid FROM {attendance_sessions} GROUP BY courseid")) {
foreach ($courses as $c) {
// Adding own status for course (now it must have own).
if (!$DB->count_records('attendance_statuses', array( 'courseid'=> $c->courseid))) {
$statuses = $DB->get_records('attendance_statuses', array('courseid'=> 0));
foreach ($statuses as $stat) {
$rec = $stat;
$rec->courseid = $c->courseid;
$DB->insert_record('attendance_statuses', $rec);
}
}
$statuses = $DB->get_records('attendance_statuses', array('courseid'=> $c->courseid));
$statlist = implode(',', array_keys($statuses));
$sess = $DB->get_records_select_menu('attendance_sessions',
"courseid = ? AND lasttakenby > 0", array($c->courseid));
$sesslist = implode(',', array_keys($sess));
foreach ($statuses as $stat) {
execute("UPDATE {attendance_log}
SET statusid = {$stat->id}, statusset = '$statlist'
WHERE sessionid IN ($sesslist) AND status = '$stat->status'");
}
$sessions = $DB->get_records_list('attendance_sessions', array('id'=> $sesslist));
foreach ($sessions as $sess) {
execute("UPDATE {attendance_log}
SET timetaken = {$sess->lasttaken},
takenby = {$sess->lasttakenby}
WHERE sessionid = {$sess->id}");
}
}
}
upgrade_mod_savepoint(true, 2008102406, 'attforblock');
}
if ($oldversion < 2008102409) {
$table = new xmldb_table('attendance_statuses');
$field = new xmldb_field('status');
$dbman->drop_field($table, $field);
$index = new xmldb_index('status');
$index->set_attributes(XMLDB_INDEX_NOTUNIQUE, array('status'));
$dbman->drop_index($table, $index);
$table = new xmldb_table('attendance_log');
$field = new xmldb_field('status');
$dbman->drop_field($table, $field);
$index = new xmldb_index('status');
$index->set_attributes(XMLDB_INDEX_NOTUNIQUE, array('status'));
$dbman->drop_index($table, $index);
$table = new xmldb_table('attendance_sessions');
$field = new xmldb_field('creator');
$dbman->drop_field($table, $field);
upgrade_mod_savepoint(true, 2008102409, 'attforblock');
}
if ($oldversion < 2010070900) {
$table = new xmldb_table('attendance_sessions');
$field = new xmldb_field('groupid');
$field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'courseid');
if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field);
}
$index = new xmldb_index('groupid');
$index->set_attributes(XMLDB_INDEX_NOTUNIQUE, array('groupid'));
if (!$dbman->index_exists($table, $index)) {
$dbman->add_index($table, $index);
}
upgrade_mod_savepoint(true, 2010070900, 'attforblock');
}
if ($oldversion < 2010123003) {
$table = new xmldb_table('attendance_sessions');
$field = new xmldb_field('attendanceid');
$field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'groupid');
if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field);
}
$index = new xmldb_index('attendanceid');
$index->set_attributes(XMLDB_INDEX_NOTUNIQUE, array('attendanceid'));
if (!$dbman->index_exists($table, $index)) {
$dbman->add_index($table, $index);
}
$sql = "UPDATE {attendance_sessions} AS ses
JOIN {attforblock} AS att
ON (ses.courseid = att.course)
SET ses.attendanceid=att.id";
$DB->execute($sql);
$table = new xmldb_table('attendance_statuses');
$field = new xmldb_field('attendanceid');
$field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'courseid');
if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field);
}
$index = new xmldb_index('attendanceid');
$index->set_attributes(XMLDB_INDEX_NOTUNIQUE, array('attendanceid'));
if (!$dbman->index_exists($table, $index)) {
$dbman->add_index($table, $index);
}
$sql = "UPDATE {attendance_statuses} AS sta
JOIN {attforblock} as att
ON (sta.courseid = att.course)
SET sta.attendanceid = att.id";
$DB->execute($sql);
upgrade_mod_savepoint(true, 2010123003, 'attforblock');
}
if ($oldversion < 2011061800) {
$table = new xmldb_table('attendance_sessions');
$field = new xmldb_field('description');
$field->set_attributes(XMLDB_TYPE_TEXT, 'small', null, XMLDB_NOTNULL, null, null, 'timemodified');
$dbman->change_field_type($table, $field);
$field = new xmldb_field('descriptionformat', XMLDB_TYPE_INTEGER, '4',
XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'description');
if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field);
}
// Conditionally migrate to html format in intro.
if ($CFG->texteditors !== 'textarea') {
$rs = $DB->get_recordset('attendance_sessions', array('descriptionformat' => FORMAT_MOODLE),
'', 'id,description,descriptionformat');
foreach ($rs as $s) {
$s->description = text_to_html($s->description, false, false, true);
$s->descriptionformat = FORMAT_HTML;
$DB->update_record('attendance_sessions', $s);
upgrade_set_timeout();
}
$rs->close();
}
// Now we can create more than one attendances per course
// thus sessions and statuses belongs to attendance
// so we don't need courseid fields in attendance_sessions and attendance_statuses.
$index = new xmldb_index('courseid', XMLDB_INDEX_NOTUNIQUE, array('courseid'));
if ($dbman->index_exists($table, $index)) {
$dbman->drop_index($table, $index);
}
$field = new xmldb_field('courseid');
if ($dbman->field_exists($table, $field)) {
$dbman->drop_field($table, $field);
}
$table = new xmldb_table('attendance_statuses');
if ($dbman->index_exists($table, $index)) {
$dbman->drop_index($table, $index);
}
if ($dbman->field_exists($table, $field)) {
$dbman->drop_field($table, $field);
}
upgrade_mod_savepoint(true, 2011061800, 'attforblock');
}
return $result; return $result;
} }

10
duration_form.php

@ -24,7 +24,7 @@
require_once($CFG->libdir.'/formslib.php'); require_once($CFG->libdir.'/formslib.php');
class mod_attforblock_duration_form extends moodleform { class mod_attendance_duration_form extends moodleform {
public function definition() { public function definition() {
@ -36,8 +36,8 @@ class mod_attforblock_duration_form extends moodleform {
$modcontext = $this->_customdata['modcontext']; $modcontext = $this->_customdata['modcontext'];
$ids = $this->_customdata['ids']; $ids = $this->_customdata['ids'];
$mform->addElement('header', 'general', get_string('changeduration', 'attforblock')); $mform->addElement('header', 'general', get_string('changeduration', 'attendance'));
$mform->addElement('static', 'count', get_string('countofselected', 'attforblock'), count(explode('_', $ids))); $mform->addElement('static', 'count', get_string('countofselected', 'attendance'), count(explode('_', $ids)));
for ($i=0; $i<=23; $i++) { for ($i=0; $i<=23; $i++) {
$hours[$i] = sprintf("%02d", $i); $hours[$i] = sprintf("%02d", $i);
@ -47,7 +47,7 @@ class mod_attforblock_duration_form extends moodleform {
} }
$durselect[] =& $mform->createElement('select', 'hours', '', $hours); $durselect[] =& $mform->createElement('select', 'hours', '', $hours);
$durselect[] =& $mform->createElement('select', 'minutes', '', $minutes, false, true); $durselect[] =& $mform->createElement('select', 'minutes', '', $minutes, false, true);
$mform->addGroup($durselect, 'durtime', get_string('newduration', 'attforblock'), array(' '), true); $mform->addGroup($durselect, 'durtime', get_string('newduration', 'attendance'), array(' '), true);
$mform->addElement('hidden', 'ids', $ids); $mform->addElement('hidden', 'ids', $ids);
$mform->addElement('hidden', 'id', $cm->id); $mform->addElement('hidden', 'id', $cm->id);
@ -55,7 +55,7 @@ class mod_attforblock_duration_form extends moodleform {
$mform->setDefaults(array('durtime' => array('hours'=>0, 'minutes'=>0))); $mform->setDefaults(array('durtime' => array('hours'=>0, 'minutes'=>0)));
$submit_string = get_string('update', 'attforblock'); $submit_string = get_string('update', 'attendance');
$this->add_action_buttons(true, $submit_string); $this->add_action_buttons(true, $submit_string);
} }

26
export.php

@ -30,13 +30,13 @@ require_once(dirname(__FILE__).'/renderhelpers.php');
$id = required_param('id', PARAM_INT); $id = required_param('id', PARAM_INT);
$cm = get_coursemodule_from_id('attforblock', $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);
$att = $DB->get_record('attforblock', array('id' => $cm->instance), '*', MUST_EXIST); $att = $DB->get_record('attendance', array('id' => $cm->instance), '*', MUST_EXIST);
require_login($course, true, $cm); require_login($course, true, $cm);
$att = new attforblock($att, $cm, $course, $PAGE->context); $att = new attendance($att, $cm, $course, $PAGE->context);
$att->perm->require_export_capability(); $att->perm->require_export_capability();
@ -44,11 +44,11 @@ $PAGE->set_url($att->url_export());
$PAGE->set_title($course->shortname. ": ".$att->name); $PAGE->set_title($course->shortname. ": ".$att->name);
$PAGE->set_heading($course->fullname); $PAGE->set_heading($course->fullname);
$PAGE->set_cacheable(true); $PAGE->set_cacheable(true);
$PAGE->set_button($OUTPUT->update_module_button($cm->id, 'attforblock')); $PAGE->set_button($OUTPUT->update_module_button($cm->id, 'attendance'));
$PAGE->navbar->add(get_string('export', 'quiz')); $PAGE->navbar->add(get_string('export', 'quiz'));
$formparams = array('course' => $course, 'cm' => $cm, 'modcontext' => $PAGE->context); $formparams = array('course' => $course, 'cm' => $cm, 'modcontext' => $PAGE->context);
$mform = new mod_attforblock_export_form($att->url_export(), $formparams); $mform = new mod_attendance_export_form($att->url_export(), $formparams);
if ($mform->is_submitted()) { if ($mform->is_submitted()) {
$formdata = $mform->get_data(); $formdata = $mform->get_data();
@ -71,7 +71,7 @@ if ($mform->is_submitted()) {
} }
$att->pageparams = $pageparams; $att->pageparams = $pageparams;
$reportdata = new attforblock_report_data($att); $reportdata = new attendance_report_data($att);
if ($reportdata->users) { if ($reportdata->users) {
$filename = clean_filename($course->shortname.'_Attendances_'.userdate(time(), '%Y%m%d-%H%M')); $filename = clean_filename($course->shortname.'_Attendances_'.userdate(time(), '%Y%m%d-%H%M'));
@ -82,7 +82,7 @@ if ($mform->is_submitted()) {
$data->group = $group ? $group->name : get_string('allparticipants'); $data->group = $group ? $group->name : get_string('allparticipants');
if (isset($formdata->ident['id'])) { if (isset($formdata->ident['id'])) {
$data->tabhead[] = get_string('studentid', 'attforblock'); $data->tabhead[] = get_string('studentid', 'attendance');
} }
if (isset($formdata->ident['uname'])) { if (isset($formdata->ident['uname'])) {
$data->tabhead[] = get_string('username'); $data->tabhead[] = get_string('username');
@ -93,13 +93,13 @@ if ($mform->is_submitted()) {
if (count($reportdata->sessions) > 0) { if (count($reportdata->sessions) > 0) {
foreach ($reportdata->sessions as $sess) { foreach ($reportdata->sessions as $sess) {
$text = userdate($sess->sessdate, get_string('strftimedmyhm', 'attforblock')); $text = userdate($sess->sessdate, get_string('strftimedmyhm', 'attendance'));
$text .= ' '; $text .= ' ';
$text .= $sess->groupid ? $reportdata->groups[$sess->groupid]->name : get_string('commonsession', 'attforblock'); $text .= $sess->groupid ? $reportdata->groups[$sess->groupid]->name : get_string('commonsession', 'attendance');
$data->tabhead[] = $text; $data->tabhead[] = $text;
} }
} else { } else {
print_error('sessionsnotfound', 'attforblock', $att->url_manage()); print_error('sessionsnotfound', 'attendance', $att->url_manage());
} }
if ($reportdata->gradable) { if ($reportdata->gradable) {
$data->tabhead[] = get_string('grade'); $data->tabhead[] = get_string('grade');
@ -135,10 +135,10 @@ if ($mform->is_submitted()) {
} }
} }
$output = $PAGE->get_renderer('mod_attforblock'); $output = $PAGE->get_renderer('mod_attendance');
$tabs = new attforblock_tabs($att, attforblock_tabs::TAB_EXPORT); $tabs = new attendance_tabs($att, attendance_tabs::TAB_EXPORT);
echo $output->header(); echo $output->header();
echo $output->heading(get_string('attendanceforthecourse', 'attforblock').' :: ' .$course->fullname); echo $output->heading(get_string('attendanceforthecourse', 'attendance').' :: ' .$course->fullname);
echo $output->render($tabs); echo $output->render($tabs);
$mform->display(); $mform->display();

20
export_form.php

@ -24,7 +24,7 @@
require_once($CFG->libdir.'/formslib.php'); require_once($CFG->libdir.'/formslib.php');
class mod_attforblock_export_form extends moodleform { class mod_attendance_export_form extends moodleform {
public function definition() { public function definition() {
@ -50,24 +50,24 @@ class mod_attforblock_export_form extends moodleform {
$mform->addElement('select', 'group', get_string('group'), $grouplist); $mform->addElement('select', 'group', get_string('group'), $grouplist);
$ident = array(); $ident = array();
$ident[] =& $mform->createElement('checkbox', 'id', '', get_string('studentid', 'attforblock')); $ident[] =& $mform->createElement('checkbox', 'id', '', get_string('studentid', 'attendance'));
$ident[] =& $mform->createElement('checkbox', 'uname', '', get_string('username')); $ident[] =& $mform->createElement('checkbox', 'uname', '', get_string('username'));
$mform->addGroup($ident, 'ident', get_string('identifyby', 'attforblock'), array('<br />'), true); $mform->addGroup($ident, 'ident', get_string('identifyby', 'attendance'), array('<br />'), true);
$mform->setDefaults(array('ident[id]' => true, 'ident[uname]' => true)); $mform->setDefaults(array('ident[id]' => true, 'ident[uname]' => true));
$mform->addElement('checkbox', 'includeallsessions', get_string('includeall', 'attforblock'), get_string('yes')); $mform->addElement('checkbox', 'includeallsessions', get_string('includeall', 'attendance'), get_string('yes'));
$mform->setDefault('includeallsessions', true); $mform->setDefault('includeallsessions', true);
$mform->addElement('checkbox', 'includenottaken', get_string('includenottaken', 'attforblock'), get_string('yes')); $mform->addElement('checkbox', 'includenottaken', get_string('includenottaken', 'attendance'), get_string('yes'));
$mform->addElement('date_selector', 'sessionstartdate', get_string('startofperiod', 'attforblock')); $mform->addElement('date_selector', 'sessionstartdate', get_string('startofperiod', 'attendance'));
$mform->setDefault('sessionstartdate', $course->startdate); $mform->setDefault('sessionstartdate', $course->startdate);
$mform->disabledIf('sessionstartdate', 'includeallsessions', 'checked'); $mform->disabledIf('sessionstartdate', 'includeallsessions', 'checked');
$mform->addElement('date_selector', 'sessionenddate', get_string('endofperiod', 'attforblock')); $mform->addElement('date_selector', 'sessionenddate', get_string('endofperiod', 'attendance'));
$mform->disabledIf('sessionenddate', 'includeallsessions', 'checked'); $mform->disabledIf('sessionenddate', 'includeallsessions', 'checked');
$mform->addElement('select', 'format', get_string('format'), $mform->addElement('select', 'format', get_string('format'),
array('excel' => get_string('downloadexcel', 'attforblock'), array('excel' => get_string('downloadexcel', 'attendance'),
'ooo' => get_string('downloadooo', 'attforblock'), 'ooo' => get_string('downloadooo', 'attendance'),
'text' => get_string('downloadtext', 'attforblock') 'text' => get_string('downloadtext', 'attendance')
)); ));
$submit_string = get_string('ok'); $submit_string = get_string('ok');

4
index.php

@ -30,8 +30,8 @@ $course = $DB->get_record('course', array('id' => $id), '*', MUST_EXIST);
require_login($course); require_login($course);
// TODO: check if this is correct behaviour - other modules list all the instances of the module in the course. // TODO: check if this is correct behaviour - other modules list all the instances of the module in the course.
if ($att = array_pop(get_all_instances_in_course('attforblock', $course, null, true))) { if ($att = array_pop(get_all_instances_in_course('attendance', $course, null, true))) {
redirect("view.php?id=$att->coursemodule"); redirect("view.php?id=$att->coursemodule");
} else { } else {
print_error('notfound', 'attforblock'); print_error('notfound', 'attendance');
} }

21
lang/en/attforblock.php → lang/en/attendance.php

@ -14,7 +14,7 @@
// 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/>.
$string['attforblock:addinstance'] = 'Add a new attendance activity'; $string['attendance:addinstance'] = 'Add a new attendance activity';
$string['Aacronym'] = 'A'; $string['Aacronym'] = 'A';
$string['Afull'] = 'Absent'; $string['Afull'] = 'Absent';
$string['Eacronym'] = 'E'; $string['Eacronym'] = 'E';
@ -38,14 +38,15 @@ $string['attendancepercent'] = 'Attendance percent';
$string['attendancereport'] = 'Attendance report'; $string['attendancereport'] = 'Attendance report';
$string['attendancesuccess'] = 'Attendance has been successfully taken'; $string['attendancesuccess'] = 'Attendance has been successfully taken';
$string['attendanceupdated'] = 'Attendance successfully updated'; $string['attendanceupdated'] = 'Attendance successfully updated';
$string['attforblock:canbelisted'] = 'Appears in the roster'; $string['attendance:canbelisted'] = 'Appears in the roster';
$string['attforblock:changepreferences'] = 'Changing Preferences'; $string['attendance:changepreferences'] = 'Changing Preferences';
$string['attforblock:changeattendances'] = 'Changing Attendances'; $string['attendance:changeattendances'] = 'Changing Attendances';
$string['attforblock:export'] = 'Export Reports'; $string['attendance:export'] = 'Export Reports';
$string['attforblock:manageattendances'] = 'Manage Attendances'; $string['attendance:manageattendances'] = 'Manage Attendances';
$string['attforblock:takeattendances'] = 'Taking Attendances'; $string['attendance:takeattendances'] = 'Taking Attendances';
$string['attforblock:view'] = 'Viewing Attendances'; $string['attendance:view'] = 'Viewing Attendances';
$string['attforblock:viewreports'] = 'Viewing Reports'; $string['attendance:viewreports'] = 'Viewing Reports';
$string['attforblockdirstillexists'] = 'old mod/attforblock directory still exists - you must delete this directory on your server before running this upgrade.';
$string['attrecords'] = 'Attendances records'; $string['attrecords'] = 'Attendances records';
$string['calclose'] = 'Close'; $string['calclose'] = 'Close';
$string['calmonths'] = 'January,February,March,April,May,June,July,August,September,October,November,December'; $string['calmonths'] = 'January,February,March,April,May,June,July,August,September,October,November,December';
@ -131,6 +132,7 @@ $string['nosessiondayselected'] = 'No Session day selected';
$string['nosessionexists'] = 'No Session exists for this course'; $string['nosessionexists'] = 'No Session exists for this course';
$string['nosessionsselected'] = 'No sessions selected'; $string['nosessionsselected'] = 'No sessions selected';
$string['notfound'] = 'Attendance activity not found in this course!'; $string['notfound'] = 'Attendance activity not found in this course!';
$string['noupgradefromthisversion'] = 'The Attendance module cannot upgrade from the version of attforblock you have installed. - please delete attforblock or upgrade it to the latest version before isntalling the new attendance module';
$string['olddate'] = 'Old date'; $string['olddate'] = 'Old date';
$string['period'] = 'Frequency'; $string['period'] = 'Frequency';
$string['pluginname'] = 'Attendance'; $string['pluginname'] = 'Attendance';
@ -184,6 +186,7 @@ $string['strftimeshortdate'] = '%d.%m.%Y';
$string['studentid'] = 'Student ID'; $string['studentid'] = 'Student ID';
$string['takeattendance'] = 'Take attendance'; $string['takeattendance'] = 'Take attendance';
$string['thiscourse'] = 'This course'; $string['thiscourse'] = 'This course';
$string['tablerenamefailed'] = 'Rename of old attforblock table to attendance failed';
$string['update'] = 'Update'; $string['update'] = 'Update';
$string['variable'] = 'variable'; $string['variable'] = 'variable';
$string['variablesupdated'] = 'Variables successfully updated'; $string['variablesupdated'] = 'Variables successfully updated';

192
lib.php

@ -15,7 +15,7 @@
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/** /**
* Library of functions and constants for module attforblock * Library of functions and constants for module attendance
* *
* @package mod_attendance * @package mod_attendance
* @copyright 2011 Artem Andreev <andreev.artem@gmail.com> * @copyright 2011 Artem Andreev <andreev.artem@gmail.com>
@ -29,7 +29,7 @@
* @param string $feature FEATURE_xx constant for requested feature * @param string $feature FEATURE_xx constant for requested feature
* @return mixed true if the feature is supported, null if unknown * @return mixed true if the feature is supported, null if unknown
*/ */
function attforblock_supports($feature) { function attendance_supports($feature) {
switch($feature) { switch($feature) {
case FEATURE_GRADE_HAS_GRADE: case FEATURE_GRADE_HAS_GRADE:
return true; return true;
@ -66,41 +66,41 @@ function att_add_default_statuses($attid) {
} }
} }
function attforblock_add_instance($attforblock) { function attendance_add_instance($attendance) {
global $DB; global $DB;
$attforblock->timemodified = time(); $attendance->timemodified = time();
$attforblock->id = $DB->insert_record('attforblock', $attforblock); $attendance->id = $DB->insert_record('attendance', $attendance);
att_add_default_statuses($attforblock->id); att_add_default_statuses($attendance->id);
attforblock_grade_item_update($attforblock); attendance_grade_item_update($attendance);
// attforblock_update_grades($attforblock); // attendance_update_grades($attendance);
return $attforblock->id; return $attendance->id;
} }
function attforblock_update_instance($attforblock) { function attendance_update_instance($attendance) {
global $DB; global $DB;
$attforblock->timemodified = time(); $attendance->timemodified = time();
$attforblock->id = $attforblock->instance; $attendance->id = $attendance->instance;
if (! $DB->update_record('attforblock', $attforblock)) { if (! $DB->update_record('attendance', $attendance)) {
return false; return false;
} }
attforblock_grade_item_update($attforblock); attendance_grade_item_update($attendance);
return true; return true;
} }
function attforblock_delete_instance($id) { function attendance_delete_instance($id) {
global $DB; global $DB;
if (! $attforblock = $DB->get_record('attforblock', array('id'=> $id))) { if (! $attendance = $DB->get_record('attendance', array('id'=> $id))) {
return false; return false;
} }
@ -110,17 +110,17 @@ function attforblock_delete_instance($id) {
} }
$DB->delete_records('attendance_statuses', array('attendanceid'=> $id)); $DB->delete_records('attendance_statuses', array('attendanceid'=> $id));
$DB->delete_records('attforblock', array('id'=> $id)); $DB->delete_records('attendance', array('id'=> $id));
attforblock_grade_item_delete($attforblock); attendance_grade_item_delete($attendance);
return true; return true;
} }
function attforblock_delete_course($course, $feedback=true) { function attendance_delete_course($course, $feedback=true) {
global $DB; global $DB;
$attids = array_keys($DB->get_records('attforblock', array('course'=> $course->id), '', 'id')); $attids = array_keys($DB->get_records('attendance', array('course'=> $course->id), '', 'id'));
$sessids = array_keys($DB->get_records_list('attendance_sessions', 'attendanceid', $attids, '', 'id')); $sessids = array_keys($DB->get_records_list('attendance_sessions', 'attendanceid', $attids, '', 'id'));
if ($sessids) { if ($sessids) {
$DB->delete_records_list('attendance_log', 'sessionid', $sessids); $DB->delete_records_list('attendance_log', 'sessionid', $sessids);
@ -129,7 +129,7 @@ function attforblock_delete_course($course, $feedback=true) {
$DB->delete_records_list('attendance_statuses', 'attendanceid', $attids); $DB->delete_records_list('attendance_statuses', 'attendanceid', $attids);
$DB->delete_records_list('attendance_sessions', 'attendanceid', $attids); $DB->delete_records_list('attendance_sessions', 'attendanceid', $attids);
} }
$DB->delete_records('attforblock', array('course'=> $course->id)); $DB->delete_records('attendance', array('course'=> $course->id));
return true; return true;
} }
@ -138,17 +138,17 @@ function attforblock_delete_course($course, $feedback=true) {
* Called by course/reset.php * Called by course/reset.php
* @param $mform form passed by reference * @param $mform form passed by reference
*/ */
function attforblock_reset_course_form_definition(&$mform) { function attendance_reset_course_form_definition(&$mform) {
$mform->addElement('header', 'attendanceheader', get_string('modulename', 'attforblock')); $mform->addElement('header', 'attendanceheader', get_string('modulename', 'attendance'));
$mform->addElement('static', 'description', get_string('description', 'attforblock'), $mform->addElement('static', 'description', get_string('description', 'attendance'),
get_string('resetdescription', 'attforblock')); get_string('resetdescription', 'attendance'));
$mform->addElement('checkbox', 'reset_attendance_log', get_string('deletelogs', 'attforblock')); $mform->addElement('checkbox', 'reset_attendance_log', get_string('deletelogs', 'attendance'));
$mform->addElement('checkbox', 'reset_attendance_sessions', get_string('deletesessions', 'attforblock')); $mform->addElement('checkbox', 'reset_attendance_sessions', get_string('deletesessions', 'attendance'));
$mform->disabledIf('reset_attendance_sessions', 'reset_attendance_log', 'notchecked'); $mform->disabledIf('reset_attendance_sessions', 'reset_attendance_log', 'notchecked');
$mform->addElement('checkbox', 'reset_attendance_statuses', get_string('resetstatuses', 'attforblock')); $mform->addElement('checkbox', 'reset_attendance_statuses', get_string('resetstatuses', 'attendance'));
$mform->setAdvanced('reset_attendance_statuses'); $mform->setAdvanced('reset_attendance_statuses');
$mform->disabledIf('reset_attendance_statuses', 'reset_attendance_log', 'notchecked'); $mform->disabledIf('reset_attendance_statuses', 'reset_attendance_log', 'notchecked');
} }
@ -156,16 +156,16 @@ function attforblock_reset_course_form_definition(&$mform) {
/** /**
* Course reset form defaults. * Course reset form defaults.
*/ */
function attforblock_reset_course_form_defaults($course) { function attendance_reset_course_form_defaults($course) {
return array('reset_attendance_log'=>0, 'reset_attendance_statuses'=>0, 'reset_attendance_sessions'=>0); return array('reset_attendance_log'=>0, 'reset_attendance_statuses'=>0, 'reset_attendance_sessions'=>0);
} }
function attforblock_reset_userdata($data) { function attendance_reset_userdata($data) {
global $DB; global $DB;
$status = array(); $status = array();
$attids = array_keys($DB->get_records('attforblock', array('course'=> $data->courseid), '', 'id')); $attids = array_keys($DB->get_records('attendance', array('course'=> $data->courseid), '', 'id'));
if (!empty($data->reset_attendance_log)) { if (!empty($data->reset_attendance_log)) {
$sess = $DB->get_records_list('attendance_sessions', 'attendanceid', $attids, '', 'id'); $sess = $DB->get_records_list('attendance_sessions', 'attendanceid', $attids, '', 'id');
@ -176,8 +176,8 @@ function attforblock_reset_userdata($data) {
$DB->set_field_select('attendance_sessions', 'lasttaken', 0, "attendanceid $sql", $params); $DB->set_field_select('attendance_sessions', 'lasttaken', 0, "attendanceid $sql", $params);
$status[] = array( $status[] = array(
'component' => get_string('modulenameplural', 'attforblock'), 'component' => get_string('modulenameplural', 'attendance'),
'item' => get_string('attendancedata', 'attforblock'), 'item' => get_string('attendancedata', 'attendance'),
'error' => false 'error' => false
); );
} }
@ -190,8 +190,8 @@ function attforblock_reset_userdata($data) {
} }
$status[] = array( $status[] = array(
'component' => get_string('modulenameplural', 'attforblock'), 'component' => get_string('modulenameplural', 'attendance'),
'item' => get_string('sessions', 'attforblock'), 'item' => get_string('sessions', 'attendance'),
'error' => false 'error' => false
); );
} }
@ -200,8 +200,8 @@ function attforblock_reset_userdata($data) {
$DB->delete_records_list('attendance_sessions', 'attendanceid', $attids); $DB->delete_records_list('attendance_sessions', 'attendanceid', $attids);
$status[] = array( $status[] = array(
'component' => get_string('modulenameplural', 'attforblock'), 'component' => get_string('modulenameplural', 'attendance'),
'item' => get_string('statuses', 'attforblock'), 'item' => get_string('statuses', 'attendance'),
'error' => false 'error' => false
); );
} }
@ -215,13 +215,13 @@ function attforblock_reset_userdata($data) {
* $return->time = the time they did it * $return->time = the time they did it
* $return->info = a short text description * $return->info = a short text description
*/ */
function attforblock_user_outline($course, $user, $mod, $attforblock) { function attendance_user_outline($course, $user, $mod, $attendance) {
global $CFG; global $CFG;
require_once(dirname(__FILE__).'/locallib.php'); require_once(dirname(__FILE__).'/locallib.php');
require_once($CFG->libdir.'/gradelib.php'); require_once($CFG->libdir.'/gradelib.php');
$grades = grade_get_grades($course->id, 'mod', 'attforblock', $attforblock->id, $user->id); $grades = grade_get_grades($course->id, 'mod', 'attendance', $attendance->id, $user->id);
$result = new stdClass(); $result = new stdClass();
if (!empty($grades->items[0]->grades)) { if (!empty($grades->items[0]->grades)) {
@ -230,11 +230,11 @@ function attforblock_user_outline($course, $user, $mod, $attforblock) {
} else { } else {
$result->time = 0; $result->time = 0;
} }
if (has_capability('mod/attforblock:canbelisted', $mod->context, $user->id)) { if (has_capability('mod/attendance:canbelisted', $mod->context, $user->id)) {
$statuses = att_get_statuses($attforblock->id); $statuses = att_get_statuses($attendance->id);
$grade = att_get_user_grade(att_get_user_statuses_stat($attforblock->id, $course->startdate, $grade = att_get_user_grade(att_get_user_statuses_stat($attendance->id, $course->startdate,
$user->id), $statuses); $user->id), $statuses);
$maxgrade = att_get_user_max_grade(att_get_user_taken_sessions_count($attforblock->id, $course->startdate, $maxgrade = att_get_user_max_grade(att_get_user_taken_sessions_count($attendance->id, $course->startdate,
$user->id), $statuses); $user->id), $statuses);
$result->info = $grade.' / '.$maxgrade; $result->info = $grade.' / '.$maxgrade;
@ -247,37 +247,37 @@ function attforblock_user_outline($course, $user, $mod, $attforblock) {
* a given particular instance of this module, for user activity reports. * a given particular instance of this module, for user activity reports.
* *
*/ */
function attforblock_user_complete($course, $user, $mod, $attforblock) { function attendance_user_complete($course, $user, $mod, $attendance) {
global $CFG; global $CFG;
require_once(dirname(__FILE__).'/renderhelpers.php'); require_once(dirname(__FILE__).'/renderhelpers.php');
require_once($CFG->libdir.'/gradelib.php'); require_once($CFG->libdir.'/gradelib.php');
if (has_capability('mod/attforblock:canbelisted', $mod->context, $user->id)) { if (has_capability('mod/attendance:canbelisted', $mod->context, $user->id)) {
echo construct_full_user_stat_html_table($attforblock, $course, $user); echo construct_full_user_stat_html_table($attendance, $course, $user);
} }
} }
function attforblock_print_recent_activity($course, $isteacher, $timestart) { function attendance_print_recent_activity($course, $isteacher, $timestart) {
return false; return false;
} }
function attforblock_cron () { function attendance_cron () {
return true; return true;
} }
/** /**
* Return grade for given user or all users. * Return grade for given user or all users.
* *
* @param int $attforblockid id of attforblock * @param int $attendanceid id of attendance
* @param int $userid optional user id, 0 means all users * @param int $userid optional user id, 0 means all users
* @return array array of grades, false if none * @return array array of grades, false if none
*/ */
/*function attforblock_get_user_grades($attforblock, $userid=0) { /*function attendance_get_user_grades($attendance, $userid=0) {
global $CFG, $DB; global $CFG, $DB;
require_once('_locallib.php'); require_once('_locallib.php');
if (! $course = $DB->get_record('course', array('id'=> $attforblock->course))) { if (! $course = $DB->get_record('course', array('id'=> $attendance->course))) {
error("Course is misconfigured"); error("Course is misconfigured");
} }
@ -285,13 +285,13 @@ function attforblock_cron () {
if ($userid) { if ($userid) {
$result = array(); $result = array();
$result[$userid]->userid = $userid; $result[$userid]->userid = $userid;
$result[$userid]->rawgrade = $attforblock->grade * get_percent($userid, $course, $attforblock) / 100; $result[$userid]->rawgrade = $attendance->grade * get_percent($userid, $course, $attendance) / 100;
} else { } else {
if ($students = get_course_students($course->id)) { if ($students = get_course_students($course->id)) {
$result = array(); $result = array();
foreach ($students as $student) { foreach ($students as $student) {
$result[$student->id]->userid = $student->id; $result[$student->id]->userid = $student->id;
$result[$student->id]->rawgrade = $attforblock->grade * get_percent($student->id, $course, $attforblock) / 100; $result[$student->id]->rawgrade = $attendance->grade * get_percent($student->id, $course, $attendance) / 100;
} }
} }
} }
@ -302,37 +302,37 @@ function attforblock_cron () {
/** /**
* Update grades by firing grade_updated event * Update grades by firing grade_updated event
* *
* @param object $attforblock null means all attforblocks * @param object $attendance null means all attendances
* @param int $userid specific user only, 0 mean all * @param int $userid specific user only, 0 mean all
*/ */
/*function attforblock_update_grades($attforblock=null, $userid=0, $nullifnone=true) { /*function attendance_update_grades($attendance=null, $userid=0, $nullifnone=true) {
global $CFG, $DB; global $CFG, $DB;
if (!function_exists('grade_update')) { //workaround for buggy PHP versions if (!function_exists('grade_update')) { //workaround for buggy PHP versions
require_once($CFG->libdir.'/gradelib.php'); require_once($CFG->libdir.'/gradelib.php');
} }
if ($attforblock != null) { if ($attendance != null) {
if ($grades = attforblock_get_user_grades($attforblock, $userid)) { if ($grades = attendance_get_user_grades($attendance, $userid)) {
foreach($grades as $k=>$v) { foreach($grades as $k=>$v) {
if ($v->rawgrade == -1) { if ($v->rawgrade == -1) {
$grades[$k]->rawgrade = null; $grades[$k]->rawgrade = null;
} }
} }
attforblock_grade_item_update($attforblock, $grades); attendance_grade_item_update($attendance, $grades);
} else { } else {
attforblock_grade_item_update($attforblock); attendance_grade_item_update($attendance);
} }
} else { } else {
$sql = "SELECT a.*, cm.idnumber as cmidnumber, a.course as courseid $sql = "SELECT a.*, cm.idnumber as cmidnumber, a.course as courseid
FROM {attforblock} a, {course_modules} cm, {modules} m FROM {attendance} a, {course_modules} cm, {modules} m
WHERE m.name='attforblock' AND m.id=cm.module AND cm.instance=a.id"; WHERE m.name='attendance' AND m.id=cm.module AND cm.instance=a.id";
if ($rs = $DB->get_records_sql($sql)) { if ($rs = $DB->get_records_sql($sql)) {
foreach ($rs as $attforblock) { foreach ($rs as $attendance) {
// if ($attforblock->grade != 0) { // if ($attendance->grade != 0) {
attforblock_update_grades($attforblock); attendance_update_grades($attendance);
// } else { // } else {
// attforblock_grade_item_update($attforblock); // attendance_grade_item_update($attendance);
// } // }
} }
$rs->close($rs); $rs->close($rs);
@ -341,13 +341,13 @@ function attforblock_cron () {
}*/ }*/
/** /**
* Create grade item for given attforblock * Create grade item for given attendance
* *
* @param object $attforblock object with extra cmidnumber * @param object $attendance object with extra cmidnumber
* @param mixed optional array/object of grade(s); 'reset' means reset grades in gradebook * @param mixed optional array/object of grade(s); 'reset' means reset grades in gradebook
* @return int 0 if ok, error code otherwise * @return int 0 if ok, error code otherwise
*/ */
function attforblock_grade_item_update($attforblock, $grades=null) { function attendance_grade_item_update($attendance, $grades=null) {
global $CFG, $DB; global $CFG, $DB;
require_once('locallib.php'); require_once('locallib.php');
@ -356,29 +356,29 @@ function attforblock_grade_item_update($attforblock, $grades=null) {
require_once($CFG->libdir.'/gradelib.php'); require_once($CFG->libdir.'/gradelib.php');
} }
if (!isset($attforblock->courseid)) { if (!isset($attendance->courseid)) {
$attforblock->courseid = $attforblock->course; $attendance->courseid = $attendance->course;
} }
if (! $course = $DB->get_record('course', array('id'=> $attforblock->course))) { if (! $course = $DB->get_record('course', array('id'=> $attendance->course))) {
error("Course is misconfigured"); error("Course is misconfigured");
} }
// $attforblock->grade = get_maxgrade($course); // $attendance->grade = get_maxgrade($course);
if (!empty($attforblock->cmidnumber)) { if (!empty($attendance->cmidnumber)) {
$params = array('itemname'=>$attforblock->name, 'idnumber'=>$attforblock->cmidnumber); $params = array('itemname'=>$attendance->name, 'idnumber'=>$attendance->cmidnumber);
} else { } else {
// MDL-14303. // MDL-14303.
$cm = get_coursemodule_from_instance('attforblock', $attforblock->id); $cm = get_coursemodule_from_instance('attendance', $attendance->id);
$params = array('itemname'=>$attforblock->name/*, 'idnumber'=>$attforblock->id*/); $params = array('itemname'=>$attendance->name/*, 'idnumber'=>$attendance->id*/);
} }
if ($attforblock->grade > 0) { if ($attendance->grade > 0) {
$params['gradetype'] = GRADE_TYPE_VALUE; $params['gradetype'] = GRADE_TYPE_VALUE;
$params['grademax'] = $attforblock->grade; $params['grademax'] = $attendance->grade;
$params['grademin'] = 0; $params['grademin'] = 0;
} else if ($attforblock->grade < 0) { } else if ($attendance->grade < 0) {
$params['gradetype'] = GRADE_TYPE_SCALE; $params['gradetype'] = GRADE_TYPE_SCALE;
$params['scaleid'] = -$attforblock->grade; $params['scaleid'] = -$attendance->grade;
} else { } else {
$params['gradetype'] = GRADE_TYPE_NONE; $params['gradetype'] = GRADE_TYPE_NONE;
@ -389,28 +389,28 @@ function attforblock_grade_item_update($attforblock, $grades=null) {
$grades = null; $grades = null;
} }
return grade_update('mod/attforblock', $attforblock->courseid, 'mod', 'attforblock', $attforblock->id, 0, $grades, $params); return grade_update('mod/attendance', $attendance->courseid, 'mod', 'attendance', $attendance->id, 0, $grades, $params);
} }
/** /**
* Delete grade item for given attforblock * Delete grade item for given attendance
* *
* @param object $attforblock object * @param object $attendance object
* @return object attforblock * @return object attendance
*/ */
function attforblock_grade_item_delete($attforblock) { function attendance_grade_item_delete($attendance) {
global $CFG; global $CFG;
require_once($CFG->libdir.'/gradelib.php'); require_once($CFG->libdir.'/gradelib.php');
if (!isset($attforblock->courseid)) { if (!isset($attendance->courseid)) {
$attforblock->courseid = $attforblock->course; $attendance->courseid = $attendance->course;
} }
return grade_update('mod/attforblock', $attforblock->courseid, 'mod', 'attforblock', return grade_update('mod/attendance', $attendance->courseid, 'mod', 'attendance',
$attforblock->id, 0, null, array('deleted'=>1)); $attendance->id, 0, null, array('deleted'=>1));
} }
function attforblock_get_participants($attforblockid) { function attendance_get_participants($attendanceid) {
return false; return false;
} }
@ -420,11 +420,11 @@ function attforblock_get_participants($attforblockid) {
* modified if necessary. See book, glossary or journal modules * modified if necessary. See book, glossary or journal modules
* as reference. * as reference.
* *
* @param int $attforblockid * @param int $attendanceid
* @param int $scaleid * @param int $scaleid
* @return boolean True if the scale is used by any attendance * @return boolean True if the scale is used by any attendance
*/ */
function attforblock_scale_used ($attforblockid, $scaleid) { function attendance_scale_used ($attendanceid, $scaleid) {
return false; return false;
} }
@ -436,7 +436,7 @@ function attforblock_scale_used ($attforblockid, $scaleid) {
* @param int $scaleid * @param int $scaleid
* @return bool true if the scale is used by any book * @return bool true if the scale is used by any book
*/ */
function attforblock_scale_used_anywhere($scaleid) { function attendance_scale_used_anywhere($scaleid) {
return false; return false;
} }
@ -451,7 +451,7 @@ function attforblock_scale_used_anywhere($scaleid) {
* @param bool $forcedownload * @param bool $forcedownload
* @return bool false if file not found, does not return if found - justsend the file * @return bool false if file not found, does not return if found - justsend the file
*/ */
function attforblock_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload) { function attendance_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload) {
global $CFG, $DB; global $CFG, $DB;
if ($context->contextlevel != CONTEXT_MODULE) { if ($context->contextlevel != CONTEXT_MODULE) {
@ -460,7 +460,7 @@ function attforblock_pluginfile($course, $cm, $context, $filearea, $args, $force
require_login($course, false, $cm); require_login($course, false, $cm);
if (!$att = $DB->get_record('attforblock', array('id' => $cm->instance))) { if (!$att = $DB->get_record('attendance', array('id' => $cm->instance))) {
return false; return false;
} }
@ -477,7 +477,7 @@ function attforblock_pluginfile($course, $cm, $context, $filearea, $args, $force
$fs = get_file_storage(); $fs = get_file_storage();
$relativepath = implode('/', $args); $relativepath = implode('/', $args);
$fullpath = "/$context->id/mod_attforblock/$filearea/$sessid/$relativepath"; $fullpath = "/$context->id/mod_attendance/$filearea/$sessid/$relativepath";
if (!$file = $fs->get_file_by_hash(sha1($fullpath)) or $file->is_directory()) { if (!$file = $fs->get_file_by_hash(sha1($fullpath)) or $file->is_directory()) {
return false; return false;
} }

138
locallib.php

@ -15,7 +15,7 @@
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/** /**
* local functions and constants for module attforblock * local functions and constants for module attendance
* *
* @package mod_attendance * @package mod_attendance
* @copyright 2011 Artem Andreev <andreev.artem@gmail.com> * @copyright 2011 Artem Andreev <andreev.artem@gmail.com>
@ -37,7 +37,7 @@ define('ATT_VIEW_ALL', 5);
define('ATT_SORT_LASTNAME', 1); define('ATT_SORT_LASTNAME', 1);
define('ATT_SORT_FIRSTNAME', 2); define('ATT_SORT_FIRSTNAME', 2);
class attforblock_permissions { class attendance_permissions {
private $canview; private $canview;
private $canviewreports; private $canviewreports;
private $cantake; private $cantake;
@ -58,31 +58,31 @@ class attforblock_permissions {
public function can_view() { public function can_view() {
if (is_null($this->canview)) { if (is_null($this->canview)) {
$this->canview = has_capability('mod/attforblock:view', $this->context); $this->canview = has_capability('mod/attendance:view', $this->context);
} }
return $this->canview; return $this->canview;
} }
public function require_view_capability() { public function require_view_capability() {
require_capability('mod/attforblock:view', $this->context); require_capability('mod/attendance:view', $this->context);
} }
public function can_view_reports() { public function can_view_reports() {
if (is_null($this->canviewreports)) { if (is_null($this->canviewreports)) {
$this->canviewreports = has_capability('mod/attforblock:viewreports', $this->context); $this->canviewreports = has_capability('mod/attendance:viewreports', $this->context);
} }
return $this->canviewreports; return $this->canviewreports;
} }
public function require_view_reports_capability() { public function require_view_reports_capability() {
require_capability('mod/attforblock:viewreports', $this->context); require_capability('mod/attendance:viewreports', $this->context);
} }
public function can_take() { public function can_take() {
if (is_null($this->cantake)) { if (is_null($this->cantake)) {
$this->cantake = has_capability('mod/attforblock:takeattendances', $this->context); $this->cantake = has_capability('mod/attendance:takeattendances', $this->context);
} }
return $this->cantake; return $this->cantake;
@ -93,7 +93,7 @@ class attforblock_permissions {
return false; return false;
} }
if ($groupid == attforblock::SESSION_COMMON if ($groupid == attendance::SESSION_COMMON
|| $this->can_access_all_groups() || $this->can_access_all_groups()
|| array_key_exists($groupid, groups_get_activity_allowed_groups($this->cm))) { || array_key_exists($groupid, groups_get_activity_allowed_groups($this->cm))) {
return true; return true;
@ -104,7 +104,7 @@ class attforblock_permissions {
public function can_change() { public function can_change() {
if (is_null($this->canchange)) { if (is_null($this->canchange)) {
$this->canchange = has_capability('mod/attforblock:changeattendances', $this->context); $this->canchange = has_capability('mod/attendance:changeattendances', $this->context);
} }
return $this->canchange; return $this->canchange;
@ -112,43 +112,43 @@ class attforblock_permissions {
public function can_manage() { public function can_manage() {
if (is_null($this->canmanage)) { if (is_null($this->canmanage)) {
$this->canmanage = has_capability('mod/attforblock:manageattendances', $this->context); $this->canmanage = has_capability('mod/attendance:manageattendances', $this->context);
} }
return $this->canmanage; return $this->canmanage;
} }
public function require_manage_capability() { public function require_manage_capability() {
require_capability('mod/attforblock:manageattendances', $this->context); require_capability('mod/attendance:manageattendances', $this->context);
} }
public function can_change_preferences() { public function can_change_preferences() {
if (is_null($this->canchangepreferences)) { if (is_null($this->canchangepreferences)) {
$this->canchangepreferences = has_capability('mod/attforblock:changepreferences', $this->context); $this->canchangepreferences = has_capability('mod/attendance:changepreferences', $this->context);
} }
return $this->canchangepreferences; return $this->canchangepreferences;
} }
public function require_change_preferences_capability() { public function require_change_preferences_capability() {
require_capability('mod/attforblock:changepreferences', $this->context); require_capability('mod/attendance:changepreferences', $this->context);
} }
public function can_export() { public function can_export() {
if (is_null($this->canexport)) { if (is_null($this->canexport)) {
$this->canexport = has_capability('mod/attforblock:export', $this->context); $this->canexport = has_capability('mod/attendance:export', $this->context);
} }
return $this->canexport; return $this->canexport;
} }
public function require_export_capability() { public function require_export_capability() {
require_capability('mod/attforblock:export', $this->context); require_capability('mod/attendance:export', $this->context);
} }
public function can_be_listed() { public function can_be_listed() {
if (is_null($this->canbelisted)) { if (is_null($this->canbelisted)) {
$this->canbelisted = has_capability('mod/attforblock:canbelisted', $this->context, null, false); $this->canbelisted = has_capability('mod/attendance:canbelisted', $this->context, null, false);
} }
return $this->canbelisted; return $this->canbelisted;
@ -327,10 +327,10 @@ class att_page_with_filter_controls {
if ($allowedgroups) { if ($allowedgroups) {
if ($groupmode == VISIBLEGROUPS or has_capability('moodle/site:accessallgroups', $PAGE->context)) { if ($groupmode == VISIBLEGROUPS or has_capability('moodle/site:accessallgroups', $PAGE->context)) {
$this->sessgroupslist[self::SESSTYPE_ALL] = get_string('all', 'attforblock'); $this->sessgroupslist[self::SESSTYPE_ALL] = get_string('all', 'attendance');
} }
if ($groupmode == VISIBLEGROUPS) { if ($groupmode == VISIBLEGROUPS) {
$this->sessgroupslist[self::SESSTYPE_COMMON] = get_string('commonsessions', 'attforblock'); $this->sessgroupslist[self::SESSTYPE_COMMON] = get_string('commonsessions', 'attendance');
} }
foreach ($allowedgroups as $group) { foreach ($allowedgroups as $group) {
$this->sessgroupslist[$group->id] = format_string($group->name); $this->sessgroupslist[$group->id] = format_string($group->name);
@ -436,17 +436,17 @@ class att_take_page_params {
private function init_view_mode() { private function init_view_mode() {
if (isset($this->viewmode)) { if (isset($this->viewmode)) {
set_user_preference("attforblock_take_view_mode", $this->viewmode); set_user_preference("attendance_take_view_mode", $this->viewmode);
} else { } else {
$this->viewmode = get_user_preferences("attforblock_take_view_mode", self::DEFAULT_VIEW_MODE); $this->viewmode = get_user_preferences("attendance_take_view_mode", self::DEFAULT_VIEW_MODE);
} }
} }
private function init_gridcols() { private function init_gridcols() {
if (isset($this->gridcols)) { if (isset($this->gridcols)) {
set_user_preference("attforblock_gridcolumns", $this->gridcols); set_user_preference("attendance_gridcolumns", $this->gridcols);
} else { } else {
$this->gridcols = get_user_preferences("attforblock_gridcolumns", 5); $this->gridcols = get_user_preferences("attendance_gridcolumns", 5);
} }
} }
@ -527,7 +527,7 @@ class att_preferences_page_params {
class attforblock { class attendance {
const SESSION_COMMON = 0; const SESSION_COMMON = 0;
const SESSION_GROUP = 1; const SESSION_GROUP = 1;
@ -552,7 +552,7 @@ class attforblock {
/** current page parameters */ /** current page parameters */
public $pageparams; public $pageparams;
/** @var attforblock_permissions permission of current user for attendance instance*/ /** @var attendance_permissions permission of current user for attendance instance*/
public $perm; public $perm;
private $groupmode; private $groupmode;
@ -572,17 +572,17 @@ class attforblock {
* Makes deep copy of all passed records properties. Replaces integer $course attribute * Makes deep copy of all passed records properties. Replaces integer $course attribute
* with a full database record (course should not be stored in instances table anyway). * with a full database record (course should not be stored in instances table anyway).
* *
* @param stdClass $dbrecord Attandance instance data from {attforblock} table * @param stdClass $dbrecord Attandance instance data from {attendance} table
* @param stdClass $cm Course module record as returned by {@link get_coursemodule_from_id()} * @param stdClass $cm Course module record as returned by {@link get_coursemodule_from_id()}
* @param stdClass $course Course record from {course} table * @param stdClass $course Course record from {course} table
* @param stdClass $context The context of the workshop instance * @param stdClass $context The context of the workshop instance
*/ */
public function __construct(stdclass $dbrecord, stdclass $cm, stdclass $course, stdclass $context=null, $pageparams=null) { public function __construct(stdclass $dbrecord, stdclass $cm, stdclass $course, stdclass $context=null, $pageparams=null) {
foreach ($dbrecord as $field => $value) { foreach ($dbrecord as $field => $value) {
if (property_exists('attforblock', $field)) { if (property_exists('attendance', $field)) {
$this->{$field} = $value; $this->{$field} = $value;
} else { } else {
throw new coding_exception('The attendance table has a field with no property in the attforblock class'); throw new coding_exception('The attendance table has a field with no property in the attendance class');
} }
} }
$this->cm = $cm; $this->cm = $cm;
@ -595,7 +595,7 @@ class attforblock {
$this->pageparams = $pageparams; $this->pageparams = $pageparams;
$this->perm = new attforblock_permissions($this->cm, $this->context); $this->perm = new attendance_permissions($this->cm, $this->context);
} }
public function get_group_mode() { public function get_group_mode() {
@ -717,10 +717,10 @@ class attforblock {
$sessions = $DB->get_records_select('attendance_sessions', $where, $params, 'sessdate asc'); $sessions = $DB->get_records_select('attendance_sessions', $where, $params, 'sessdate asc');
foreach ($sessions as $sess) { foreach ($sessions as $sess) {
if (empty($sess->description)) { if (empty($sess->description)) {
$sess->description = get_string('nodescription', 'attforblock'); $sess->description = get_string('nodescription', 'attendance');
} else { } else {
$sess->description = file_rewrite_pluginfile_urls($sess->description, $sess->description = file_rewrite_pluginfile_urls($sess->description,
'pluginfile.php', $this->context->id, 'mod_attforblock', 'session', $sess->id); 'pluginfile.php', $this->context->id, 'mod_attendance', 'session', $sess->id);
} }
} }
@ -732,7 +732,7 @@ class attforblock {
*/ */
public function url_manage($params=array()) { public function url_manage($params=array()) {
$params = array_merge(array('id' => $this->cm->id), $params); $params = array_merge(array('id' => $this->cm->id), $params);
return new moodle_url('/mod/attforblock/manage.php', $params); return new moodle_url('/mod/attendance/manage.php', $params);
} }
/** /**
@ -740,7 +740,7 @@ class attforblock {
*/ */
public function url_sessions($params=array()) { public function url_sessions($params=array()) {
$params = array_merge(array('id' => $this->cm->id), $params); $params = array_merge(array('id' => $this->cm->id), $params);
return new moodle_url('/mod/attforblock/sessions.php', $params); return new moodle_url('/mod/attendance/sessions.php', $params);
} }
/** /**
@ -748,7 +748,7 @@ class attforblock {
*/ */
public function url_report($params=array()) { public function url_report($params=array()) {
$params = array_merge(array('id' => $this->cm->id), $params); $params = array_merge(array('id' => $this->cm->id), $params);
return new moodle_url('/mod/attforblock/report.php', $params); return new moodle_url('/mod/attendance/report.php', $params);
} }
/** /**
@ -756,7 +756,7 @@ class attforblock {
*/ */
public function url_export() { public function url_export() {
$params = array('id' => $this->cm->id); $params = array('id' => $this->cm->id);
return new moodle_url('/mod/attforblock/export.php', $params); return new moodle_url('/mod/attendance/export.php', $params);
} }
/** /**
@ -764,7 +764,7 @@ class attforblock {
*/ */
public function url_preferences($params=array()) { public function url_preferences($params=array()) {
$params = array_merge(array('id' => $this->cm->id), $params); $params = array_merge(array('id' => $this->cm->id), $params);
return new moodle_url('/mod/attforblock/preferences.php', $params); return new moodle_url('/mod/attendance/preferences.php', $params);
} }
/** /**
@ -772,12 +772,12 @@ class attforblock {
*/ */
public function url_take($params=array()) { public function url_take($params=array()) {
$params = array_merge(array('id' => $this->cm->id), $params); $params = array_merge(array('id' => $this->cm->id), $params);
return new moodle_url('/mod/attforblock/take.php', $params); return new moodle_url('/mod/attendance/take.php', $params);
} }
public function url_view($params=array()) { public function url_view($params=array()) {
$params = array_merge(array('id' => $this->cm->id), $params); $params = array_merge(array('id' => $this->cm->id), $params);
return new moodle_url('/mod/attforblock/view.php', $params); return new moodle_url('/mod/attendance/view.php', $params);
} }
public function add_sessions($sessions) { public function add_sessions($sessions) {
@ -788,7 +788,7 @@ class attforblock {
$sess->id = $DB->insert_record('attendance_sessions', $sess); $sess->id = $DB->insert_record('attendance_sessions', $sess);
$description = file_save_draft_area_files($sess->descriptionitemid, $description = file_save_draft_area_files($sess->descriptionitemid,
$this->context->id, 'mod_attforblock', 'session', $sess->id, $this->context->id, 'mod_attendance', 'session', $sess->id,
array('subdirs' => false, 'maxfiles' => -1, 'maxbytes' => 0), array('subdirs' => false, 'maxfiles' => -1, 'maxbytes' => 0),
$sess->description); $sess->description);
$DB->set_field('attendance_sessions', 'description', $description, array('id' => $sess->id)); $DB->set_field('attendance_sessions', 'description', $description, array('id' => $sess->id));
@ -812,7 +812,7 @@ class attforblock {
$sess->sessdate = $formdata->sessiondate; $sess->sessdate = $formdata->sessiondate;
$sess->duration = $formdata->durtime['hours']*HOURSECS + $formdata->durtime['minutes']*MINSECS; $sess->duration = $formdata->durtime['hours']*HOURSECS + $formdata->durtime['minutes']*MINSECS;
$description = file_save_draft_area_files($formdata->sdescription['itemid'], $description = file_save_draft_area_files($formdata->sdescription['itemid'],
$this->context->id, 'mod_attforblock', 'session', $sessionid, $this->context->id, 'mod_attendance', 'session', $sessionid,
array('subdirs' => false, 'maxfiles' => -1, 'maxbytes' => 0), $formdata->sdescription['text']); array('subdirs' => false, 'maxfiles' => -1, 'maxbytes' => 0), $formdata->sdescription['text']);
$sess->description = $description; $sess->description = $description;
$sess->descriptionformat = $formdata->sdescription['format']; $sess->descriptionformat = $formdata->sdescription['format'];
@ -873,7 +873,7 @@ class attforblock {
$url = $this->url_take($params); $url = $this->url_take($params);
$this->log('attendance taked', $url, $USER->firstname.' '.$USER->lastname); $this->log('attendance taked', $url, $USER->firstname.' '.$USER->lastname);
redirect($this->url_manage(), get_string('attendancesuccess', 'attforblock')); redirect($this->url_manage(), get_string('attendancesuccess', 'attendance'));
} }
/** /**
@ -891,7 +891,7 @@ class attforblock {
$orderby = "u.lastname ASC, u.firstname ASC"; $orderby = "u.lastname ASC, u.firstname ASC";
} }
$users = get_enrolled_users($this->context, 'mod/attforblock: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)) {
@ -955,10 +955,10 @@ class attforblock {
$this->sessioninfo[$sessionid] = $DB->get_record('attendance_sessions', array('id' => $sessionid)); $this->sessioninfo[$sessionid] = $DB->get_record('attendance_sessions', array('id' => $sessionid));
} }
if (empty($this->sessioninfo[$sessionid]->description)) { if (empty($this->sessioninfo[$sessionid]->description)) {
$this->sessioninfo[$sessionid]->description = get_string('nodescription', 'attforblock'); $this->sessioninfo[$sessionid]->description = get_string('nodescription', 'attendance');
} else { } else {
$this->sessioninfo[$sessionid]->description = file_rewrite_pluginfile_urls($this->sessioninfo[$sessionid]->description, $this->sessioninfo[$sessionid]->description = file_rewrite_pluginfile_urls($this->sessioninfo[$sessionid]->description,
'pluginfile.php', $this->context->id, 'mod_attforblock', 'session', $this->sessioninfo[$sessionid]->id); 'pluginfile.php', $this->context->id, 'mod_attendance', 'session', $this->sessioninfo[$sessionid]->id);
} }
return $this->sessioninfo[$sessionid]; return $this->sessioninfo[$sessionid];
} }
@ -971,10 +971,10 @@ class attforblock {
foreach ($sessions as $sess) { foreach ($sessions as $sess) {
if (empty($sess->description)) { if (empty($sess->description)) {
$sess->description = get_string('nodescription', 'attforblock'); $sess->description = get_string('nodescription', 'attendance');
} else { } else {
$sess->description = file_rewrite_pluginfile_urls($sess->description, $sess->description = file_rewrite_pluginfile_urls($sess->description,
'pluginfile.php', $this->context->id, 'mod_attforblock', 'session', $sess->id); 'pluginfile.php', $this->context->id, 'mod_attendance', 'session', $sess->id);
} }
} }
@ -1050,7 +1050,7 @@ class attforblock {
$this->get_user_max_grade($userid)) * $this->grade; $this->get_user_max_grade($userid)) * $this->grade;
} }
return grade_update('mod/attforblock', $this->course->id, 'mod', 'attforblock', return grade_update('mod/attendance', $this->course->id, 'mod', 'attendance',
$this->id, 0, $grades); $this->id, 0, $grades);
} }
@ -1134,10 +1134,10 @@ class attforblock {
foreach ($sessions as $sess) { foreach ($sessions as $sess) {
if (empty($sess->description)) { if (empty($sess->description)) {
$sess->description = get_string('nodescription', 'attforblock'); $sess->description = get_string('nodescription', 'attendance');
} else { } else {
$sess->description = file_rewrite_pluginfile_urls($sess->description, $sess->description = file_rewrite_pluginfile_urls($sess->description,
'pluginfile.php', $this->context->id, 'mod_attforblock', 'session', $sess->id); 'pluginfile.php', $this->context->id, 'mod_attendance', 'session', $sess->id);
} }
} }
@ -1151,7 +1151,7 @@ class attforblock {
$DB->delete_records_select('attendance_log', "sessionid $sql", $params); $DB->delete_records_select('attendance_log', "sessionid $sql", $params);
$DB->delete_records_list('attendance_sessions', 'id', $sessionsids); $DB->delete_records_list('attendance_sessions', 'id', $sessionsids);
$this->log('sessions deleted', null, get_string('sessionsids', 'attforblock').implode(', ', $sessionsids)); $this->log('sessions deleted', null, get_string('sessionsids', 'attendance').implode(', ', $sessionsids));
} }
public function update_sessions_duration($sessionsids, $duration) { public function update_sessions_duration($sessionsids, $duration) {
@ -1166,7 +1166,7 @@ class attforblock {
} }
$this->log('sessions duration updated', $this->url_manage(), $this->log('sessions duration updated', $this->url_manage(),
get_string('sessionsids', 'attforblock').implode(', ', $sessionsids)); get_string('sessionsids', 'attendance').implode(', ', $sessionsids));
} }
public function remove_status($statusid) { public function remove_status($statusid) {
@ -1189,7 +1189,7 @@ class attforblock {
$this->log('status added', $this->url_preferences(), $acronym.': '.$description.' ('.$grade.')'); $this->log('status added', $this->url_preferences(), $acronym.': '.$description.' ('.$grade.')');
} else { } else {
print_error('cantaddstatus', 'attforblock', $this->url_preferences()); print_error('cantaddstatus', 'attendance', $this->url_preferences());
} }
} }
@ -1238,7 +1238,7 @@ class attforblock {
} }
$logurl = att_log_convert_url($url); $logurl = att_log_convert_url($url);
add_to_log($this->course->id, 'attforblock', $action, $logurl, $info, $this->cm->id); add_to_log($this->course->id, 'attendance', $action, $logurl, $info, $this->cm->id);
} }
} }
@ -1317,7 +1317,7 @@ function att_get_user_courses_attendances($userid) {
$sql = "SELECT att.id as attid, att.course as courseid, course.fullname as coursefullname, $sql = "SELECT att.id as attid, att.course as courseid, course.fullname as coursefullname,
course.startdate as coursestartdate, att.name as attname, att.grade as attgrade course.startdate as coursestartdate, att.name as attname, att.grade as attgrade
FROM {attforblock} att FROM {attendance} att
JOIN {course} course JOIN {course} course
ON att.course = course.id ON att.course = course.id
WHERE att.course $usql WHERE att.course $usql
@ -1339,13 +1339,13 @@ function att_calc_user_grade_fraction($grade, $maxgrade) {
function att_get_gradebook_maxgrade($attid) { function att_get_gradebook_maxgrade($attid) {
global $DB; global $DB;
return $DB->get_field('attforblock', 'grade', array('id' => $attid)); return $DB->get_field('attendance', 'grade', array('id' => $attid));
} }
function att_update_all_users_grades($attid, $course, $context) { function att_update_all_users_grades($attid, $course, $context) {
$grades = array(); $grades = array();
$userids = array_keys(get_enrolled_users($context, 'mod/attforblock:canbelisted', 0, 'u.id')); $userids = array_keys(get_enrolled_users($context, 'mod/attendance:canbelisted', 0, 'u.id'));
$statuses = att_get_statuses($attid); $statuses = att_get_statuses($attid);
$gradebook_maxgrade = att_get_gradebook_maxgrade($attid); $gradebook_maxgrade = att_get_gradebook_maxgrade($attid);
@ -1360,7 +1360,7 @@ function att_update_all_users_grades($attid, $course, $context) {
$grades[$userid] = $grade; $grades[$userid] = $grade;
} }
return grade_update('mod/attforblock', $course->id, 'mod', 'attforblock', return grade_update('mod/attendance', $course->id, 'mod', 'attendance',
$attid, 0, $grades); $attid, 0, $grades);
} }
@ -1374,9 +1374,33 @@ function att_log_convert_url(moodle_url $fullurl) {
static $baseurl; static $baseurl;
if (!isset($baseurl)) { if (!isset($baseurl)) {
$baseurl = new moodle_url('/mod/attforblock/'); $baseurl = new moodle_url('/mod/attendance/');
$baseurl = $baseurl->out(); $baseurl = $baseurl->out();
} }
return substr($fullurl->out(), strlen($baseurl)); return substr($fullurl->out(), strlen($baseurl));
} }
function attforblock_upgrade() {
global $DB, $CFG;
$module = $DB->get_record('modules', array('name' => 'attforblock'));
if ($module->version !== '2012120700') {
print_error("noupgradefromthisversion", 'attendance');
}
if (file_exists($CFG->dirroot.'/mod/attforblock')) {
print_error("attforblockdirstillexists", 'attendance');
}
// Now rename attforblock table and replace with attendance?
$dbman = $DB->get_manager(); // Loads ddl manager and xmldb classes.
$table = new xmldb_table('attforblock');
$newtable = new xmldb_table('attendance'); // Sanity check to make sure 'attendance' table doesn't already exist.
if ($dbman->table_exists($table) && !$dbman->table_exists($newtable)) {
$dbman->rename_table($table, 'attendance');
} else {
print_error("tablerenamefailed", 'attendance');
}
// Now convert module record.
$module->name = 'attendance';
$DB->update_record('modules', $module);
}

24
manage.php

@ -17,7 +17,7 @@
/** /**
* Manage attendance sessions * Manage attendance sessions
* *
* @package mod_attforblock * @package mod_attendance
* @copyright 2011 Artem Andreev <andreev.artem@gmail.com> * @copyright 2011 Artem Andreev <andreev.artem@gmail.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/ */
@ -32,14 +32,14 @@ $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);
$cm = get_coursemodule_from_id('attforblock', $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);
$att = $DB->get_record('attforblock', array('id' => $cm->instance), '*', MUST_EXIST); $att = $DB->get_record('attendance', array('id' => $cm->instance), '*', MUST_EXIST);
require_login($course, true, $cm); require_login($course, true, $cm);
$pageparams->init($cm); $pageparams->init($cm);
$att = new attforblock($att, $cm, $course, $PAGE->context, $pageparams); $att = new attendance($att, $cm, $course, $PAGE->context, $pageparams);
if (!$att->perm->can_manage() && !$att->perm->can_take() && !$att->perm->can_change()) { if (!$att->perm->can_manage() && !$att->perm->can_take() && !$att->perm->can_change()) {
redirect($att->url_view()); redirect($att->url_view());
} }
@ -50,8 +50,8 @@ if ($from === 'block') {
$size = count($sessions); $size = count($sessions);
if ($size == 1) { if ($size == 1) {
$sess = reset($sessions); $sess = reset($sessions);
$nottaken = !$sess->lasttaken && has_capability('mod/attforblock:takeattendances', $PAGE->context); $nottaken = !$sess->lasttaken && has_capability('mod/attendance:takeattendances', $PAGE->context);
$canchange = $sess->lasttaken && has_capability('mod/attforblock:changeattendances', $PAGE->context); $canchange = $sess->lasttaken && has_capability('mod/attendance:changeattendances', $PAGE->context);
if ($nottaken || $canchange) { if ($nottaken || $canchange) {
redirect($att->url_take(array('sessionid' => $sess->id, 'grouptype' => $sess->groupid))); redirect($att->url_take(array('sessionid' => $sess->id, 'grouptype' => $sess->groupid)));
} }
@ -66,18 +66,18 @@ $PAGE->set_url($att->url_manage());
$PAGE->set_title($course->shortname. ": ".$att->name); $PAGE->set_title($course->shortname. ": ".$att->name);
$PAGE->set_heading($course->fullname); $PAGE->set_heading($course->fullname);
$PAGE->set_cacheable(true); $PAGE->set_cacheable(true);
$PAGE->set_button($OUTPUT->update_module_button($cm->id, 'attforblock')); $PAGE->set_button($OUTPUT->update_module_button($cm->id, 'attendance'));
$PAGE->navbar->add($att->name); $PAGE->navbar->add($att->name);
$output = $PAGE->get_renderer('mod_attforblock'); $output = $PAGE->get_renderer('mod_attendance');
$tabs = new attforblock_tabs($att, attforblock_tabs::TAB_SESSIONS); $tabs = new attendance_tabs($att, attendance_tabs::TAB_SESSIONS);
$filtercontrols = new attforblock_filter_controls($att); $filtercontrols = new attendance_filter_controls($att);
$sesstable = new attforblock_manage_data($att); $sesstable = new attendance_manage_data($att);
// Output starts here. // Output starts here.
echo $output->header(); echo $output->header();
echo $output->heading(get_string('attendanceforthecourse', 'attforblock').' :: ' .$course->fullname); echo $output->heading(get_string('attendanceforthecourse', 'attendance').' :: ' .$course->fullname);
echo $output->render($tabs); echo $output->render($tabs);
echo $output->render($filtercontrols); echo $output->render($filtercontrols);
echo $output->render($sesstable); echo $output->render($sesstable);

8
mod_form.php

@ -15,9 +15,9 @@
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/** /**
* Forms for updating/adding attforblock * Forms for updating/adding attendance
* *
* @package mod_attforblock * @package mod_attendance
* @copyright 2011 Artem Andreev <andreev.artem@gmail.com> * @copyright 2011 Artem Andreev <andreev.artem@gmail.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/ */
@ -28,7 +28,7 @@ if (!defined('MOODLE_INTERNAL')) {
require_once($CFG->dirroot.'/course/moodleform_mod.php'); require_once($CFG->dirroot.'/course/moodleform_mod.php');
class mod_attforblock_mod_form extends moodleform_mod { class mod_attendance_mod_form extends moodleform_mod {
public function definition() { public function definition() {
@ -40,7 +40,7 @@ class mod_attforblock_mod_form extends moodleform_mod {
$mform->addElement('text', 'name', get_string('name'), array('size'=>'64')); $mform->addElement('text', 'name', get_string('name'), array('size'=>'64'));
$mform->setType('name', PARAM_TEXT); $mform->setType('name', PARAM_TEXT);
$mform->addRule('name', null, 'required', null, 'client'); $mform->addRule('name', null, 'required', null, 'client');
$mform->setDefault('name', get_string('modulename', 'attforblock')); $mform->setDefault('name', get_string('modulename', 'attendance'));
$mform->addElement('modgrade', 'grade', get_string('grade')); $mform->addElement('modgrade', 'grade', get_string('grade'));
$mform->setDefault('grade', 100); $mform->setDefault('grade', 100);

6
module.js

@ -1,6 +1,6 @@
M.mod_attforblock = {} M.mod_attendance = {}
M.mod_attforblock.init_manage = function(Y) { M.mod_attendance.init_manage = function(Y) {
Y.on('click', function(e) { Y.on('click', function(e) {
if (e.target.get('checked')) { if (e.target.get('checked')) {
@ -11,7 +11,7 @@ M.mod_attforblock.init_manage = function(Y) {
}, '#cb_selector' ); }, '#cb_selector' );
}; };
M.mod_attforblock.set_preferences_action = function(action) { M.mod_attendance.set_preferences_action = function(action) {
var item = document.getElementById('preferencesaction'); var item = document.getElementById('preferencesaction');
if (item) { if (item) {
item.setAttribute('value', action); item.setAttribute('value', action);

32
preferences.php

@ -17,7 +17,7 @@
/** /**
* Manage attendance settings * Manage attendance settings
* *
* @package mod_attforblock * @package mod_attendance
* @copyright 2011 Artem Andreev <andreev.artem@gmail.com> * @copyright 2011 Artem Andreev <andreev.artem@gmail.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/ */
@ -31,22 +31,22 @@ $id = required_param('id', PARAM_INT);
$pageparams->action = optional_param('action', null, PARAM_INT); $pageparams->action = optional_param('action', null, PARAM_INT);
$pageparams->statusid = optional_param('statusid', null, PARAM_INT); $pageparams->statusid = optional_param('statusid', null, PARAM_INT);
$cm = get_coursemodule_from_id('attforblock', $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);
$att = $DB->get_record('attforblock', array('id' => $cm->instance), '*', MUST_EXIST); $att = $DB->get_record('attendance', array('id' => $cm->instance), '*', MUST_EXIST);
require_login($course, true, $cm); require_login($course, true, $cm);
$att = new attforblock($att, $cm, $course, $PAGE->context, $pageparams); $att = new attendance($att, $cm, $course, $PAGE->context, $pageparams);
$att->perm->require_change_preferences_capability(); $att->perm->require_change_preferences_capability();
$PAGE->set_url($att->url_preferences()); $PAGE->set_url($att->url_preferences());
$PAGE->set_title($course->shortname. ": ".$att->name.' - '.get_string('settings', 'attforblock')); $PAGE->set_title($course->shortname. ": ".$att->name.' - '.get_string('settings', 'attendance'));
$PAGE->set_heading($course->fullname); $PAGE->set_heading($course->fullname);
$PAGE->set_cacheable(true); $PAGE->set_cacheable(true);
$PAGE->set_button($OUTPUT->update_module_button($cm->id, 'attforblock')); $PAGE->set_button($OUTPUT->update_module_button($cm->id, 'attendance'));
$PAGE->navbar->add(get_string('settings', 'attforblock')); $PAGE->navbar->add(get_string('settings', 'attendance'));
switch ($att->pageparams->action) { switch ($att->pageparams->action) {
case att_preferences_page_params::ACTION_ADD: case att_preferences_page_params::ACTION_ADD:
@ -58,24 +58,24 @@ switch ($att->pageparams->action) {
break; break;
case att_preferences_page_params::ACTION_DELETE: case att_preferences_page_params::ACTION_DELETE:
if (att_has_logs_for_status($att->pageparams->statusid)) { if (att_has_logs_for_status($att->pageparams->statusid)) {
print_error('cantdeletestatus', 'attforblock', "attsettings.php?id=$id"); print_error('cantdeletestatus', 'attendance', "attsettings.php?id=$id");
} }
$confirm = optional_param('confirm', null, PARAM_INT); $confirm = optional_param('confirm', null, PARAM_INT);
if (isset($confirm)) { if (isset($confirm)) {
$att->remove_status($att->pageparams->statusid); $att->remove_status($att->pageparams->statusid);
redirect($att->url_preferences(), get_string('statusdeleted', 'attforblock')); redirect($att->url_preferences(), get_string('statusdeleted', 'attendance'));
} }
$statuses = $att->get_statuses(); $statuses = $att->get_statuses();
$status = $statuses[$att->pageparams->statusid]; $status = $statuses[$att->pageparams->statusid];
$message = get_string('deletecheckfull', '', get_string('variable', 'attforblock')); $message = get_string('deletecheckfull', '', get_string('variable', 'attendance'));
$message .= str_repeat(html_writer::empty_tag('br'), 2); $message .= str_repeat(html_writer::empty_tag('br'), 2);
$message .= $status->acronym.': '. $message .= $status->acronym.': '.
($status->description ? $status->description : get_string('nodescription', 'attforblock')); ($status->description ? $status->description : get_string('nodescription', 'attendance'));
$params = array_merge($att->pageparams->get_significant_params(), array('confirm' => 1)); $params = array_merge($att->pageparams->get_significant_params(), array('confirm' => 1));
echo $OUTPUT->header(); echo $OUTPUT->header();
echo $OUTPUT->heading(get_string('attendanceforthecourse', 'attforblock').' :: ' .$course->fullname); echo $OUTPUT->heading(get_string('attendanceforthecourse', 'attendance').' :: ' .$course->fullname);
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;
@ -97,14 +97,14 @@ switch ($att->pageparams->action) {
break; break;
} }
$output = $PAGE->get_renderer('mod_attforblock'); $output = $PAGE->get_renderer('mod_attendance');
$tabs = new attforblock_tabs($att, attforblock_tabs::TAB_PREFERENCES); $tabs = new attendance_tabs($att, attendance_tabs::TAB_PREFERENCES);
$prefdata = new attforblock_preferences_data($att); $prefdata = new attendance_preferences_data($att);
// Output starts here. // Output starts here.
echo $output->header(); echo $output->header();
echo $output->heading(get_string('attendanceforthecourse', 'attforblock').' :: ' .$course->fullname); echo $output->heading(get_string('attendanceforthecourse', 'attendance').' :: ' .$course->fullname);
echo $output->render($tabs); echo $output->render($tabs);
echo $output->render($prefdata); echo $output->render($prefdata);

58
renderables.php

@ -17,7 +17,7 @@
/** /**
* Attendance module renderable components are defined here * Attendance module renderable components are defined here
* *
* @package mod_attforblock * @package mod_attendance
* @copyright 2011 Artem Andreev <andreev.artem@gmail.com> * @copyright 2011 Artem Andreev <andreev.artem@gmail.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/ */
@ -30,10 +30,10 @@ require_once(dirname(__FILE__).'/locallib.php');
/** /**
* Represents info about attendance tabs. * Represents info about attendance tabs.
* *
* Proxy class for security reasons (renderers must not have access to all attforblock methods) * Proxy class for security reasons (renderers must not have access to all attendance methods)
* *
*/ */
class attforblock_tabs implements renderable { class attendance_tabs implements renderable {
const TAB_SESSIONS = 1; const TAB_SESSIONS = 1;
const TAB_ADD = 2; const TAB_ADD = 2;
const TAB_REPORT = 3; const TAB_REPORT = 3;
@ -42,16 +42,16 @@ class attforblock_tabs implements renderable {
public $currenttab; public $currenttab;
/** @var attforblock */ /** @var attendance */
private $att; private $att;
/** /**
* Prepare info about sessions for attendance taking into account view parameters. * Prepare info about sessions for attendance taking into account view parameters.
* *
* @param attforblock $att instance * @param attendance $att instance
* @param $currenttab - one of attforblock_tabs constants * @param $currenttab - one of attendance_tabs constants
*/ */
public function __construct(attforblock $att, $currenttab=null) { public function __construct(attendance $att, $currenttab=null) {
$this->att = $att; $this->att = $att;
$this->currenttab = $currenttab; $this->currenttab = $currenttab;
} }
@ -66,18 +66,18 @@ class attforblock_tabs implements renderable {
$this->att->perm->can_take() or $this->att->perm->can_take() or
$this->att->perm->can_change()) { $this->att->perm->can_change()) {
$toprow[] = new tabobject(self::TAB_SESSIONS, $this->att->url_manage()->out(), $toprow[] = new tabobject(self::TAB_SESSIONS, $this->att->url_manage()->out(),
get_string('sessions', 'attforblock')); get_string('sessions', 'attendance'));
} }
if ($this->att->perm->can_manage()) { if ($this->att->perm->can_manage()) {
$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' => att_sessions_page_params::ACTION_ADD)),
get_string('add', 'attforblock')); get_string('add', 'attendance'));
} }
if ($this->att->perm->can_view_reports()) { if ($this->att->perm->can_view_reports()) {
$toprow[] = new tabobject(self::TAB_REPORT, $this->att->url_report()->out(), $toprow[] = new tabobject(self::TAB_REPORT, $this->att->url_report()->out(),
get_string('report', 'attforblock')); get_string('report', 'attendance'));
} }
if ($this->att->perm->can_export()) { if ($this->att->perm->can_export()) {
@ -87,7 +87,7 @@ class attforblock_tabs implements renderable {
if ($this->att->perm->can_change_preferences()) { if ($this->att->perm->can_change_preferences()) {
$toprow[] = new tabobject(self::TAB_PREFERENCES, $this->att->url_preferences()->out(), $toprow[] = new tabobject(self::TAB_PREFERENCES, $this->att->url_preferences()->out(),
get_string('settings', 'attforblock')); get_string('settings', 'attendance'));
} }
return array($toprow); return array($toprow);
@ -95,7 +95,7 @@ class attforblock_tabs implements renderable {
} }
class attforblock_filter_controls implements renderable { class attendance_filter_controls implements renderable {
/** @var int current view mode */ /** @var int current view mode */
public $pageparams; public $pageparams;
@ -112,7 +112,7 @@ class attforblock_filter_controls implements renderable {
private $att; private $att;
public function __construct(attforblock $att) { public function __construct(attendance $att) {
global $PAGE; global $PAGE;
$this->pageparams = $att->pageparams; $this->pageparams = $att->pageparams;
@ -129,13 +129,13 @@ class attforblock_filter_controls implements renderable {
switch ($this->pageparams->view) { switch ($this->pageparams->view) {
case ATT_VIEW_DAYS: case ATT_VIEW_DAYS:
$format = get_string('strftimedm', 'attforblock'); $format = get_string('strftimedm', 'attendance');
$this->prevcur = make_timestamp($year, $mon, $mday - 1); $this->prevcur = make_timestamp($year, $mon, $mday - 1);
$this->nextcur = make_timestamp($year, $mon, $mday + 1); $this->nextcur = make_timestamp($year, $mon, $mday + 1);
$this->curdatetxt = userdate($att->pageparams->startdate, $format); $this->curdatetxt = userdate($att->pageparams->startdate, $format);
break; break;
case ATT_VIEW_WEEKS: case ATT_VIEW_WEEKS:
$format = get_string('strftimedm', 'attforblock'); $format = get_string('strftimedm', 'attendance');
$this->prevcur = $att->pageparams->startdate - WEEKSECS; $this->prevcur = $att->pageparams->startdate - WEEKSECS;
$this->nextcur = $att->pageparams->startdate + WEEKSECS; $this->nextcur = $att->pageparams->startdate + WEEKSECS;
$this->curdatetxt = userdate($att->pageparams->startdate, $format). $this->curdatetxt = userdate($att->pageparams->startdate, $format).
@ -190,28 +190,28 @@ class attforblock_filter_controls implements renderable {
* Represents info about attendance sessions taking into account view parameters. * Represents info about attendance sessions taking into account view parameters.
* *
*/ */
class attforblock_manage_data implements renderable { class attendance_manage_data implements renderable {
/** @var array of sessions*/ /** @var array of sessions*/
public $sessions; public $sessions;
/** @var int number of hidden sessions (sessions before $course->startdate)*/ /** @var int number of hidden sessions (sessions before $course->startdate)*/
public $hiddensessionscount; public $hiddensessionscount;
/** @var attforblock_permissions permission of current user for attendance instance*/ /** @var attendance_permissions permission of current user for attendance instance*/
public $perm; public $perm;
public $groups; public $groups;
public $hiddensesscount; public $hiddensesscount;
/** @var attforblock */ /** @var attendance */
private $att; private $att;
/** /**
* Prepare info about attendance sessions taking into account view parameters. * Prepare info about attendance sessions taking into account view parameters.
* *
* @param attforblock $att instance * @param attendance $att instance
*/ */
public function __construct(attforblock $att) { public function __construct(attendance $att) {
$this->perm = $att->perm; $this->perm = $att->perm;
$this->sessions = $att->get_filtered_sessions(); $this->sessions = $att->get_filtered_sessions();
@ -235,7 +235,7 @@ class attforblock_manage_data implements renderable {
} }
} }
class attforblock_take_data implements renderable { class attendance_take_data implements renderable {
public $users; public $users;
public $pageparams; public $pageparams;
@ -258,7 +258,7 @@ class attforblock_take_data implements renderable {
private $urlparams; private $urlparams;
private $att; private $att;
public function __construct(attforblock $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);
} else { } else {
@ -315,7 +315,7 @@ class attforblock_take_data implements renderable {
} }
} }
class attforblock_user_data implements renderable { class attendance_user_data implements renderable {
public $user; public $user;
public $pageparams; public $pageparams;
@ -343,7 +343,7 @@ class attforblock_user_data implements renderable {
private $urlpath; private $urlpath;
private $urlparams; private $urlparams;
public function __construct(attforblock $att, $userid) { public function __construct(attendance $att, $userid) {
global $CFG; global $CFG;
$this->user = $att->get_user($userid); $this->user = $att->get_user($userid);
@ -365,7 +365,7 @@ class attforblock_user_data implements renderable {
$this->maxgrade = $att->get_user_max_grade($userid); $this->maxgrade = $att->get_user_max_grade($userid);
} }
$this->filtercontrols = new attforblock_filter_controls($att); $this->filtercontrols = new attendance_filter_controls($att);
$this->sessionslog = $att->get_user_filtered_sessions_log_extended($userid); $this->sessionslog = $att->get_user_filtered_sessions_log_extended($userid);
@ -417,7 +417,7 @@ class attforblock_user_data implements renderable {
} }
} }
class attforblock_report_data implements renderable { class attendance_report_data implements renderable {
public $perm; public $perm;
public $pageparams; public $pageparams;
@ -447,7 +447,7 @@ class attforblock_report_data implements renderable {
private $att; private $att;
public function __construct(attforblock $att) { public function __construct(attendance $att) {
global $CFG; global $CFG;
$this->perm = $att->perm; $this->perm = $att->perm;
@ -500,12 +500,12 @@ class attforblock_report_data implements renderable {
} }
class attforblock_preferences_data implements renderable { class attendance_preferences_data implements renderable {
public $statuses; public $statuses;
private $att; private $att;
public function __construct(attforblock $att) { public function __construct(attendance $att) {
$this->statuses = $att->get_statuses(false); $this->statuses = $att->get_statuses(false);
foreach ($this->statuses as $st) { foreach ($this->statuses as $st) {

190
renderer.php

@ -17,7 +17,7 @@
/** /**
* Attendance module renderering methods * Attendance module renderering methods
* *
* @package mod_attforblock * @package mod_attendance
* @copyright 2011 Artem Andreev <andreev.artem@gmail.com> * @copyright 2011 Artem Andreev <andreev.artem@gmail.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/ */
@ -33,7 +33,7 @@ require_once(dirname(__FILE__).'/renderhelpers.php');
* *
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/ */
class mod_attforblock_renderer extends plugin_renderer_base { class mod_attendance_renderer extends plugin_renderer_base {
// External API - methods to render attendance renderable components. // External API - methods to render attendance renderable components.
/** /**
@ -42,7 +42,7 @@ class mod_attforblock_renderer extends plugin_renderer_base {
* @param atttabs - tabs to display * @param atttabs - tabs to display
* @return string html code * @return string html code
*/ */
protected function render_attforblock_tabs(attforblock_tabs $atttabs) { protected function render_attendance_tabs(attendance_tabs $atttabs) {
return print_tabs($atttabs->get_tabs(), $atttabs->currenttab, null, null, true); return print_tabs($atttabs->get_tabs(), $atttabs->currenttab, null, null, true);
} }
@ -52,7 +52,7 @@ class mod_attforblock_renderer extends plugin_renderer_base {
* @param fcontrols - filter controls data to display * @param fcontrols - filter controls data to display
* @return string html code * @return string html code
*/ */
protected function render_attforblock_filter_controls(attforblock_filter_controls $fcontrols) { protected function render_attendance_filter_controls(attendance_filter_controls $fcontrols) {
$filtertable = new html_table(); $filtertable = new html_table();
$filtertable->attributes['class'] = ' '; $filtertable->attributes['class'] = ' ';
$filtertable->width = '100%'; $filtertable->width = '100%';
@ -70,14 +70,14 @@ class mod_attforblock_renderer extends plugin_renderer_base {
return $o; return $o;
} }
protected function render_sess_group_selector(attforblock_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 att_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,
$fcontrols->get_current_sesstype(), null, 'selectgroup'); $fcontrols->get_current_sesstype(), null, 'selectgroup');
$select->label = get_string('sessions', 'attforblock'); $select->label = get_string('sessions', 'attendance');
$output = $this->output->render($select); $output = $this->output->render($select);
return html_writer::tag('div', $output, array('class' => 'groupselector')); return html_writer::tag('div', $output, array('class' => 'groupselector'));
@ -90,25 +90,25 @@ class mod_attforblock_renderer extends plugin_renderer_base {
return ''; return '';
} }
protected function render_curdate_controls(attforblock_filter_controls $fcontrols) { protected function render_curdate_controls(attendance_filter_controls $fcontrols) {
global $CFG; global $CFG;
$curdate_controls = ''; $curdate_controls = '';
if ($fcontrols->curdatetxt) { if ($fcontrols->curdatetxt) {
$this->page->requires->strings_for_js(array('calclose', 'caltoday'), 'attforblock'); $this->page->requires->strings_for_js(array('calclose', 'caltoday'), 'attendance');
$jsvals = array( $jsvals = array(
'cal_months' => explode(',', get_string('calmonths', 'attforblock')), 'cal_months' => explode(',', get_string('calmonths', 'attendance')),
'cal_week_days' => explode(',', get_string('calweekdays', 'attforblock')), 'cal_week_days' => explode(',', get_string('calweekdays', 'attendance')),
'cal_start_weekday' => $CFG->calendar_startwday, 'cal_start_weekday' => $CFG->calendar_startwday,
'cal_cur_date' => $fcontrols->curdate); 'cal_cur_date' => $fcontrols->curdate);
$curdate_controls = html_writer::script(js_writer::set_variable('M.attforblock', $jsvals)); $curdate_controls = html_writer::script(js_writer::set_variable('M.attendance', $jsvals));
$this->page->requires->js('/mod/attforblock/calendar.js'); $this->page->requires->js('/mod/attendance/calendar.js');
$curdate_controls .= html_writer::link($fcontrols->url(array('curdate' => $fcontrols->prevcur)), $curdate_controls .= html_writer::link($fcontrols->url(array('curdate' => $fcontrols->prevcur)),
$this->output->larrow()); $this->output->larrow());
$params = array( $params = array(
'title' => get_string('calshow', 'attforblock'), 'title' => get_string('calshow', 'attendance'),
'id' => 'show', 'id' => 'show',
'type' => 'button'); 'type' => 'button');
$button_form = html_writer::tag('button', $fcontrols->curdatetxt, $params); $button_form = html_writer::tag('button', $fcontrols->curdatetxt, $params);
@ -136,12 +136,12 @@ class mod_attforblock_renderer extends plugin_renderer_base {
return $curdate_controls; return $curdate_controls;
} }
protected function render_view_controls(attforblock_filter_controls $fcontrols) { protected function render_view_controls(attendance_filter_controls $fcontrols) {
$views[ATT_VIEW_ALL] = get_string('all', 'attforblock'); $views[ATT_VIEW_ALL] = get_string('all', 'attendance');
$views[ATT_VIEW_ALLPAST] = get_string('allpast', 'attforblock'); $views[ATT_VIEW_ALLPAST] = get_string('allpast', 'attendance');
$views[ATT_VIEW_MONTHS] = get_string('months', 'attforblock'); $views[ATT_VIEW_MONTHS] = get_string('months', 'attendance');
$views[ATT_VIEW_WEEKS] = get_string('weeks', 'attforblock'); $views[ATT_VIEW_WEEKS] = get_string('weeks', 'attendance');
$views[ATT_VIEW_DAYS] = get_string('days', 'attforblock'); $views[ATT_VIEW_DAYS] = get_string('days', 'attendance');
$viewcontrols = ''; $viewcontrols = '';
foreach ($views as $key => $sview) { foreach ($views as $key => $sview) {
if ($key != $fcontrols->pageparams->view) { if ($key != $fcontrols->pageparams->view) {
@ -158,10 +158,10 @@ class mod_attforblock_renderer extends plugin_renderer_base {
/** /**
* Renders attendance sessions managing table * Renders attendance sessions managing table
* *
* @param attforblock_manage_data $sessdata to display * @param attendance_manage_data $sessdata to display
* @return string html code * @return string html code
*/ */
protected function render_attforblock_manage_data(attforblock_manage_data $sessdata) { protected function render_attendance_manage_data(attendance_manage_data $sessdata) {
$o = $this->render_sess_manage_table($sessdata) . $this->render_sess_manage_control($sessdata); $o = $this->render_sess_manage_table($sessdata) . $this->render_sess_manage_control($sessdata);
$o = html_writer::tag('form', $o, array('method' => 'post', 'action' => $sessdata->url_sessions()->out())); $o = html_writer::tag('form', $o, array('method' => 'post', 'action' => $sessdata->url_sessions()->out()));
$o = $this->output->container($o, 'generalbox attwidth'); $o = $this->output->container($o, 'generalbox attwidth');
@ -170,17 +170,17 @@ class mod_attforblock_renderer extends plugin_renderer_base {
return $o; return $o;
} }
protected function render_sess_manage_table(attforblock_manage_data $sessdata) { protected function render_sess_manage_table(attendance_manage_data $sessdata) {
$this->page->requires->js_init_call('M.mod_attforblock.init_manage'); $this->page->requires->js_init_call('M.mod_attendance.init_manage');
$table = new html_table(); $table = new html_table();
$table->width = '100%'; $table->width = '100%';
$table->head = array( $table->head = array(
'#', '#',
get_string('sessiontypeshort', 'attforblock'), get_string('sessiontypeshort', 'attendance'),
get_string('date'), get_string('date'),
get_string('time'), get_string('time'),
get_string('description', 'attforblock'), get_string('description', 'attendance'),
get_string('actions'), get_string('actions'),
html_writer::checkbox('cb_selector', 0, false, '', array('id' => 'cb_selector')) html_writer::checkbox('cb_selector', 0, false, '', array('id' => 'cb_selector'))
); );
@ -195,7 +195,7 @@ class mod_attforblock_renderer extends plugin_renderer_base {
$table->data[$sess->id][] = $i; $table->data[$sess->id][] = $i;
$table->data[$sess->id][] = $sess->groupid ? $sessdata->groups[$sess->groupid]->name : $table->data[$sess->id][] = $sess->groupid ? $sessdata->groups[$sess->groupid]->name :
get_string('commonsession', 'attforblock'); get_string('commonsession', 'attendance');
$table->data[$sess->id][] = $dta['date']; $table->data[$sess->id][] = $dta['date'];
$table->data[$sess->id][] = $dta['time']; $table->data[$sess->id][] = $dta['time'];
$table->data[$sess->id][] = $sess->description; $table->data[$sess->id][] = $sess->description;
@ -206,20 +206,20 @@ class mod_attforblock_renderer extends plugin_renderer_base {
return html_writer::table($table); return html_writer::table($table);
} }
private function construct_date_time_actions(attforblock_manage_data $sessdata, $sess) { private function construct_date_time_actions(attendance_manage_data $sessdata, $sess) {
$actions = ''; $actions = '';
$date = userdate($sess->sessdate, get_string('strftimedmyw', 'attforblock')); $date = userdate($sess->sessdate, get_string('strftimedmyw', 'attendance'));
$time = $this->construct_time($sess->sessdate, $sess->duration); $time = $this->construct_time($sess->sessdate, $sess->duration);
if ($sess->lasttaken > 0) { if ($sess->lasttaken > 0) {
if ($sessdata->perm->can_change()) { if ($sessdata->perm->can_change()) {
$url = $sessdata->url_take($sess->id, $sess->groupid); $url = $sessdata->url_take($sess->id, $sess->groupid);
$title = get_string('changeattendance', 'attforblock'); $title = get_string('changeattendance', 'attendance');
$date = html_writer::link($url, $date, array('title' => $title)); $date = html_writer::link($url, $date, array('title' => $title));
$time = html_writer::link($url, $time, array('title' => $title)); $time = html_writer::link($url, $time, array('title' => $title));
$actions = $this->output->action_icon($url, new pix_icon('redo', $title, 'attforblock')); $actions = $this->output->action_icon($url, new pix_icon('redo', $title, 'attendance'));
} else { } else {
$date = '<i>' . $date . '</i>'; $date = '<i>' . $date . '</i>';
$time = '<i>' . $time . '</i>'; $time = '<i>' . $time . '</i>';
@ -227,36 +227,36 @@ class mod_attforblock_renderer extends plugin_renderer_base {
} else { } else {
if ($sessdata->perm->can_take()) { if ($sessdata->perm->can_take()) {
$url = $sessdata->url_take($sess->id, $sess->groupid); $url = $sessdata->url_take($sess->id, $sess->groupid);
$title = get_string('takeattendance', 'attforblock'); $title = get_string('takeattendance', 'attendance');
$actions = $this->output->action_icon($url, new pix_icon('t/go', $title)); $actions = $this->output->action_icon($url, new pix_icon('t/go', $title));
} }
} }
if ($sessdata->perm->can_manage()) { if ($sessdata->perm->can_manage()) {
$url = $sessdata->url_sessions($sess->id, att_sessions_page_params::ACTION_UPDATE); $url = $sessdata->url_sessions($sess->id, att_sessions_page_params::ACTION_UPDATE);
$title = get_string('editsession', 'attforblock'); $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, att_sessions_page_params::ACTION_DELETE);
$title = get_string('deletesession', 'attforblock'); $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));
} }
return array('date' => $date, 'time' => $time, 'actions' => $actions); return array('date' => $date, 'time' => $time, 'actions' => $actions);
} }
protected function render_sess_manage_control(attforblock_manage_data $sessdata) { protected function render_sess_manage_control(attendance_manage_data $sessdata) {
$table = new html_table(); $table = new html_table();
$table->attributes['class'] = ' '; $table->attributes['class'] = ' ';
$table->width = '100%'; $table->width = '100%';
$table->align = array('left', 'right'); $table->align = array('left', 'right');
$table->data[0][] = $this->output->help_icon('hiddensessions', 'attforblock', $table->data[0][] = $this->output->help_icon('hiddensessions', 'attendance',
get_string('hiddensessions', 'attforblock').': '.$sessdata->hiddensessionscount); get_string('hiddensessions', 'attendance').': '.$sessdata->hiddensessionscount);
if ($sessdata->perm->can_manage()) { if ($sessdata->perm->can_manage()) {
$options = array( $options = array(
att_sessions_page_params::ACTION_DELETE_SELECTED => get_string('delete'), att_sessions_page_params::ACTION_DELETE_SELECTED => get_string('delete'),
att_sessions_page_params::ACTION_CHANGE_DURATION => get_string('changeduration', 'attforblock')); 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(
'type' => 'submit', 'type' => 'submit',
@ -264,32 +264,32 @@ class mod_attforblock_renderer extends plugin_renderer_base {
'value' => get_string('ok')); 'value' => get_string('ok'));
$controls .= html_writer::empty_tag('input', $attributes); $controls .= html_writer::empty_tag('input', $attributes);
} else { } else {
$controls = get_string('youcantdo', 'attforblock'); // You can't do anything. $controls = get_string('youcantdo', 'attendance'); // You can't do anything.
} }
$table->data[0][] = $controls; $table->data[0][] = $controls;
return html_writer::table($table); return html_writer::table($table);
} }
protected function render_attforblock_take_data(attforblock_take_data $takedata) { protected function render_attendance_take_data(attendance_take_data $takedata) {
$controls = $this->render_attforblock_take_controls($takedata); $controls = $this->render_attendance_take_controls($takedata);
if ($takedata->pageparams->viewmode == att_take_page_params::SORTED_LIST) { if ($takedata->pageparams->viewmode == att_take_page_params::SORTED_LIST) {
$table = $this->render_attforblock_take_list($takedata); $table = $this->render_attendance_take_list($takedata);
} else { } else {
$table = $this->render_attforblock_take_grid($takedata); $table = $this->render_attendance_take_grid($takedata);
} }
$table .= html_writer::input_hidden_params($takedata->url()); $table .= html_writer::input_hidden_params($takedata->url());
$params = array( $params = array(
'type' => 'submit', 'type' => 'submit',
'value' => get_string('save', 'attforblock')); 'value' => get_string('save', 'attendance'));
$table .= html_writer::tag('center', html_writer::empty_tag('input', $params)); $table .= html_writer::tag('center', html_writer::empty_tag('input', $params));
$table = html_writer::tag('form', $table, array('method' => 'post', 'action' => $takedata->url_path())); $table = html_writer::tag('form', $table, array('method' => 'post', 'action' => $takedata->url_path()));
return $controls.$table; return $controls.$table;
} }
protected function render_attforblock_take_controls(attforblock_take_data $takedata) { protected function render_attendance_take_controls(attendance_take_data $takedata) {
$table = new html_table(); $table = new html_table();
$table->attributes['class'] = ' '; $table->attributes['class'] = ' ';
@ -299,11 +299,11 @@ class mod_attforblock_renderer extends plugin_renderer_base {
return $this->output->container(html_writer::table($table), 'generalbox takecontrols'); return $this->output->container(html_writer::table($table), 'generalbox takecontrols');
} }
private function construct_take_session_info(attforblock_take_data $takedata) { private function construct_take_session_info(attendance_take_data $takedata) {
$sess = $takedata->sessioninfo; $sess = $takedata->sessioninfo;
$date = userdate($sess->sessdate, get_string('strftimedate')); $date = userdate($sess->sessdate, get_string('strftimedate'));
$starttime = userdate($sess->sessdate, get_string('strftimehm', 'attforblock')); $starttime = userdate($sess->sessdate, get_string('strftimehm', 'attendance'));
$endtime = userdate($sess->sessdate + $sess->duration, get_string('strftimehm', 'attforblock')); $endtime = userdate($sess->sessdate + $sess->duration, get_string('strftimehm', 'attendance'));
$time = html_writer::tag('nobr', $starttime . ($sess->duration > 0 ? ' - ' . $endtime : '')); $time = html_writer::tag('nobr', $starttime . ($sess->duration > 0 ? ' - ' . $endtime : ''));
$sessinfo = $date.' '.$time; $sessinfo = $date.' '.$time;
$sessinfo .= html_writer::empty_tag('br'); $sessinfo .= html_writer::empty_tag('br');
@ -313,9 +313,9 @@ class mod_attforblock_renderer extends plugin_renderer_base {
return $sessinfo; return $sessinfo;
} }
private function construct_take_controls(attforblock_take_data $takedata) { private function construct_take_controls(attendance_take_data $takedata) {
$controls = ''; $controls = '';
if ($takedata->pageparams->grouptype == attforblock::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()))) {
$controls .= groups_print_activity_menu($takedata->cm, $takedata->url(), true); $controls .= groups_print_activity_menu($takedata->cm, $takedata->url(), true);
@ -324,19 +324,19 @@ class mod_attforblock_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', 'attforblock'), att_take_page_params::SORTED_LIST => get_string('sortedlist', 'attendance'),
att_take_page_params::SORTED_GRID => get_string('sortedgrid', 'attforblock')); att_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', 'attforblock')); $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_GRID) { if ($takedata->pageparams->viewmode == att_take_page_params::SORTED_GRID) {
$options = array (1 => '1 '.get_string('column', 'attforblock'), '2 '.get_string('columns', 'attforblock'), $options = array (1 => '1 '.get_string('column', 'attendance'), '2 '.get_string('columns', 'attendance'),
'3 '.get_string('columns', 'attforblock'), '4 '.get_string('columns', 'attforblock'), '3 '.get_string('columns', 'attendance'), '4 '.get_string('columns', 'attendance'),
'5 '.get_string('columns', 'attforblock'), '6 '.get_string('columns', 'attforblock'), '5 '.get_string('columns', 'attendance'), '6 '.get_string('columns', 'attendance'),
'7 '.get_string('columns', 'attforblock'), '8 '.get_string('columns', 'attforblock'), '7 '.get_string('columns', 'attendance'), '8 '.get_string('columns', 'attendance'),
'9 '.get_string('columns', 'attforblock'), '10 '.get_string('columns', 'attforblock')); '9 '.get_string('columns', 'attendance'), '10 '.get_string('columns', 'attendance'));
$select = new single_select($takedata->url(), 'gridcols', $options, $takedata->pageparams->gridcols, null); $select = new single_select($takedata->url(), 'gridcols', $options, $takedata->pageparams->gridcols, null);
$select->class = 'singleselect inline'; $select->class = 'singleselect inline';
$controls .= $this->output->render($select); $controls .= $this->output->render($select);
@ -348,13 +348,13 @@ class mod_attforblock_renderer extends plugin_renderer_base {
$options = array(); $options = array();
foreach ($takedata->sessions4copy as $sess) { foreach ($takedata->sessions4copy as $sess) {
$start = userdate($sess->sessdate, get_string('strftimehm', 'attforblock')); $start = userdate($sess->sessdate, get_string('strftimehm', 'attendance'));
$end = $sess->duration ? ' - '.userdate($sess->sessdate + $sess->duration, $end = $sess->duration ? ' - '.userdate($sess->sessdate + $sess->duration,
get_string('strftimehm', 'attforblock')) : ''; get_string('strftimehm', 'attendance')) : '';
$options[$sess->id] = $start . $end; $options[$sess->id] = $start . $end;
} }
$select = new single_select($takedata->url(array(), array('copyfrom')), 'copyfrom', $options); $select = new single_select($takedata->url(array(), array('copyfrom')), 'copyfrom', $options);
$select->set_label(get_string('copyfrom', 'attforblock')); $select->set_label(get_string('copyfrom', 'attendance'));
$select->class = 'singleselect inline'; $select->class = 'singleselect inline';
$controls .= $this->output->render($select); $controls .= $this->output->render($select);
} }
@ -362,7 +362,7 @@ class mod_attforblock_renderer extends plugin_renderer_base {
return $controls; return $controls;
} }
protected function render_attforblock_take_list(attforblock_take_data $takedata) { protected function render_attendance_take_list(attendance_take_data $takedata) {
$table = new html_table(); $table = new html_table();
$table->width = '0%'; $table->width = '0%';
$table->head = array( $table->head = array(
@ -374,11 +374,11 @@ class mod_attforblock_renderer extends plugin_renderer_base {
$table->wrap[1] = 'nowrap'; $table->wrap[1] = 'nowrap';
foreach ($takedata->statuses as $st) { foreach ($takedata->statuses as $st) {
$table->head[] = html_writer::link("javascript:select_all_in(null, 'st" . $st->id . "', null);", $st->acronym, $table->head[] = html_writer::link("javascript:select_all_in(null, 'st" . $st->id . "', null);", $st->acronym,
array('title' => get_string('setallstatusesto', 'attforblock', $st->description))); array('title' => get_string('setallstatusesto', 'attendance', $st->description)));
$table->align[] = 'center'; $table->align[] = 'center';
$table->size[] = '20px'; $table->size[] = '20px';
} }
$table->head[] = get_string('remarks', 'attforblock'); $table->head[] = get_string('remarks', 'attendance');
$table->align[] = 'center'; $table->align[] = 'center';
$table->size[] = '20px'; $table->size[] = '20px';
$table->attributes['class'] = 'generaltable takelist'; $table->attributes['class'] = 'generaltable takelist';
@ -416,7 +416,7 @@ class mod_attforblock_renderer extends plugin_renderer_base {
return html_writer::table($table); return html_writer::table($table);
} }
protected function render_attforblock_take_grid(attforblock_take_data $takedata) { protected function render_attendance_take_grid(attendance_take_data $takedata) {
$table = new html_table(); $table = new html_table();
for ($i=0; $i < $takedata->pageparams->gridcols; $i++) { for ($i=0; $i < $takedata->pageparams->gridcols; $i++) {
$table->align[] = 'center'; $table->align[] = 'center';
@ -427,7 +427,7 @@ class mod_attforblock_renderer extends plugin_renderer_base {
$head = array(); $head = array();
foreach ($takedata->statuses as $st) { foreach ($takedata->statuses as $st) {
$head[] = html_writer::link("javascript:select_all_in(null, 'st" . $st->id . "', null);", $st->acronym, $head[] = html_writer::link("javascript:select_all_in(null, 'st" . $st->id . "', null);", $st->acronym,
array('title' => get_string('setallstatusesto', 'attforblock', $st->description))); array('title' => get_string('setallstatusesto', 'attendance', $st->description)));
} }
$table->head[] = implode('&nbsp;&nbsp;', $head); $table->head[] = implode('&nbsp;&nbsp;', $head);
@ -489,15 +489,15 @@ class mod_attforblock_renderer extends plugin_renderer_base {
return $fullnamehead; return $fullnamehead;
} }
private function construct_take_user_controls(attforblock_take_data $takedata, $user) { private function construct_take_user_controls(attendance_take_data $takedata, $user) {
$celldata = array(); $celldata = array();
if ($user->enrolmentend and $user->enrolmentend < $takedata->sessioninfo->sessdate) { if ($user->enrolmentend and $user->enrolmentend < $takedata->sessioninfo->sessdate) {
$celldata['text'] = get_string('enrolmentend', 'attforblock', userdate($user->enrolmentend, '%d.%m.%Y')); $celldata['text'] = get_string('enrolmentend', 'attendance', userdate($user->enrolmentend, '%d.%m.%Y'));
$celldata['colspan'] = count($takedata->statuses) + 1; $celldata['colspan'] = count($takedata->statuses) + 1;
$celldata['class'] = 'userwithoutenrol'; $celldata['class'] = 'userwithoutenrol';
} else if (!$user->enrolmentend and $user->enrolmentstatus == ENROL_USER_SUSPENDED) { } else if (!$user->enrolmentend and $user->enrolmentstatus == ENROL_USER_SUSPENDED) {
// No enrolmentend and ENROL_USER_SUSPENDED. // No enrolmentend and ENROL_USER_SUSPENDED.
$celldata['text'] = get_string('enrolmentsuspended', 'attforblock'); $celldata['text'] = get_string('enrolmentsuspended', 'attendance');
$celldata['colspan'] = count($takedata->statuses) + 1; $celldata['colspan'] = count($takedata->statuses) + 1;
$celldata['class'] = 'userwithoutenrol'; $celldata['class'] = 'userwithoutenrol';
} else { } else {
@ -533,7 +533,7 @@ class mod_attforblock_renderer extends plugin_renderer_base {
$celldata['text'][] = html_writer::empty_tag('input', $params); $celldata['text'][] = html_writer::empty_tag('input', $params);
if ($user->enrolmentstart > $takedata->sessioninfo->sessdate + $takedata->sessioninfo->duration) { if ($user->enrolmentstart > $takedata->sessioninfo->sessdate + $takedata->sessioninfo->duration) {
$celldata['warning'] = get_string('enrolmentstart', 'attforblock', $celldata['warning'] = get_string('enrolmentstart', 'attendance',
userdate($user->enrolmentstart, '%H:%M %d.%m.%Y')); userdate($user->enrolmentstart, '%H:%M %d.%m.%Y'));
$celldata['class'] = 'userwithoutenrol'; $celldata['class'] = 'userwithoutenrol';
} }
@ -542,7 +542,7 @@ class mod_attforblock_renderer extends plugin_renderer_base {
return $celldata; return $celldata;
} }
protected function render_attforblock_user_data(attforblock_user_data $userdata) { protected function render_attendance_user_data(attendance_user_data $userdata) {
$o = $this->render_user_report_tabs($userdata); $o = $this->render_user_report_tabs($userdata);
$table = new html_table(); $table = new html_table();
@ -557,21 +557,21 @@ class mod_attforblock_renderer extends plugin_renderer_base {
return $o; return $o;
} }
protected function render_user_report_tabs(attforblock_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(att_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' => att_view_page_params::MODE_THIS_COURSE)),
get_string('thiscourse', 'attforblock')); get_string('thiscourse', 'attendance'));
$tabs[] = new tabobject(att_view_page_params::MODE_ALL_COURSES, $tabs[] = new tabobject(att_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' => att_view_page_params::MODE_ALL_COURSES)),
get_string('allcourses', 'attforblock')); get_string('allcourses', 'attendance'));
return print_tabs(array($tabs), $userdata->pageparams->mode, null, null, true); return print_tabs(array($tabs), $userdata->pageparams->mode, null, null, true);
} }
private function construct_user_data(attforblock_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 == att_view_page_params::MODE_THIS_COURSE) {
@ -580,7 +580,7 @@ class mod_attforblock_renderer extends plugin_renderer_base {
$o .= construct_user_data_stat($userdata->stat, $userdata->statuses, $o .= construct_user_data_stat($userdata->stat, $userdata->statuses,
$userdata->gradable, $userdata->grade, $userdata->maxgrade, $userdata->decimalpoints); $userdata->gradable, $userdata->grade, $userdata->maxgrade, $userdata->decimalpoints);
$o .= $this->render_attforblock_filter_controls($userdata->filtercontrols); $o .= $this->render_attendance_filter_controls($userdata->filtercontrols);
$o .= $this->construct_user_sessions_log($userdata); $o .= $this->construct_user_sessions_log($userdata);
} else { } else {
@ -603,17 +603,17 @@ class mod_attforblock_renderer extends plugin_renderer_base {
return $o; return $o;
} }
private function construct_user_sessions_log(attforblock_user_data $userdata) { private function construct_user_sessions_log(attendance_user_data $userdata) {
$table = new html_table(); $table = new html_table();
$table->attributes['class'] = 'generaltable attwidth boxaligncenter'; $table->attributes['class'] = 'generaltable attwidth boxaligncenter';
$table->head = array( $table->head = array(
'#', '#',
get_string('sessiontypeshort', 'attforblock'), get_string('sessiontypeshort', 'attendance'),
get_string('date'), get_string('date'),
get_string('time'), get_string('time'),
get_string('description', 'attforblock'), get_string('description', 'attendance'),
get_string('status', 'attforblock'), get_string('status', 'attendance'),
get_string('remarks', 'attforblock') get_string('remarks', 'attendance')
); );
$table->align = array('', '', '', 'left', 'left', 'center', 'left'); $table->align = array('', '', '', 'left', 'left', 'center', 'left');
$table->size = array('1px', '1px', '1px', '1px', '*', '1px', '1px'); $table->size = array('1px', '1px', '1px', '1px', '*', '1px', '1px');
@ -625,20 +625,20 @@ class mod_attforblock_renderer extends plugin_renderer_base {
$row = new html_table_row(); $row = new html_table_row();
$row->cells[] = $i; $row->cells[] = $i;
$row->cells[] = html_writer::tag('nobr', $sess->groupid ? $userdata->groups[$sess->groupid]->name : $row->cells[] = html_writer::tag('nobr', $sess->groupid ? $userdata->groups[$sess->groupid]->name :
get_string('commonsession', 'attforblock')); get_string('commonsession', 'attendance'));
$row->cells[] = userdate($sess->sessdate, get_string('strftimedmyw', 'attforblock')); $row->cells[] = userdate($sess->sessdate, get_string('strftimedmyw', 'attendance'));
$row->cells[] = $this->construct_time($sess->sessdate, $sess->duration); $row->cells[] = $this->construct_time($sess->sessdate, $sess->duration);
$row->cells[] = $sess->description; $row->cells[] = $sess->description;
if (isset($sess->statusid)) { if (isset($sess->statusid)) {
$row->cells[] = $userdata->statuses[$sess->statusid]->description; $row->cells[] = $userdata->statuses[$sess->statusid]->description;
$row->cells[] = $sess->remarks; $row->cells[] = $sess->remarks;
} else if ($sess->sessdate < $userdata->user->enrolmentstart) { } else if ($sess->sessdate < $userdata->user->enrolmentstart) {
$cell = new html_table_cell(get_string('enrolmentstart', 'attforblock', $cell = new html_table_cell(get_string('enrolmentstart', 'attendance',
userdate($userdata->user->enrolmentstart, '%d.%m.%Y'))); userdate($userdata->user->enrolmentstart, '%d.%m.%Y')));
$cell->colspan = 2; $cell->colspan = 2;
$row->cells[] = $cell; $row->cells[] = $cell;
} else if ($userdata->user->enrolmentend and $sess->sessdate > $userdata->user->enrolmentend) { } else if ($userdata->user->enrolmentend and $sess->sessdate > $userdata->user->enrolmentend) {
$cell = new html_table_cell(get_string('enrolmentend', 'attforblock', $cell = new html_table_cell(get_string('enrolmentend', 'attendance',
userdate($userdata->user->enrolmentend, '%d.%m.%Y'))); userdate($userdata->user->enrolmentend, '%d.%m.%Y')));
$cell->colspan = 2; $cell->colspan = 2;
$row->cells[] = $cell; $row->cells[] = $cell;
@ -659,7 +659,7 @@ class mod_attforblock_renderer extends plugin_renderer_base {
return $time; return $time;
} }
protected function render_attforblock_report_data(attforblock_report_data $reportdata) { protected function render_attendance_report_data(attendance_report_data $reportdata) {
$table = new html_table(); $table = new html_table();
$table->attributes['class'] = 'generaltable attwidth'; $table->attributes['class'] = 'generaltable attwidth';
@ -674,14 +674,14 @@ class mod_attforblock_renderer extends plugin_renderer_base {
$table->size[] = ''; $table->size[] = '';
foreach ($reportdata->sessions as $sess) { foreach ($reportdata->sessions as $sess) {
$sesstext = userdate($sess->sessdate, get_string('strftimedm', 'attforblock')); $sesstext = userdate($sess->sessdate, get_string('strftimedm', 'attendance'));
$sesstext .= html_writer::empty_tag('br'); $sesstext .= html_writer::empty_tag('br');
$sesstext .= userdate($sess->sessdate, '('.get_string('strftimehm', 'attforblock').')'); $sesstext .= userdate($sess->sessdate, '('.get_string('strftimehm', 'attendance').')');
if (is_null($sess->lasttaken) and $reportdata->perm->can_take() or $reportdata->perm->can_change()) { if (is_null($sess->lasttaken) and $reportdata->perm->can_take() or $reportdata->perm->can_change()) {
$sesstext = html_writer::link($reportdata->url_take($sess->id, $sess->groupid), $sesstext); $sesstext = html_writer::link($reportdata->url_take($sess->id, $sess->groupid), $sesstext);
} }
$sesstext .= html_writer::empty_tag('br'); $sesstext .= html_writer::empty_tag('br');
$sesstext .= $sess->groupid ? $reportdata->groups[$sess->groupid]->name : get_string('commonsession', 'attforblock'); $sesstext .= $sess->groupid ? $reportdata->groups[$sess->groupid]->name : get_string('commonsession', 'attendance');
$table->head[] = $sesstext; $table->head[] = $sesstext;
$table->align[] = 'center'; $table->align[] = 'center';
@ -727,13 +727,13 @@ class mod_attforblock_renderer extends plugin_renderer_base {
return html_writer::table($table); return html_writer::table($table);
} }
protected function render_attforblock_preferences_data(attforblock_preferences_data $prefdata) { protected function render_attendance_preferences_data(attendance_preferences_data $prefdata) {
$this->page->requires->js('/mod/attforblock/module.js'); $this->page->requires->js('/mod/attendance/module.js');
$table = new html_table(); $table = new html_table();
$table->width = '100%'; $table->width = '100%';
$table->head = array('#', $table->head = array('#',
get_string('acronym', 'attforblock'), get_string('acronym', 'attendance'),
get_string('description'), get_string('description'),
get_string('grade'), get_string('grade'),
get_string('action')); get_string('action'));
@ -754,13 +754,13 @@ class mod_attforblock_renderer extends plugin_renderer_base {
$table->data[$i][] = $this->construct_text_input('newacronym', 2, 2); $table->data[$i][] = $this->construct_text_input('newacronym', 2, 2);
$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', 'attforblock'), $table->data[$i][] = $this->construct_preferences_button(get_string('add', 'attendance'),
att_preferences_page_params::ACTION_ADD); att_preferences_page_params::ACTION_ADD);
$o = html_writer::tag('h1', get_string('myvariables', 'attforblock')); $o = html_writer::tag('h1', get_string('myvariables', 'attendance'));
$o .= html_writer::table($table); $o .= html_writer::table($table);
$o .= html_writer::input_hidden_params($prefdata->url(array(), false)); $o .= html_writer::input_hidden_params($prefdata->url(array(), false));
$o .= $this->construct_preferences_button(get_string('update', 'attforblock'), att_preferences_page_params::ACTION_SAVE); $o .= $this->construct_preferences_button(get_string('update', 'attendance'), att_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');
@ -814,7 +814,7 @@ class mod_attforblock_renderer extends plugin_renderer_base {
$attributes = array( $attributes = array(
'type' => 'submit', 'type' => 'submit',
'value' => $text, 'value' => $text,
'onclick' => 'M.mod_attforblock.set_preferences_action('.$action.')'); 'onclick' => 'M.mod_attendance.set_preferences_action('.$action.')');
return html_writer::empty_tag('input', $attributes); return html_writer::empty_tag('input', $attributes);
} }

36
renderhelpers.php

@ -17,7 +17,7 @@
/** /**
* Attendance module renderering helpers * Attendance module renderering helpers
* *
* @package mod_attforblock * @package mod_attendance
* @copyright 2011 Artem Andreev <andreev.artem@gmail.com> * @copyright 2011 Artem Andreev <andreev.artem@gmail.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/ */
@ -35,7 +35,7 @@ class user_sessions_cells_generator {
protected $reportdata; protected $reportdata;
protected $user; protected $user;
public function __construct(attforblock_report_data $reportdata, $user) { public function __construct(attendance_report_data $reportdata, $user) {
$this->reportdata = $reportdata; $this->reportdata = $reportdata;
$this->user = $user; $this->user = $user;
} }
@ -52,14 +52,14 @@ class user_sessions_cells_generator {
} }
} else { } else {
if ($this->user->enrolmentstart > $sess->sessdate) { if ($this->user->enrolmentstart > $sess->sessdate) {
$starttext = get_string('enrolmentstart', 'attforblock', userdate($this->user->enrolmentstart, '%d.%m.%Y')); $starttext = get_string('enrolmentstart', 'attendance', userdate($this->user->enrolmentstart, '%d.%m.%Y'));
$this->construct_enrolments_info_cell($starttext); $this->construct_enrolments_info_cell($starttext);
} else if ($this->user->enrolmentend and $this->user->enrolmentend < $sess->sessdate) { } else if ($this->user->enrolmentend and $this->user->enrolmentend < $sess->sessdate) {
$endtext = get_string('enrolmentend', 'attforblock', userdate($this->user->enrolmentend, '%d.%m.%Y')); $endtext = get_string('enrolmentend', 'attendance', userdate($this->user->enrolmentend, '%d.%m.%Y'));
$this->construct_enrolments_info_cell($endtext); $this->construct_enrolments_info_cell($endtext);
} else if (!$this->user->enrolmentend and $this->user->enrolmentstatus == ENROL_USER_SUSPENDED) { } else if (!$this->user->enrolmentend and $this->user->enrolmentstatus == ENROL_USER_SUSPENDED) {
// No enrolmentend and ENROL_USER_SUSPENDED. // No enrolmentend and ENROL_USER_SUSPENDED.
$suspendext = get_string('enrolmentsuspended', 'attforblock', userdate($this->user->enrolmentend, '%d.%m.%Y')); $suspendext = get_string('enrolmentsuspended', 'attendance', userdate($this->user->enrolmentend, '%d.%m.%Y'));
$this->construct_enrolments_info_cell($suspendext); $this->construct_enrolments_info_cell($suspendext);
} else { } else {
if ($sess->groupid == 0 or array_key_exists($sess->groupid, $this->reportdata->usersgroups[$this->user->id])) { if ($sess->groupid == 0 or array_key_exists($sess->groupid, $this->reportdata->usersgroups[$this->user->id])) {
@ -172,14 +172,14 @@ class user_sessions_cells_text_generator extends user_sessions_cells_generator {
} }
function construct_session_time($datetime, $duration) { function construct_session_time($datetime, $duration) {
$starttime = userdate($datetime, get_string('strftimehm', 'attforblock')); $starttime = userdate($datetime, get_string('strftimehm', 'attendance'));
$endtime = userdate($datetime + $duration, get_string('strftimehm', 'attforblock')); $endtime = userdate($datetime + $duration, get_string('strftimehm', 'attendance'));
return $starttime . ($duration > 0 ? ' - ' . $endtime : ''); return $starttime . ($duration > 0 ? ' - ' . $endtime : '');
} }
function construct_session_full_date_time($datetime, $duration) { function construct_session_full_date_time($datetime, $duration) {
$sessinfo = userdate($datetime, get_string('strftimedmyw', 'attforblock')); $sessinfo = userdate($datetime, get_string('strftimedmyw', 'attendance'));
$sessinfo .= ' '.construct_session_time($datetime, $duration); $sessinfo .= ' '.construct_session_time($datetime, $duration);
return $sessinfo; return $sessinfo;
@ -191,7 +191,7 @@ function construct_user_data_stat($stat, $statuses, $gradable, $grade, $maxgrade
$stattable = new html_table(); $stattable = new html_table();
$stattable->attributes['class'] = 'attlist'; $stattable->attributes['class'] = 'attlist';
$row = new html_table_row(); $row = new html_table_row();
$row->cells[] = get_string('sessionscompleted', 'attforblock').':'; $row->cells[] = get_string('sessionscompleted', 'attendance').':';
$row->cells[] = $stat['completed']; $row->cells[] = $stat['completed'];
$stattable->data[] = $row; $stattable->data[] = $row;
@ -205,13 +205,13 @@ function construct_user_data_stat($stat, $statuses, $gradable, $grade, $maxgrade
if ($gradable) { if ($gradable) {
$row = new html_table_row(); $row = new html_table_row();
$row->cells[] = get_string('attendancegrade', 'attforblock') . $row->cells[] = get_string('attendancegrade', 'attendance') .
$OUTPUT->help_icon('gradebookexplanation', 'attforblock') . ':'; $OUTPUT->help_icon('gradebookexplanation', 'attendance') . ':';
$row->cells[] = $grade . ' / ' . $maxgrade; $row->cells[] = $grade . ' / ' . $maxgrade;
$stattable->data[] = $row; $stattable->data[] = $row;
$row = new html_table_row(); $row = new html_table_row();
$row->cells[] = get_string('attendancepercent', 'attforblock') . ':'; $row->cells[] = get_string('attendancepercent', 'attendance') . ':';
if ($maxgrade == 0) { if ($maxgrade == 0) {
$percent = 0; $percent = 0;
} else { } else {
@ -224,16 +224,16 @@ function construct_user_data_stat($stat, $statuses, $gradable, $grade, $maxgrade
return html_writer::table($stattable); return html_writer::table($stattable);
} }
function construct_full_user_stat_html_table($attforblock, $course, $user) { function construct_full_user_stat_html_table($attendance, $course, $user) {
global $CFG; global $CFG;
$gradeable = $attforblock->grade > 0; $gradeable = $attendance->grade > 0;
$statuses = att_get_statuses($attforblock->id); $statuses = att_get_statuses($attendance->id);
$userstatusesstat = att_get_user_statuses_stat($attforblock->id, $course->startdate, $user->id); $userstatusesstat = att_get_user_statuses_stat($attendance->id, $course->startdate, $user->id);
$stat['completed'] = att_get_user_taken_sessions_count($attforblock->id, $course->startdate, $user->id); $stat['completed'] = att_get_user_taken_sessions_count($attendance->id, $course->startdate, $user->id);
$stat['statuses'] = $userstatusesstat; $stat['statuses'] = $userstatusesstat;
if ($gradeable) { if ($gradeable) {
$grade = att_get_user_grade($userstatusesstat, $statuses); $grade = att_get_user_grade($userstatusesstat, $statuses);
$maxgrade = att_get_user_max_grade(att_get_user_taken_sessions_count($attforblock->id, $course->startdate, $maxgrade = att_get_user_max_grade(att_get_user_taken_sessions_count($attendance->id, $course->startdate,
$user->id), $statuses); $user->id), $statuses);
if (!$decimalpoints = grade_get_setting($course->id, 'decimalpoints')) { if (!$decimalpoints = grade_get_setting($course->id, 'decimalpoints')) {
$decimalpoints = $CFG->grade_decimalpoints; $decimalpoints = $CFG->grade_decimalpoints;

24
report.php

@ -17,7 +17,7 @@
/** /**
* Attendance report * Attendance report
* *
* @package mod_attforblock * @package mod_attendance
* @copyright 2011 Artem Andreev <andreev.artem@gmail.com> * @copyright 2011 Artem Andreev <andreev.artem@gmail.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/ */
@ -34,29 +34,29 @@ $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);
$cm = get_coursemodule_from_id('attforblock', $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);
$att = $DB->get_record('attforblock', array('id' => $cm->instance), '*', MUST_EXIST); $att = $DB->get_record('attendance', array('id' => $cm->instance), '*', MUST_EXIST);
require_login($course, true, $cm); require_login($course, true, $cm);
$pageparams->init($cm); $pageparams->init($cm);
$att = new attforblock($att, $cm, $course, $PAGE->context, $pageparams); $att = new attendance($att, $cm, $course, $PAGE->context, $pageparams);
$att->perm->require_view_reports_capability(); $att->perm->require_view_reports_capability();
$PAGE->set_url($att->url_report()); $PAGE->set_url($att->url_report());
$PAGE->set_pagelayout('report'); $PAGE->set_pagelayout('report');
$PAGE->set_title($course->shortname. ": ".$att->name.' - '.get_string('report', 'attforblock')); $PAGE->set_title($course->shortname. ": ".$att->name.' - '.get_string('report', 'attendance'));
$PAGE->set_heading($course->fullname); $PAGE->set_heading($course->fullname);
$PAGE->set_cacheable(true); $PAGE->set_cacheable(true);
$PAGE->set_button($OUTPUT->update_module_button($cm->id, 'attforblock')); $PAGE->set_button($OUTPUT->update_module_button($cm->id, 'attendance'));
$PAGE->navbar->add(get_string('report', 'attforblock')); $PAGE->navbar->add(get_string('report', 'attendance'));
$output = $PAGE->get_renderer('mod_attforblock'); $output = $PAGE->get_renderer('mod_attendance');
$tabs = new attforblock_tabs($att, attforblock_tabs::TAB_REPORT); $tabs = new attendance_tabs($att, attendance_tabs::TAB_REPORT);
$filtercontrols = new attforblock_filter_controls($att); $filtercontrols = new attendance_filter_controls($att);
$reportdata = new attforblock_report_data($att); $reportdata = new attendance_report_data($att);
global $USER; global $USER;
$att->log('report viewed', null, $USER->firstname.' '.$USER->lastname); $att->log('report viewed', null, $USER->firstname.' '.$USER->lastname);
@ -64,7 +64,7 @@ $att->log('report viewed', null, $USER->firstname.' '.$USER->lastname);
// Output starts here. // Output starts here.
echo $output->header(); echo $output->header();
echo $output->heading(get_string('attendanceforthecourse', 'attforblock').' :: ' .$course->fullname); echo $output->heading(get_string('attendanceforthecourse', 'attendance').' :: ' .$course->fullname);
echo $output->render($tabs); echo $output->render($tabs);
echo $output->render($filtercontrols); echo $output->render($filtercontrols);
echo $output->render($reportdata); echo $output->render($reportdata);

50
sessions.php

@ -17,7 +17,7 @@
/** /**
* Adding attendance sessions * Adding attendance sessions
* *
* @package mod_attforblock * @package mod_attendance
* @copyright 2011 Artem Andreev <andreev.artem@gmail.com> * @copyright 2011 Artem Andreev <andreev.artem@gmail.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/ */
@ -33,13 +33,13 @@ $pageparams = new att_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);
$cm = get_coursemodule_from_id('attforblock', $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);
$att = $DB->get_record('attforblock', array('id' => $cm->instance), '*', MUST_EXIST); $att = $DB->get_record('attendance', array('id' => $cm->instance), '*', MUST_EXIST);
require_login($course, true, $cm); require_login($course, true, $cm);
$att = new attforblock($att, $cm, $course, $PAGE->context, $pageparams); $att = new attendance($att, $cm, $course, $PAGE->context, $pageparams);
$att->perm->require_manage_capability(); $att->perm->require_manage_capability();
@ -47,19 +47,19 @@ $PAGE->set_url($att->url_sessions());
$PAGE->set_title($course->shortname. ": ".$att->name); $PAGE->set_title($course->shortname. ": ".$att->name);
$PAGE->set_heading($course->fullname); $PAGE->set_heading($course->fullname);
$PAGE->set_cacheable(true); $PAGE->set_cacheable(true);
$PAGE->set_button($OUTPUT->update_module_button($cm->id, 'attforblock')); $PAGE->set_button($OUTPUT->update_module_button($cm->id, 'attendance'));
$PAGE->navbar->add($att->name); $PAGE->navbar->add($att->name);
$formparams = array('course' => $course, 'cm' => $cm, 'modcontext' => $PAGE->context); $formparams = array('course' => $course, 'cm' => $cm, 'modcontext' => $PAGE->context);
switch ($att->pageparams->action) { switch ($att->pageparams->action) {
case att_sessions_page_params::ACTION_ADD: case att_sessions_page_params::ACTION_ADD:
$url = $att->url_sessions(array('action' => att_sessions_page_params::ACTION_ADD)); $url = $att->url_sessions(array('action' => att_sessions_page_params::ACTION_ADD));
$mform = new mod_attforblock_add_form($url, $formparams); $mform = new mod_attendance_add_form($url, $formparams);
if ($formdata = $mform->get_data()) { if ($formdata = $mform->get_data()) {
$sessions = construct_sessions_data_for_add($formdata); $sessions = construct_sessions_data_for_add($formdata);
$att->add_sessions($sessions); $att->add_sessions($sessions);
redirect($url, get_string('sessionsgenerated', 'attforblock')); redirect($url, get_string('sessionsgenerated', 'attendance'));
} }
break; break;
case att_sessions_page_params::ACTION_UPDATE: case att_sessions_page_params::ACTION_UPDATE:
@ -67,7 +67,7 @@ switch ($att->pageparams->action) {
$url = $att->url_sessions(array('action' => att_sessions_page_params::ACTION_UPDATE, 'sessionid' => $sessionid)); $url = $att->url_sessions(array('action' => att_sessions_page_params::ACTION_UPDATE, 'sessionid' => $sessionid));
$formparams['sessionid'] = $sessionid; $formparams['sessionid'] = $sessionid;
$mform = new mod_attforblock_update_form($url, $formparams); $mform = new mod_attendance_update_form($url, $formparams);
if ($mform->is_cancelled()) { if ($mform->is_cancelled()) {
redirect($att->url_manage()); redirect($att->url_manage());
@ -76,7 +76,7 @@ switch ($att->pageparams->action) {
if ($formdata = $mform->get_data()) { if ($formdata = $mform->get_data()) {
$att->update_session_from_form_data($formdata, $sessionid); $att->update_session_from_form_data($formdata, $sessionid);
redirect($att->url_manage(), get_string('sessionupdated', 'attforblock')); redirect($att->url_manage(), get_string('sessionupdated', 'attendance'));
} }
break; break;
case att_sessions_page_params::ACTION_DELETE: case att_sessions_page_params::ACTION_DELETE:
@ -86,21 +86,21 @@ switch ($att->pageparams->action) {
if (isset($confirm)) { if (isset($confirm)) {
$att->delete_sessions(array($sessionid)); $att->delete_sessions(array($sessionid));
att_update_all_users_grades($att->id, $att->course, $att->context); att_update_all_users_grades($att->id, $att->course, $att->context);
redirect($att->url_manage(), get_string('sessiondeleted', 'attforblock')); redirect($att->url_manage(), get_string('sessiondeleted', 'attendance'));
} }
$sessinfo = $att->get_session_info($sessionid); $sessinfo = $att->get_session_info($sessionid);
$message = get_string('deletecheckfull', '', get_string('session', 'attforblock')); $message = get_string('deletecheckfull', '', get_string('session', 'attendance'));
$message .= str_repeat(html_writer::empty_tag('br'), 2); $message .= str_repeat(html_writer::empty_tag('br'), 2);
$message .= userdate($sessinfo->sessdate, get_string('strftimedmyhm', 'attforblock')); $message .= userdate($sessinfo->sessdate, get_string('strftimedmyhm', 'attendance'));
$message .= html_writer::empty_tag('br'); $message .= html_writer::empty_tag('br');
$message .= $sessinfo->description; $message .= $sessinfo->description;
$params = array('action' => $att->pageparams->action, 'sessionid' => $sessionid, 'confirm' => 1); $params = array('action' => $att->pageparams->action, 'sessionid' => $sessionid, 'confirm' => 1);
echo $OUTPUT->header(); echo $OUTPUT->header();
echo $OUTPUT->heading(get_string('attendanceforthecourse', 'attforblock').' :: ' .$course->fullname); echo $OUTPUT->heading(get_string('attendanceforthecourse', 'attendance').' :: ' .$course->fullname);
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;
@ -113,22 +113,22 @@ switch ($att->pageparams->action) {
$att->delete_sessions($sessionsids); $att->delete_sessions($sessionsids);
att_update_all_users_grades($att->id, $att->course, $att->context); att_update_all_users_grades($att->id, $att->course, $att->context);
redirect($att->url_manage(), get_string('sessiondeleted', 'attforblock')); redirect($att->url_manage(), get_string('sessiondeleted', 'attendance'));
} }
$fromform = data_submitted(); $fromform = data_submitted();
// Nothing selected. // Nothing selected.
if (!isset($fromform->sessid)) { if (!isset($fromform->sessid)) {
print_error ('nosessionsselected', 'attforblock', $att->url_manage()); print_error ('nosessionsselected', 'attendance', $att->url_manage());
} }
$sessionsinfo = $att->get_sessions_info($fromform->sessid); $sessionsinfo = $att->get_sessions_info($fromform->sessid);
$message = get_string('deletecheckfull', '', get_string('session', 'attforblock')); $message = get_string('deletecheckfull', '', get_string('session', 'attendance'));
$message .= html_writer::empty_tag('br'); $message .= html_writer::empty_tag('br');
foreach ($sessionsinfo as $sessinfo) { foreach ($sessionsinfo as $sessinfo) {
$message .= html_writer::empty_tag('br'); $message .= html_writer::empty_tag('br');
$message .= userdate($sessinfo->sessdate, get_string('strftimedmyhm', 'attforblock')); $message .= userdate($sessinfo->sessdate, get_string('strftimedmyhm', 'attendance'));
$message .= html_writer::empty_tag('br'); $message .= html_writer::empty_tag('br');
$message .= $sessinfo->description; $message .= $sessinfo->description;
} }
@ -137,7 +137,7 @@ switch ($att->pageparams->action) {
$params = array('action' => $att->pageparams->action, 'sessionsids' => $sessionsids, 'confirm' => 1); $params = array('action' => $att->pageparams->action, 'sessionsids' => $sessionsids, 'confirm' => 1);
echo $OUTPUT->header(); echo $OUTPUT->header();
echo $OUTPUT->heading(get_string('attendanceforthecourse', 'attforblock').' :: ' .$course->fullname); echo $OUTPUT->heading(get_string('attendanceforthecourse', 'attendance').' :: ' .$course->fullname);
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;
@ -147,7 +147,7 @@ switch ($att->pageparams->action) {
$url = $att->url_sessions(array('action' => att_sessions_page_params::ACTION_CHANGE_DURATION)); $url = $att->url_sessions(array('action' => att_sessions_page_params::ACTION_CHANGE_DURATION));
$formparams['ids'] = $slist; $formparams['ids'] = $slist;
$mform = new mod_attforblock_duration_form($url, $formparams); $mform = new mod_attendance_duration_form($url, $formparams);
if ($mform->is_cancelled()) { if ($mform->is_cancelled()) {
redirect($att->url_manage()); redirect($att->url_manage());
@ -157,20 +157,20 @@ switch ($att->pageparams->action) {
$sessionsids = explode('_', $fromform->ids); $sessionsids = explode('_', $fromform->ids);
$duration = $formdata->durtime['hours']*HOURSECS + $formdata->durtime['minutes']*MINSECS; $duration = $formdata->durtime['hours']*HOURSECS + $formdata->durtime['minutes']*MINSECS;
$att->update_sessions_duration($sessionsids, $duration); $att->update_sessions_duration($sessionsids, $duration);
redirect($att->url_manage(), get_string('sessionupdated', 'attforblock')); redirect($att->url_manage(), get_string('sessionupdated', 'attendance'));
} }
if ($slist === '') { if ($slist === '') {
print_error('nosessionsselected', 'attforblock', $att->url_manage()); print_error('nosessionsselected', 'attendance', $att->url_manage());
} }
break; break;
} }
$output = $PAGE->get_renderer('mod_attforblock'); $output = $PAGE->get_renderer('mod_attendance');
$tabs = new attforblock_tabs($att, attforblock_tabs::TAB_ADD); $tabs = new attendance_tabs($att, attendance_tabs::TAB_ADD);
echo $output->header(); echo $output->header();
echo $output->heading(get_string('attendanceforthecourse', 'attforblock').' :: ' .$course->fullname); echo $output->heading(get_string('attendanceforthecourse', 'attendance').' :: ' .$course->fullname);
echo $output->render($tabs); echo $output->render($tabs);
$mform->display(); $mform->display();
@ -243,7 +243,7 @@ function construct_sessions_data_for_add($formdata) {
} }
function fill_groupid($formdata, &$sessions, $sess) { function fill_groupid($formdata, &$sessions, $sess) {
if ($formdata->sessiontype == attforblock::SESSION_COMMON) { if ($formdata->sessiontype == attendance::SESSION_COMMON) {
$sess = clone $sess; $sess = clone $sess;
$sess->groupid = 0; $sess->groupid = 0;
$sessions[] = $sess; $sessions[] = $sess;

62
styles.css

@ -1,4 +1,4 @@
.path-mod-attforblock .attbtn { .path-mod-attendance .attbtn {
border:1px solid #AAAAAA; border:1px solid #AAAAAA;
margin-left: 2px; margin-left: 2px;
margin-right: 2px; margin-right: 2px;
@ -10,116 +10,116 @@
-khtml-border-radius: 5px; -khtml-border-radius: 5px;
} }
.path-mod-attforblock .attcurbtn { .path-mod-attendance .attcurbtn {
margin-left: 2px; margin-left: 2px;
margin-right: 2px; margin-right: 2px;
padding: 5px; padding: 5px;
} }
.path-mod-attforblock .attfiltercontrols { .path-mod-attendance .attfiltercontrols {
margin-bottom: 10px; margin-bottom: 10px;
margin-right:auto; margin-right:auto;
margin-left:auto; margin-left:auto;
} }
.path-mod-attforblock .attfiltercontrols #currentdate{ .path-mod-attendance .attfiltercontrols #currentdate{
display: inline; display: inline;
} }
.path-mod-attforblock .attwidth { .path-mod-attendance .attwidth {
width:90%; width:90%;
margin: auto; margin: auto;
} }
.path-mod-attforblock .userwithoutenrol, .path-mod-attendance .userwithoutenrol,
.path-mod-attforblock .userwithoutenrol a{ .path-mod-attendance .userwithoutenrol a{
color: gray; color: gray;
} }
.path-mod-attforblock .userwithoutdata, .path-mod-attendance .userwithoutdata,
.path-mod-attforblock .userwithoutdata a{ .path-mod-attendance .userwithoutdata a{
color: red; color: red;
} }
.path-mod-attforblock .takelist td { .path-mod-attendance .takelist td {
vertical-align: middle; vertical-align: middle;
} }
.path-mod-attforblock .takelist .userpicture { .path-mod-attendance .takelist .userpicture {
margin:0 3px; margin:0 3px;
vertical-align:middle; vertical-align:middle;
} }
.path-mod-attforblock .takegrid input { .path-mod-attendance .takegrid input {
margin: 0px 3px 0px 6px; margin: 0px 3px 0px 6px;
} }
.path-mod-attforblock .takegrid .fullname { .path-mod-attendance .takegrid .fullname {
font-size: 0.8em; font-size: 0.8em;
} }
.path-mod-attforblock table.controls { .path-mod-attendance table.controls {
width: 100%; width: 100%;
text-align: center; text-align: center;
} }
.path-mod-attforblock table.controls tr { .path-mod-attendance table.controls tr {
vertical-align: top; vertical-align: top;
} }
.path-mod-attforblock table.controls td.right, .path-mod-attendance table.controls td.right,
.path-mod-attforblock table.controls td.left { .path-mod-attendance table.controls td.left {
padding-bottom: 4px; padding-bottom: 4px;
padding-left: 4px; padding-left: 4px;
padding-right: 4px; padding-right: 4px;
padding-top: 4px; padding-top: 4px;
} }
.path-mod-attforblock table.controls .right { .path-mod-attendance table.controls .right {
text-align: right; text-align: right;
} }
/* for IE7*/ /* for IE7*/
.path-mod-attforblock .filtercontrols td { .path-mod-attendance .filtercontrols td {
padding:6px; padding:6px;
} }
.path-mod-attforblock .takecontrols { .path-mod-attendance .takecontrols {
width: 800px; width: 800px;
margin: 0px auto 20px auto; margin: 0px auto 20px auto;
} }
.path-mod-attforblock .takecontrols table{ .path-mod-attendance .takecontrols table{
margin: 0px auto; margin: 0px auto;
} }
.path-mod-attforblock .takecontrols .c0 { .path-mod-attendance .takecontrols .c0 {
width: 500px; width: 500px;
text-align: left; text-align: left;
} }
.path-mod-attforblock .takecontrols .c1 { .path-mod-attendance .takecontrols .c1 {
text-align: right; text-align: right;
} }
.path-mod-attforblock .inline, .path-mod-attendance .inline,
.path-mod-attforblock .inline form, .path-mod-attendance .inline form,
.path-mod-attforblock .inline div { .path-mod-attendance .inline div {
display: inline; display: inline;
} }
.path-mod-attforblock table.userinfobox { .path-mod-attendance table.userinfobox {
border: 1px solid #EEEEEE; border: 1px solid #EEEEEE;
padding: 0px; padding: 0px;
} }
.path-mod-attforblock table.userinfobox td.left { .path-mod-attendance table.userinfobox td.left {
background-color: #EEEEEE; background-color: #EEEEEE;
padding: 30px 10px; padding: 30px 10px;
} }
.path-mod-attforblock table.attlist td.c0 { .path-mod-attendance table.attlist td.c0 {
text-align: right; text-align: right;
} }
#page-mod-attforblock-preferences .generalbox { #page-mod-attendance-preferences .generalbox {
text-align: center; text-align: center;
} }
.path-mod-attforblock .attsessions_manage_table .action-icon img.smallicon { .path-mod-attendance .attsessions_manage_table .action-icon img.smallicon {
margin-left: 5px; margin-left: 5px;
} }

20
take.php

@ -17,7 +17,7 @@
/** /**
* Take Attendance * Take Attendance
* *
* @package mod_attforblock * @package mod_attendance
* @copyright 2011 Artem Andreev <andreev.artem@gmail.com> * @copyright 2011 Artem Andreev <andreev.artem@gmail.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/ */
@ -35,20 +35,20 @@ $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);
$cm = get_coursemodule_from_id('attforblock', $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);
$att = $DB->get_record('attforblock', array('id' => $cm->instance), '*', MUST_EXIST); $att = $DB->get_record('attendance', array('id' => $cm->instance), '*', MUST_EXIST);
require_login($course, true, $cm); require_login($course, true, $cm);
$pageparams->group = groups_get_activity_group($cm, true); $pageparams->group = groups_get_activity_group($cm, true);
$pageparams->init($course->id); $pageparams->init($course->id);
$att = new attforblock($att, $cm, $course, $PAGE->context, $pageparams); $att = new attendance($att, $cm, $course, $PAGE->context, $pageparams);
if (!$att->perm->can_take_session($pageparams->grouptype)) { if (!$att->perm->can_take_session($pageparams->grouptype)) {
$group = groups_get_group($pageparams->grouptype); $group = groups_get_group($pageparams->grouptype);
throw new moodle_exception('cannottakeforgroup', 'attforblock', '', $group->name); throw new moodle_exception('cannottakeforgroup', 'attendance', '', $group->name);
} }
if ($formdata = data_submitted()) { if ($formdata = data_submitted()) {
@ -59,17 +59,17 @@ $PAGE->set_url($att->url_take());
$PAGE->set_title($course->shortname. ": ".$att->name); $PAGE->set_title($course->shortname. ": ".$att->name);
$PAGE->set_heading($course->fullname); $PAGE->set_heading($course->fullname);
$PAGE->set_cacheable(true); $PAGE->set_cacheable(true);
$PAGE->set_button($OUTPUT->update_module_button($cm->id, 'attforblock')); $PAGE->set_button($OUTPUT->update_module_button($cm->id, 'attendance'));
$PAGE->navbar->add($att->name); $PAGE->navbar->add($att->name);
$output = $PAGE->get_renderer('mod_attforblock'); $output = $PAGE->get_renderer('mod_attendance');
$tabs = new attforblock_tabs($att); $tabs = new attendance_tabs($att);
$sesstable = new attforblock_take_data($att); $sesstable = new attendance_take_data($att);
// Output starts here. // Output starts here.
echo $output->header(); echo $output->header();
echo $output->heading(get_string('attendanceforthecourse', 'attforblock').' :: ' .$course->fullname); echo $output->heading(get_string('attendanceforthecourse', 'attendance').' :: ' .$course->fullname);
echo $output->render($tabs); echo $output->render($tabs);
echo $output->render($sesstable); echo $output->render($sesstable);

20
update_form.php

@ -17,7 +17,7 @@
/** /**
* Update form * Update form
* *
* @package mod_attforblock * @package mod_attendance
* @copyright 2011 Artem Andreev <andreev.artem@gmail.com> * @copyright 2011 Artem Andreev <andreev.artem@gmail.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/ */
@ -25,7 +25,7 @@
require_once($CFG->libdir.'/formslib.php'); require_once($CFG->libdir.'/formslib.php');
class mod_attforblock_update_form extends moodleform { class mod_attendance_update_form extends moodleform {
public function definition() { public function definition() {
global $CFG, $DB; global $CFG, $DB;
@ -42,16 +42,16 @@ class mod_attforblock_update_form extends moodleform {
$dhours = floor($sess->duration / HOURSECS); $dhours = floor($sess->duration / HOURSECS);
$dmins = floor(($sess->duration - $dhours * HOURSECS) / MINSECS); $dmins = floor(($sess->duration - $dhours * HOURSECS) / MINSECS);
$defopts = array('maxfiles'=>EDITOR_UNLIMITED_FILES, 'noclean'=>true, 'context'=>$modcontext); $defopts = array('maxfiles'=>EDITOR_UNLIMITED_FILES, 'noclean'=>true, 'context'=>$modcontext);
$sess = file_prepare_standard_editor($sess, 'description', $defopts, $modcontext, 'mod_attforblock', 'session', $sess->id); $sess = file_prepare_standard_editor($sess, 'description', $defopts, $modcontext, 'mod_attendance', 'session', $sess->id);
$data = array('sessiondate' => $sess->sessdate, $data = array('sessiondate' => $sess->sessdate,
'durtime' => array('hours' => $dhours, 'minutes' => $dmins), 'durtime' => array('hours' => $dhours, 'minutes' => $dmins),
'sdescription' => $sess->description_editor); 'sdescription' => $sess->description_editor);
$mform->addElement('header', 'general', get_string('changesession', 'attforblock')); $mform->addElement('header', 'general', get_string('changesession', 'attendance'));
$mform->addElement('static', 'olddate', get_string('olddate', 'attforblock'), $mform->addElement('static', 'olddate', get_string('olddate', 'attendance'),
userdate($sess->sessdate, get_string('strftimedmyhm', 'attforblock'))); userdate($sess->sessdate, get_string('strftimedmyhm', 'attendance')));
$mform->addElement('date_time_selector', 'sessiondate', get_string('newdate', 'attforblock')); $mform->addElement('date_time_selector', 'sessiondate', get_string('newdate', 'attendance'));
for ($i=0; $i<=23; $i++) { for ($i=0; $i<=23; $i++) {
$hours[$i] = sprintf("%02d", $i); $hours[$i] = sprintf("%02d", $i);
@ -61,14 +61,14 @@ class mod_attforblock_update_form extends moodleform {
} }
$durselect[] =& $mform->createElement('select', 'hours', '', $hours); $durselect[] =& $mform->createElement('select', 'hours', '', $hours);
$durselect[] =& $mform->createElement('select', 'minutes', '', $minutes, false, true); $durselect[] =& $mform->createElement('select', 'minutes', '', $minutes, false, true);
$mform->addGroup($durselect, 'durtime', get_string('duration', 'attforblock'), array(' '), true); $mform->addGroup($durselect, 'durtime', get_string('duration', 'attendance'), array(' '), true);
$mform->addElement('editor', 'sdescription', get_string('description', 'attforblock'), null, $defopts); $mform->addElement('editor', 'sdescription', get_string('description', 'attendance'), null, $defopts);
$mform->setType('sdescription', PARAM_RAW); $mform->setType('sdescription', PARAM_RAW);
$mform->setDefaults($data); $mform->setDefaults($data);
$submit_string = get_string('update', 'attforblock'); $submit_string = get_string('update', 'attendance');
$this->add_action_buttons(true, $submit_string); $this->add_action_buttons(true, $submit_string);
} }
} }

12
version.php

@ -17,7 +17,7 @@
/** /**
* Version information * Version information
* *
* @package mod_attforblock * @package mod_attendance
* @copyright 2011 Artem Andreev <andreev.artem@gmail.com> * @copyright 2011 Artem Andreev <andreev.artem@gmail.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/ */
@ -27,4 +27,12 @@ $module->requires = 2012120300;
$module->release = '2.4.1'; $module->release = '2.4.1';
$module->maturity = MATURITY_ALPHA; $module->maturity = MATURITY_ALPHA;
$module->cron = 0; $module->cron = 0;
$module->component = 'mod_attforblock'; $module->component = 'mod_attendance';
// Nasty upgrade code to check if need to upgrade from attforblock.
// TODO: remove this asap.
global $DB;
if ($DB->record_exists('modules', array('name' =>'attforblock'))) {
require_once('locallib.php');
attforblock_upgrade();
}

14
view.php

@ -17,7 +17,7 @@
/** /**
* Prints attendance info for particular user * Prints attendance info for particular user
* *
* @package mod_attforblock * @package mod_attendance
* @copyright 2011 Artem Andreev <andreev.artem@gmail.com> * @copyright 2011 Artem Andreev <andreev.artem@gmail.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/ */
@ -34,14 +34,14 @@ $pageparams->mode = optional_param('mode', att_view_page_params::MODE_THIS
$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);
$cm = get_coursemodule_from_id('attforblock', $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);
$attforblock = $DB->get_record('attforblock', array('id' => $cm->instance), '*', MUST_EXIST); $attendance = $DB->get_record('attendance', array('id' => $cm->instance), '*', MUST_EXIST);
require_login($course, true, $cm); require_login($course, true, $cm);
$pageparams->init($cm); $pageparams->init($cm);
$att = new attforblock($attforblock, $cm, $course, $PAGE->context, $pageparams); $att = new attendance($attendance, $cm, $course, $PAGE->context, $pageparams);
// Not specified studentid for displaying attendance? // Not specified studentid for displaying attendance?
// Redirect to appropriate page if can. // Redirect to appropriate page if can.
@ -59,12 +59,12 @@ $PAGE->set_url($att->url_view());
$PAGE->set_title($course->shortname. ": ".$att->name); $PAGE->set_title($course->shortname. ": ".$att->name);
$PAGE->set_heading($course->fullname); $PAGE->set_heading($course->fullname);
$PAGE->set_cacheable(true); $PAGE->set_cacheable(true);
$PAGE->navbar->add(get_string('attendancereport', 'attforblock')); $PAGE->navbar->add(get_string('attendancereport', 'attendance'));
$output = $PAGE->get_renderer('mod_attforblock'); $output = $PAGE->get_renderer('mod_attendance');
$userid = isset($pageparams->studentid) ? $pageparams->studentid : $USER->id; $userid = isset($pageparams->studentid) ? $pageparams->studentid : $USER->id;
$userdata = new attforblock_user_data($att, $userid); $userdata = new attendance_user_data($att, $userid);
echo $output->header(); echo $output->header();

Loading…
Cancel
Save