Browse Source

coding guideline stuff

MOODLE_23_STABLE
Dan Marsden 12 years ago
parent
commit
fa31be8eb4
  1. 73
      add_form.php
  2. 7
      backup/moodle2/backup_attforblock_activity_task.class.php
  3. 2
      backup/moodle2/backup_attforblock_settingslib.php
  4. 37
      backup/moodle2/backup_attforblock_stepslib.php
  5. 45
      backup/moodle2/restore_attforblock_activity_task.class.php
  6. 24
      backup/moodle2/restore_attforblock_stepslib.php
  7. 1
      calendar.js
  8. 17
      db/access.php
  9. 65
      db/upgrade.php
  10. 19
      duration_form.php
  11. 26
      export.php
  12. 32
      export_form.php
  13. 6
      lang/en/attforblock.php
  14. 128
      lib.php
  15. 219
      locallib.php
  16. 22
      manage.php
  17. 11
      mod_form.php
  18. 9
      module.js
  19. 24
      preferences.php
  20. 71
      renderables.php
  21. 188
      renderer.php
  22. 47
      renderhelpers.php
  23. 14
      report.php
  24. 49
      sessions.php
  25. 4
      take.php
  26. 28
      update_form.php
  27. 6
      version.php
  28. 11
      view.php

73
add_form.php

@ -35,7 +35,7 @@ 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', 'attforblock'));
$groupmode = groups_get_activity_groupmode($cm); $groupmode = groups_get_activity_groupmode($cm);
switch ($groupmode) { switch ($groupmode) {
@ -53,18 +53,21 @@ class mod_attforblock_add_form extends moodleform {
break; break;
case VISIBLEGROUPS: case VISIBLEGROUPS:
$radio=array(); $radio=array();
$radio[] = &$mform->createElement('radio', 'sessiontype', '', get_string('commonsession','attforblock'), attforblock::SESSION_COMMON); $radio[] = &$mform->createElement('radio', 'sessiontype', '',
$radio[] = &$mform->createElement('radio', 'sessiontype', '', get_string('groupsession','attforblock'), attforblock::SESSION_GROUP); get_string('commonsession', 'attforblock'), attforblock::SESSION_COMMON);
$mform->addGroup($radio, 'sessiontype', get_string('sessiontype','attforblock'), ' ', false); $radio[] = &$mform->createElement('radio', 'sessiontype', '',
get_string('groupsession', 'attforblock'), attforblock::SESSION_GROUP);
$mform->addGroup($radio, 'sessiontype', get_string('sessiontype', 'attforblock'), ' ', false);
$mform->addHelpButton('sessiontype', 'sessiontype', 'attforblock'); $mform->addHelpButton('sessiontype', 'sessiontype', 'attforblock');
$mform->setDefault('sessiontype', attforblock::SESSION_COMMON); $mform->setDefault('sessiontype', attforblock::SESSION_COMMON);
break; break;
} }
if ($groupmode == SEPARATEGROUPS or $groupmode == VISIBLEGROUPS) { if ($groupmode == SEPARATEGROUPS or $groupmode == VISIBLEGROUPS) {
if ($groupmode == SEPARATEGROUPS and !has_capability('moodle/site:accessallgroups', $modcontext)) if ($groupmode == SEPARATEGROUPS and !has_capability('moodle/site:accessallgroups', $modcontext)) {
$groups = groups_get_all_groups ($course->id, $USER->id); $groups = groups_get_all_groups ($course->id, $USER->id);
else } else {
$groups = groups_get_all_groups($course->id); $groups = groups_get_all_groups($course->id);
}
if ($groups) { if ($groups) {
$selectgroups = array(); $selectgroups = array();
foreach ($groups as $group) { foreach ($groups as $group) {
@ -72,74 +75,72 @@ 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', attforblock::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', 'attforblock'));
if ($groupmode == SEPARATEGROUPS) if ($groupmode == SEPARATEGROUPS) {
return; return;
} }
} }
}
$mform->addElement('checkbox', 'addmultiply', '', get_string('createmultiplesessions','attforblock')); $mform->addElement('checkbox', 'addmultiply', '', get_string('createmultiplesessions', 'attforblock'));
$mform->addHelpButton('addmultiply', 'createmultiplesessions', 'attforblock'); $mform->addHelpButton('addmultiply', 'createmultiplesessions', 'attforblock');
// $mform->addElement('date_selector', 'sessiondate', get_string('sessiondate','attforblock')); $mform->addElement('date_time_selector', 'sessiondate', get_string('sessiondate', 'attforblock'));
$mform->addElement('date_time_selector', 'sessiondate', get_string('sessiondate','attforblock'));
for ($i=0; $i<=23; $i++) { for ($i=0; $i<=23; $i++) {
$hours[$i] = sprintf("%02d",$i); $hours[$i] = sprintf("%02d", $i);
} }
for ($i=0; $i<60; $i+=5) { for ($i=0; $i<60; $i+=5) {
$minutes[$i] = sprintf("%02d",$i); $minutes[$i] = sprintf("%02d", $i);
} }
$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', 'attforblock'), array(' '), true);
$mform->addElement('date_selector', 'sessionenddate', get_string('sessionenddate','attforblock')); $mform->addElement('date_selector', 'sessionenddate', get_string('sessionenddate', 'attforblock'));
$mform->disabledIf('sessionenddate', 'addmultiply', 'notchecked'); $mform->disabledIf('sessionenddate', 'addmultiply', 'notchecked');
$sdays = array(); $sdays = array();
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'));
} }
$sdays[] =& $mform->createElement('checkbox', 'Mon', '', get_string('monday','calendar')); $sdays[] =& $mform->createElement('checkbox', 'Mon', '', get_string('monday', 'calendar'));
$sdays[] =& $mform->createElement('checkbox', 'Tue', '', get_string('tuesday','calendar')); $sdays[] =& $mform->createElement('checkbox', 'Tue', '', get_string('tuesday', 'calendar'));
$sdays[] =& $mform->createElement('checkbox', 'Wed', '', get_string('wednesday','calendar')); $sdays[] =& $mform->createElement('checkbox', 'Wed', '', get_string('wednesday', 'calendar'));
$sdays[] =& $mform->createElement('checkbox', 'Thu', '', get_string('thursday','calendar')); $sdays[] =& $mform->createElement('checkbox', 'Thu', '', get_string('thursday', 'calendar'));
$sdays[] =& $mform->createElement('checkbox', 'Fri', '', get_string('friday','calendar')); $sdays[] =& $mform->createElement('checkbox', 'Fri', '', get_string('friday', 'calendar'));
$sdays[] =& $mform->createElement('checkbox', 'Sat', '', get_string('saturday','calendar')); $sdays[] =& $mform->createElement('checkbox', 'Sat', '', get_string('saturday', 'calendar'));
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', 'attforblock'), 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', 'attforblock'));
$mform->addGroup($periodgroup, 'periodgroup', get_string('period','attforblock'), array(' '), false); $mform->addGroup($periodgroup, 'periodgroup', get_string('period', 'attforblock'), array(' '), false);
$mform->disabledIf('periodgroup', 'addmultiply', 'notchecked'); $mform->disabledIf('periodgroup', 'addmultiply', 'notchecked');
$mform->addElement('editor', 'sdescription', get_string('description', 'attforblock'), null, array('maxfiles'=>EDITOR_UNLIMITED_FILES, 'noclean'=>true, 'context'=>$modcontext)); $mform->addElement('editor', 'sdescription', get_string('description', 'attforblock'),
null, array('maxfiles'=>EDITOR_UNLIMITED_FILES, 'noclean'=>true, 'context'=>$modcontext));
$mform->setType('sdescription', PARAM_RAW); $mform->setType('sdescription', PARAM_RAW);
//-------------------------------------------------------------------------------
// buttons
$submit_string = get_string('addsession', 'attforblock'); $submit_string = get_string('addsession', 'attforblock');
$this->add_action_buttons(false, $submit_string); $this->add_action_buttons(false, $submit_string);
} }
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'] == attforblock::SESSION_GROUP and empty($data['groups'])) {
$errors['groups'] = get_string('errorgroupsnotselected','attforblock'); $errors['groups'] = get_string('errorgroupsnotselected', 'attforblock');
} }
return $errors; return $errors;
} }

7
backup/moodle2/backup_attforblock_activity_task.class.php

@ -37,7 +37,6 @@ class backup_attforblock_activity_task extends backup_activity_task {
* Define (add) particular settings this activity can have * Define (add) particular settings this activity can have
*/ */
protected function define_my_settings() { protected function define_my_settings() {
// No particular settings for this activity
} }
/** /**
@ -54,13 +53,13 @@ class backup_attforblock_activity_task extends backup_activity_task {
static public function encode_content_links($content) { static public function encode_content_links($content) {
global $CFG; global $CFG;
$base = preg_quote($CFG->wwwroot,"/"); $base = preg_quote($CFG->wwwroot, "/");
//Link to attforblock view by moduleid // Link to attforblock view by moduleid.
$search = "/(" . $base . "\/mod\/attforblock\/view.php\?id\=)([0-9]+)/"; $search = "/(" . $base . "\/mod\/attforblock\/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 attforblock view by moduleid and studentid.
$search = "/(" . $base . "\/mod\/attforblock\/view.php\?id\=)([0-9]+)\&studentid\=([0-9]+)/"; $search = "/(" . $base . "\/mod\/attforblock\/view.php\?id\=)([0-9]+)\&studentid\=([0-9]+)/";
$content= preg_replace($search, '$@ATTFORBLOCKVIEWBYIDSTUD*$2*$3@$', $content); $content= preg_replace($search, '$@ATTFORBLOCKVIEWBYIDSTUD*$2*$3@$', $content);

2
backup/moodle2/backup_attforblock_settingslib.php

@ -23,4 +23,4 @@
// This activity has not particular settings but the inherited from the generic // This activity has not particular settings but the inherited from the generic
// backup_activity_task so here there isn't any class definition, like the ones // backup_activity_task so here there isn't any class definition, like the ones
// existing in /backup/moodle2/backup_settingslib.php (activities section) // existing in /backup/moodle2/backup_settingslib.php (activities section).

37
backup/moodle2/backup_attforblock_stepslib.php

@ -32,13 +32,10 @@ class backup_attforblock_activity_structure_step extends backup_activity_structu
protected function define_structure() { protected function define_structure() {
// are we including userinfo? // Are we including userinfo?
$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( $attforblock = new backup_nested_element('attforblock', array('id'), array(
'name', 'grade')); 'name', 'grade'));
@ -51,18 +48,13 @@ class backup_attforblock_activity_structure_step extends backup_activity_structu
'groupid', 'sessdate', 'duration', 'lasttaken', 'lasttakenby', 'groupid', 'sessdate', 'duration', 'lasttaken', 'lasttakenby',
'timemodified', 'description', 'descriptionformat')); 'timemodified', 'description', 'descriptionformat'));
//////////////////////////////////////////////////////////////////////// // XML nodes declaration - user data.
// XML nodes declaration - user data
////////////////////////////////////////////////////////////////////////
$logs = new backup_nested_element('logs'); $logs = new backup_nested_element('logs');
$log = new backup_nested_element('log', array('id'), array( $log = new backup_nested_element('log', array('id'), array(
'sessionid', 'studentid', 'statusid', 'lasttaken', 'statusset', 'sessionid', 'studentid', 'statusid', 'lasttaken', 'statusset',
'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); $attforblock->add_child($statuses);
$statuses->add_child($status); $statuses->add_child($status);
@ -72,9 +64,7 @@ class backup_attforblock_activity_structure_step extends backup_activity_structu
$session->add_child($logs); $session->add_child($logs);
$logs->add_child($log); $logs->add_child($log);
//////////////////////////////////////////////////////////////////////// // Data sources - non-user data.
// data sources - non-user data
////////////////////////////////////////////////////////////////////////
$attforblock->set_source_table('attforblock', array('id' => backup::VAR_ACTIVITYID)); $attforblock->set_source_table('attforblock', array('id' => backup::VAR_ACTIVITYID));
@ -82,30 +72,21 @@ class backup_attforblock_activity_structure_step extends backup_activity_structu
$session->set_source_table('attendance_sessions', array('attendanceid' => backup::VAR_PARENTID)); $session->set_source_table('attendance_sessions', array('attendanceid' => backup::VAR_PARENTID));
//////////////////////////////////////////////////////////////////////// // Data sources - user related data.
// data sources - user related data
////////////////////////////////////////////////////////////////////////
if ($userinfo) { if ($userinfo) {
$log->set_source_table('attendance_log', array('sessionid' => backup::VAR_PARENTID)); $log->set_source_table('attendance_log', array('sessionid' => backup::VAR_PARENTID));
} }
//////////////////////////////////////////////////////////////////////// // Id annotations.
// id annotations
////////////////////////////////////////////////////////////////////////
$session->annotate_ids('user', 'lasttakenby'); $session->annotate_ids('user', 'lasttakenby');
$session->annotate_ids('group', 'groupid'); $session->annotate_ids('group', 'groupid');
$log->annotate_ids('user', 'studentid'); $log->annotate_ids('user', 'studentid');
$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_attforblock', '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($attforblock);
} }
} }

45
backup/moodle2/restore_attforblock_activity_task.class.php

@ -35,14 +35,12 @@ class restore_attforblock_activity_task extends restore_activity_task {
* Define (add) particular settings this activity can have * Define (add) particular settings this activity can have
*/ */
protected function define_my_settings() { protected function define_my_settings() {
// No particular settings for this activity
} }
/** /**
* 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() {
// Choice only has one structure step
$this->add_step(new restore_attforblock_activity_structure_step('attforblock_structure', 'attforblock.xml')); $this->add_step(new restore_attforblock_activity_structure_step('attforblock_structure', 'attforblock.xml'));
} }
@ -84,48 +82,7 @@ class restore_attforblock_activity_task extends restore_activity_task {
static public function define_restore_log_rules() { static public function define_restore_log_rules() {
$rules = array(); $rules = array();
// TODO: log restore // TODO: log restore.
/*
$rules[] = new restore_log_rule('attforblock', 'add', 'view.php?id={course_module}', '{attforblock}');
$rules[] = new restore_log_rule('attforblock', 'update', 'view.php?id={course_module}', '{attforblock}');
$rules[] = new restore_log_rule('attforblock', 'view', 'view.php?id={course_module}', '{attforblock}');
$rules[] = new restore_log_rule('attforblock', 'add assessment',
'assessment.php?asid={attforblock_assessment}', '{attforblock_submission}');
$rules[] = new restore_log_rule('attforblock', 'update assessment',
'assessment.php?asid={attforblock_assessment}', '{attforblock_submission}');
$rules[] = new restore_log_rule('attforblock', 'add reference assessment',
'exassessment.php?asid={attforblock_referenceassessment}', '{attforblock_examplesubmission}');
$rules[] = new restore_log_rule('attforblock', 'update reference assessment',
'exassessment.php?asid={attforblock_referenceassessment}', '{attforblock_examplesubmission}');
$rules[] = new restore_log_rule('attforblock', 'add example assessment',
'exassessment.php?asid={attforblock_exampleassessment}', '{attforblock_examplesubmission}');
$rules[] = new restore_log_rule('attforblock', 'update example assessment',
'exassessment.php?asid={attforblock_exampleassessment}', '{attforblock_examplesubmission}');
$rules[] = new restore_log_rule('attforblock', 'view submission',
'submission.php?cmid={course_module}&id={attforblock_submission}', '{attforblock_submission}');
$rules[] = new restore_log_rule('attforblock', 'add submission',
'submission.php?cmid={course_module}&id={attforblock_submission}', '{attforblock_submission}');
$rules[] = new restore_log_rule('attforblock', 'update submission',
'submission.php?cmid={course_module}&id={attforblock_submission}', '{attforblock_submission}');
$rules[] = new restore_log_rule('attforblock', 'view example',
'exsubmission.php?cmid={course_module}&id={attforblock_examplesubmission}', '{attforblock_examplesubmission}');
$rules[] = new restore_log_rule('attforblock', 'add example',
'exsubmission.php?cmid={course_module}&id={attforblock_examplesubmission}', '{attforblock_examplesubmission}');
$rules[] = new restore_log_rule('attforblock', 'update example',
'exsubmission.php?cmid={course_module}&id={attforblock_examplesubmission}', '{attforblock_examplesubmission}');
$rules[] = new restore_log_rule('attforblock', 'update aggregate grades', 'view.php?id={course_module}', '{attforblock}');
$rules[] = new restore_log_rule('attforblock', 'update switch phase', 'view.php?id={course_module}', '[phase]');
$rules[] = new restore_log_rule('attforblock', 'update clear aggregated grades', 'view.php?id={course_module}', '{attforblock}');
$rules[] = new restore_log_rule('attforblock', 'update clear assessments', 'view.php?id={course_module}', '{attforblock}');
*
*/
return $rules; return $rules;
} }

24
backup/moodle2/restore_attforblock_stepslib.php

@ -36,12 +36,9 @@ class restore_attforblock_activity_structure_step extends restore_activity_struc
$paths = array(); $paths = array();
$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('attforblock', '/activity/attforblock');
$paths[] = new restore_path_element('attforblock_status', $paths[] = new restore_path_element('attforblock_status',
@ -50,19 +47,16 @@ class restore_attforblock_activity_structure_step extends restore_activity_struc
$paths[] = new restore_path_element('attforblock_session', $paths[] = new restore_path_element('attforblock_session',
'/activity/attforblock/sessions/session'); '/activity/attforblock/sessions/session');
// End here if no-user data has been selected // End here if no-user data has been selected.
if (!$userinfo) { if (!$userinfo) {
return $this->prepare_activity_structure($paths); return $this->prepare_activity_structure($paths);
} }
//////////////////////////////////////////////////////////////////////// // XML interesting paths - user data.
// XML interesting paths - user data
////////////////////////////////////////////////////////////////////////
$paths[] = new restore_path_element('attforblock_log', $paths[] = new restore_path_element('attforblock_log',
'/activity/attforblock/sessions/session/logs/log'); '/activity/attforblock/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);
} }
@ -73,9 +67,9 @@ class restore_attforblock_activity_structure_step extends restore_activity_struc
$oldid = $data->id; $oldid = $data->id;
$data->course = $this->get_courseid(); $data->course = $this->get_courseid();
// insert the attforblock record // Insert the attforblock record.
$newitemid = $DB->insert_record('attforblock', $data); $newitemid = $DB->insert_record('attforblock', $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);
} }
@ -118,7 +112,9 @@ class restore_attforblock_activity_structure_step extends restore_activity_struc
$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('attforblock_status', $data->statusid);
$statusset = explode(',', $data->statusset); $statusset = explode(',', $data->statusset);
foreach ($statusset as $st) $st = $this->get_mappingid('attforblock_status', $st); foreach ($statusset as $st) {
$st = $this->get_mappingid('attforblock_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);
$data->takenby = $this->get_mappingid('user', $data->takenby); $data->takenby = $this->get_mappingid('user', $data->takenby);

1
calendar.js

@ -98,4 +98,3 @@ YUI().use('yui2-container', 'yui2-calendar', function(Y) {
}); });
}); });
}); });

17
db/access.php

@ -47,9 +47,7 @@
$capabilities = array( $capabilities = array(
'mod/attforblock:view' => array( 'mod/attforblock:view' => array(
'captype' => 'read', 'captype' => 'read',
'contextlevel' => CONTEXT_MODULE, 'contextlevel' => CONTEXT_MODULE,
'archetypes' => array( 'archetypes' => array(
@ -62,7 +60,6 @@ $capabilities = array(
'mod/attforblock:addinstance' => array( 'mod/attforblock:addinstance' => array(
'riskbitmask' => RISK_XSS, 'riskbitmask' => RISK_XSS,
'captype' => 'write', 'captype' => 'write',
'contextlevel' => CONTEXT_COURSE, 'contextlevel' => CONTEXT_COURSE,
'archetypes' => array( 'archetypes' => array(
@ -73,9 +70,7 @@ $capabilities = array(
), ),
'mod/attforblock:viewreports' => array( 'mod/attforblock:viewreports' => array(
'riskbitmask' => RISK_PERSONAL, 'riskbitmask' => RISK_PERSONAL,
'captype' => 'read', 'captype' => 'read',
'contextlevel' => CONTEXT_MODULE, 'contextlevel' => CONTEXT_MODULE,
'archetypes' => array( 'archetypes' => array(
@ -86,9 +81,7 @@ $capabilities = array(
), ),
'mod/attforblock:takeattendances' => array( 'mod/attforblock:takeattendances' => array(
'riskbitmask' => RISK_DATALOSS, 'riskbitmask' => RISK_DATALOSS,
'captype' => 'write', 'captype' => 'write',
'contextlevel' => CONTEXT_MODULE, 'contextlevel' => CONTEXT_MODULE,
'archetypes' => array( 'archetypes' => array(
@ -99,9 +92,7 @@ $capabilities = array(
), ),
'mod/attforblock:changeattendances' => array( 'mod/attforblock:changeattendances' => array(
'riskbitmask' => RISK_DATALOSS, 'riskbitmask' => RISK_DATALOSS,
'captype' => 'write', 'captype' => 'write',
'contextlevel' => CONTEXT_MODULE, 'contextlevel' => CONTEXT_MODULE,
'archetypes' => array( 'archetypes' => array(
@ -112,9 +103,7 @@ $capabilities = array(
), ),
'mod/attforblock:manageattendances' => array( 'mod/attforblock:manageattendances' => array(
'riskbitmask' => RISK_CONFIG, 'riskbitmask' => RISK_CONFIG,
'captype' => 'write', 'captype' => 'write',
'contextlevel' => CONTEXT_MODULE, 'contextlevel' => CONTEXT_MODULE,
'archetypes' => array( 'archetypes' => array(
@ -124,9 +113,7 @@ $capabilities = array(
), ),
'mod/attforblock:changepreferences' => array( 'mod/attforblock:changepreferences' => array(
'riskbitmask' => RISK_CONFIG, 'riskbitmask' => RISK_CONFIG,
'captype' => 'write', 'captype' => 'write',
'contextlevel' => CONTEXT_MODULE, 'contextlevel' => CONTEXT_MODULE,
'archetypes' => array( 'archetypes' => array(
@ -136,9 +123,7 @@ $capabilities = array(
), ),
'mod/attforblock:export' => array( 'mod/attforblock:export' => array(
'riskbitmask' => RISK_PERSONAL, 'riskbitmask' => RISK_PERSONAL,
'captype' => 'read', 'captype' => 'read',
'contextlevel' => CONTEXT_MODULE, 'contextlevel' => CONTEXT_MODULE,
'archetypes' => array( 'archetypes' => array(
@ -149,9 +134,7 @@ $capabilities = array(
'mod/attforblock:canbelisted' => array( 'mod/attforblock:canbelisted' => array(
'riskbitmask' => RISK_PERSONAL, 'riskbitmask' => RISK_PERSONAL,
'captype' => 'read', 'captype' => 'read',
'contextlevel' => CONTEXT_MODULE, 'contextlevel' => CONTEXT_MODULE,
'archetypes' => array( 'archetypes' => array(

65
db/upgrade.php

@ -15,36 +15,16 @@
// 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 attforblock module.
//
// Sometimes, changes between versions involve
// alterations to database structures and other
// major things that may break installations.
//
// The upgrade function in this file will attempt
// to perform all the necessary actions to upgrade
// your older installtion to the current version.
//
// If there's something it cannot do itself, it
// will tell you what you need to do.
//
// The commands in here will all be database-neutral,
// using the functions defined in lib/ddllib.php
function xmldb_attforblock_upgrade($oldversion=0) { function xmldb_attforblock_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;
/// And upgrade begins here. For each one, you'll need one if ($oldversion < 2008021904) { // New version in version.php.
/// block of code similar to the next one. Please, delete
/// this comment lines once this file start handling proper
/// upgrade code.
if ($oldversion < 2008021904) { //New version in version.php
global $USER; global $USER;
if ($sessions = $DB->get_records('attendance_sessions', array('takenby'=> 0))) { if ($sessions = $DB->get_records('attendance_sessions', array('takenby'=> 0))) {
foreach ($sessions as $sess) { foreach ($sessions as $sess) {
@ -67,17 +47,12 @@ function xmldb_attforblock_upgrade($oldversion=0) {
$field->set_attributes(XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '100', 'name'); $field->set_attributes(XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '100', 'name');
$dbman->add_field($table, $field); $dbman->add_field($table, $field);
$table = new xmldb_table('attendance_sessions'); $table = new xmldb_table('attendance_sessions');
$field = new xmldb_field('courseid'); $field = new xmldb_field('courseid');
$field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'id'); $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'id');
$dbman->change_field_unsigned($table, $field); $dbman->change_field_unsigned($table, $field);
// $field = new xmldb_field('creator');
// $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'courseid');
// change_field_unsigned($table, $field);
$field = new xmldb_field('sessdate'); $field = new xmldb_field('sessdate');
$field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'creator'); $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'creator');
$dbman->change_field_unsigned($table, $field); $dbman->change_field_unsigned($table, $field);
@ -100,7 +75,6 @@ function xmldb_attforblock_upgrade($oldversion=0) {
$field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, 'lasttaken'); $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, 'lasttaken');
$dbman->change_field_unsigned($table, $field); $dbman->change_field_unsigned($table, $field);
$table = new xmldb_table('attendance_log'); $table = new xmldb_table('attendance_log');
$field = new xmldb_field('attsid'); $field = new xmldb_field('attsid');
@ -127,7 +101,7 @@ function xmldb_attforblock_upgrade($oldversion=0) {
$field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'timetaken'); $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'timetaken');
$dbman->add_field($table, $field); $dbman->add_field($table, $field);
//Indexes // Indexes.
$index = new xmldb_index('statusid'); $index = new xmldb_index('statusid');
$index->set_attributes(XMLDB_INDEX_NOTUNIQUE, array('statusid')); $index->set_attributes(XMLDB_INDEX_NOTUNIQUE, array('statusid'));
$dbman->add_index($table, $index); $dbman->add_index($table, $index);
@ -136,7 +110,7 @@ function xmldb_attforblock_upgrade($oldversion=0) {
$index->set_attributes(XMLDB_INDEX_NOTUNIQUE, array('attsid')); $index->set_attributes(XMLDB_INDEX_NOTUNIQUE, array('attsid'));
$dbman->drop_index($table, $index); $dbman->drop_index($table, $index);
$field = new xmldb_field('attsid'); //Rename field $field = new xmldb_field('attsid'); // Rename field.
$field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'id'); $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'id');
$dbman->rename_field($table, $field, 'sessionid'); $dbman->rename_field($table, $field, 'sessionid');
@ -144,7 +118,6 @@ function xmldb_attforblock_upgrade($oldversion=0) {
$index->set_attributes(XMLDB_INDEX_NOTUNIQUE, array('sessionid')); $index->set_attributes(XMLDB_INDEX_NOTUNIQUE, array('sessionid'));
$dbman->add_index($table, $index); $dbman->add_index($table, $index);
$table = new xmldb_table('attendance_settings'); $table = new xmldb_table('attendance_settings');
$field = new xmldb_field('courseid'); $field = new xmldb_field('courseid');
@ -159,7 +132,7 @@ function xmldb_attforblock_upgrade($oldversion=0) {
$field->set_attributes(XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'visible'); $field->set_attributes(XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'visible');
$dbman->add_field($table, $field); $dbman->add_field($table, $field);
//Indexes // Indexes.
$index = new xmldb_index('visible'); $index = new xmldb_index('visible');
$index->set_attributes(XMLDB_INDEX_NOTUNIQUE, array('visible')); $index->set_attributes(XMLDB_INDEX_NOTUNIQUE, array('visible'));
$dbman->add_index($table, $index); $dbman->add_index($table, $index);
@ -177,10 +150,10 @@ function xmldb_attforblock_upgrade($oldversion=0) {
if ($courses = $DB->get_records_sql("SELECT courseid FROM {attendance_sessions} GROUP BY courseid")) { if ($courses = $DB->get_records_sql("SELECT courseid FROM {attendance_sessions} GROUP BY courseid")) {
foreach ($courses as $c) { foreach ($courses as $c) {
//Adding own status for course (now it must have own) // Adding own status for course (now it must have own).
if (!$DB->count_records('attendance_statuses', array( 'courseid'=> $c->courseid))) { if (!$DB->count_records('attendance_statuses', array( 'courseid'=> $c->courseid))) {
$statuses = $DB->get_records('attendance_statuses', array('courseid'=> 0)); $statuses = $DB->get_records('attendance_statuses', array('courseid'=> 0));
foreach($statuses as $stat) { foreach ($statuses as $stat) {
$rec = $stat; $rec = $stat;
$rec->courseid = $c->courseid; $rec->courseid = $c->courseid;
$DB->insert_record('attendance_statuses', $rec); $DB->insert_record('attendance_statuses', $rec);
@ -188,15 +161,16 @@ function xmldb_attforblock_upgrade($oldversion=0) {
} }
$statuses = $DB->get_records('attendance_statuses', array('courseid'=> $c->courseid)); $statuses = $DB->get_records('attendance_statuses', array('courseid'=> $c->courseid));
$statlist = implode(',', array_keys($statuses)); $statlist = implode(',', array_keys($statuses));
$sess = $DB->get_records_select_menu('attendance_sessions', "courseid = ? AND lasttakenby > 0", array($c->courseid)); $sess = $DB->get_records_select_menu('attendance_sessions',
"courseid = ? AND lasttakenby > 0", array($c->courseid));
$sesslist = implode(',', array_keys($sess)); $sesslist = implode(',', array_keys($sess));
foreach($statuses as $stat) { foreach ($statuses as $stat) {
execute("UPDATE {attendance_log} execute("UPDATE {attendance_log}
SET statusid = {$stat->id}, statusset = '$statlist' SET statusid = {$stat->id}, statusset = '$statlist'
WHERE sessionid IN ($sesslist) AND status = '$stat->status'"); WHERE sessionid IN ($sesslist) AND status = '$stat->status'");
} }
$sessions = $DB->get_records_list('attendance_sessions', array('id'=> $sesslist)); $sessions = $DB->get_records_list('attendance_sessions', array('id'=> $sesslist));
foreach($sessions as $sess) { foreach ($sessions as $sess) {
execute("UPDATE {attendance_log} execute("UPDATE {attendance_log}
SET timetaken = {$sess->lasttaken}, SET timetaken = {$sess->lasttaken},
takenby = {$sess->lasttakenby} takenby = {$sess->lasttakenby}
@ -206,7 +180,6 @@ function xmldb_attforblock_upgrade($oldversion=0) {
} }
} }
upgrade_mod_savepoint(true, 2008102406, 'attforblock'); upgrade_mod_savepoint(true, 2008102406, 'attforblock');
} }
if ($oldversion < 2008102409) { if ($oldversion < 2008102409) {
@ -219,7 +192,6 @@ function xmldb_attforblock_upgrade($oldversion=0) {
$index->set_attributes(XMLDB_INDEX_NOTUNIQUE, array('status')); $index->set_attributes(XMLDB_INDEX_NOTUNIQUE, array('status'));
$dbman->drop_index($table, $index); $dbman->drop_index($table, $index);
$table = new xmldb_table('attendance_log'); $table = new xmldb_table('attendance_log');
$field = new xmldb_field('status'); $field = new xmldb_field('status');
@ -234,7 +206,6 @@ function xmldb_attforblock_upgrade($oldversion=0) {
$field = new xmldb_field('creator'); $field = new xmldb_field('creator');
$dbman->drop_field($table, $field); $dbman->drop_field($table, $field);
upgrade_mod_savepoint(true, 2008102409, 'attforblock'); upgrade_mod_savepoint(true, 2008102409, 'attforblock');
} }
if ($oldversion < 2010070900) { if ($oldversion < 2010070900) {
@ -306,15 +277,17 @@ function xmldb_attforblock_upgrade($oldversion=0) {
$field->set_attributes(XMLDB_TYPE_TEXT, 'small', null, XMLDB_NOTNULL, null, null, 'timemodified'); $field->set_attributes(XMLDB_TYPE_TEXT, 'small', null, XMLDB_NOTNULL, null, null, 'timemodified');
$dbman->change_field_type($table, $field); $dbman->change_field_type($table, $field);
$field = new xmldb_field('descriptionformat', XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'description'); $field = new xmldb_field('descriptionformat', XMLDB_TYPE_INTEGER, '4',
XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'description');
if (!$dbman->field_exists($table, $field)) { if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field); $dbman->add_field($table, $field);
} }
// conditionally migrate to html format in intro // Conditionally migrate to html format in intro.
if ($CFG->texteditors !== 'textarea') { if ($CFG->texteditors !== 'textarea') {
$rs = $DB->get_recordset('attendance_sessions', array('descriptionformat' => FORMAT_MOODLE), '', 'id,description,descriptionformat'); $rs = $DB->get_recordset('attendance_sessions', array('descriptionformat' => FORMAT_MOODLE),
'', 'id,description,descriptionformat');
foreach ($rs as $s) { foreach ($rs as $s) {
$s->description = text_to_html($s->description, false, false, true); $s->description = text_to_html($s->description, false, false, true);
$s->descriptionformat = FORMAT_HTML; $s->descriptionformat = FORMAT_HTML;
@ -324,9 +297,9 @@ function xmldb_attforblock_upgrade($oldversion=0) {
$rs->close(); $rs->close();
} }
// now we can create more than one attendances per course // Now we can create more than one attendances per course
// thus sessions and statuses belongs to attendance // thus sessions and statuses belongs to attendance
// so we don't need courseid fields in attendance_sessions and attendance_statuses // so we don't need courseid fields in attendance_sessions and attendance_statuses.
$index = new xmldb_index('courseid', XMLDB_INDEX_NOTUNIQUE, array('courseid')); $index = new xmldb_index('courseid', XMLDB_INDEX_NOTUNIQUE, array('courseid'));
if ($dbman->index_exists($table, $index)) { if ($dbman->index_exists($table, $index)) {
$dbman->drop_index($table, $index); $dbman->drop_index($table, $index);

19
duration_form.php

@ -26,7 +26,7 @@ require_once($CFG->libdir.'/formslib.php');
class mod_attforblock_duration_form extends moodleform { class mod_attforblock_duration_form extends moodleform {
function definition() { public function definition() {
global $CFG; global $CFG;
$mform =& $this->_form; $mform =& $this->_form;
@ -36,18 +36,18 @@ 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', 'attforblock'));
$mform->addElement('static', 'count', get_string('countofselected','attforblock'), count(explode('_', $ids))); $mform->addElement('static', 'count', get_string('countofselected', 'attforblock'), 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);
} }
for ($i=0; $i<60; $i+=5) { for ($i=0; $i<60; $i+=5) {
$minutes[$i] = sprintf("%02d",$i); $minutes[$i] = sprintf("%02d", $i);
} }
$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', 'attforblock'), 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,15 +55,8 @@ 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)));
//-------------------------------------------------------------------------------
// buttons
$submit_string = get_string('update', 'attforblock'); $submit_string = get_string('update', 'attforblock');
$this->add_action_buttons(true, $submit_string); $this->add_action_buttons(true, $submit_string);
// $mform->addElement('hidden', 'id', $cm->id);
// $mform->addElement('hidden', 'sessionid', $sessionid);
// $mform->addElement('hidden', 'action', 'changeduration');
} }
} }

26
export.php

@ -92,7 +92,7 @@ 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', 'attforblock'));
$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', 'attforblock');
@ -101,12 +101,13 @@ if ($mform->is_submitted()) {
} else { } else {
print_error('sessionsnotfound', 'attforblock', $att->url_manage()); print_error('sessionsnotfound', 'attforblock', $att->url_manage());
} }
if ($reportdata->gradable) if ($reportdata->gradable) {
$data->tabhead[] = get_string('grade'); $data->tabhead[] = get_string('grade');
}
$i = 0; $i = 0;
$data->table = array(); $data->table = array();
foreach($reportdata->users as $user) { foreach ($reportdata->users as $user) {
if (isset($formdata->ident['id'])) { if (isset($formdata->ident['id'])) {
$data->table[$i][] = $user->id; $data->table[$i][] = $user->id;
} }
@ -117,15 +118,16 @@ if ($mform->is_submitted()) {
$data->table[$i][] = $user->firstname; $data->table[$i][] = $user->firstname;
$cellsgenerator = new user_sessions_cells_text_generator($reportdata, $user); $cellsgenerator = new user_sessions_cells_text_generator($reportdata, $user);
$data->table[$i] = array_merge($data->table[$i], $cellsgenerator->get_cells()); $data->table[$i] = array_merge($data->table[$i], $cellsgenerator->get_cells());
if ($reportdata->gradable) if ($reportdata->gradable) {
$data->table[$i][] = $reportdata->grades[$user->id].' / '.$reportdata->maxgrades[$user->id]; $data->table[$i][] = $reportdata->grades[$user->id].' / '.$reportdata->maxgrades[$user->id];
}
$i++; $i++;
} }
if ($formdata->format === 'text') { if ($formdata->format === 'text') {
ExportToCSV($data, $filename); exporttocsv($data, $filename);
} else { } else {
ExportToTableEd($data, $filename, $formdata->format); exporttotableed($data, $filename, $formdata->format);
} }
exit; exit;
} else { } else {
@ -136,7 +138,7 @@ if ($mform->is_submitted()) {
$output = $PAGE->get_renderer('mod_attforblock'); $output = $PAGE->get_renderer('mod_attforblock');
$tabs = new attforblock_tabs($att, attforblock_tabs::TAB_EXPORT); $tabs = new attforblock_tabs($att, attforblock_tabs::TAB_EXPORT);
echo $output->header(); echo $output->header();
echo $output->heading(get_string('attendanceforthecourse','attforblock').' :: ' .$course->fullname); echo $output->heading(get_string('attendanceforthecourse', 'attforblock').' :: ' .$course->fullname);
echo $output->render($tabs); echo $output->render($tabs);
$mform->display(); $mform->display();
@ -144,7 +146,7 @@ $mform->display();
echo $OUTPUT->footer(); echo $OUTPUT->footer();
function ExportToTableEd($data, $filename, $format) { function exporttotableed($data, $filename, $format) {
global $CFG; global $CFG;
if ($format === 'excel') { if ($format === 'excel') {
@ -156,11 +158,11 @@ function ExportToTableEd($data, $filename, $format) {
$filename .= ".ods"; $filename .= ".ods";
$workbook = new MoodleODSWorkbook("-"); $workbook = new MoodleODSWorkbook("-");
} }
/// Sending HTTP headers // Sending HTTP headers.
$workbook->send($filename); $workbook->send($filename);
/// Creating the first worksheet // Creating the first worksheet.
$myxls = $workbook->add_worksheet('Attendances'); $myxls = $workbook->add_worksheet('Attendances');
/// format types // Format types.
$formatbc = $workbook->add_format(); $formatbc = $workbook->add_format();
$formatbc->set_bold(1); $formatbc->set_bold(1);
@ -186,7 +188,7 @@ function ExportToTableEd($data, $filename, $format) {
$workbook->close(); $workbook->close();
} }
function ExportToCSV($data, $filename) { function exporttocsv($data, $filename) {
$filename .= ".txt"; $filename .= ".txt";
header("Content-Type: application/download\n"); header("Content-Type: application/download\n");

32
export_form.php

@ -26,7 +26,7 @@ require_once($CFG->libdir.'/formslib.php');
class mod_attforblock_export_form extends moodleform { class mod_attforblock_export_form extends moodleform {
function definition() { public function definition() {
global $CFG, $USER; global $CFG, $USER;
$mform =& $this->_form; $mform =& $this->_form;
@ -35,8 +35,7 @@ class mod_attforblock_export_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('export', 'quiz'));
$mform->addElement('header', 'general', get_string('export','quiz'));
$groupmode=groups_get_activity_groupmode($cm); $groupmode=groups_get_activity_groupmode($cm);
$groups = groups_get_activity_allowed_groups($cm, $USER->id); $groups = groups_get_activity_allowed_groups($cm, $USER->id);
@ -53,40 +52,29 @@ class mod_attforblock_export_form extends moodleform {
$ident = array(); $ident = array();
$ident[] =& $mform->createElement('checkbox', 'id', '', get_string('studentid', 'attforblock')); $ident[] =& $mform->createElement('checkbox', 'id', '', get_string('studentid', 'attforblock'));
$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', 'attforblock'), 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', 'attforblock'), 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', 'attforblock'), get_string('yes'));
$mform->addElement('date_selector', 'sessionstartdate', get_string('startofperiod','attforblock')); $mform->addElement('date_selector', 'sessionstartdate', get_string('startofperiod', 'attforblock'));
$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', 'attforblock'));
$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', 'attforblock'),
'ooo' => get_string('downloadooo','attforblock'), 'ooo' => get_string('downloadooo', 'attforblock'),
'text' => get_string('downloadtext','attforblock') 'text' => get_string('downloadtext', 'attforblock')
)); ));
// buttons
$submit_string = get_string('ok'); $submit_string = get_string('ok');
$this->add_action_buttons(false, $submit_string); $this->add_action_buttons(false, $submit_string);
$mform->addElement('hidden', 'id', $cm->id); $mform->addElement('hidden', 'id', $cm->id);
} }
// function validation($data, $files) {
// $errors = parent::validation($data, $files);
// if (($data['timeend']!=0) && ($data['timestart']!=0)
// && $data['timeend'] <= $data['timestart']) {
// $errors['timeend'] = get_string('timestartenderror', 'forum');
// }
// return $errors;
// }
} }

6
lang/en/attforblock.php

@ -52,7 +52,7 @@ $string['calmonths'] = 'January,February,March,April,May,June,July,August,Septem
$string['calshow'] = 'Choose date'; $string['calshow'] = 'Choose date';
$string['caltoday'] = 'Today'; $string['caltoday'] = 'Today';
$string['calweekdays'] = 'Su,Mo,Tu,We,Th,Fr,Sa'; $string['calweekdays'] = 'Su,Mo,Tu,We,Th,Fr,Sa';
$string['cannottakeforgroup'] = 'You can\'t take attendance for group "{$a}"' ; $string['cannottakeforgroup'] = 'You can\'t take attendance for group "{$a}"';
$string['changeattendance'] = 'Change attendance'; $string['changeattendance'] = 'Change attendance';
$string['changeduration'] = 'Change duration'; $string['changeduration'] = 'Change duration';
$string['changesession'] = 'Change session'; $string['changesession'] = 'Change session';
@ -177,9 +177,9 @@ $string['statuses'] = 'Statuses';
$string['statusdeleted'] = 'Status deleted'; $string['statusdeleted'] = 'Status deleted';
$string['strftimedm'] = '%d.%m'; $string['strftimedm'] = '%d.%m';
$string['strftimedmy'] = '%d.%m.%Y'; $string['strftimedmy'] = '%d.%m.%Y';
$string['strftimedmyhm'] = '%d.%m.%Y %H.%M'; // line added to allow multiple sessions in the same day $string['strftimedmyhm'] = '%d.%m.%Y %H.%M'; // Line added to allow multiple sessions in the same day.
$string['strftimedmyw'] = '%d.%m.%y&nbsp;(%a)'; $string['strftimedmyw'] = '%d.%m.%y&nbsp;(%a)';
$string['strftimehm'] = '%H:%M'; //line added to allow display of time $string['strftimehm'] = '%H:%M'; // Line added to allow display of time.
$string['strftimeshortdate'] = '%d.%m.%Y'; $string['strftimeshortdate'] = '%d.%m.%Y';
$string['studentid'] = 'Student ID'; $string['studentid'] = 'Student ID';
$string['takeattendance'] = 'Take attendance'; $string['takeattendance'] = 'Take attendance';

128
lib.php

@ -31,20 +31,27 @@
*/ */
function attforblock_supports($feature) { function attforblock_supports($feature) {
switch($feature) { switch($feature) {
case FEATURE_GRADE_HAS_GRADE: return true; case FEATURE_GRADE_HAS_GRADE:
case FEATURE_GROUPS: return true; return true;
// Artem Andreev: AFAIK it's not tested case FEATURE_GROUPS:
// we need implement filtration of groups list by grouping return true;
case FEATURE_GROUPINGS: return false;
// Artem Andreev: AFAIK it's not tested // Artem Andreev: AFAIK it's not tested
// harder "All courses" report // we need implement filtration of groups list by grouping.
case FEATURE_GROUPMEMBERSONLY: return false; case FEATURE_GROUPINGS:
case FEATURE_MOD_INTRO: return false; return false;
case FEATURE_BACKUP_MOODLE2: return true;
// Artem Andreev: AFAIK it's not tested // Artem Andreev: AFAIK it's not tested
// harder "All courses" report.
case FEATURE_GROUPMEMBERSONLY:
return false;
case FEATURE_MOD_INTRO:
return false;
case FEATURE_BACKUP_MOODLE2:
return true;
// Artem Andreev: AFAIK it's not tested.
case FEATURE_COMPLETION_TRACKS_VIEWS: case FEATURE_COMPLETION_TRACKS_VIEWS:
return false; return false;
default: return null; default:
return null;
} }
} }
@ -52,7 +59,7 @@ function att_add_default_statuses($attid) {
global $DB; global $DB;
$statuses = $DB->get_records('attendance_statuses', array('attendanceid'=> 0), 'id'); $statuses = $DB->get_records('attendance_statuses', array('attendanceid'=> 0), 'id');
foreach($statuses as $st) { foreach ($statuses as $st) {
$rec = $st; $rec = $st;
$rec->attendanceid = $attid; $rec->attendanceid = $attid;
$DB->insert_record('attendance_statuses', $rec); $DB->insert_record('attendance_statuses', $rec);
@ -60,11 +67,6 @@ function att_add_default_statuses($attid) {
} }
function attforblock_add_instance($attforblock) { function attforblock_add_instance($attforblock) {
/// Given an object containing all the necessary data,
/// (defined by the form in mod.html) this function
/// will create a new instance and return the id number
/// of the new instance.
global $DB; global $DB;
$attforblock->timemodified = time(); $attforblock->timemodified = time();
@ -74,16 +76,12 @@ function attforblock_add_instance($attforblock) {
att_add_default_statuses($attforblock->id); att_add_default_statuses($attforblock->id);
attforblock_grade_item_update($attforblock); attforblock_grade_item_update($attforblock);
//attforblock_update_grades($attforblock); // attforblock_update_grades($attforblock);
return $attforblock->id; return $attforblock->id;
} }
function attforblock_update_instance($attforblock) { function attforblock_update_instance($attforblock) {
/// Given an object containing all the necessary data,
/// (defined by the form in mod.html) this function
/// will update an existing instance with new data.
global $DB; global $DB;
$attforblock->timemodified = time(); $attforblock->timemodified = time();
@ -119,13 +117,14 @@ function attforblock_delete_instance($id) {
return true; return true;
} }
function attforblock_delete_course($course, $feedback=true){ function attforblock_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('attforblock', 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);
}
if ($attids) { if ($attids) {
$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);
@ -144,12 +143,12 @@ function attforblock_reset_course_form_definition(&$mform) {
$mform->addElement('static', 'description', get_string('description', 'attforblock'), $mform->addElement('static', 'description', get_string('description', 'attforblock'),
get_string('resetdescription', 'attforblock')); get_string('resetdescription', 'attforblock'));
$mform->addElement('checkbox', 'reset_attendance_log', get_string('deletelogs','attforblock')); $mform->addElement('checkbox', 'reset_attendance_log', get_string('deletelogs', 'attforblock'));
$mform->addElement('checkbox', 'reset_attendance_sessions', get_string('deletesessions','attforblock')); $mform->addElement('checkbox', 'reset_attendance_sessions', get_string('deletesessions', 'attforblock'));
$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', 'attforblock'));
$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');
} }
@ -186,7 +185,7 @@ function attforblock_reset_userdata($data) {
if (!empty($data->reset_attendance_statuses)) { if (!empty($data->reset_attendance_statuses)) {
$DB->delete_records_list('attendance_statuses', 'attendanceid', $attids); $DB->delete_records_list('attendance_statuses', 'attendanceid', $attids);
foreach($attids as $attid) { foreach ($attids as $attid) {
att_add_default_statuses($attid); att_add_default_statuses($attid);
} }
@ -209,13 +208,14 @@ function attforblock_reset_userdata($data) {
return $status; return $status;
} }
/*
* Return a small object with summary information about what a
* user has done with a given particular instance of this module
* Used for user activity reports.
* $return->time = the time they did it
* $return->info = a short text description
*/
function attforblock_user_outline($course, $user, $mod, $attforblock) { function attforblock_user_outline($course, $user, $mod, $attforblock) {
/// Return a small object with summary information about what a
/// user has done with a given particular instance of this module
/// Used for user activity reports.
/// $return->time = the time they did it
/// $return->info = a short text description
global $CFG; global $CFG;
require_once(dirname(__FILE__).'/locallib.php'); require_once(dirname(__FILE__).'/locallib.php');
@ -227,23 +227,27 @@ function attforblock_user_outline($course, $user, $mod, $attforblock) {
if (!empty($grades->items[0]->grades)) { if (!empty($grades->items[0]->grades)) {
$grade = reset($grades->items[0]->grades); $grade = reset($grades->items[0]->grades);
$result->time = $grade->dategraded; $result->time = $grade->dategraded;
} } else {
else
$result->time = 0; $result->time = 0;
}
if (has_capability('mod/attforblock:canbelisted', $mod->context, $user->id)) { if (has_capability('mod/attforblock:canbelisted', $mod->context, $user->id)) {
$statuses = att_get_statuses($attforblock->id); $statuses = att_get_statuses($attforblock->id);
$grade = att_get_user_grade(att_get_user_statuses_stat($attforblock->id, $course->startdate, $user->id), $statuses); $grade = att_get_user_grade(att_get_user_statuses_stat($attforblock->id, $course->startdate,
$maxgrade = att_get_user_max_grade(att_get_user_taken_sessions_count($attforblock->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,
$user->id), $statuses);
$result->info = $grade.' / '.$maxgrade; $result->info = $grade.' / '.$maxgrade;
} }
return $result; return $result;
} }
/*
* Print a detailed representation of what a user has done with
* a given particular instance of this module, for user activity reports.
*
*/
function attforblock_user_complete($course, $user, $mod, $attforblock) { function attforblock_user_complete($course, $user, $mod, $attforblock) {
/// Print a detailed representation of what a user has done with
/// a given particular instance of this module, for user activity reports.
global $CFG; global $CFG;
require_once(dirname(__FILE__).'/renderhelpers.php'); require_once(dirname(__FILE__).'/renderhelpers.php');
@ -252,23 +256,12 @@ function attforblock_user_complete($course, $user, $mod, $attforblock) {
if (has_capability('mod/attforblock:canbelisted', $mod->context, $user->id)) { if (has_capability('mod/attforblock:canbelisted', $mod->context, $user->id)) {
echo construct_full_user_stat_html_table($attforblock, $course, $user); echo construct_full_user_stat_html_table($attforblock, $course, $user);
} }
//return true;
} }
function attforblock_print_recent_activity($course, $isteacher, $timestart) { function attforblock_print_recent_activity($course, $isteacher, $timestart) {
/// Given a course and a time, this module should find recent activity return false;
/// that has occurred in attforblock activities and print it out.
/// Return true if there was output, or false is there was none.
return false; // True if anything was printed, otherwise false
} }
function attforblock_cron () { function attforblock_cron () {
/// Function to be run periodically according to the moodle cron
/// This function searches for things that need to be done, such
/// as sending out mail, toggling flags etc ...
return true; return true;
} }
@ -354,12 +347,12 @@ function attforblock_cron () {
* @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 attforblock_grade_item_update($attforblock, $grades=null) {
global $CFG, $DB; global $CFG, $DB;
require_once('locallib.php'); require_once('locallib.php');
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');
} }
@ -369,12 +362,12 @@ function attforblock_grade_item_update($attforblock, $grades=NULL) {
if (! $course = $DB->get_record('course', array('id'=> $attforblock->course))) { if (! $course = $DB->get_record('course', array('id'=> $attforblock->course))) {
error("Course is misconfigured"); error("Course is misconfigured");
} }
//$attforblock->grade = get_maxgrade($course); // $attforblock->grade = get_maxgrade($course);
if(!empty($attforblock->cmidnumber)){ if (!empty($attforblock->cmidnumber)) {
$params = array('itemname'=>$attforblock->name, 'idnumber'=>$attforblock->cmidnumber); $params = array('itemname'=>$attforblock->name, 'idnumber'=>$attforblock->cmidnumber);
}else{ } else {
// MDL-14303 // MDL-14303.
$cm = get_coursemodule_from_instance('attforblock', $attforblock->id); $cm = get_coursemodule_from_instance('attforblock', $attforblock->id);
$params = array('itemname'=>$attforblock->name/*, 'idnumber'=>$attforblock->id*/); $params = array('itemname'=>$attforblock->name/*, 'idnumber'=>$attforblock->id*/);
} }
@ -383,8 +376,7 @@ function attforblock_grade_item_update($attforblock, $grades=NULL) {
$params['gradetype'] = GRADE_TYPE_VALUE; $params['gradetype'] = GRADE_TYPE_VALUE;
$params['grademax'] = $attforblock->grade; $params['grademax'] = $attforblock->grade;
$params['grademin'] = 0; $params['grademin'] = 0;
} } else if ($attforblock->grade < 0) {
else if ($attforblock->grade < 0) {
$params['gradetype'] = GRADE_TYPE_SCALE; $params['gradetype'] = GRADE_TYPE_SCALE;
$params['scaleid'] = -$attforblock->grade; $params['scaleid'] = -$attforblock->grade;
@ -394,7 +386,7 @@ function attforblock_grade_item_update($attforblock, $grades=NULL) {
if ($grades === 'reset') { if ($grades === 'reset') {
$params['reset'] = true; $params['reset'] = true;
$grades = NULL; $grades = null;
} }
return grade_update('mod/attforblock', $attforblock->courseid, 'mod', 'attforblock', $attforblock->id, 0, $grades, $params); return grade_update('mod/attforblock', $attforblock->courseid, 'mod', 'attforblock', $attforblock->id, 0, $grades, $params);
@ -414,15 +406,11 @@ function attforblock_grade_item_delete($attforblock) {
$attforblock->courseid = $attforblock->course; $attforblock->courseid = $attforblock->course;
} }
return grade_update('mod/attforblock', $attforblock->courseid, 'mod', 'attforblock', $attforblock->id, 0, NULL, array('deleted'=>1)); return grade_update('mod/attforblock', $attforblock->courseid, 'mod', 'attforblock',
$attforblock->id, 0, null, array('deleted'=>1));
} }
function attforblock_get_participants($attforblockid) { function attforblock_get_participants($attforblockid) {
//Must return an array of user records (all data) who are participants
//for a given instance of attforblock. Must include every user involved
//in the instance, independient of his role (student, teacher, admin...)
//See other modules as example.
return false; return false;
} }
@ -476,7 +464,7 @@ function attforblock_pluginfile($course, $cm, $context, $filearea, $args, $force
return false; return false;
} }
// 'session' area is served by pluginfile.php // Session area is served by pluginfile.php.
$fileareas = array('session'); $fileareas = array('session');
if (!in_array($filearea, $fileareas)) { if (!in_array($filearea, $fileareas)) {
return false; return false;
@ -495,7 +483,3 @@ function attforblock_pluginfile($course, $cm, $context, $filearea, $args, $force
} }
send_stored_file($file, 0, 0, true); send_stored_file($file, 0, 0, true);
} }
//////////////////////////////////////////////////////////////////////////////////////
/// Any other attforblock functions go here. Each of them must have a name that
/// starts with attforblock_

219
locallib.php

@ -57,8 +57,9 @@ 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/attforblock:view', $this->context);
}
return $this->canview; return $this->canview;
} }
@ -68,8 +69,9 @@ class attforblock_permissions {
} }
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/attforblock:viewreports', $this->context);
}
return $this->canviewreports; return $this->canviewreports;
} }
@ -79,8 +81,9 @@ class attforblock_permissions {
} }
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/attforblock:takeattendances', $this->context);
}
return $this->cantake; return $this->cantake;
} }
@ -100,15 +103,17 @@ 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/attforblock:changeattendances', $this->context);
}
return $this->canchange; return $this->canchange;
} }
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/attforblock:manageattendances', $this->context);
}
return $this->canmanage; return $this->canmanage;
} }
@ -118,8 +123,9 @@ class attforblock_permissions {
} }
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/attforblock:changepreferences', $this->context);
}
return $this->canchangepreferences; return $this->canchangepreferences;
} }
@ -129,8 +135,9 @@ class attforblock_permissions {
} }
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/attforblock:export', $this->context);
}
return $this->canexport; return $this->canexport;
} }
@ -140,15 +147,17 @@ class attforblock_permissions {
} }
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/attforblock:canbelisted', $this->context, null, false);
}
return $this->canbelisted; return $this->canbelisted;
} }
public function can_access_all_groups() { public function can_access_all_groups() {
if (is_null($this->canaccessallgroups)) if (is_null($this->canaccessallgroups)) {
$this->canaccessallgroups = has_capability('moodle/site:accessallgroups', $this->context); $this->canaccessallgroups = has_capability('moodle/site:accessallgroups', $this->context);
}
return $this->canaccessallgroups; return $this->canaccessallgroups;
} }
@ -197,11 +206,9 @@ class att_page_with_filter_controls {
if (isset($this->view)) { if (isset($this->view)) {
$SESSION->attcurrentattview[$this->cm->course] = $this->view; $SESSION->attcurrentattview[$this->cm->course] = $this->view;
} } else if (isset($SESSION->attcurrentattview[$this->cm->course])) {
elseif (isset($SESSION->attcurrentattview[$this->cm->course])) {
$this->view = $SESSION->attcurrentattview[$this->cm->course]; $this->view = $SESSION->attcurrentattview[$this->cm->course];
} } else {
else {
$this->view = $this->defaultview; $this->view = $this->defaultview;
} }
} }
@ -211,11 +218,9 @@ class att_page_with_filter_controls {
if (isset($this->curdate)) { if (isset($this->curdate)) {
$SESSION->attcurrentattdate[$this->cm->course] = $this->curdate; $SESSION->attcurrentattdate[$this->cm->course] = $this->curdate;
} } else if (isset($SESSION->attcurrentattdate[$this->cm->course])) {
elseif (isset($SESSION->attcurrentattdate[$this->cm->course])) {
$this->curdate = $SESSION->attcurrentattdate[$this->cm->course]; $this->curdate = $SESSION->attcurrentattdate[$this->cm->course];
} } else {
else {
$this->curdate = time(); $this->curdate = time();
} }
} }
@ -223,11 +228,13 @@ class att_page_with_filter_controls {
public function init_start_end_date() { public function init_start_end_date() {
global $CFG; global $CFG;
// HOURSECS solves issue for weeks view with Daylight saving time and clocks adjusting by one hour backward // HOURSECS solves issue for weeks view with Daylight saving time and clocks adjusting by one hour backward.
$date = usergetdate($this->curdate + HOURSECS); $date = usergetdate($this->curdate + HOURSECS);
$mday = $date['mday']; $mday = $date['mday'];
$wday = $date['wday'] - $CFG->calendar_startwday; $wday = $date['wday'] - $CFG->calendar_startwday;
if ($wday < 0) $wday += 7; if ($wday < 0) {
$wday += 7;
}
$mon = $date['mon']; $mon = $date['mon'];
$year = $date['year']; $year = $date['year'];
@ -260,8 +267,7 @@ class att_page_with_filter_controls {
if (!array_key_exists('attsessiontype', $SESSION)) { if (!array_key_exists('attsessiontype', $SESSION)) {
$SESSION->attsessiontype = array($this->cm->course => self::SESSTYPE_ALL); $SESSION->attsessiontype = array($this->cm->course => self::SESSTYPE_ALL);
} } else if (!array_key_exists($this->cm->course, $SESSION->attsessiontype)) {
elseif (!array_key_exists($this->cm->course, $SESSION->attsessiontype)) {
$SESSION->attsessiontype[$this->cm->course] = self::SESSTYPE_ALL; $SESSION->attsessiontype[$this->cm->course] = self::SESSTYPE_ALL;
} }
@ -270,10 +276,10 @@ class att_page_with_filter_controls {
if ($group > self::SESSTYPE_NO_VALUE) { if ($group > self::SESSTYPE_NO_VALUE) {
$SESSION->attsessiontype[$this->cm->course] = $group; $SESSION->attsessiontype[$this->cm->course] = $group;
if ($group > self::SESSTYPE_ALL) { if ($group > self::SESSTYPE_ALL) {
// set activegroup in $SESSION // Set activegroup in $SESSION.
groups_get_activity_group($this->cm, true); groups_get_activity_group($this->cm, true);
} else { } else {
// reset activegroup in $SESSION // Reset activegroup in $SESSION.
unset($SESSION->activegroup[$this->cm->course][VISIBLEGROUPS][$this->cm->groupingid]); unset($SESSION->activegroup[$this->cm->course][VISIBLEGROUPS][$this->cm->groupingid]);
unset($SESSION->activegroup[$this->cm->course]['aag'][$this->cm->groupingid]); unset($SESSION->activegroup[$this->cm->course]['aag'][$this->cm->groupingid]);
unset($SESSION->activegroup[$this->cm->course][SEPARATEGROUPS][$this->cm->groupingid]); unset($SESSION->activegroup[$this->cm->course][SEPARATEGROUPS][$this->cm->groupingid]);
@ -282,23 +288,23 @@ class att_page_with_filter_controls {
} else { } else {
$this->sesstype = $SESSION->attsessiontype[$this->cm->course]; $this->sesstype = $SESSION->attsessiontype[$this->cm->course];
} }
} elseif ($this->selectortype == self::SELECTOR_GROUP) { } else if ($this->selectortype == self::SELECTOR_GROUP) {
if ($group == 0) { if ($group == 0) {
$SESSION->attsessiontype[$this->cm->course] = self::SESSTYPE_ALL; $SESSION->attsessiontype[$this->cm->course] = self::SESSTYPE_ALL;
$this->sesstype = self::SESSTYPE_ALL; $this->sesstype = self::SESSTYPE_ALL;
} } else if ($group > 0) {
elseif ($group > 0) {
$SESSION->attsessiontype[$this->cm->course] = $group; $SESSION->attsessiontype[$this->cm->course] = $group;
$this->sesstype = $group; $this->sesstype = $group;
} } else {
else {
$this->sesstype = $SESSION->attsessiontype[$this->cm->course]; $this->sesstype = $SESSION->attsessiontype[$this->cm->course];
} }
} }
if (is_null($this->sessgroupslist)) $this->calc_sessgroupslist(); if (is_null($this->sessgroupslist)) {
// for example, we set SESSTYPE_ALL but user can access only to limited set of groups $this->calc_sessgroupslist();
if (!array_key_exists($this->sesstype, $this->sessgroupslist)){ }
// For example, we set SESSTYPE_ALL but user can access only to limited set of groups.
if (!array_key_exists($this->sesstype, $this->sessgroupslist)) {
reset($this->sessgroupslist); reset($this->sessgroupslist);
$this->sesstype = key($this->sessgroupslist); $this->sesstype = key($this->sessgroupslist);
} }
@ -309,8 +315,9 @@ class att_page_with_filter_controls {
$this->sessgroupslist = array(); $this->sessgroupslist = array();
$groupmode = groups_get_activity_groupmode($this->cm); $groupmode = groups_get_activity_groupmode($this->cm);
if ($groupmode == NOGROUPS) if ($groupmode == NOGROUPS) {
return; return;
}
if ($groupmode == VISIBLEGROUPS or has_capability('moodle/site:accessallgroups', $PAGE->context)) { if ($groupmode == VISIBLEGROUPS or has_capability('moodle/site:accessallgroups', $PAGE->context)) {
$allowedgroups = groups_get_all_groups($this->cm->course, 0, $this->cm->groupingid); $allowedgroups = groups_get_all_groups($this->cm->course, 0, $this->cm->groupingid);
@ -332,15 +339,17 @@ class att_page_with_filter_controls {
} }
public function get_sess_groups_list() { public function get_sess_groups_list() {
if (is_null($this->sessgroupslist)) if (is_null($this->sessgroupslist)) {
$this->calc_sessgroupslist_sesstype(); $this->calc_sessgroupslist_sesstype();
}
return $this->sessgroupslist; return $this->sessgroupslist;
} }
public function get_current_sesstype() { public function get_current_sesstype() {
if (is_null($this->sesstype)) if (is_null($this->sesstype)) {
$this->calc_sessgroupslist_sesstype(); $this->calc_sessgroupslist_sesstype();
}
return $this->sesstype; return $this->sesstype;
} }
@ -365,8 +374,12 @@ class att_view_page_params extends att_page_with_filter_controls {
public function get_significant_params() { public function get_significant_params() {
$params = array(); $params = array();
if (isset($this->studentid)) $params['studentid'] = $this->studentid; if (isset($this->studentid)) {
if ($this->mode != self::MODE_THIS_COURSE) $params['mode'] = $this->mode; $params['studentid'] = $this->studentid;
}
if ($this->mode != self::MODE_THIS_COURSE) {
$params['mode'] = $this->mode;
}
return $params; return $params;
} }
@ -411,8 +424,12 @@ class att_take_page_params {
public $gridcols; public $gridcols;
public function init() { public function init() {
if (!isset($this->group)) $this->group = 0; if (!isset($this->group)) {
if (!isset($this->sort)) $this->sort = ATT_SORT_LASTNAME; $this->group = 0;
}
if (!isset($this->sort)) {
$this->sort = ATT_SORT_LASTNAME;
}
$this->init_view_mode(); $this->init_view_mode();
$this->init_gridcols(); $this->init_gridcols();
} }
@ -420,8 +437,7 @@ 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("attforblock_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("attforblock_take_view_mode", self::DEFAULT_VIEW_MODE);
} }
} }
@ -429,8 +445,7 @@ class att_take_page_params {
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("attforblock_gridcolumns", $this->gridcols);
} } else {
else {
$this->gridcols = get_user_preferences("attforblock_gridcolumns", 5); $this->gridcols = get_user_preferences("attforblock_gridcolumns", 5);
} }
} }
@ -440,9 +455,15 @@ class att_take_page_params {
$params['sessionid'] = $this->sessionid; $params['sessionid'] = $this->sessionid;
$params['grouptype'] = $this->grouptype; $params['grouptype'] = $this->grouptype;
if ($this->group) $params['group'] = $this->group; if ($this->group) {
if ($this->sort != ATT_SORT_LASTNAME) $params['sort'] = $this->sort; $params['group'] = $this->group;
if (isset($this->copyfrom)) $params['copyfrom'] = $this->copyfrom; }
if ($this->sort != ATT_SORT_LASTNAME) {
$params['sort'] = $this->sort;
}
if (isset($this->copyfrom)) {
$params['copyfrom'] = $this->copyfrom;
}
return $params; return $params;
} }
@ -459,15 +480,20 @@ class att_report_page_params extends att_page_with_filter_controls {
public function init($cm) { public function init($cm) {
parent::init($cm); parent::init($cm);
if (!isset($this->group)) $this->group = $this->get_current_sesstype() > 0 ? $this->get_current_sesstype() : 0; if (!isset($this->group)) {
if (!isset($this->sort)) $this->sort = ATT_SORT_LASTNAME; $this->group = $this->get_current_sesstype() > 0 ? $this->get_current_sesstype() : 0;
}
if (!isset($this->sort)) {
$this->sort = ATT_SORT_LASTNAME;
}
} }
public function get_significant_params() { public function get_significant_params() {
$params = array(); $params = array();
//if ($this->group) $params['group'] = $this->group; if ($this->sort != ATT_SORT_LASTNAME) {
if ($this->sort != ATT_SORT_LASTNAME) $params['sort'] = $this->sort; $params['sort'] = $this->sort;
}
return $params; return $params;
} }
@ -488,8 +514,12 @@ class att_preferences_page_params {
public function get_significant_params() { public function get_significant_params() {
$params = array(); $params = array();
if (isset($this->action)) $params['action'] = $this->action; if (isset($this->action)) {
if (isset($this->statusid)) $params['statusid'] = $this->statusid; $params['action'] = $this->action;
}
if (isset($this->statusid)) {
$params['statusid'] = $this->statusid;
}
return $params; return $params;
} }
@ -529,12 +559,10 @@ class attforblock {
private $statuses; private $statuses;
// Cache // Array by sessionid.
// array by sessionid
private $sessioninfo = array(); private $sessioninfo = array();
// arrays by userid // Arrays by userid.
private $usertakensesscount = array(); private $usertakensesscount = array();
private $userstatusesstat = array(); private $userstatusesstat = array();
@ -549,13 +577,12 @@ class attforblock {
* @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('attforblock', $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 field for which there is no property in the attforblock class');
} }
} }
$this->cm = $cm; $this->cm = $cm;
@ -572,9 +599,9 @@ class attforblock {
} }
public function get_group_mode() { public function get_group_mode() {
if (is_null($this->groupmode)) if (is_null($this->groupmode)) {
$this->groupmode = groups_get_activity_groupmode($this->cm); $this->groupmode = groups_get_activity_groupmode($this->cm);
}
return $this->groupmode; return $this->groupmode;
} }
@ -588,7 +615,7 @@ class attforblock {
public function get_current_sessions() { public function get_current_sessions() {
global $DB; global $DB;
$today = time(); // because we compare with database, we don't need to use usertime() $today = time(); // Because we compare with database, we don't need to use usertime().
$sql = "SELECT * $sql = "SELECT *
FROM {attendance_sessions} FROM {attendance_sessions}
@ -691,8 +718,7 @@ 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', 'attforblock');
} } 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_attforblock', 'session', $sess->id);
} }
@ -805,8 +831,8 @@ class attforblock {
$now = time(); $now = time();
$sesslog = array(); $sesslog = array();
$formdata = (array)$formdata; $formdata = (array)$formdata;
foreach($formdata as $key => $value) { foreach ($formdata as $key => $value) {
if(substr($key, 0, 4) == 'user') { if (substr($key, 0, 4) == 'user') {
$sid = substr($key, 4); $sid = substr($key, 4);
$sesslog[$sid] = new stdClass(); $sesslog[$sid] = new stdClass();
$sesslog[$sid]->studentid = $sid; $sesslog[$sid]->studentid = $sid;
@ -825,11 +851,11 @@ class attforblock {
if (array_key_exists($log->studentid, $dbsesslog)) { if (array_key_exists($log->studentid, $dbsesslog)) {
$log->id = $dbsesslog[$log->studentid]->id; $log->id = $dbsesslog[$log->studentid]->id;
$DB->update_record('attendance_log', $log); $DB->update_record('attendance_log', $log);
} } else {
else
$DB->insert_record('attendance_log', $log, false); $DB->insert_record('attendance_log', $log, false);
} }
} }
}
$rec = new stdClass(); $rec = new stdClass();
$rec->id = $this->pageparams->sessionid; $rec->id = $this->pageparams->sessionid;
@ -837,7 +863,9 @@ class attforblock {
$rec->lasttakenby = $USER->id; $rec->lasttakenby = $USER->id;
$DB->update_record('attendance_sessions', $rec); $DB->update_record('attendance_sessions', $rec);
if ($this->grade != 0) $this->update_users_grade(array_keys($sesslog)); if ($this->grade != 0) {
$this->update_users_grade(array_keys($sesslog));
}
$params = array( $params = array(
'sessionid' => $this->pageparams->sessionid, 'sessionid' => $this->pageparams->sessionid,
@ -845,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', 'attforblock'));
} }
/** /**
@ -854,23 +882,22 @@ class attforblock {
public function get_users($groupid = 0) { public function get_users($groupid = 0) {
global $DB; global $DB;
//fields we need from the user table // Fields we need from the user table.
$userfields = user_picture::fields('u').',u.username'; $userfields = user_picture::fields('u').',u.username';
if (isset($this->pageparams->sort) and ($this->pageparams->sort == ATT_SORT_FIRSTNAME)) { if (isset($this->pageparams->sort) and ($this->pageparams->sort == ATT_SORT_FIRSTNAME)) {
$orderby = "u.firstname ASC, u.lastname ASC"; $orderby = "u.firstname ASC, u.lastname ASC";
} } else {
else {
$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/attforblock: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)) {
list($usql, $uparams) = $DB->get_in_or_equal(array_keys($users), SQL_PARAMS_NAMED, 'usid0'); list($usql, $uparams) = $DB->get_in_or_equal(array_keys($users), SQL_PARAMS_NAMED, 'usid0');
//CONTRIB-3549 // CONTRIB-3549.
$sql = "SELECT ue.userid, ue.status, ue.timestart, ue.timeend $sql = "SELECT ue.userid, ue.status, ue.timestart, ue.timeend
FROM {user_enrolments} ue FROM {user_enrolments} ue
JOIN {enrol} e ON e.id = ue.enrolid JOIN {enrol} e ON e.id = ue.enrolid
@ -924,16 +951,15 @@ class attforblock {
public function get_session_info($sessionid) { public function get_session_info($sessionid) {
global $DB; global $DB;
if (!array_key_exists($sessionid, $this->sessioninfo)) if (!array_key_exists($sessionid, $this->sessioninfo)) {
$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', 'attforblock');
} } 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_attforblock', 'session', $this->sessioninfo[$sessionid]->id);
} }
return $this->sessioninfo[$sessionid]; return $this->sessioninfo[$sessionid];
} }
@ -946,8 +972,7 @@ 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', 'attforblock');
} } 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_attforblock', 'session', $sess->id);
} }
@ -971,9 +996,9 @@ class attforblock {
} }
public function get_user_taken_sessions_count($userid) { public function get_user_taken_sessions_count($userid) {
if (!array_key_exists($userid, $this->usertakensesscount)) if (!array_key_exists($userid, $this->usertakensesscount)) {
$this->usertakensesscount[$userid] = att_get_user_taken_sessions_count($this->id, $this->course->startdate, $userid); $this->usertakensesscount[$userid] = att_get_user_taken_sessions_count($this->id, $this->course->startdate, $userid);
}
return $this->usertakensesscount[$userid]; return $this->usertakensesscount[$userid];
} }
@ -1010,7 +1035,7 @@ class attforblock {
// * all sessions between user start enrolment date and now; // * all sessions between user start enrolment date and now;
// * all sessions between user start and end enrolment date. // * all sessions between user start and end enrolment date.
// While implementing those methods we need recalculate grades of all users // While implementing those methods we need recalculate grades of all users
// on session adding // on session adding.
public function get_user_max_grade($userid) { public function get_user_max_grade($userid) {
return att_get_user_max_grade($this->get_user_taken_sessions_count($userid), $this->get_statuses()); return att_get_user_max_grade($this->get_user_taken_sessions_count($userid), $this->get_statuses());
} }
@ -1021,7 +1046,8 @@ class attforblock {
foreach ($userids as $userid) { foreach ($userids as $userid) {
$grades[$userid] = new stdClass(); $grades[$userid] = new stdClass();
$grades[$userid]->userid = $userid; $grades[$userid]->userid = $userid;
$grades[$userid]->rawgrade = att_calc_user_grade_fraction($this->get_user_grade($userid), $this->get_user_max_grade($userid)) * $this->grade; $grades[$userid]->rawgrade = att_calc_user_grade_fraction($this->get_user_grade($userid),
$this->get_user_max_grade($userid)) * $this->grade;
} }
return grade_update('mod/attforblock', $this->course->id, 'mod', 'attforblock', return grade_update('mod/attforblock', $this->course->id, 'mod', 'attforblock',
@ -1059,7 +1085,7 @@ class attforblock {
public function get_user_filtered_sessions_log_extended($userid) { public function get_user_filtered_sessions_log_extended($userid) {
global $DB; global $DB;
// all taked sessions (including previous groups) // All taked sessions (including previous groups).
if ($this->pageparams->startdate && $this->pageparams->enddate) { if ($this->pageparams->startdate && $this->pageparams->enddate) {
$where = "ats.attendanceid = :aid AND ats.sessdate >= :csdate AND $where = "ats.attendanceid = :aid AND ats.sessdate >= :csdate AND
@ -1083,8 +1109,7 @@ class attforblock {
'edate' => $this->pageparams->enddate); 'edate' => $this->pageparams->enddate);
$sessions = $DB->get_records_sql($sql, $params); $sessions = $DB->get_records_sql($sql, $params);
// All sessions for current groups.
// all sessions for current groups
$groups = array_keys(groups_get_all_groups($this->course->id, $userid)); $groups = array_keys(groups_get_all_groups($this->course->id, $userid));
$groups[] = 0; $groups[] = 0;
@ -1107,12 +1132,10 @@ class attforblock {
$params = array_merge($params, $gparams); $params = array_merge($params, $gparams);
$sessions = array_merge($sessions, $DB->get_records_sql($sql, $params)); $sessions = array_merge($sessions, $DB->get_records_sql($sql, $params));
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', 'attforblock');
} } 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_attforblock', 'session', $sess->id);
} }
@ -1142,7 +1165,8 @@ class attforblock {
$DB->update_record('attendance_sessions', $sess); $DB->update_record('attendance_sessions', $sess);
} }
$this->log('sessions duration updated', $this->url_manage(), get_string('sessionsids', 'attforblock').implode(', ', $sessionsids)); $this->log('sessions duration updated', $this->url_manage(),
get_string('sessionsids', 'attforblock').implode(', ', $sessionsids));
} }
public function remove_status($statusid) { public function remove_status($statusid) {
@ -1223,9 +1247,11 @@ function att_get_statuses($attid, $onlyvisible=true) {
global $DB; global $DB;
if ($onlyvisible) { if ($onlyvisible) {
$statuses = $DB->get_records_select('attendance_statuses', "attendanceid = :aid AND visible = 1 AND deleted = 0", array('aid' => $attid), 'grade DESC'); $statuses = $DB->get_records_select('attendance_statuses', "attendanceid = :aid AND visible = 1 AND deleted = 0",
array('aid' => $attid), 'grade DESC');
} else { } else {
$statuses = $DB->get_records_select('attendance_statuses', "attendanceid = :aid AND deleted = 0", array('aid' => $attid), 'grade DESC'); $statuses = $DB->get_records_select('attendance_statuses', "attendanceid = :aid AND deleted = 0",
array('aid' => $attid), 'grade DESC');
} }
return $statuses; return $statuses;
@ -1303,10 +1329,11 @@ function att_get_user_courses_attendances($userid) {
} }
function att_calc_user_grade_fraction($grade, $maxgrade) { function att_calc_user_grade_fraction($grade, $maxgrade) {
if ($maxgrade == 0) if ($maxgrade == 0) {
return 0; return 0;
else } else {
return $grade / $maxgrade; return $grade / $maxgrade;
}
} }
function att_get_gradebook_maxgrade($attid) { function att_get_gradebook_maxgrade($attid) {

22
manage.php

@ -28,9 +28,9 @@ require_once(dirname(__FILE__).'/locallib.php');
$pageparams = new att_manage_page_params(); $pageparams = new att_manage_page_params();
$id = required_param('id', PARAM_INT); $id = required_param('id', PARAM_INT);
$from = optional_param('from', NULL, PARAM_ACTION); $from = optional_param('from', null, PARAM_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('attforblock', $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);
@ -40,10 +40,11 @@ require_login($course, true, $cm);
$pageparams->init($cm); $pageparams->init($cm);
$att = new attforblock($att, $cm, $course, $PAGE->context, $pageparams); $att = new attforblock($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());
}
// if teacher is coming from block, then check for a session exists for today // If teacher is coming from block, then check for a session exists for today.
if ($from === 'block') { if ($from === 'block') {
$sessions = $att->get_today_sessions(); $sessions = $att->get_today_sessions();
$size = count($sessions); $size = count($sessions);
@ -51,11 +52,12 @@ if ($from === 'block') {
$sess = reset($sessions); $sess = reset($sessions);
$nottaken = !$sess->lasttaken && has_capability('mod/attforblock:takeattendances', $PAGE->context); $nottaken = !$sess->lasttaken && has_capability('mod/attforblock:takeattendances', $PAGE->context);
$canchange = $sess->lasttaken && has_capability('mod/attforblock:changeattendances', $PAGE->context); $canchange = $sess->lasttaken && has_capability('mod/attforblock: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)));
} elseif ($size > 1) { }
} else if ($size > 1) {
$att->curdate = $today; $att->curdate = $today;
//temporally set $view for single access to page from block // Temporarily set $view for single access to page from block.
$att->view = ATT_VIEW_DAYS; $att->view = ATT_VIEW_DAYS;
} }
} }
@ -72,10 +74,10 @@ $tabs = new attforblock_tabs($att, attforblock_tabs::TAB_SESSIONS);
$filtercontrols = new attforblock_filter_controls($att); $filtercontrols = new attforblock_filter_controls($att);
$sesstable = new attforblock_manage_data($att); $sesstable = new attforblock_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', 'attforblock').' :: ' .$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);

11
mod_form.php

@ -23,19 +23,18 @@
*/ */
if (!defined('MOODLE_INTERNAL')) { if (!defined('MOODLE_INTERNAL')) {
die('Direct access to this script is forbidden.'); /// It must be included from a Moodle page die('Direct access to this script is forbidden.');
} }
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_attforblock_mod_form extends moodleform_mod {
function definition() { public function definition() {
global $CFG; global $CFG;
$mform =& $this->_form; $mform =& $this->_form;
//-------------------------------------------------------------------------------
$mform->addElement('header', 'general', get_string('general', 'form')); $mform->addElement('header', 'general', get_string('general', 'form'));
$mform->addElement('text', 'name', get_string('name'), array('size'=>'64')); $mform->addElement('text', 'name', get_string('name'), array('size'=>'64'));
@ -46,12 +45,8 @@ class mod_attforblock_mod_form extends moodleform_mod {
$mform->addElement('modgrade', 'grade', get_string('grade')); $mform->addElement('modgrade', 'grade', get_string('grade'));
$mform->setDefault('grade', 100); $mform->setDefault('grade', 100);
//-------------------------------------------------------------------------------
$this->standard_coursemodule_elements(true); $this->standard_coursemodule_elements(true);
//-------------------------------------------------------------------------------
// buttons
$this->add_action_buttons(); $this->add_action_buttons();
} }

9
module.js

@ -3,20 +3,19 @@ M.mod_attforblock = {}
M.mod_attforblock.init_manage = function(Y) { M.mod_attforblock.init_manage = function(Y) {
Y.on('click', function(e) { Y.on('click', function(e) {
if (e.target.get('checked')) if (e.target.get('checked')) {
checkall(); checkall();
else } else {
checknone(); checknone();
}
}, '#cb_selector' ); }, '#cb_selector' );
}; };
M.mod_attforblock.set_preferences_action = function(action) { M.mod_attforblock.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);
} } else {
else {
item = document.getElementById('preferencesform'); item = document.getElementById('preferencesform');
var input = document.createElement("input"); var input = document.createElement("input");
input.setAttribute("type", "hidden"); input.setAttribute("type", "hidden");

24
preferences.php

@ -28,8 +28,8 @@ require_once(dirname(__FILE__).'/locallib.php');
$pageparams = new att_preferences_page_params(); $pageparams = new att_preferences_page_params();
$id = required_param('id', PARAM_INT); $id = required_param('id', PARAM_INT);
$pageparams->action = optional_param('action', NULL, PARAM_INT); $pageparams->action = optional_param('action', null, PARAM_INT);
$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('attforblock', $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);
@ -50,30 +50,32 @@ $PAGE->navbar->add(get_string('settings', 'attforblock'));
switch ($att->pageparams->action) { switch ($att->pageparams->action) {
case att_preferences_page_params::ACTION_ADD: case att_preferences_page_params::ACTION_ADD:
$newacronym = optional_param('newacronym', null, PARAM_MULTILANG); $newacronym = optional_param('newacronym', null, PARAM_TEXT);
$newdescription = optional_param('newdescription', null, PARAM_MULTILANG); $newdescription = optional_param('newdescription', null, PARAM_TEXT);
$newgrade = optional_param('newgrade', 0, PARAM_INT); $newgrade = optional_param('newgrade', 0, PARAM_INT);
$att->add_status($newacronym, $newdescription, $newgrade); $att->add_status($newacronym, $newdescription, $newgrade);
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', 'attforblock', "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', 'attforblock'));
} }
$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', 'attforblock'));
$message .= str_repeat(html_writer::empty_tag('br'), 2); $message .= str_repeat(html_writer::empty_tag('br'), 2);
$message .= $status->acronym.': '.($status->description ? $status->description : get_string('nodescription', 'attforblock')); $message .= $status->acronym.': '.
($status->description ? $status->description : get_string('nodescription', 'attforblock'));
$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', 'attforblock').' :: ' .$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;
@ -99,10 +101,10 @@ $output = $PAGE->get_renderer('mod_attforblock');
$tabs = new attforblock_tabs($att, attforblock_tabs::TAB_PREFERENCES); $tabs = new attforblock_tabs($att, attforblock_tabs::TAB_PREFERENCES);
$prefdata = new attforblock_preferences_data($att); $prefdata = new attforblock_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', 'attforblock').' :: ' .$course->fullname);
echo $output->render($tabs); echo $output->render($tabs);
echo $output->render($prefdata); echo $output->render($prefdata);

71
renderables.php

@ -51,7 +51,7 @@ class attforblock_tabs implements renderable {
* @param attforblock $att instance * @param attforblock $att instance
* @param $currenttab - one of attforblock_tabs constants * @param $currenttab - one of attforblock_tabs constants
*/ */
public function __construct(attforblock $att, $currenttab=NULL) { public function __construct(attforblock $att, $currenttab=null) {
$this->att = $att; $this->att = $att;
$this->currenttab = $currenttab; $this->currenttab = $currenttab;
} }
@ -66,27 +66,28 @@ 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', 'attforblock'));
} }
if ($this->att->perm->can_manage()) { if ($this->att->perm->can_manage()) {
$toprow[] = new tabobject(self::TAB_ADD, $this->att->url_sessions()->out(true, array('action' => att_sessions_page_params::ACTION_ADD)), $toprow[] = new tabobject(self::TAB_ADD,
get_string('add','attforblock')); $this->att->url_sessions()->out(true, array('action' => att_sessions_page_params::ACTION_ADD)),
get_string('add', 'attforblock'));
} }
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', 'attforblock'));
} }
if ($this->att->perm->can_export()) { if ($this->att->perm->can_export()) {
$toprow[] = new tabobject(self::TAB_EXPORT, $this->att->url_export()->out(), $toprow[] = new tabobject(self::TAB_EXPORT, $this->att->url_export()->out(),
get_string('export','quiz')); get_string('export', 'quiz'));
} }
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', 'attforblock'));
} }
return array($toprow); return array($toprow);
@ -137,7 +138,8 @@ class attforblock_filter_controls implements renderable {
$format = get_string('strftimedm', 'attforblock'); $format = get_string('strftimedm', 'attforblock');
$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)." - ".userdate($att->pageparams->enddate, $format); $this->curdatetxt = userdate($att->pageparams->startdate, $format).
" - ".userdate($att->pageparams->enddate, $format);
break; break;
case ATT_VIEW_MONTHS: case ATT_VIEW_MONTHS:
$format = '%B'; $format = '%B';
@ -228,7 +230,7 @@ class attforblock_manage_data implements renderable {
/** /**
* Must be called without or with both parameters * Must be called without or with both parameters
*/ */
public function url_sessions($sessionid=NULL, $action=NULL) { public function url_sessions($sessionid=null, $action=null) {
return url_helpers::url_sessions($this->att, $sessionid, $action); return url_helpers::url_sessions($this->att, $sessionid, $action);
} }
} }
@ -259,8 +261,7 @@ class attforblock_take_data implements renderable {
public function __construct(attforblock $att) { public function __construct(attforblock $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 {
$this->users = $att->get_users($att->pageparams->group); $this->users = $att->get_users($att->pageparams->group);
} }
@ -275,16 +276,17 @@ class attforblock_take_data implements renderable {
$this->sessioninfo = $att->get_session_info($att->pageparams->sessionid); $this->sessioninfo = $att->get_session_info($att->pageparams->sessionid);
$this->updatemode = $this->sessioninfo->lasttaken > 0; $this->updatemode = $this->sessioninfo->lasttaken > 0;
if (isset($att->pageparams->copyfrom)) if (isset($att->pageparams->copyfrom)) {
$this->sessionlog = $att->get_session_log($att->pageparams->copyfrom); $this->sessionlog = $att->get_session_log($att->pageparams->copyfrom);
elseif ($this->updatemode) } else if ($this->updatemode) {
$this->sessionlog = $att->get_session_log($att->pageparams->sessionid); $this->sessionlog = $att->get_session_log($att->pageparams->sessionid);
else } else {
$this->sessionlog = array(); $this->sessionlog = array();
}
if (!$this->updatemode) {
if (!$this->updatemode)
$this->sessions4copy = $att->get_today_sessions_for_copy($this->sessioninfo); $this->sessions4copy = $att->get_today_sessions_for_copy($this->sessioninfo);
}
$this->urlpath = $att->url_take()->out_omit_querystring(); $this->urlpath = $att->url_take()->out_omit_querystring();
$params = $att->pageparams->get_significant_params(); $params = $att->pageparams->get_significant_params();
@ -297,8 +299,9 @@ class attforblock_take_data implements renderable {
public function url($params=array(), $excludeparams=array()) { public function url($params=array(), $excludeparams=array()) {
$params = array_merge($this->urlparams, $params); $params = array_merge($this->urlparams, $params);
foreach ($excludeparams as $paramkey) foreach ($excludeparams as $paramkey) {
unset($params[$paramkey]); unset($params[$paramkey]);
}
return new moodle_url($this->urlpath, $params); return new moodle_url($this->urlpath, $params);
} }
@ -362,14 +365,12 @@ 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 attforblock_filter_controls($att);
$this->sessionslog = $att->get_user_filtered_sessions_log_extended($userid); $this->sessionslog = $att->get_user_filtered_sessions_log_extended($userid);
$this->groups = groups_get_all_groups($att->course->id); $this->groups = groups_get_all_groups($att->course->id);
} } else {
else {
$this->coursesatts = att_get_user_courses_attendances($userid); $this->coursesatts = att_get_user_courses_attendances($userid);
$this->statuses = array(); $this->statuses = array();
@ -397,11 +398,10 @@ class attforblock_user_data implements renderable {
// * all sessions between user start enrolment date and now; // * all sessions between user start enrolment date and now;
// * all sessions between user start and end enrolment date. // * all sessions between user start and end enrolment date.
$this->maxgrade[$ca->attid] = att_get_user_max_grade($user_taken_sessions_count, $statuses); $this->maxgrade[$ca->attid] = att_get_user_max_grade($user_taken_sessions_count, $statuses);
} } else {
else { // For more comfortable and universal work with arrays.
//for more comfortable and universal work with arrays $this->grade[$ca->attid] = null;
$this->grade[$ca->attid] = NULL; $this->maxgrade[$ca->attid] = null;
$this->maxgrade[$ca->attid] = NULL;
} }
} }
} }
@ -428,7 +428,7 @@ class attforblock_report_data implements renderable {
public $sessions; public $sessions;
public $statuses; public $statuses;
// includes disablrd/deleted statuses // Includes disablrd/deleted statuses.
public $allstatuses; public $allstatuses;
public $gradable; public $gradable;
@ -508,14 +508,17 @@ class attforblock_preferences_data implements renderable {
public function __construct(attforblock $att) { public function __construct(attforblock $att) {
$this->statuses = $att->get_statuses(false); $this->statuses = $att->get_statuses(false);
foreach ($this->statuses as $st) $st->haslogs = att_has_logs_for_status ($st->id); foreach ($this->statuses as $st) {
$st->haslogs = att_has_logs_for_status ($st->id);
}
$this->att = $att; $this->att = $att;
} }
public function url($params=array(), $significant_params=TRUE) { public function url($params=array(), $significant_params=true) {
if ($significant_params) if ($significant_params) {
$params = array_merge($this->att->pageparams->get_significant_params(), $params); $params = array_merge($this->att->pageparams->get_significant_params(), $params);
}
return $this->att->url_preferences($params); return $this->att->url_preferences($params);
} }
@ -524,8 +527,9 @@ class attforblock_preferences_data implements renderable {
class url_helpers { class url_helpers {
public static function url_take($att, $sessionid, $grouptype) { public static function url_take($att, $sessionid, $grouptype) {
$params = array('sessionid' => $sessionid); $params = array('sessionid' => $sessionid);
if (isset($grouptype)) if (isset($grouptype)) {
$params['grouptype'] = $grouptype; $params['grouptype'] = $grouptype;
}
return $att->url_take($params); return $att->url_take($params);
} }
@ -533,11 +537,12 @@ class url_helpers {
/** /**
* Must be called without or with both parameters * Must be called without or with both parameters
*/ */
public static function url_sessions($att, $sessionid=NULL, $action=NULL) { public static function url_sessions($att, $sessionid=null, $action=null) {
if (isset($sessionid) && isset($action)) if (isset($sessionid) && isset($action)) {
$params = array('sessionid' => $sessionid, 'action' => $action); $params = array('sessionid' => $sessionid, 'action' => $action);
else } else {
$params = array(); $params = array();
}
return $att->url_sessions($params); return $att->url_sessions($params);
} }

188
renderer.php

@ -34,10 +34,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_attforblock_renderer extends plugin_renderer_base {
// External API - methods to render attendance renderable components.
////////////////////////////////////////////////////////////////////////////
// External API - methods to render attendance renderable components
////////////////////////////////////////////////////////////////////////////
/** /**
* Renders tabs for attendance * Renders tabs for attendance
@ -46,7 +43,7 @@ class mod_attforblock_renderer extends plugin_renderer_base {
* @return string html code * @return string html code
*/ */
protected function render_attforblock_tabs(attforblock_tabs $atttabs) { protected function render_attforblock_tabs(attforblock_tabs $atttabs) {
return print_tabs($atttabs->get_tabs(), $atttabs->currenttab, NULL, NULL, true); return print_tabs($atttabs->get_tabs(), $atttabs->currenttab, null, null, true);
} }
/** /**
@ -100,15 +97,16 @@ class mod_attforblock_renderer extends plugin_renderer_base {
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'), 'attforblock');
$jsvals = array( $jsvals = array(
'cal_months' => explode(',', get_string('calmonths','attforblock')), 'cal_months' => explode(',', get_string('calmonths', 'attforblock')),
'cal_week_days' => explode(',', get_string('calweekdays','attforblock')), 'cal_week_days' => explode(',', get_string('calweekdays', 'attforblock')),
'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.attforblock', $jsvals));
$this->page->requires->js('/mod/attforblock/calendar.js'); $this->page->requires->js('/mod/attforblock/calendar.js');
$curdate_controls .= html_writer::link($fcontrols->url(array('curdate' => $fcontrols->prevcur)), $this->output->larrow()); $curdate_controls .= html_writer::link($fcontrols->url(array('curdate' => $fcontrols->prevcur)),
$this->output->larrow());
$params = array( $params = array(
'title' => get_string('calshow', 'attforblock'), 'title' => get_string('calshow', 'attforblock'),
'id' => 'show', 'id' => 'show',
@ -131,7 +129,8 @@ class mod_attforblock_renderer extends plugin_renderer_base {
$button_form = html_writer::tag('form', $button_form, $params); $button_form = html_writer::tag('form', $button_form, $params);
$curdate_controls .= $button_form; $curdate_controls .= $button_form;
$curdate_controls .= html_writer::link($fcontrols->url(array('curdate' => $fcontrols->nextcur)), $this->output->rarrow()); $curdate_controls .= html_writer::link($fcontrols->url(array('curdate' => $fcontrols->nextcur)),
$this->output->rarrow());
} }
return $curdate_controls; return $curdate_controls;
@ -148,10 +147,10 @@ class mod_attforblock_renderer extends plugin_renderer_base {
if ($key != $fcontrols->pageparams->view) { if ($key != $fcontrols->pageparams->view) {
$link = html_writer::link($fcontrols->url(array('view' => $key)), $sview); $link = html_writer::link($fcontrols->url(array('view' => $key)), $sview);
$viewcontrols .= html_writer::tag('span', $link, array('class' => 'attbtn')); $viewcontrols .= html_writer::tag('span', $link, array('class' => 'attbtn'));
} } else {
else
$viewcontrols .= html_writer::tag('span', $sview, array('class' => 'attcurbtn')); $viewcontrols .= html_writer::tag('span', $sview, array('class' => 'attcurbtn'));
} }
}
return html_writer::tag('nobr', $viewcontrols); return html_writer::tag('nobr', $viewcontrols);
} }
@ -181,7 +180,7 @@ class mod_attforblock_renderer extends plugin_renderer_base {
get_string('sessiontypeshort', 'attforblock'), get_string('sessiontypeshort', 'attforblock'),
get_string('date'), get_string('date'),
get_string('time'), get_string('time'),
get_string('description','attforblock'), get_string('description', 'attforblock'),
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 +194,8 @@ class mod_attforblock_renderer extends plugin_renderer_base {
$dta = $this->construct_date_time_actions($sessdata, $sess); $dta = $this->construct_date_time_actions($sessdata, $sess);
$table->data[$sess->id][] = $i; $table->data[$sess->id][] = $i;
$table->data[$sess->id][] = $sess->groupid ? $sessdata->groups[$sess->groupid]->name : get_string('commonsession', 'attforblock'); $table->data[$sess->id][] = $sess->groupid ? $sessdata->groups[$sess->groupid]->name :
get_string('commonsession', 'attforblock');
$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;
@ -211,11 +211,10 @@ class mod_attforblock_renderer extends plugin_renderer_base {
$date = userdate($sess->sessdate, get_string('strftimedmyw', 'attforblock')); $date = userdate($sess->sessdate, get_string('strftimedmyw', 'attforblock'));
$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', 'attforblock');
$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));
@ -228,17 +227,17 @@ 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', 'attforblock');
$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', 'attforblock');
$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', 'attforblock');
$actions .= $this->output->action_icon($url, new pix_icon('t/delete', $title)); $actions .= $this->output->action_icon($url, new pix_icon('t/delete', $title));
} }
@ -265,7 +264,7 @@ 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', 'attforblock'); // You can't do anything.
} }
$table->data[0][] = $controls; $table->data[0][] = $controls;
@ -275,14 +274,15 @@ class mod_attforblock_renderer extends plugin_renderer_base {
protected function render_attforblock_take_data(attforblock_take_data $takedata) { protected function render_attforblock_take_data(attforblock_take_data $takedata) {
$controls = $this->render_attforblock_take_controls($takedata); $controls = $this->render_attforblock_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_attforblock_take_list($takedata);
else } else {
$table = $this->render_attforblock_take_grid($takedata); $table = $this->render_attforblock_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', 'attforblock'));
$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()));
@ -324,19 +324,20 @@ 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', 'attforblock'),
att_take_page_params::SORTED_GRID => get_string('sortedgrid','attforblock')); att_take_page_params::SORTED_GRID => get_string('sortedgrid', 'attforblock'));
$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', 'attforblock'));
$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'),'3 '.get_string('columns','attforblock'), $options = array (1 => '1 '.get_string('column', 'attforblock'), '2 '.get_string('columns', 'attforblock'),
'4 '.get_string('columns','attforblock'),'5 '.get_string('columns','attforblock'),'6 '.get_string('columns','attforblock'), '3 '.get_string('columns', 'attforblock'), '4 '.get_string('columns', 'attforblock'),
'7 '.get_string('columns','attforblock'),'8 '.get_string('columns','attforblock'),'9 '.get_string('columns','attforblock'), '5 '.get_string('columns', 'attforblock'), '6 '.get_string('columns', 'attforblock'),
'10 '.get_string('columns','attforblock')); '7 '.get_string('columns', 'attforblock'), '8 '.get_string('columns', 'attforblock'),
$select = new single_select($takedata->url(), 'gridcols', $options, $takedata->pageparams->gridcols, NULL); '9 '.get_string('columns', 'attforblock'), '10 '.get_string('columns', 'attforblock'));
$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,11 +349,12 @@ 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', 'attforblock'));
$end = $sess->duration ? ' - '.userdate($sess->sessdate + $sess->duration, get_string('strftimehm', 'attforblock')) : ''; $end = $sess->duration ? ' - '.userdate($sess->sessdate + $sess->duration,
get_string('strftimehm', 'attforblock')) : '';
$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', 'attforblock'));
$select->class = 'singleselect inline'; $select->class = 'singleselect inline';
$controls .= $this->output->render($select); $controls .= $this->output->render($select);
} }
@ -371,7 +373,8 @@ class mod_attforblock_renderer extends plugin_renderer_base {
$table->size = array('20px', ''); $table->size = array('20px', '');
$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, array('title' => get_string('setallstatusesto', 'attforblock', $st->description))); $table->head[] = html_writer::link("javascript:select_all_in(null, 'st" . $st->id . "', null);", $st->acronym,
array('title' => get_string('setallstatusesto', 'attforblock', $st->description)));
$table->align[] = 'center'; $table->align[] = 'center';
$table->size[] = '20px'; $table->size[] = '20px';
} }
@ -399,11 +402,13 @@ class mod_attforblock_renderer extends plugin_renderer_base {
$cell = new html_table_cell($ucdata['text']); $cell = new html_table_cell($ucdata['text']);
$cell->colspan = $ucdata['colspan']; $cell->colspan = $ucdata['colspan'];
$row->cells[] = $cell; $row->cells[] = $cell;
} } else {
else
$row->cells = array_merge($row->cells, $ucdata['text']); $row->cells = array_merge($row->cells, $ucdata['text']);
}
if (array_key_exists('class', $ucdata)) $row->attributes['class'] = $ucdata['class']; if (array_key_exists('class', $ucdata)) {
$row->attributes['class'] = $ucdata['class'];
}
$table->data[] = $row; $table->data[] = $row;
} }
@ -421,13 +426,14 @@ class mod_attforblock_renderer extends plugin_renderer_base {
$table->headspan = $takedata->pageparams->gridcols; $table->headspan = $takedata->pageparams->gridcols;
$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, array('title' => get_string('setallstatusesto', 'attforblock', $st->description))); $head[] = html_writer::link("javascript:select_all_in(null, 'st" . $st->id . "', null);", $st->acronym,
array('title' => get_string('setallstatusesto', 'attforblock', $st->description)));
} }
$table->head[] = implode('&nbsp;&nbsp;', $head); $table->head[] = implode('&nbsp;&nbsp;', $head);
$i = 0; $i = 0;
$row = new html_table_row(); $row = new html_table_row();
foreach($takedata->users as $user) { foreach ($takedata->users as $user) {
$celltext = $this->output->user_picture($user, array('size' => 100)); $celltext = $this->output->user_picture($user, array('size' => 100));
$celltext .= html_writer::empty_tag('br'); $celltext .= html_writer::empty_tag('br');
$fullname = html_writer::link($takedata->url_view(array('studentid' => $user->id)), fullname($user)); $fullname = html_writer::link($takedata->url_view(array('studentid' => $user->id)), fullname($user));
@ -441,7 +447,9 @@ class mod_attforblock_renderer extends plugin_renderer_base {
} }
$cell = new html_table_cell($celltext); $cell = new html_table_cell($celltext);
if (array_key_exists('class', $ucdata)) $cell->attributes['class'] = $ucdata['class']; if (array_key_exists('class', $ucdata)) {
$cell->attributes['class'] = $ucdata['class'];
}
$row->cells[] = $cell; $row->cells[] = $cell;
$i++; $i++;
@ -450,7 +458,9 @@ class mod_attforblock_renderer extends plugin_renderer_base {
$row = new html_table_row(); $row = new html_table_row();
} }
} }
if ($i % $takedata->pageparams->gridcols > 0) $table->data[] = $row; if ($i % $takedata->pageparams->gridcols > 0) {
$table->data[] = $row;
}
return html_writer::table($table); return html_writer::table($table);
} }
@ -458,15 +468,17 @@ class mod_attforblock_renderer extends plugin_renderer_base {
private function construct_fullname_head($data) { private function construct_fullname_head($data) {
global $CFG; global $CFG;
if ($data->pageparams->sort == ATT_SORT_LASTNAME) if ($data->pageparams->sort == ATT_SORT_LASTNAME) {
$firstname = html_writer::link($data->url(array('sort' => ATT_SORT_FIRSTNAME)), get_string('firstname')); $firstname = html_writer::link($data->url(array('sort' => ATT_SORT_FIRSTNAME)), get_string('firstname'));
else } else {
$firstname = get_string('firstname'); $firstname = get_string('firstname');
}
if ($data->pageparams->sort == ATT_SORT_FIRSTNAME) if ($data->pageparams->sort == ATT_SORT_FIRSTNAME) {
$lastname = html_writer::link($data->url(array('sort' => ATT_SORT_LASTNAME)), get_string('lastname')); $lastname = html_writer::link($data->url(array('sort' => ATT_SORT_LASTNAME)), get_string('lastname'));
else } else {
$lastname = get_string('lastname'); $lastname = get_string('lastname');
}
if ($CFG->fullnamedisplay == 'lastname firstname') { if ($CFG->fullnamedisplay == 'lastname firstname') {
$fullnamehead = "$lastname / $firstname"; $fullnamehead = "$lastname / $firstname";
@ -483,16 +495,15 @@ class mod_attforblock_renderer extends plugin_renderer_base {
$celldata['text'] = get_string('enrolmentend', 'attforblock', userdate($user->enrolmentend, '%d.%m.%Y')); $celldata['text'] = get_string('enrolmentend', 'attforblock', 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) {
// no enrolmentend and ENROL_USER_SUSPENDED // No enrolmentend and ENROL_USER_SUSPENDED.
elseif (!$user->enrolmentend and $user->enrolmentstatus == ENROL_USER_SUSPENDED) {
$celldata['text'] = get_string('enrolmentsuspended', 'attforblock'); $celldata['text'] = get_string('enrolmentsuspended', 'attforblock');
$celldata['colspan'] = count($takedata->statuses) + 1; $celldata['colspan'] = count($takedata->statuses) + 1;
$celldata['class'] = 'userwithoutenrol'; $celldata['class'] = 'userwithoutenrol';
} } else {
else { if ($takedata->updatemode and !array_key_exists($user->id, $takedata->sessionlog)) {
if ($takedata->updatemode and !array_key_exists($user->id, $takedata->sessionlog))
$celldata['class'] = 'userwithoutdata'; $celldata['class'] = 'userwithoutdata';
}
$celldata['text'] = array(); $celldata['text'] = array();
foreach ($takedata->statuses as $st) { foreach ($takedata->statuses as $st) {
@ -501,25 +512,29 @@ class mod_attforblock_renderer extends plugin_renderer_base {
'name' => 'user'.$user->id, 'name' => 'user'.$user->id,
'class' => 'st'.$st->id, 'class' => 'st'.$st->id,
'value' => $st->id); 'value' => $st->id);
if (array_key_exists($user->id, $takedata->sessionlog) and $st->id == $takedata->sessionlog[$user->id]->statusid) if (array_key_exists($user->id, $takedata->sessionlog) and $st->id == $takedata->sessionlog[$user->id]->statusid) {
$params['checked'] = ''; $params['checked'] = '';
}
$input = html_writer::empty_tag('input', $params); $input = html_writer::empty_tag('input', $params);
if ($takedata->pageparams->viewmode == att_take_page_params::SORTED_GRID) if ($takedata->pageparams->viewmode == att_take_page_params::SORTED_GRID) {
$input = html_writer::tag('nobr', $input . $st->acronym); $input = html_writer::tag('nobr', $input . $st->acronym);
}
$celldata['text'][] = $input; $celldata['text'][] = $input;
} }
$params = array( $params = array(
'type' => 'text', 'type' => 'text',
'name' => 'remarks'.$user->id); 'name' => 'remarks'.$user->id);
if (array_key_exists($user->id, $takedata->sessionlog)) if (array_key_exists($user->id, $takedata->sessionlog)) {
$params['value'] = $takedata->sessionlog[$user->id]->remarks; $params['value'] = $takedata->sessionlog[$user->id]->remarks;
}
$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', userdate($user->enrolmentstart, '%H:%M %d.%m.%Y')); $celldata['warning'] = get_string('enrolmentstart', 'attforblock',
userdate($user->enrolmentstart, '%H:%M %d.%m.%Y'));
$celldata['class'] = 'userwithoutenrol'; $celldata['class'] = 'userwithoutenrol';
} }
} }
@ -547,13 +562,13 @@ class mod_attforblock_renderer extends plugin_renderer_base {
$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', 'attforblock'));
$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', 'attforblock'));
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(attforblock_user_data $userdata) {
@ -568,8 +583,7 @@ class mod_attforblock_renderer extends plugin_renderer_base {
$o .= $this->render_attforblock_filter_controls($userdata->filtercontrols); $o .= $this->render_attforblock_filter_controls($userdata->filtercontrols);
$o .= $this->construct_user_sessions_log($userdata); $o .= $this->construct_user_sessions_log($userdata);
} } else {
else {
$prevcid = 0; $prevcid = 0;
foreach ($userdata->coursesatts as $ca) { foreach ($userdata->coursesatts as $ca) {
if ($prevcid != $ca->courseid) { if ($prevcid != $ca->courseid) {
@ -597,9 +611,9 @@ class mod_attforblock_renderer extends plugin_renderer_base {
get_string('sessiontypeshort', 'attforblock'), get_string('sessiontypeshort', 'attforblock'),
get_string('date'), get_string('date'),
get_string('time'), get_string('time'),
get_string('description','attforblock'), get_string('description', 'attforblock'),
get_string('status','attforblock'), get_string('status', 'attforblock'),
get_string('remarks','attforblock') get_string('remarks', 'attforblock')
); );
$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');
@ -610,25 +624,25 @@ 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 : get_string('commonsession', 'attforblock')); $row->cells[] = html_writer::tag('nobr', $sess->groupid ? $userdata->groups[$sess->groupid]->name :
get_string('commonsession', 'attforblock'));
$row->cells[] = userdate($sess->sessdate, get_string('strftimedmyw', 'attforblock')); $row->cells[] = userdate($sess->sessdate, get_string('strftimedmyw', 'attforblock'));
$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) {
elseif ($sess->sessdate < $userdata->user->enrolmentstart) { $cell = new html_table_cell(get_string('enrolmentstart', 'attforblock',
$cell = new html_table_cell(get_string('enrolmentstart', 'attforblock', 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) {
elseif ($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', 'attforblock', 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;
} } else {
else {
$row->cells[] = '?'; $row->cells[] = '?';
$row->cells[] = ''; $row->cells[] = '';
} }
@ -650,7 +664,7 @@ class mod_attforblock_renderer extends plugin_renderer_base {
$table->attributes['class'] = 'generaltable attwidth'; $table->attributes['class'] = 'generaltable attwidth';
// user picture // User picture.
$table->head[] = ''; $table->head[] = '';
$table->align[] = 'left'; $table->align[] = 'left';
$table->size[] = '1px'; $table->size[] = '1px';
@ -663,8 +677,9 @@ class mod_attforblock_renderer extends plugin_renderer_base {
$sesstext = userdate($sess->sessdate, get_string('strftimedm', 'attforblock')); $sesstext = userdate($sess->sessdate, get_string('strftimedm', 'attforblock'));
$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', 'attforblock').')');
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', 'attforblock');
@ -694,12 +709,13 @@ class mod_attforblock_renderer extends plugin_renderer_base {
$row->cells = array_merge($row->cells, $cellsgenerator->get_cells()); $row->cells = array_merge($row->cells, $cellsgenerator->get_cells());
foreach ($reportdata->statuses as $status) { foreach ($reportdata->statuses as $status) {
if (array_key_exists($status->id, $reportdata->usersstats[$user->id])) if (array_key_exists($status->id, $reportdata->usersstats[$user->id])) {
$row->cells[] = $reportdata->usersstats[$user->id][$status->id]->stcnt; $row->cells[] = $reportdata->usersstats[$user->id][$status->id]->stcnt;
else } else {
// no attendance data for this $status => no statistic for this status // No attendance data for this $status => no statistic for this status.
$row->cells[] = 0; $row->cells[] = 0;
} }
}
if ($reportdata->gradable) { if ($reportdata->gradable) {
$row->cells[] = $reportdata->grades[$user->id].' / '.$reportdata->maxgrades[$user->id]; $row->cells[] = $reportdata->grades[$user->id].' / '.$reportdata->maxgrades[$user->id];
@ -738,13 +754,15 @@ 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'), att_preferences_page_params::ACTION_ADD); $table->data[$i][] = $this->construct_preferences_button(get_string('add', 'attforblock'),
att_preferences_page_params::ACTION_ADD);
$o = html_writer::tag('h1', get_string('myvariables','attforblock')); $o = html_writer::tag('h1', get_string('myvariables', 'attforblock'));
$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', 'attforblock'), att_preferences_page_params::ACTION_SAVE);
$o = html_writer::tag('form', $o, array('id' => 'preferencesform', 'method' => 'post', 'action' => $prefdata->url(array(), false)->out_omit_querystring())); $o = html_writer::tag('form', $o, array('id' => 'preferencesform', 'method' => 'post',
'action' => $prefdata->url(array(), false)->out_omit_querystring()));
$o = $this->output->container($o, 'generalbox attwidth'); $o = $this->output->container($o, 'generalbox attwidth');
return $o; return $o;
@ -770,8 +788,7 @@ class mod_attforblock_renderer extends plugin_renderer_base {
$showhideicon = $OUTPUT->action_icon( $showhideicon = $OUTPUT->action_icon(
$prefdata->url($params), $prefdata->url($params),
new pix_icon("t/hide", get_string('hide'))); new pix_icon("t/hide", get_string('hide')));
} } else {
else {
$params = array( $params = array(
'action' => att_preferences_page_params::ACTION_SHOW, 'action' => att_preferences_page_params::ACTION_SHOW,
'statusid' => $st->id); 'statusid' => $st->id);
@ -786,8 +803,9 @@ class mod_attforblock_renderer extends plugin_renderer_base {
$deleteicon = $OUTPUT->action_icon( $deleteicon = $OUTPUT->action_icon(
$prefdata->url($params), $prefdata->url($params),
new pix_icon("t/delete", get_string('delete'))); new pix_icon("t/delete", get_string('delete')));
} else {
$deleteicon = '';
} }
else $deleteicon = '';
return $showhideicon . $deleteicon; return $showhideicon . $deleteicon;
} }

47
renderhelpers.php

@ -54,24 +54,22 @@ class user_sessions_cells_generator {
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', 'attforblock', 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) {
elseif ($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', 'attforblock', 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) {
// no enrolmentend and ENROL_USER_SUSPENDED // No enrolmentend and ENROL_USER_SUSPENDED.
elseif (!$this->user->enrolmentend and $this->user->enrolmentstatus == ENROL_USER_SUSPENDED) {
$suspendext = get_string('enrolmentsuspended', 'attforblock', userdate($this->user->enrolmentend, '%d.%m.%Y')); $suspendext = get_string('enrolmentsuspended', 'attforblock', 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]))
$this->construct_not_taken_cell('?'); $this->construct_not_taken_cell('?');
else } else {
$this->construct_not_existing_for_user_session_cell(''); $this->construct_not_existing_for_user_session_cell('');
} }
} }
} }
}
$this->finalize_cells(); $this->finalize_cells();
return $this->cells; return $this->cells;
@ -102,7 +100,6 @@ class user_sessions_cells_generator {
} }
protected function finalize_cells() { protected function finalize_cells() {
} }
} }
@ -122,19 +119,18 @@ class user_sessions_cells_html_generator extends user_sessions_cells_generator {
if (is_null($this->cell)) { if (is_null($this->cell)) {
$this->cell = new html_table_cell($text); $this->cell = new html_table_cell($text);
$this->cell->colspan = 1; $this->cell->colspan = 1;
} } else {
else {
if ($this->cell->text != $text) { if ($this->cell->text != $text) {
$this->cells[] = $this->cell; $this->cells[] = $this->cell;
$this->cell = new html_table_cell($text); $this->cell = new html_table_cell($text);
$this->cell->colspan = 1; $this->cell->colspan = 1;
} } else {
else
$this->cell->colspan++; $this->cell->colspan++;
} }
} }
}
private function close_open_cell_if_needed(){ private function close_open_cell_if_needed() {
if ($this->cell) { if ($this->cell) {
$this->cells[] = $this->cell; $this->cells[] = $this->cell;
$this->cell = null; $this->cell = null;
@ -152,9 +148,10 @@ class user_sessions_cells_html_generator extends user_sessions_cells_generator {
} }
protected function finalize_cells() { protected function finalize_cells() {
if ($this->cell) if ($this->cell) {
$this->cells[] = $this->cell; $this->cells[] = $this->cell;
} }
}
} }
class user_sessions_cells_text_generator extends user_sessions_cells_generator { class user_sessions_cells_text_generator extends user_sessions_cells_generator {
@ -168,10 +165,10 @@ class user_sessions_cells_text_generator extends user_sessions_cells_generator {
if ($this->enrolments_info_cell_text != $text) { if ($this->enrolments_info_cell_text != $text) {
$this->enrolments_info_cell_text = $text; $this->enrolments_info_cell_text = $text;
$this->cells[] = $text; $this->cells[] = $text;
} } else {
else
$this->cells[] = '←'; $this->cells[] = '←';
} }
}
} }
function construct_session_time($datetime, $duration) { function construct_session_time($datetime, $duration) {
@ -194,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', 'attforblock').':';
$row->cells[] = $stat['completed']; $row->cells[] = $stat['completed'];
$stattable->data[] = $row; $stattable->data[] = $row;
@ -208,12 +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') . $OUTPUT->help_icon('gradebookexplanation', 'attforblock') . ':'; $row->cells[] = get_string('attendancegrade', 'attforblock') .
$OUTPUT->help_icon('gradebookexplanation', 'attforblock') . ':';
$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', 'attforblock') . ':';
if ($maxgrade == 0) { if ($maxgrade == 0) {
$percent = 0; $percent = 0;
} else { } else {
@ -228,7 +226,6 @@ function construct_user_data_stat($stat, $statuses, $gradable, $grade, $maxgrade
function construct_full_user_stat_html_table($attforblock, $course, $user) { function construct_full_user_stat_html_table($attforblock, $course, $user) {
global $CFG; global $CFG;
$gradeable = $attforblock->grade > 0; $gradeable = $attforblock->grade > 0;
$statuses = att_get_statuses($attforblock->id); $statuses = att_get_statuses($attforblock->id);
$userstatusesstat = att_get_user_statuses_stat($attforblock->id, $course->startdate, $user->id); $userstatusesstat = att_get_user_statuses_stat($attforblock->id, $course->startdate, $user->id);
@ -236,12 +233,12 @@ function construct_full_user_stat_html_table($attforblock, $course, $user) {
$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, $user->id), $statuses); $maxgrade = att_get_user_max_grade(att_get_user_taken_sessions_count($attforblock->id, $course->startdate,
$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;
} }
} } else {
else {
$grade = 0; $grade = 0;
$maxgrade = 0; $maxgrade = 0;
$decimalpoints = 0; $decimalpoints = 0;

14
report.php

@ -28,9 +28,9 @@ require_once(dirname(__FILE__).'/locallib.php');
$pageparams = new att_report_page_params(); $pageparams = new att_report_page_params();
$id = required_param('id', PARAM_INT); $id = required_param('id', PARAM_INT);
$from = optional_param('from', NULL, PARAM_ACTION); $from = optional_param('from', null, PARAM_ACTION);
$pageparams->view = optional_param('view', NULL, PARAM_INT); $pageparams->view = optional_param('view', null, PARAM_INT);
$pageparams->curdate = optional_param('curdate', NULL, PARAM_INT); $pageparams->curdate = optional_param('curdate', null, PARAM_INT);
$pageparams->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);
@ -47,11 +47,11 @@ $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', 'attforblock'));
$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, 'attforblock'));
$PAGE->navbar->add(get_string('report','attforblock')); $PAGE->navbar->add(get_string('report', 'attforblock'));
$output = $PAGE->get_renderer('mod_attforblock'); $output = $PAGE->get_renderer('mod_attforblock');
$tabs = new attforblock_tabs($att, attforblock_tabs::TAB_REPORT); $tabs = new attforblock_tabs($att, attforblock_tabs::TAB_REPORT);
@ -61,10 +61,10 @@ $reportdata = new attforblock_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);
/// 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', 'attforblock').' :: ' .$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);

49
sessions.php

@ -59,7 +59,7 @@ switch ($att->pageparams->action) {
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', 'attforblock'));
} }
break; break;
case att_sessions_page_params::ACTION_UPDATE: case att_sessions_page_params::ACTION_UPDATE:
@ -76,17 +76,17 @@ 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', 'attforblock'));
} }
break; break;
case att_sessions_page_params::ACTION_DELETE: case att_sessions_page_params::ACTION_DELETE:
$sessionid = required_param('sessionid', PARAM_INT); $sessionid = required_param('sessionid', PARAM_INT);
$confirm = optional_param('confirm', NULL, PARAM_INT); $confirm = optional_param('confirm', null, PARAM_INT);
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', 'attforblock'));
} }
$sessinfo = $att->get_session_info($sessionid); $sessinfo = $att->get_session_info($sessionid);
@ -100,12 +100,12 @@ switch ($att->pageparams->action) {
$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', 'attforblock').' :: ' .$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;
case att_sessions_page_params::ACTION_DELETE_SELECTED: case att_sessions_page_params::ACTION_DELETE_SELECTED:
$confirm = optional_param('confirm', NULL, PARAM_INT); $confirm = optional_param('confirm', null, PARAM_INT);
if (isset($confirm)) { if (isset($confirm)) {
$sessionsids = required_param('sessionsids', PARAM_ALPHANUMEXT); $sessionsids = required_param('sessionsids', PARAM_ALPHANUMEXT);
@ -113,13 +113,14 @@ 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', 'attforblock'));
} }
$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', 'attforblock', $att->url_manage());
}
$sessionsinfo = $att->get_sessions_info($fromform->sessid); $sessionsinfo = $att->get_sessions_info($fromform->sessid);
@ -136,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', 'attforblock').' :: ' .$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;
@ -156,11 +157,12 @@ 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', 'attforblock'));
} }
if ($slist === '') if ($slist === '') {
print_error ('nosessionsselected','attforblock', $att->url_manage()); print_error('nosessionsselected', 'attforblock', $att->url_manage());
}
break; break;
} }
@ -168,7 +170,7 @@ switch ($att->pageparams->action) {
$output = $PAGE->get_renderer('mod_attforblock'); $output = $PAGE->get_renderer('mod_attforblock');
$tabs = new attforblock_tabs($att, attforblock_tabs::TAB_ADD); $tabs = new attforblock_tabs($att, attforblock_tabs::TAB_ADD);
echo $output->header(); echo $output->header();
echo $output->heading(get_string('attendanceforthecourse','attforblock').' :: ' .$course->fullname); echo $output->heading(get_string('attendanceforthecourse', 'attforblock').' :: ' .$course->fullname);
echo $output->render($tabs); echo $output->render($tabs);
$mform->display(); $mform->display();
@ -185,17 +187,19 @@ function construct_sessions_data_for_add($formdata) {
if (isset($formdata->addmultiply)) { if (isset($formdata->addmultiply)) {
$startdate = $formdata->sessiondate; $startdate = $formdata->sessiondate;
$starttime = $startdate - usergetmidnight($startdate); $starttime = $startdate - usergetmidnight($startdate);
$enddate = $formdata->sessionenddate + DAYSECS; // because enddate in 0:0am $enddate = $formdata->sessionenddate + DAYSECS; // Because enddate in 0:0am.
if ($enddate < $startdate) return NULL; if ($enddate < $startdate) {
return null;
}
$days = (int)ceil(($enddate - $startdate) / DAYSECS); $days = (int)ceil(($enddate - $startdate) / DAYSECS);
// Getting first day of week // Getting first day of week.
$sdate = $startdate; $sdate = $startdate;
$dinfo = usergetdate($sdate); $dinfo = usergetdate($sdate);
if ($CFG->calendar_startwday === '0') { //week start from sunday if ($CFG->calendar_startwday === '0') { // Week start from sunday.
$startweek = $startdate - $dinfo['wday'] * DAYSECS; //call new variable $startweek = $startdate - $dinfo['wday'] * DAYSECS; // Call new variable.
} else { } else {
$wday = $dinfo['wday'] === 0 ? 7 : $dinfo['wday']; $wday = $dinfo['wday'] === 0 ? 7 : $dinfo['wday'];
$startweek = $startdate - ($wday-1) * DAYSECS; $startweek = $startdate - ($wday-1) * DAYSECS;
@ -204,9 +208,9 @@ function construct_sessions_data_for_add($formdata) {
$wdaydesc = array(0=>'Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'); $wdaydesc = array(0=>'Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat');
while ($sdate < $enddate) { while ($sdate < $enddate) {
if($sdate < $startweek + WEEKSECS) { if ($sdate < $startweek + WEEKSECS) {
$dinfo = usergetdate($sdate); $dinfo = usergetdate($sdate);
if(array_key_exists($wdaydesc[$dinfo['wday']], $formdata->sdays)) { if (array_key_exists($wdaydesc[$dinfo['wday']], $formdata->sdays)) {
$sess = new stdClass(); $sess = new stdClass();
$sess->sessdate = usergetmidnight($sdate) + $starttime; $sess->sessdate = usergetmidnight($sdate) + $starttime;
$sess->duration = $duration; $sess->duration = $duration;
@ -243,8 +247,7 @@ function fill_groupid($formdata, &$sessions, $sess) {
$sess = clone $sess; $sess = clone $sess;
$sess->groupid = 0; $sess->groupid = 0;
$sessions[] = $sess; $sessions[] = $sess;
} } else {
else {
foreach ($formdata->groups as $groupid) { foreach ($formdata->groups as $groupid) {
$sess = clone $sess; $sess = clone $sess;
$sess->groupid = $groupid; $sess->groupid = $groupid;

4
take.php

@ -66,10 +66,10 @@ $output = $PAGE->get_renderer('mod_attforblock');
$tabs = new attforblock_tabs($att); $tabs = new attforblock_tabs($att);
$sesstable = new attforblock_take_data($att); $sesstable = new attforblock_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', 'attforblock').' :: ' .$course->fullname);
echo $output->render($tabs); echo $output->render($tabs);
echo $output->render($sesstable); echo $output->render($sesstable);

28
update_form.php

@ -26,8 +26,7 @@
require_once($CFG->libdir.'/formslib.php'); require_once($CFG->libdir.'/formslib.php');
class mod_attforblock_update_form extends moodleform { class mod_attforblock_update_form extends moodleform {
public function definition() {
function definition() {
global $CFG, $DB; global $CFG, $DB;
$mform =& $this->_form; $mform =& $this->_form;
@ -48,39 +47,28 @@ class mod_attforblock_update_form extends moodleform {
'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', 'attforblock'));
$mform->addElement('static', 'olddate', get_string('olddate','attforblock'), userdate($sess->sessdate, get_string('strftimedmyhm', 'attforblock'))); $mform->addElement('static', 'olddate', get_string('olddate', 'attforblock'),
$mform->addElement('date_time_selector', 'sessiondate', get_string('newdate','attforblock')); userdate($sess->sessdate, get_string('strftimedmyhm', 'attforblock')));
$mform->addElement('date_time_selector', 'sessiondate', get_string('newdate', 'attforblock'));
for ($i=0; $i<=23; $i++) { for ($i=0; $i<=23; $i++) {
$hours[$i] = sprintf("%02d",$i); $hours[$i] = sprintf("%02d", $i);
} }
for ($i=0; $i<60; $i+=5) { for ($i=0; $i<60; $i+=5) {
$minutes[$i] = sprintf("%02d",$i); $minutes[$i] = sprintf("%02d", $i);
} }
$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', 'attforblock'), array(' '), true);
$mform->addElement('editor', 'sdescription', get_string('description', 'attforblock'), null, $defopts); $mform->addElement('editor', 'sdescription', get_string('description', 'attforblock'), null, $defopts);
$mform->setType('sdescription', PARAM_RAW); $mform->setType('sdescription', PARAM_RAW);
$mform->setDefaults($data); $mform->setDefaults($data);
//-------------------------------------------------------------------------------
// buttons
$submit_string = get_string('update', 'attforblock'); $submit_string = get_string('update', 'attforblock');
$this->add_action_buttons(true, $submit_string); $this->add_action_buttons(true, $submit_string);
} }
// function validation($data, $files) {
// $errors = parent::validation($data, $files);
// if (($data['timeend']!=0) && ($data['timestart']!=0)
// && $data['timeend'] <= $data['timestart']) {
// $errors['timeend'] = get_string('timestartenderror', 'forum');
// }
// return $errors;
// }
} }

6
version.php

@ -22,9 +22,9 @@
* @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
*/ */
$module->version = 2012120700; // The current module version (Date: YYYYMMDDXX) $module->version = 2012120700;
$module->requires = 2012120300; $module->requires = 2012120300;
$module->release = '2.4.1'; $module->release = '2.4.1';
$module->maturity = MATURITY_ALPHA; $module->maturity = MATURITY_ALPHA;
$module->cron = 0; // Period for cron to check this module (secs) $module->cron = 0;
$module->component = 'mod_attforblock'; // Full name of the plugin (used for diagnostics) $module->component = 'mod_attforblock';

11
view.php

@ -29,10 +29,10 @@ require_once(dirname(__FILE__).'/locallib.php');
$pageparams = new att_view_page_params(); $pageparams = new att_view_page_params();
$id = required_param('id', PARAM_INT); $id = required_param('id', PARAM_INT);
$pageparams->studentid = optional_param('studentid', NULL, PARAM_INT); $pageparams->studentid = optional_param('studentid', null, PARAM_INT);
$pageparams->mode = optional_param('mode', att_view_page_params::MODE_THIS_COURSE, PARAM_INT); $pageparams->mode = optional_param('mode', att_view_page_params::MODE_THIS_COURSE, PARAM_INT);
$pageparams->view = optional_param('view', NULL, PARAM_INT); $pageparams->view = optional_param('view', null, PARAM_INT);
$pageparams->curdate = optional_param('curdate', NULL, PARAM_INT); $pageparams->curdate = optional_param('curdate', null, PARAM_INT);
$cm = get_coursemodule_from_id('attforblock', $id, 0, false, MUST_EXIST); $cm = get_coursemodule_from_id('attforblock', $id, 0, false, MUST_EXIST);
$course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST); $course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST);
@ -44,12 +44,11 @@ $pageparams->init($cm);
$att = new attforblock($attforblock, $cm, $course, $PAGE->context, $pageparams); $att = new attforblock($attforblock, $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.
if (!$pageparams->studentid) { if (!$pageparams->studentid) {
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_manage()); redirect($att->url_manage());
} } else if ($att->perm->can_view_reports()) {
elseif ($att->perm->can_view_reports()) {
redirect($att->url_report()); redirect($att->url_report());
} }
} }

Loading…
Cancel
Save