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. 26
      db/install.php
  10. 241
      db/upgrade.php
  11. 21
      duration_form.php
  12. 58
      export.php
  13. 34
      export_form.php
  14. 6
      lang/en/attforblock.php
  15. 130
      lib.php
  16. 231
      locallib.php
  17. 22
      manage.php
  18. 11
      mod_form.php
  19. 9
      module.js
  20. 32
      preferences.php
  21. 77
      renderables.php
  22. 208
      renderer.php
  23. 85
      renderhelpers.php
  24. 18
      report.php
  25. 83
      sessions.php
  26. 6
      take.php
  27. 28
      update_form.php
  28. 6
      version.php
  29. 13
      view.php

73
add_form.php

@ -35,7 +35,7 @@ class mod_attforblock_add_form extends moodleform {
$cm = $this->_customdata['cm'];
$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);
switch ($groupmode) {
@ -53,18 +53,21 @@ class mod_attforblock_add_form extends moodleform {
break;
case VISIBLEGROUPS:
$radio=array();
$radio[] = &$mform->createElement('radio', 'sessiontype', '', get_string('commonsession','attforblock'), attforblock::SESSION_COMMON);
$radio[] = &$mform->createElement('radio', 'sessiontype', '', get_string('groupsession','attforblock'), attforblock::SESSION_GROUP);
$mform->addGroup($radio, 'sessiontype', get_string('sessiontype','attforblock'), ' ', false);
$radio[] = &$mform->createElement('radio', 'sessiontype', '',
get_string('commonsession', 'attforblock'), attforblock::SESSION_COMMON);
$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->setDefault('sessiontype', attforblock::SESSION_COMMON);
break;
}
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);
else
} else {
$groups = groups_get_all_groups($course->id);
}
if ($groups) {
$selectgroups = array();
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->setMultiple(true);
$mform->disabledIf('groups','sessiontype','neq', attforblock::SESSION_GROUP);
}
else {
$mform->disabledIf('groups', 'sessiontype', 'neq', attforblock::SESSION_GROUP);
} else {
$mform->updateElementAttr($radio, array('disabled'=>'disabled'));
$mform->addElement('static', 'groups', get_string('groups', 'group'),
get_string('nogroups', 'attforblock'));
if ($groupmode == SEPARATEGROUPS)
if ($groupmode == SEPARATEGROUPS) {
return;
}
}
}
$mform->addElement('checkbox', 'addmultiply', '', get_string('createmultiplesessions','attforblock'));
$mform->addElement('checkbox', 'addmultiply', '', get_string('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++) {
$hours[$i] = sprintf("%02d",$i);
$hours[$i] = sprintf("%02d", $i);
}
for ($i=0; $i<60; $i+=5) {
$minutes[$i] = sprintf("%02d",$i);
$minutes[$i] = sprintf("%02d", $i);
}
$durtime = array();
$durtime[] =& $mform->createElement('select', 'hours', get_string('hour', 'form'), $hours, 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');
$sdays = array();
if ($CFG->calendar_startwday === '0') { //week start from sunday
$sdays[] =& $mform->createElement('checkbox', 'Sun', '', get_string('sunday','calendar'));
if ($CFG->calendar_startwday === '0') { // Week start from sunday.
$sdays[] =& $mform->createElement('checkbox', 'Sun', '', get_string('sunday', 'calendar'));
}
$sdays[] =& $mform->createElement('checkbox', 'Mon', '', get_string('monday','calendar'));
$sdays[] =& $mform->createElement('checkbox', 'Tue', '', get_string('tuesday','calendar'));
$sdays[] =& $mform->createElement('checkbox', 'Wed', '', get_string('wednesday','calendar'));
$sdays[] =& $mform->createElement('checkbox', 'Thu', '', get_string('thursday','calendar'));
$sdays[] =& $mform->createElement('checkbox', 'Fri', '', get_string('friday','calendar'));
$sdays[] =& $mform->createElement('checkbox', 'Sat', '', get_string('saturday','calendar'));
if ($CFG->calendar_startwday !== '0') { //week start from sunday
$sdays[] =& $mform->createElement('checkbox', 'Sun', '', get_string('sunday','calendar'));
$sdays[] =& $mform->createElement('checkbox', 'Mon', '', get_string('monday', 'calendar'));
$sdays[] =& $mform->createElement('checkbox', 'Tue', '', get_string('tuesday', 'calendar'));
$sdays[] =& $mform->createElement('checkbox', 'Wed', '', get_string('wednesday', 'calendar'));
$sdays[] =& $mform->createElement('checkbox', 'Thu', '', get_string('thursday', 'calendar'));
$sdays[] =& $mform->createElement('checkbox', 'Fri', '', get_string('friday', 'calendar'));
$sdays[] =& $mform->createElement('checkbox', 'Sat', '', get_string('saturday', 'calendar'));
if ($CFG->calendar_startwday !== '0') { // Week start from sunday.
$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');
$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[] =& $mform->createElement('select', 'period', '', $period, false, true);
$periodgroup[] =& $mform->createElement('static', 'perioddesc', '', get_string('week','attforblock'));
$mform->addGroup($periodgroup, 'periodgroup', get_string('period','attforblock'), array(' '), false);
$periodgroup[] =& $mform->createElement('static', 'perioddesc', '', get_string('week', 'attforblock'));
$mform->addGroup($periodgroup, 'periodgroup', get_string('period', 'attforblock'), array(' '), false);
$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);
//-------------------------------------------------------------------------------
// buttons
$submit_string = get_string('addsession', 'attforblock');
$this->add_action_buttons(false, $submit_string);
}
function validation($data, $files) {
public function validation($data, $files) {
$errors = parent::validation($data, $files);
if ($data['sessiontype'] == attforblock::SESSION_GROUP and empty($data['groups'])) {
$errors['groups'] = get_string('errorgroupsnotselected','attforblock');
$errors['groups'] = get_string('errorgroupsnotselected', 'attforblock');
}
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
*/
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) {
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]+)/";
$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]+)/";
$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
// 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() {
// are we including userinfo?
// Are we including 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(
'name', 'grade'));
@ -51,18 +48,13 @@ class backup_attforblock_activity_structure_step extends backup_activity_structu
'groupid', 'sessdate', 'duration', 'lasttaken', 'lasttakenby',
'timemodified', 'description', 'descriptionformat'));
////////////////////////////////////////////////////////////////////////
// XML nodes declaration - user data
////////////////////////////////////////////////////////////////////////
// XML nodes declaration - user data.
$logs = new backup_nested_element('logs');
$log = new backup_nested_element('log', array('id'), array(
'sessionid', 'studentid', 'statusid', 'lasttaken', 'statusset',
'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);
$statuses->add_child($status);
@ -72,9 +64,7 @@ class backup_attforblock_activity_structure_step extends backup_activity_structu
$session->add_child($logs);
$logs->add_child($log);
////////////////////////////////////////////////////////////////////////
// data sources - non-user data
////////////////////////////////////////////////////////////////////////
// Data sources - non-user data.
$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));
////////////////////////////////////////////////////////////////////////
// data sources - user related data
////////////////////////////////////////////////////////////////////////
// Data sources - user related data.
if ($userinfo) {
$log->set_source_table('attendance_log', array('sessionid' => backup::VAR_PARENTID));
}
////////////////////////////////////////////////////////////////////////
// id annotations
////////////////////////////////////////////////////////////////////////
// Id annotations.
$session->annotate_ids('user', 'lasttakenby');
$session->annotate_ids('group', 'groupid');
$log->annotate_ids('user', 'studentid');
$log->annotate_ids('user', 'takenby');
////////////////////////////////////////////////////////////////////////
// file annotations
////////////////////////////////////////////////////////////////////////
// File annotations.
$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);
}
}

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
*/
protected function define_my_settings() {
// No particular settings for this activity
}
/**
* Define (add) particular steps this activity can have
*/
protected function define_my_steps() {
// Choice only has one structure step
$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() {
$rules = array();
// 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}');
*
*/
// TODO: log restore.
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();
$userinfo = $this->get_setting_value('userinfo'); // are we including userinfo?
////////////////////////////////////////////////////////////////////////
// XML interesting paths - non-user data
////////////////////////////////////////////////////////////////////////
$userinfo = $this->get_setting_value('userinfo'); // Are we including userinfo?
// XML interesting paths - non-user data.
$paths[] = new restore_path_element('attforblock', '/activity/attforblock');
$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',
'/activity/attforblock/sessions/session');
// End here if no-user data has been selected
// End here if no-user data has been selected.
if (!$userinfo) {
return $this->prepare_activity_structure($paths);
}
////////////////////////////////////////////////////////////////////////
// XML interesting paths - user data
////////////////////////////////////////////////////////////////////////
// XML interesting paths - user data.
$paths[] = new restore_path_element('attforblock_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);
}
@ -73,9 +67,9 @@ class restore_attforblock_activity_structure_step extends restore_activity_struc
$oldid = $data->id;
$data->course = $this->get_courseid();
// insert the attforblock record
// Insert the attforblock record.
$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);
}
@ -118,7 +112,9 @@ class restore_attforblock_activity_structure_step extends restore_activity_struc
$data->studentid = $this->get_mappingid('user', $data->studentid);
$data->statusid = $this->get_mappingid('attforblock_status', $data->statusid);
$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->timetaken = $this->apply_date_offset($data->timetaken);
$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(
'mod/attforblock:view' => array(
'captype' => 'read',
'contextlevel' => CONTEXT_MODULE,
'archetypes' => array(
@ -62,7 +60,6 @@ $capabilities = array(
'mod/attforblock:addinstance' => array(
'riskbitmask' => RISK_XSS,
'captype' => 'write',
'contextlevel' => CONTEXT_COURSE,
'archetypes' => array(
@ -73,9 +70,7 @@ $capabilities = array(
),
'mod/attforblock:viewreports' => array(
'riskbitmask' => RISK_PERSONAL,
'captype' => 'read',
'contextlevel' => CONTEXT_MODULE,
'archetypes' => array(
@ -86,9 +81,7 @@ $capabilities = array(
),
'mod/attforblock:takeattendances' => array(
'riskbitmask' => RISK_DATALOSS,
'captype' => 'write',
'contextlevel' => CONTEXT_MODULE,
'archetypes' => array(
@ -99,9 +92,7 @@ $capabilities = array(
),
'mod/attforblock:changeattendances' => array(
'riskbitmask' => RISK_DATALOSS,
'captype' => 'write',
'contextlevel' => CONTEXT_MODULE,
'archetypes' => array(
@ -112,9 +103,7 @@ $capabilities = array(
),
'mod/attforblock:manageattendances' => array(
'riskbitmask' => RISK_CONFIG,
'captype' => 'write',
'contextlevel' => CONTEXT_MODULE,
'archetypes' => array(
@ -124,9 +113,7 @@ $capabilities = array(
),
'mod/attforblock:changepreferences' => array(
'riskbitmask' => RISK_CONFIG,
'captype' => 'write',
'contextlevel' => CONTEXT_MODULE,
'archetypes' => array(
@ -136,9 +123,7 @@ $capabilities = array(
),
'mod/attforblock:export' => array(
'riskbitmask' => RISK_PERSONAL,
'captype' => 'read',
'contextlevel' => CONTEXT_MODULE,
'archetypes' => array(
@ -149,9 +134,7 @@ $capabilities = array(
'mod/attforblock:canbelisted' => array(
'riskbitmask' => RISK_PERSONAL,
'captype' => 'read',
'contextlevel' => CONTEXT_MODULE,
'archetypes' => array(

26
db/install.php

@ -31,18 +31,18 @@
function xmldb_attforblock_install() {
global $DB;
$result = true;
$arr = array('P' => 2, 'A' => 0, 'L' => 1, 'E' => 1);
foreach ($arr as $k => $v) {
$rec = new stdClass;
$rec->attendanceid = 0;
$rec->acronym = get_string($k.'acronym', 'attforblock');
$rec->description = get_string($k.'full', 'attforblock');
$rec->grade = $v;
$rec->visible = 1;
$rec->deleted = 0;
$result = $result && $DB->insert_record('attendance_statuses', $rec);
}
$result = true;
$arr = array('P' => 2, 'A' => 0, 'L' => 1, 'E' => 1);
foreach ($arr as $k => $v) {
$rec = new stdClass;
$rec->attendanceid = 0;
$rec->acronym = get_string($k.'acronym', 'attforblock');
$rec->description = get_string($k.'full', 'attforblock');
$rec->grade = $v;
$rec->visible = 1;
$rec->deleted = 0;
$result = $result && $DB->insert_record('attendance_statuses', $rec);
}
return $result;
return $result;
}

241
db/upgrade.php

@ -14,228 +14,199 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
// This file keeps track of upgrades to
// 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
// This file keeps track of upgrades to
// the attforblock module.
function xmldb_attforblock_upgrade($oldversion=0) {
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;
/// And upgrade begins here. For each one, you'll need one
/// 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;
if ($sessions = $DB->get_records('attendance_sessions', array('takenby'=> 0))) {
foreach ($sessions as $sess) {
if ($DB->count_records('attendance_log', array('attsid'=> $sess->id)) > 0) {
$sess->takenby = $USER->id;
$sess->timetaken = $sess->timemodified ? $sess->timemodified : time();
$sess->description = addslashes($sess->description);
$result = $DB->update_record('attendance_sessions', $sess) and $result;
}
}
}
if ($oldversion < 2008021904) { // New version in version.php.
global $USER;
if ($sessions = $DB->get_records('attendance_sessions', array('takenby'=> 0))) {
foreach ($sessions as $sess) {
if ($DB->count_records('attendance_log', array('attsid'=> $sess->id)) > 0) {
$sess->takenby = $USER->id;
$sess->timetaken = $sess->timemodified ? $sess->timemodified : time();
$sess->description = addslashes($sess->description);
$result = $DB->update_record('attendance_sessions', $sess) and $result;
}
}
}
upgrade_mod_savepoint(true, 2008021904, 'attforblock');
}
}
if ($oldversion < 2008102401) {
$table = new xmldb_table('attforblock');
$field = new xmldb_field('grade');
$field->set_attributes(XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '100', 'name');
$dbman->add_field($table, $field);
$table = new xmldb_table('attendance_sessions');
$field = new xmldb_field('courseid');
$field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'id');
$dbman->change_field_unsigned($table, $field);
// $field = new xmldb_field('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->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'creator');
$dbman->change_field_unsigned($table, $field);
$field = new xmldb_field('duration');
$field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'sessdate');
$dbman->add_field($table, $field);
$field = new xmldb_field('timetaken');
$field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'takenby');
$dbman->change_field_unsigned($table, $field);
$dbman->rename_field($table, $field, 'lasttaken');
$dbman->rename_field($table, $field, 'lasttaken');
$field = new xmldb_field('takenby');
$field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'lasttaken');
$dbman->change_field_unsigned($table, $field);
$dbman->rename_field($table, $field, 'lasttakenby');
$field = new xmldb_field('timemodified');
$field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, 'lasttaken');
$dbman->change_field_unsigned($table, $field);
$table = new xmldb_table('attendance_log');
$table = new xmldb_table('attendance_log');
$field = new xmldb_field('attsid');
$field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'id');
$dbman->change_field_unsigned($table, $field);
$field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'id');
$dbman->change_field_unsigned($table, $field);
$field = new xmldb_field('studentid');
$field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'attsid');
$dbman->change_field_unsigned($table, $field);
$field = new xmldb_field('statusid');
$dbman->change_field_unsigned($table, $field);
$field = new xmldb_field('statusid');
$field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'status');
$dbman->add_field($table, $field);
$dbman->add_field($table, $field);
$field = new xmldb_field('statusset');
$field->set_attributes(XMLDB_TYPE_CHAR, '100', null, null, null, null, 'statusid');
$dbman->add_field($table, $field);
$field = new xmldb_field('timetaken');
$field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'statusid');
$dbman->add_field($table, $field);
$dbman->add_field($table, $field);
$field = new xmldb_field('takenby');
$field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'timetaken');
$dbman->add_field($table, $field);
//Indexes
$dbman->add_field($table, $field);
// Indexes.
$index = new xmldb_index('statusid');
$index->set_attributes(XMLDB_INDEX_NOTUNIQUE, array('statusid'));
$dbman->add_index($table, $index);
$dbman->add_index($table, $index);
$index = new xmldb_index('attsid');
$index->set_attributes(XMLDB_INDEX_NOTUNIQUE, array('attsid'));
$dbman->drop_index($table, $index);
$field = new xmldb_field('attsid'); //Rename field
$field = new xmldb_field('attsid'); // Rename field.
$field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'id');
$dbman->rename_field($table, $field, 'sessionid');
$index = new xmldb_index('sessionid');
$index->set_attributes(XMLDB_INDEX_NOTUNIQUE, array('sessionid'));
$dbman->add_index($table, $index);
$table = new xmldb_table('attendance_settings');
$table = new xmldb_table('attendance_settings');
$field = new xmldb_field('courseid');
$field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'id');
$dbman->change_field_unsigned($table, $field);
$field = new xmldb_field('visible');
$field->set_attributes(XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '1', 'grade');
$dbman->add_field($table, $field);
$field = new xmldb_field('deleted');
$field->set_attributes(XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'visible');
$dbman->add_field($table, $field);
//Indexes
// Indexes.
$index = new xmldb_index('visible');
$index->set_attributes(XMLDB_INDEX_NOTUNIQUE, array('visible'));
$dbman->add_index($table, $index);
$index = new xmldb_index('deleted');
$index->set_attributes(XMLDB_INDEX_NOTUNIQUE, array('deleted'));
$dbman->add_index($table, $index);
$dbman->rename_table($table, 'attendance_statuses');
$dbman->rename_table($table, 'attendance_statuses');
upgrade_mod_savepoint(true, 2008102401, 'attforblock');
}
if ($oldversion < 2008102406) {
if ($courses = $DB->get_records_sql("SELECT courseid FROM {attendance_sessions} GROUP BY courseid")) {
foreach ($courses as $c) {
//Adding own status for course (now it must have own)
if (!$DB->count_records('attendance_statuses', array( 'courseid'=> $c->courseid))) {
$statuses = $DB->get_records('attendance_statuses', array('courseid'=> 0));
foreach($statuses as $stat) {
$rec = $stat;
$rec->courseid = $c->courseid;
$DB->insert_record('attendance_statuses', $rec);
}
}
$statuses = $DB->get_records('attendance_statuses', array('courseid'=> $c->courseid));
$statlist = implode(',', array_keys($statuses));
$sess = $DB->get_records_select_menu('attendance_sessions', "courseid = ? AND lasttakenby > 0", array($c->courseid));
$sesslist = implode(',', array_keys($sess));
foreach($statuses as $stat) {
execute("UPDATE {attendance_log}
SET statusid = {$stat->id}, statusset = '$statlist'
WHERE sessionid IN ($sesslist) AND status = '$stat->status'");
}
$sessions = $DB->get_records_list('attendance_sessions', array('id'=> $sesslist));
foreach($sessions as $sess) {
execute("UPDATE {attendance_log}
SET timetaken = {$sess->lasttaken},
takenby = {$sess->lasttakenby}
WHERE sessionid = {$sess->id}");
}
}
}
upgrade_mod_savepoint(true, 2008102406, 'attforblock');
}
if ($courses = $DB->get_records_sql("SELECT courseid FROM {attendance_sessions} GROUP BY courseid")) {
foreach ($courses as $c) {
// Adding own status for course (now it must have own).
if (!$DB->count_records('attendance_statuses', array( 'courseid'=> $c->courseid))) {
$statuses = $DB->get_records('attendance_statuses', array('courseid'=> 0));
foreach ($statuses as $stat) {
$rec = $stat;
$rec->courseid = $c->courseid;
$DB->insert_record('attendance_statuses', $rec);
}
}
$statuses = $DB->get_records('attendance_statuses', array('courseid'=> $c->courseid));
$statlist = implode(',', array_keys($statuses));
$sess = $DB->get_records_select_menu('attendance_sessions',
"courseid = ? AND lasttakenby > 0", array($c->courseid));
$sesslist = implode(',', array_keys($sess));
foreach ($statuses as $stat) {
execute("UPDATE {attendance_log}
SET statusid = {$stat->id}, statusset = '$statlist'
WHERE sessionid IN ($sesslist) AND status = '$stat->status'");
}
$sessions = $DB->get_records_list('attendance_sessions', array('id'=> $sesslist));
foreach ($sessions as $sess) {
execute("UPDATE {attendance_log}
SET timetaken = {$sess->lasttaken},
takenby = {$sess->lasttakenby}
WHERE sessionid = {$sess->id}");
}
}
}
upgrade_mod_savepoint(true, 2008102406, 'attforblock');
}
if ($oldversion < 2008102409) {
$table = new xmldb_table('attendance_statuses');
$field = new xmldb_field('status');
$dbman->drop_field($table, $field);
$index = new xmldb_index('status');
$index->set_attributes(XMLDB_INDEX_NOTUNIQUE, array('status'));
$dbman->drop_index($table, $index);
$table = new xmldb_table('attendance_log');
$field = new xmldb_field('status');
$dbman->drop_field($table, $field);
$index = new xmldb_index('status');
$index->set_attributes(XMLDB_INDEX_NOTUNIQUE, array('status'));
$dbman->drop_index($table, $index);
$table = new xmldb_table('attendance_sessions');
$field = new xmldb_field('creator');
$dbman->drop_field($table, $field);
upgrade_mod_savepoint(true, 2008102409, 'attforblock');
}
}
if ($oldversion < 2010070900) {
$table = new xmldb_table('attendance_sessions');
@ -251,7 +222,7 @@ function xmldb_attforblock_upgrade($oldversion=0) {
if (!$dbman->index_exists($table, $index)) {
$dbman->add_index($table, $index);
}
upgrade_mod_savepoint(true, 2010070900, 'attforblock');
}
@ -306,15 +277,17 @@ function xmldb_attforblock_upgrade($oldversion=0) {
$field->set_attributes(XMLDB_TYPE_TEXT, 'small', null, XMLDB_NOTNULL, null, null, 'timemodified');
$dbman->change_field_type($table, $field);
$field = new xmldb_field('descriptionformat', XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'description');
$field = new xmldb_field('descriptionformat', XMLDB_TYPE_INTEGER, '4',
XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'description');
if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field);
}
// conditionally migrate to html format in intro
// Conditionally migrate to html format in intro.
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) {
$s->description = text_to_html($s->description, false, false, true);
$s->descriptionformat = FORMAT_HTML;
@ -324,9 +297,9 @@ function xmldb_attforblock_upgrade($oldversion=0) {
$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
// 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'));
if ($dbman->index_exists($table, $index)) {
$dbman->drop_index($table, $index);

21
duration_form.php

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

58
export.php

@ -75,7 +75,7 @@ if ($mform->is_submitted()) {
if ($reportdata->users) {
$filename = clean_filename($course->shortname.'_Attendances_'.userdate(time(), '%Y%m%d-%H%M'));
$group = $formdata->group ? $reportdata->groups[$formdata->group] : 0;
$group = $formdata->group ? $reportdata->groups[$formdata->group] : 0;
$data = new stdClass;
$data->tabhead = array();
$data->course = $att->course->fullname;
@ -92,7 +92,7 @@ if ($mform->is_submitted()) {
if (count($reportdata->sessions) > 0) {
foreach($reportdata->sessions as $sess) {
foreach ($reportdata->sessions as $sess) {
$text = userdate($sess->sessdate, get_string('strftimedmyhm', 'attforblock'));
$text .= ' ';
$text .= $sess->groupid ? $reportdata->groups[$sess->groupid]->name : get_string('commonsession', 'attforblock');
@ -101,12 +101,13 @@ if ($mform->is_submitted()) {
} else {
print_error('sessionsnotfound', 'attforblock', $att->url_manage());
}
if ($reportdata->gradable)
if ($reportdata->gradable) {
$data->tabhead[] = get_string('grade');
}
$i = 0;
$data->table = array();
foreach($reportdata->users as $user) {
foreach ($reportdata->users as $user) {
if (isset($formdata->ident['id'])) {
$data->table[$i][] = $user->id;
}
@ -117,15 +118,16 @@ if ($mform->is_submitted()) {
$data->table[$i][] = $user->firstname;
$cellsgenerator = new user_sessions_cells_text_generator($reportdata, $user);
$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];
}
$i++;
}
if ($formdata->format === 'text') {
ExportToCSV($data, $filename);
exporttocsv($data, $filename);
} else {
ExportToTableEd($data, $filename, $formdata->format);
exporttotableed($data, $filename, $formdata->format);
}
exit;
} else {
@ -136,7 +138,7 @@ if ($mform->is_submitted()) {
$output = $PAGE->get_renderer('mod_attforblock');
$tabs = new attforblock_tabs($att, attforblock_tabs::TAB_EXPORT);
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);
$mform->display();
@ -144,23 +146,23 @@ $mform->display();
echo $OUTPUT->footer();
function ExportToTableEd($data, $filename, $format) {
global $CFG;
function exporttotableed($data, $filename, $format) {
global $CFG;
if ($format === 'excel') {
require_once("$CFG->libdir/excellib.class.php");
$filename .= ".xls";
$workbook = new MoodleExcelWorkbook("-");
require_once("$CFG->libdir/excellib.class.php");
$filename .= ".xls";
$workbook = new MoodleExcelWorkbook("-");
} else {
require_once("$CFG->libdir/odslib.class.php");
$filename .= ".ods";
$workbook = new MoodleODSWorkbook("-");
require_once("$CFG->libdir/odslib.class.php");
$filename .= ".ods";
$workbook = new MoodleODSWorkbook("-");
}
/// Sending HTTP headers
// Sending HTTP headers.
$workbook->send($filename);
/// Creating the first worksheet
// Creating the first worksheet.
$myxls = $workbook->add_worksheet('Attendances');
/// format types
// Format types.
$formatbc = $workbook->add_format();
$formatbc->set_bold(1);
@ -172,21 +174,21 @@ function ExportToTableEd($data, $filename, $format) {
$i = 3;
$j = 0;
foreach ($data->tabhead as $cell) {
$myxls->write($i, $j++, $cell, $formatbc);
$myxls->write($i, $j++, $cell, $formatbc);
}
$i++;
$j = 0;
foreach ($data->table as $row) {
foreach ($row as $cell) {
$myxls->write($i, $j++, $cell);
}
$i++;
$j = 0;
foreach ($row as $cell) {
$myxls->write($i, $j++, $cell);
}
$i++;
$j = 0;
}
$workbook->close();
$workbook->close();
}
function ExportToCSV($data, $filename) {
function exporttocsv($data, $filename) {
$filename .= ".txt";
header("Content-Type: application/download\n");
@ -200,6 +202,6 @@ function ExportToCSV($data, $filename) {
echo implode("\t", $data->tabhead)."\n";
foreach ($data->table as $row) {
echo implode("\t", $row)."\n";
echo implode("\t", $row)."\n";
}
}

34
export_form.php

@ -26,7 +26,7 @@ require_once($CFG->libdir.'/formslib.php');
class mod_attforblock_export_form extends moodleform {
function definition() {
public function definition() {
global $CFG, $USER;
$mform =& $this->_form;
@ -35,8 +35,7 @@ class mod_attforblock_export_form extends moodleform {
$cm = $this->_customdata['cm'];
$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);
$groups = groups_get_activity_allowed_groups($cm, $USER->id);
@ -53,40 +52,29 @@ class mod_attforblock_export_form extends moodleform {
$ident = array();
$ident[] =& $mform->createElement('checkbox', 'id', '', get_string('studentid', 'attforblock'));
$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->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->addElement('checkbox', 'includenottaken', get_string('includenottaken','attforblock'), get_string('yes'));
$mform->addElement('date_selector', 'sessionstartdate', get_string('startofperiod','attforblock'));
$mform->addElement('checkbox', 'includenottaken', get_string('includenottaken', 'attforblock'), get_string('yes'));
$mform->addElement('date_selector', 'sessionstartdate', get_string('startofperiod', 'attforblock'));
$mform->setDefault('sessionstartdate', $course->startdate);
$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->addElement('select', 'format', get_string('format'),
array('excel' => get_string('downloadexcel','attforblock'),
'ooo' => get_string('downloadooo','attforblock'),
'text' => get_string('downloadtext','attforblock')
$mform->addElement('select', 'format', get_string('format'),
array('excel' => get_string('downloadexcel', 'attforblock'),
'ooo' => get_string('downloadooo', 'attforblock'),
'text' => get_string('downloadtext', 'attforblock')
));
// buttons
$submit_string = get_string('ok');
$this->add_action_buttons(false, $submit_string);
$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['caltoday'] = 'Today';
$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['changeduration'] = 'Change duration';
$string['changesession'] = 'Change session';
@ -177,9 +177,9 @@ $string['statuses'] = 'Statuses';
$string['statusdeleted'] = 'Status deleted';
$string['strftimedm'] = '%d.%m';
$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['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['studentid'] = 'Student ID';
$string['takeattendance'] = 'Take attendance';

130
lib.php

@ -31,20 +31,27 @@
*/
function attforblock_supports($feature) {
switch($feature) {
case FEATURE_GRADE_HAS_GRADE: return true;
case FEATURE_GROUPS: return true;
case FEATURE_GRADE_HAS_GRADE:
return true;
case FEATURE_GROUPS:
return true;
// Artem Andreev: AFAIK it's not tested
// we need implement filtration of groups list by grouping
case FEATURE_GROUPINGS: return false;
// 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;
// we need implement filtration of groups list by grouping.
case FEATURE_GROUPINGS:
return false;
// 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:
return false;
default: return null;
return false;
default:
return null;
}
}
@ -52,7 +59,7 @@ function att_add_default_statuses($attid) {
global $DB;
$statuses = $DB->get_records('attendance_statuses', array('attendanceid'=> 0), 'id');
foreach($statuses as $st) {
foreach ($statuses as $st) {
$rec = $st;
$rec->attendanceid = $attid;
$DB->insert_record('attendance_statuses', $rec);
@ -60,11 +67,6 @@ function att_add_default_statuses($attid) {
}
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;
$attforblock->timemodified = time();
@ -74,16 +76,12 @@ function attforblock_add_instance($attforblock) {
att_add_default_statuses($attforblock->id);
attforblock_grade_item_update($attforblock);
//attforblock_update_grades($attforblock);
// attforblock_update_grades($attforblock);
return $attforblock->id;
}
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;
$attforblock->timemodified = time();
@ -119,13 +117,14 @@ function attforblock_delete_instance($id) {
return true;
}
function attforblock_delete_course($course, $feedback=true){
function attforblock_delete_course($course, $feedback=true) {
global $DB;
$attids = array_keys($DB->get_records('attforblock', array('course'=> $course->id), '', '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);
}
if ($attids) {
$DB->delete_records_list('attendance_statuses', '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'),
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->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->disabledIf('reset_attendance_statuses', 'reset_attendance_log', 'notchecked');
}
@ -186,7 +185,7 @@ function attforblock_reset_userdata($data) {
if (!empty($data->reset_attendance_statuses)) {
$DB->delete_records_list('attendance_statuses', 'attendanceid', $attids);
foreach($attids as $attid) {
foreach ($attids as $attid) {
att_add_default_statuses($attid);
}
@ -209,13 +208,14 @@ function attforblock_reset_userdata($data) {
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) {
/// 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;
require_once(dirname(__FILE__).'/locallib.php');
@ -227,23 +227,27 @@ function attforblock_user_outline($course, $user, $mod, $attforblock) {
if (!empty($grades->items[0]->grades)) {
$grade = reset($grades->items[0]->grades);
$result->time = $grade->dategraded;
}
else
} else {
$result->time = 0;
}
if (has_capability('mod/attforblock:canbelisted', $mod->context, $user->id)) {
$statuses = att_get_statuses($attforblock->id);
$grade = att_get_user_grade(att_get_user_statuses_stat($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);
$grade = att_get_user_grade(att_get_user_statuses_stat($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);
$result->info = $grade.' / '.$maxgrade;
}
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) {
/// Print a detailed representation of what a user has done with
/// a given particular instance of this module, for user activity reports.
global $CFG;
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)) {
echo construct_full_user_stat_html_table($attforblock, $course, $user);
}
//return true;
}
function attforblock_print_recent_activity($course, $isteacher, $timestart) {
/// Given a course and a time, this module should find recent activity
/// 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
return false;
}
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;
}
@ -354,12 +347,12 @@ function attforblock_cron () {
* @param mixed optional array/object of grade(s); 'reset' means reset grades in gradebook
* @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;
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');
}
@ -369,12 +362,12 @@ function attforblock_grade_item_update($attforblock, $grades=NULL) {
if (! $course = $DB->get_record('course', array('id'=> $attforblock->course))) {
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);
}else{
// MDL-14303
} else {
// MDL-14303.
$cm = get_coursemodule_from_instance('attforblock', $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['grademax'] = $attforblock->grade;
$params['grademin'] = 0;
}
else if ($attforblock->grade < 0) {
} else if ($attforblock->grade < 0) {
$params['gradetype'] = GRADE_TYPE_SCALE;
$params['scaleid'] = -$attforblock->grade;
@ -394,7 +386,7 @@ function attforblock_grade_item_update($attforblock, $grades=NULL) {
if ($grades === 'reset') {
$params['reset'] = true;
$grades = NULL;
$grades = null;
}
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;
}
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) {
//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;
}
@ -476,7 +464,7 @@ function attforblock_pluginfile($course, $cm, $context, $filearea, $args, $force
return false;
}
// 'session' area is served by pluginfile.php
// Session area is served by pluginfile.php.
$fileareas = array('session');
if (!in_array($filearea, $fileareas)) {
return false;
@ -495,7 +483,3 @@ function attforblock_pluginfile($course, $cm, $context, $filearea, $args, $force
}
send_stored_file($file, 0, 0, true);
}
//////////////////////////////////////////////////////////////////////////////////////
/// Any other attforblock functions go here. Each of them must have a name that
/// starts with attforblock_

231
locallib.php

@ -57,8 +57,9 @@ class attforblock_permissions {
}
public function can_view() {
if (is_null($this->canview))
if (is_null($this->canview)) {
$this->canview = has_capability('mod/attforblock:view', $this->context);
}
return $this->canview;
}
@ -68,8 +69,9 @@ class attforblock_permissions {
}
public function can_view_reports() {
if (is_null($this->canviewreports))
if (is_null($this->canviewreports)) {
$this->canviewreports = has_capability('mod/attforblock:viewreports', $this->context);
}
return $this->canviewreports;
}
@ -79,8 +81,9 @@ class attforblock_permissions {
}
public function can_take() {
if (is_null($this->cantake))
if (is_null($this->cantake)) {
$this->cantake = has_capability('mod/attforblock:takeattendances', $this->context);
}
return $this->cantake;
}
@ -100,15 +103,17 @@ class attforblock_permissions {
}
public function can_change() {
if (is_null($this->canchange))
if (is_null($this->canchange)) {
$this->canchange = has_capability('mod/attforblock:changeattendances', $this->context);
}
return $this->canchange;
}
public function can_manage() {
if (is_null($this->canmanage))
if (is_null($this->canmanage)) {
$this->canmanage = has_capability('mod/attforblock:manageattendances', $this->context);
}
return $this->canmanage;
}
@ -118,8 +123,9 @@ class attforblock_permissions {
}
public function can_change_preferences() {
if (is_null($this->canchangepreferences))
if (is_null($this->canchangepreferences)) {
$this->canchangepreferences = has_capability('mod/attforblock:changepreferences', $this->context);
}
return $this->canchangepreferences;
}
@ -129,8 +135,9 @@ class attforblock_permissions {
}
public function can_export() {
if (is_null($this->canexport))
if (is_null($this->canexport)) {
$this->canexport = has_capability('mod/attforblock:export', $this->context);
}
return $this->canexport;
}
@ -140,15 +147,17 @@ class attforblock_permissions {
}
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);
}
return $this->canbelisted;
}
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);
}
return $this->canaccessallgroups;
}
@ -197,11 +206,9 @@ class att_page_with_filter_controls {
if (isset($this->view)) {
$SESSION->attcurrentattview[$this->cm->course] = $this->view;
}
elseif (isset($SESSION->attcurrentattview[$this->cm->course])) {
} else if (isset($SESSION->attcurrentattview[$this->cm->course])) {
$this->view = $SESSION->attcurrentattview[$this->cm->course];
}
else {
} else {
$this->view = $this->defaultview;
}
}
@ -211,11 +218,9 @@ class att_page_with_filter_controls {
if (isset($this->curdate)) {
$SESSION->attcurrentattdate[$this->cm->course] = $this->curdate;
}
elseif (isset($SESSION->attcurrentattdate[$this->cm->course])) {
} else if (isset($SESSION->attcurrentattdate[$this->cm->course])) {
$this->curdate = $SESSION->attcurrentattdate[$this->cm->course];
}
else {
} else {
$this->curdate = time();
}
}
@ -223,11 +228,13 @@ class att_page_with_filter_controls {
public function init_start_end_date() {
global $CFG;
// HOURSECS solves issue for weeks view with Daylight saving time and clocks adjusting by one hour backward
// HOURSECS solves issue for weeks view with Daylight saving time and clocks adjusting by one hour backward.
$date = usergetdate($this->curdate + HOURSECS);
$mday = $date['mday'];
$wday = $date['wday'] - $CFG->calendar_startwday;
if ($wday < 0) $wday += 7;
if ($wday < 0) {
$wday += 7;
}
$mon = $date['mon'];
$year = $date['year'];
@ -260,8 +267,7 @@ class att_page_with_filter_controls {
if (!array_key_exists('attsessiontype', $SESSION)) {
$SESSION->attsessiontype = array($this->cm->course => self::SESSTYPE_ALL);
}
elseif (!array_key_exists($this->cm->course, $SESSION->attsessiontype)) {
} else if (!array_key_exists($this->cm->course, $SESSION->attsessiontype)) {
$SESSION->attsessiontype[$this->cm->course] = self::SESSTYPE_ALL;
}
@ -270,10 +276,10 @@ class att_page_with_filter_controls {
if ($group > self::SESSTYPE_NO_VALUE) {
$SESSION->attsessiontype[$this->cm->course] = $group;
if ($group > self::SESSTYPE_ALL) {
// set activegroup in $SESSION
// Set activegroup in $SESSION.
groups_get_activity_group($this->cm, true);
} 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]['aag'][$this->cm->groupingid]);
unset($SESSION->activegroup[$this->cm->course][SEPARATEGROUPS][$this->cm->groupingid]);
@ -282,23 +288,23 @@ class att_page_with_filter_controls {
} else {
$this->sesstype = $SESSION->attsessiontype[$this->cm->course];
}
} elseif ($this->selectortype == self::SELECTOR_GROUP) {
} else if ($this->selectortype == self::SELECTOR_GROUP) {
if ($group == 0) {
$SESSION->attsessiontype[$this->cm->course] = self::SESSTYPE_ALL;
$this->sesstype = self::SESSTYPE_ALL;
}
elseif ($group > 0) {
} else if ($group > 0) {
$SESSION->attsessiontype[$this->cm->course] = $group;
$this->sesstype = $group;
}
else {
} else {
$this->sesstype = $SESSION->attsessiontype[$this->cm->course];
}
}
if (is_null($this->sessgroupslist)) $this->calc_sessgroupslist();
// for example, we set SESSTYPE_ALL but user can access only to limited set of groups
if (!array_key_exists($this->sesstype, $this->sessgroupslist)){
if (is_null($this->sessgroupslist)) {
$this->calc_sessgroupslist();
}
// For example, we set SESSTYPE_ALL but user can access only to limited set of groups.
if (!array_key_exists($this->sesstype, $this->sessgroupslist)) {
reset($this->sessgroupslist);
$this->sesstype = key($this->sessgroupslist);
}
@ -309,8 +315,9 @@ class att_page_with_filter_controls {
$this->sessgroupslist = array();
$groupmode = groups_get_activity_groupmode($this->cm);
if ($groupmode == NOGROUPS)
if ($groupmode == NOGROUPS) {
return;
}
if ($groupmode == VISIBLEGROUPS or has_capability('moodle/site:accessallgroups', $PAGE->context)) {
$allowedgroups = groups_get_all_groups($this->cm->course, 0, $this->cm->groupingid);
@ -332,15 +339,17 @@ class att_page_with_filter_controls {
}
public function get_sess_groups_list() {
if (is_null($this->sessgroupslist))
if (is_null($this->sessgroupslist)) {
$this->calc_sessgroupslist_sesstype();
}
return $this->sessgroupslist;
}
public function get_current_sesstype() {
if (is_null($this->sesstype))
if (is_null($this->sesstype)) {
$this->calc_sessgroupslist_sesstype();
}
return $this->sesstype;
}
@ -365,8 +374,12 @@ class att_view_page_params extends att_page_with_filter_controls {
public function get_significant_params() {
$params = array();
if (isset($this->studentid)) $params['studentid'] = $this->studentid;
if ($this->mode != self::MODE_THIS_COURSE) $params['mode'] = $this->mode;
if (isset($this->studentid)) {
$params['studentid'] = $this->studentid;
}
if ($this->mode != self::MODE_THIS_COURSE) {
$params['mode'] = $this->mode;
}
return $params;
}
@ -411,8 +424,12 @@ class att_take_page_params {
public $gridcols;
public function init() {
if (!isset($this->group)) $this->group = 0;
if (!isset($this->sort)) $this->sort = ATT_SORT_LASTNAME;
if (!isset($this->group)) {
$this->group = 0;
}
if (!isset($this->sort)) {
$this->sort = ATT_SORT_LASTNAME;
}
$this->init_view_mode();
$this->init_gridcols();
}
@ -420,8 +437,7 @@ class att_take_page_params {
private function init_view_mode() {
if (isset($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);
}
}
@ -429,8 +445,7 @@ class att_take_page_params {
private function init_gridcols() {
if (isset($this->gridcols)) {
set_user_preference("attforblock_gridcolumns", $this->gridcols);
}
else {
} else {
$this->gridcols = get_user_preferences("attforblock_gridcolumns", 5);
}
}
@ -440,9 +455,15 @@ class att_take_page_params {
$params['sessionid'] = $this->sessionid;
$params['grouptype'] = $this->grouptype;
if ($this->group) $params['group'] = $this->group;
if ($this->sort != ATT_SORT_LASTNAME) $params['sort'] = $this->sort;
if (isset($this->copyfrom)) $params['copyfrom'] = $this->copyfrom;
if ($this->group) {
$params['group'] = $this->group;
}
if ($this->sort != ATT_SORT_LASTNAME) {
$params['sort'] = $this->sort;
}
if (isset($this->copyfrom)) {
$params['copyfrom'] = $this->copyfrom;
}
return $params;
}
@ -459,15 +480,20 @@ class att_report_page_params extends att_page_with_filter_controls {
public function init($cm) {
parent::init($cm);
if (!isset($this->group)) $this->group = $this->get_current_sesstype() > 0 ? $this->get_current_sesstype() : 0;
if (!isset($this->sort)) $this->sort = ATT_SORT_LASTNAME;
if (!isset($this->group)) {
$this->group = $this->get_current_sesstype() > 0 ? $this->get_current_sesstype() : 0;
}
if (!isset($this->sort)) {
$this->sort = ATT_SORT_LASTNAME;
}
}
public function get_significant_params() {
$params = array();
//if ($this->group) $params['group'] = $this->group;
if ($this->sort != ATT_SORT_LASTNAME) $params['sort'] = $this->sort;
if ($this->sort != ATT_SORT_LASTNAME) {
$params['sort'] = $this->sort;
}
return $params;
}
@ -488,8 +514,12 @@ class att_preferences_page_params {
public function get_significant_params() {
$params = array();
if (isset($this->action)) $params['action'] = $this->action;
if (isset($this->statusid)) $params['statusid'] = $this->statusid;
if (isset($this->action)) {
$params['action'] = $this->action;
}
if (isset($this->statusid)) {
$params['statusid'] = $this->statusid;
}
return $params;
}
@ -529,12 +559,10 @@ class attforblock {
private $statuses;
// Cache
// array by sessionid
// Array by sessionid.
private $sessioninfo = array();
// arrays by userid
// Arrays by userid.
private $usertakensesscount = array();
private $userstatusesstat = array();
@ -549,13 +577,12 @@ class attforblock {
* @param stdClass $course Course record from {course} table
* @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) {
if (property_exists('attforblock', $field)) {
$this->{$field} = $value;
}
else {
throw new coding_exception('The attendance table has field for which there is no property in the attforblock class');
} else {
throw new coding_exception('The attendance table has a field with no property in the attforblock class');
}
}
$this->cm = $cm;
@ -572,9 +599,9 @@ class attforblock {
}
public function get_group_mode() {
if (is_null($this->groupmode))
if (is_null($this->groupmode)) {
$this->groupmode = groups_get_activity_groupmode($this->cm);
}
return $this->groupmode;
}
@ -588,7 +615,7 @@ class attforblock {
public function get_current_sessions() {
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 *
FROM {attendance_sessions}
@ -691,8 +718,7 @@ class attforblock {
foreach ($sessions as $sess) {
if (empty($sess->description)) {
$sess->description = get_string('nodescription', 'attforblock');
}
else {
} else {
$sess->description = file_rewrite_pluginfile_urls($sess->description,
'pluginfile.php', $this->context->id, 'mod_attforblock', 'session', $sess->id);
}
@ -805,8 +831,8 @@ class attforblock {
$now = time();
$sesslog = array();
$formdata = (array)$formdata;
foreach($formdata as $key => $value) {
if(substr($key, 0, 4) == 'user') {
foreach ($formdata as $key => $value) {
if (substr($key, 0, 4) == 'user') {
$sid = substr($key, 4);
$sesslog[$sid] = new stdClass();
$sesslog[$sid]->studentid = $sid;
@ -825,9 +851,9 @@ class attforblock {
if (array_key_exists($log->studentid, $dbsesslog)) {
$log->id = $dbsesslog[$log->studentid]->id;
$DB->update_record('attendance_log', $log);
}
else
} else {
$DB->insert_record('attendance_log', $log, false);
}
}
}
@ -837,7 +863,9 @@ class attforblock {
$rec->lasttakenby = $USER->id;
$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(
'sessionid' => $this->pageparams->sessionid,
@ -845,7 +873,7 @@ class attforblock {
$url = $this->url_take($params);
$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) {
global $DB;
//fields we need from the user table
// Fields we need from the user table.
$userfields = user_picture::fields('u').',u.username';
if (isset($this->pageparams->sort) and ($this->pageparams->sort == ATT_SORT_FIRSTNAME)) {
$orderby = "u.firstname ASC, u.lastname ASC";
}
else {
} else {
$orderby = "u.lastname ASC, u.firstname ASC";
}
$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)) {
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
FROM {user_enrolments} ue
JOIN {enrol} e ON e.id = ue.enrolid
@ -924,16 +951,15 @@ class attforblock {
public function get_session_info($sessionid) {
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));
if (empty($this->sessioninfo[$sessionid]->description)) {
$this->sessioninfo[$sessionid]->description = get_string('nodescription', 'attforblock');
}
else {
$this->sessioninfo[$sessionid]->description = file_rewrite_pluginfile_urls($this->sessioninfo[$sessionid]->description,
'pluginfile.php', $this->context->id, 'mod_attforblock', 'session', $this->sessioninfo[$sessionid]->id);
}
}
if (empty($this->sessioninfo[$sessionid]->description)) {
$this->sessioninfo[$sessionid]->description = get_string('nodescription', 'attforblock');
} else {
$this->sessioninfo[$sessionid]->description = file_rewrite_pluginfile_urls($this->sessioninfo[$sessionid]->description,
'pluginfile.php', $this->context->id, 'mod_attforblock', 'session', $this->sessioninfo[$sessionid]->id);
}
return $this->sessioninfo[$sessionid];
}
@ -946,8 +972,7 @@ class attforblock {
foreach ($sessions as $sess) {
if (empty($sess->description)) {
$sess->description = get_string('nodescription', 'attforblock');
}
else {
} else {
$sess->description = file_rewrite_pluginfile_urls($sess->description,
'pluginfile.php', $this->context->id, 'mod_attforblock', 'session', $sess->id);
}
@ -971,9 +996,9 @@ class attforblock {
}
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);
}
return $this->usertakensesscount[$userid];
}
@ -1010,7 +1035,7 @@ class attforblock {
// * all sessions between user start enrolment date and now;
// * all sessions between user start and end enrolment date.
// While implementing those methods we need recalculate grades of all users
// on session adding
// on session adding.
public function get_user_max_grade($userid) {
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) {
$grades[$userid] = new stdClass();
$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',
@ -1059,10 +1085,10 @@ class attforblock {
public function get_user_filtered_sessions_log_extended($userid) {
global $DB;
// all taked sessions (including previous groups)
// All taked sessions (including previous groups).
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
ats.sessdate >= :sdate AND ats.sessdate < :edate";
} else {
$where = "ats.attendanceid = :aid AND ats.sessdate >= :csdate";
@ -1083,8 +1109,7 @@ class attforblock {
'edate' => $this->pageparams->enddate);
$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[] = 0;
@ -1107,12 +1132,10 @@ class attforblock {
$params = array_merge($params, $gparams);
$sessions = array_merge($sessions, $DB->get_records_sql($sql, $params));
foreach ($sessions as $sess) {
if (empty($sess->description)) {
$sess->description = get_string('nodescription', 'attforblock');
}
else {
} else {
$sess->description = file_rewrite_pluginfile_urls($sess->description,
'pluginfile.php', $this->context->id, 'mod_attforblock', 'session', $sess->id);
}
@ -1142,7 +1165,8 @@ class attforblock {
$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) {
@ -1223,9 +1247,11 @@ function att_get_statuses($attid, $onlyvisible=true) {
global $DB;
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 {
$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;
@ -1303,10 +1329,11 @@ function att_get_user_courses_attendances($userid) {
}
function att_calc_user_grade_fraction($grade, $maxgrade) {
if ($maxgrade == 0)
if ($maxgrade == 0) {
return 0;
else
} else {
return $grade / $maxgrade;
}
}
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();
$id = required_param('id', PARAM_INT);
$from = optional_param('from', NULL, PARAM_ACTION);
$pageparams->view = optional_param('view', NULL, PARAM_INT);
$pageparams->curdate = optional_param('curdate', NULL, PARAM_INT);
$from = optional_param('from', null, PARAM_ALPHANUMEXT);
$pageparams->view = optional_param('view', null, PARAM_INT);
$pageparams->curdate = optional_param('curdate', null, PARAM_INT);
$cm = get_coursemodule_from_id('attforblock', $id, 0, false, 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);
$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());
}
// 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') {
$sessions = $att->get_today_sessions();
$size = count($sessions);
@ -51,11 +52,12 @@ if ($from === 'block') {
$sess = reset($sessions);
$nottaken = !$sess->lasttaken && has_capability('mod/attforblock:takeattendances', $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)));
} elseif ($size > 1) {
}
} else if ($size > 1) {
$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;
}
}
@ -72,10 +74,10 @@ $tabs = new attforblock_tabs($att, attforblock_tabs::TAB_SESSIONS);
$filtercontrols = new attforblock_filter_controls($att);
$sesstable = new attforblock_manage_data($att);
/// Output starts here
// Output starts here.
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($filtercontrols);
echo $output->render($sesstable);

11
mod_form.php

@ -23,19 +23,18 @@
*/
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 {
function definition() {
public function definition() {
global $CFG;
$mform =& $this->_form;
//-------------------------------------------------------------------------------
$mform->addElement('header', 'general', get_string('general', 'form'));
$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->setDefault('grade', 100);
//-------------------------------------------------------------------------------
$this->standard_coursemodule_elements(true);
//-------------------------------------------------------------------------------
// buttons
$this->add_action_buttons();
}

9
module.js

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

32
preferences.php

@ -28,8 +28,8 @@ require_once(dirname(__FILE__).'/locallib.php');
$pageparams = new att_preferences_page_params();
$id = required_param('id', PARAM_INT);
$pageparams->action = optional_param('action', NULL, PARAM_INT);
$pageparams->statusid = optional_param('statusid', NULL, PARAM_INT);
$pageparams->action = optional_param('action', null, PARAM_INT);
$pageparams->statusid = optional_param('statusid', null, PARAM_INT);
$cm = get_coursemodule_from_id('attforblock', $id, 0, false, 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) {
case att_preferences_page_params::ACTION_ADD:
$newacronym = optional_param('newacronym', null, PARAM_MULTILANG);
$newdescription = optional_param('newdescription', null, PARAM_MULTILANG);
$newgrade = optional_param('newgrade', 0, PARAM_INT);
$newacronym = optional_param('newacronym', null, PARAM_TEXT);
$newdescription = optional_param('newdescription', null, PARAM_TEXT);
$newgrade = optional_param('newgrade', 0, PARAM_INT);
$att->add_status($newacronym, $newdescription, $newgrade);
break;
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");
}
$confirm = optional_param('confirm', NULL, PARAM_INT);
$confirm = optional_param('confirm', null, PARAM_INT);
if (isset($confirm)) {
$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();
$status = $statuses[$att->pageparams->statusid];
$message = get_string('deletecheckfull', '', get_string('variable', 'attforblock'));
$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));
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->footer();
exit;
@ -84,9 +86,9 @@ switch ($att->pageparams->action) {
$att->update_status($att->pageparams->statusid, null, null, null, 1);
break;
case att_preferences_page_params::ACTION_SAVE:
$acronym = required_param_array('acronym', PARAM_MULTILANG);
$description = required_param_array('description', PARAM_MULTILANG);
$grade = required_param_array('grade', PARAM_INT);
$acronym = required_param_array('acronym', PARAM_MULTILANG);
$description = required_param_array('description', PARAM_MULTILANG);
$grade = required_param_array('grade', PARAM_INT);
foreach ($acronym as $id => $v) {
$att->update_status($id, $acronym[$id], $description[$id], $grade[$id], null);
@ -99,10 +101,10 @@ $output = $PAGE->get_renderer('mod_attforblock');
$tabs = new attforblock_tabs($att, attforblock_tabs::TAB_PREFERENCES);
$prefdata = new attforblock_preferences_data($att);
/// Output starts here
// Output starts here.
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($prefdata);

77
renderables.php

@ -51,7 +51,7 @@ class attforblock_tabs implements renderable {
* @param attforblock $att instance
* @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->currenttab = $currenttab;
}
@ -66,27 +66,28 @@ class attforblock_tabs implements renderable {
$this->att->perm->can_take() or
$this->att->perm->can_change()) {
$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()) {
$toprow[] = new tabobject(self::TAB_ADD, $this->att->url_sessions()->out(true, array('action' => att_sessions_page_params::ACTION_ADD)),
get_string('add','attforblock'));
$toprow[] = new tabobject(self::TAB_ADD,
$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()) {
$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()) {
$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()) {
$toprow[] = new tabobject(self::TAB_PREFERENCES, $this->att->url_preferences()->out(),
get_string('settings','attforblock'));
get_string('settings', 'attforblock'));
}
return array($toprow);
@ -137,7 +138,8 @@ class attforblock_filter_controls implements renderable {
$format = get_string('strftimedm', 'attforblock');
$this->prevcur = $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;
case ATT_VIEW_MONTHS:
$format = '%B';
@ -228,7 +230,7 @@ class attforblock_manage_data implements renderable {
/**
* 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);
}
}
@ -259,8 +261,7 @@ class attforblock_take_data implements renderable {
public function __construct(attforblock $att) {
if ($att->pageparams->grouptype) {
$this->users = $att->get_users($att->pageparams->grouptype);
}
else {
} else {
$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->updatemode = $this->sessioninfo->lasttaken > 0;
if (isset($att->pageparams->copyfrom))
if (isset($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);
else
} else {
$this->sessionlog = array();
}
if (!$this->updatemode)
if (!$this->updatemode) {
$this->sessions4copy = $att->get_today_sessions_for_copy($this->sessioninfo);
}
$this->urlpath = $att->url_take()->out_omit_querystring();
$params = $att->pageparams->get_significant_params();
@ -293,12 +295,13 @@ class attforblock_take_data implements renderable {
$this->att = $att;
}
public function url($params=array(), $excludeparams=array()) {
$params = array_merge($this->urlparams, $params);
foreach ($excludeparams as $paramkey)
foreach ($excludeparams as $paramkey) {
unset($params[$paramkey]);
}
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->filtercontrols = new attforblock_filter_controls($att);
$this->sessionslog = $att->get_user_filtered_sessions_log_extended($userid);
$this->groups = groups_get_all_groups($att->course->id);
}
else {
} else {
$this->coursesatts = att_get_user_courses_attendances($userid);
$this->statuses = array();
@ -397,15 +398,14 @@ class attforblock_user_data implements renderable {
// * all sessions between user start enrolment date and now;
// * all sessions between user start and end enrolment date.
$this->maxgrade[$ca->attid] = att_get_user_max_grade($user_taken_sessions_count, $statuses);
}
else {
//for more comfortable and universal work with arrays
$this->grade[$ca->attid] = NULL;
$this->maxgrade[$ca->attid] = NULL;
} else {
// For more comfortable and universal work with arrays.
$this->grade[$ca->attid] = null;
$this->maxgrade[$ca->attid] = null;
}
}
}
$this->urlpath = $att->url_view()->out_omit_querystring();
$params = $att->pageparams->get_significant_params();
$params['id'] = $att->cm->id;
@ -428,7 +428,7 @@ class attforblock_report_data implements renderable {
public $sessions;
public $statuses;
// includes disablrd/deleted statuses
// Includes disablrd/deleted statuses.
public $allstatuses;
public $gradable;
@ -461,7 +461,7 @@ class attforblock_report_data implements renderable {
$this->statuses = $att->get_statuses();
$this->allstatuses = $att->get_statuses(false);
$this->gradable = $att->grade > 0;
if (!$this->decimalpoints = grade_get_setting($att->course->id, 'decimalpoints')) {
@ -508,14 +508,17 @@ class attforblock_preferences_data implements renderable {
public function __construct(attforblock $att) {
$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;
}
public function url($params=array(), $significant_params=TRUE) {
if ($significant_params)
public function url($params=array(), $significant_params=true) {
if ($significant_params) {
$params = array_merge($this->att->pageparams->get_significant_params(), $params);
}
return $this->att->url_preferences($params);
}
@ -524,8 +527,9 @@ class attforblock_preferences_data implements renderable {
class url_helpers {
public static function url_take($att, $sessionid, $grouptype) {
$params = array('sessionid' => $sessionid);
if (isset($grouptype))
if (isset($grouptype)) {
$params['grouptype'] = $grouptype;
}
return $att->url_take($params);
}
@ -533,11 +537,12 @@ class url_helpers {
/**
* Must be called without or with both parameters
*/
public static function url_sessions($att, $sessionid=NULL, $action=NULL) {
if (isset($sessionid) && isset($action))
public static function url_sessions($att, $sessionid=null, $action=null) {
if (isset($sessionid) && isset($action)) {
$params = array('sessionid' => $sessionid, 'action' => $action);
else
} else {
$params = array();
}
return $att->url_sessions($params);
}

208
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
*/
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
@ -46,7 +43,7 @@ class mod_attforblock_renderer extends plugin_renderer_base {
* @return string html code
*/
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);
}
/**
@ -92,7 +89,7 @@ class mod_attforblock_renderer extends plugin_renderer_base {
return '';
}
protected function render_curdate_controls(attforblock_filter_controls $fcontrols) {
global $CFG;
@ -100,15 +97,16 @@ class mod_attforblock_renderer extends plugin_renderer_base {
if ($fcontrols->curdatetxt) {
$this->page->requires->strings_for_js(array('calclose', 'caltoday'), 'attforblock');
$jsvals = array(
'cal_months' => explode(',', get_string('calmonths','attforblock')),
'cal_week_days' => explode(',', get_string('calweekdays','attforblock')),
'cal_months' => explode(',', get_string('calmonths', 'attforblock')),
'cal_week_days' => explode(',', get_string('calweekdays', 'attforblock')),
'cal_start_weekday' => $CFG->calendar_startwday,
'cal_cur_date' => $fcontrols->curdate);
$curdate_controls = html_writer::script(js_writer::set_variable('M.attforblock', $jsvals));
$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(
'title' => get_string('calshow', 'attforblock'),
'id' => 'show',
@ -127,11 +125,12 @@ class mod_attforblock_renderer extends plugin_renderer_base {
'action' => $fcontrols->url_path(),
'method' => 'post'
);
$button_form = html_writer::tag('form', $button_form, $params);
$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;
@ -148,14 +147,14 @@ class mod_attforblock_renderer extends plugin_renderer_base {
if ($key != $fcontrols->pageparams->view) {
$link = html_writer::link($fcontrols->url(array('view' => $key)), $sview);
$viewcontrols .= html_writer::tag('span', $link, array('class' => 'attbtn'));
}
else
} else {
$viewcontrols .= html_writer::tag('span', $sview, array('class' => 'attcurbtn'));
}
}
return html_writer::tag('nobr', $viewcontrols);
}
/**
* Renders attendance sessions managing table
*
@ -181,7 +180,7 @@ class mod_attforblock_renderer extends plugin_renderer_base {
get_string('sessiontypeshort', 'attforblock'),
get_string('date'),
get_string('time'),
get_string('description','attforblock'),
get_string('description', 'attforblock'),
get_string('actions'),
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);
$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['time'];
$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'));
$time = $this->construct_time($sess->sessdate, $sess->duration);
if($sess->lasttaken > 0)
{
if ($sess->lasttaken > 0) {
if ($sessdata->perm->can_change()) {
$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));
$time = html_writer::link($url, $time, array('title' => $title));
@ -228,17 +227,17 @@ class mod_attforblock_renderer extends plugin_renderer_base {
} else {
if ($sessdata->perm->can_take()) {
$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));
}
}
if($sessdata->perm->can_manage()) {
if ($sessdata->perm->can_manage()) {
$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));
$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));
}
@ -265,7 +264,7 @@ class mod_attforblock_renderer extends plugin_renderer_base {
'value' => get_string('ok'));
$controls .= html_writer::empty_tag('input', $attributes);
} 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;
@ -275,20 +274,21 @@ class mod_attforblock_renderer extends plugin_renderer_base {
protected function render_attforblock_take_data(attforblock_take_data $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);
else
} else {
$table = $this->render_attforblock_take_grid($takedata);
}
$table .= html_writer::input_hidden_params($takedata->url());
$params = array(
'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('form', $table, array('method' => 'post', 'action' => $takedata->url_path()));
return $controls.$table;
}
protected function render_attforblock_take_controls(attforblock_take_data $takedata) {
$table = new html_table();
$table->attributes['class'] = ' ';
@ -324,19 +324,20 @@ class mod_attforblock_renderer extends plugin_renderer_base {
$controls .= html_writer::empty_tag('br');
$options = array(
att_take_page_params::SORTED_LIST => get_string('sortedlist','attforblock'),
att_take_page_params::SORTED_GRID => get_string('sortedgrid','attforblock'));
$select = new single_select($takedata->url(), 'viewmode', $options, $takedata->pageparams->viewmode, NULL);
$select->set_label(get_string('viewmode','attforblock'));
att_take_page_params::SORTED_LIST => get_string('sortedlist', 'attforblock'),
att_take_page_params::SORTED_GRID => get_string('sortedgrid', 'attforblock'));
$select = new single_select($takedata->url(), 'viewmode', $options, $takedata->pageparams->viewmode, null);
$select->set_label(get_string('viewmode', 'attforblock'));
$select->class = 'singleselect inline';
$controls .= $this->output->render($select);
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'),
'4 '.get_string('columns','attforblock'),'5 '.get_string('columns','attforblock'),'6 '.get_string('columns','attforblock'),
'7 '.get_string('columns','attforblock'),'8 '.get_string('columns','attforblock'),'9 '.get_string('columns','attforblock'),
'10 '.get_string('columns','attforblock'));
$select = new single_select($takedata->url(), 'gridcols', $options, $takedata->pageparams->gridcols, NULL);
$options = array (1 => '1 '.get_string('column', 'attforblock'), '2 '.get_string('columns', 'attforblock'),
'3 '.get_string('columns', 'attforblock'), '4 '.get_string('columns', 'attforblock'),
'5 '.get_string('columns', 'attforblock'), '6 '.get_string('columns', 'attforblock'),
'7 '.get_string('columns', 'attforblock'), '8 '.get_string('columns', 'attforblock'),
'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';
$controls .= $this->output->render($select);
}
@ -348,15 +349,16 @@ class mod_attforblock_renderer extends plugin_renderer_base {
$options = array();
foreach ($takedata->sessions4copy as $sess) {
$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;
}
$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';
$controls .= $this->output->render($select);
}
return $controls;
}
@ -371,7 +373,8 @@ class mod_attforblock_renderer extends plugin_renderer_base {
$table->size = array('20px', '');
$table->wrap[1] = 'nowrap';
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->size[] = '20px';
}
@ -399,11 +402,13 @@ class mod_attforblock_renderer extends plugin_renderer_base {
$cell = new html_table_cell($ucdata['text']);
$cell->colspan = $ucdata['colspan'];
$row->cells[] = $cell;
}
else
} else {
$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;
}
@ -421,13 +426,14 @@ class mod_attforblock_renderer extends plugin_renderer_base {
$table->headspan = $takedata->pageparams->gridcols;
$head = array();
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);
$i = 0;
$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 .= html_writer::empty_tag('br');
$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);
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;
$i++;
@ -450,23 +458,27 @@ class mod_attforblock_renderer extends plugin_renderer_base {
$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);
}
private function construct_fullname_head($data) {
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'));
else
} else {
$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'));
else
} else {
$lastname = get_string('lastname');
}
if ($CFG->fullnamedisplay == '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['colspan'] = count($takedata->statuses) + 1;
$celldata['class'] = 'userwithoutenrol';
}
// no enrolmentend and ENROL_USER_SUSPENDED
elseif (!$user->enrolmentend and $user->enrolmentstatus == ENROL_USER_SUSPENDED) {
} else if (!$user->enrolmentend and $user->enrolmentstatus == ENROL_USER_SUSPENDED) {
// No enrolmentend and ENROL_USER_SUSPENDED.
$celldata['text'] = get_string('enrolmentsuspended', 'attforblock');
$celldata['colspan'] = count($takedata->statuses) + 1;
$celldata['class'] = 'userwithoutenrol';
}
else {
if ($takedata->updatemode and !array_key_exists($user->id, $takedata->sessionlog))
} else {
if ($takedata->updatemode and !array_key_exists($user->id, $takedata->sessionlog)) {
$celldata['class'] = 'userwithoutdata';
}
$celldata['text'] = array();
foreach ($takedata->statuses as $st) {
@ -501,25 +512,29 @@ class mod_attforblock_renderer extends plugin_renderer_base {
'name' => 'user'.$user->id,
'class' => 'st'.$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'] = '';
}
$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);
}
$celldata['text'][] = $input;
}
$params = array(
'type' => 'text',
'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;
}
$celldata['text'][] = html_writer::empty_tag('input', $params);
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';
}
}
@ -547,13 +562,13 @@ class mod_attforblock_renderer extends plugin_renderer_base {
$tabs[] = new tabobject(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,
$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) {
@ -568,8 +583,7 @@ class mod_attforblock_renderer extends plugin_renderer_base {
$o .= $this->render_attforblock_filter_controls($userdata->filtercontrols);
$o .= $this->construct_user_sessions_log($userdata);
}
else {
} else {
$prevcid = 0;
foreach ($userdata->coursesatts as $ca) {
if ($prevcid != $ca->courseid) {
@ -597,9 +611,9 @@ class mod_attforblock_renderer extends plugin_renderer_base {
get_string('sessiontypeshort', 'attforblock'),
get_string('date'),
get_string('time'),
get_string('description','attforblock'),
get_string('status','attforblock'),
get_string('remarks','attforblock')
get_string('description', 'attforblock'),
get_string('status', 'attforblock'),
get_string('remarks', 'attforblock')
);
$table->align = array('', '', '', 'left', 'left', 'center', 'left');
$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->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[] = $this->construct_time($sess->sessdate, $sess->duration);
$row->cells[] = $sess->description;
if (isset($sess->statusid)) {
$row->cells[] = $userdata->statuses[$sess->statusid]->description;
$row->cells[] = $sess->remarks;
}
elseif ($sess->sessdate < $userdata->user->enrolmentstart) {
$cell = new html_table_cell(get_string('enrolmentstart', 'attforblock', userdate($userdata->user->enrolmentstart, '%d.%m.%Y')));
} else if ($sess->sessdate < $userdata->user->enrolmentstart) {
$cell = new html_table_cell(get_string('enrolmentstart', 'attforblock',
userdate($userdata->user->enrolmentstart, '%d.%m.%Y')));
$cell->colspan = 2;
$row->cells[] = $cell;
}
elseif ($userdata->user->enrolmentend and $sess->sessdate > $userdata->user->enrolmentend) {
$cell = new html_table_cell(get_string('enrolmentend', 'attforblock', userdate($userdata->user->enrolmentend, '%d.%m.%Y')));
} else if ($userdata->user->enrolmentend and $sess->sessdate > $userdata->user->enrolmentend) {
$cell = new html_table_cell(get_string('enrolmentend', 'attforblock',
userdate($userdata->user->enrolmentend, '%d.%m.%Y')));
$cell->colspan = 2;
$row->cells[] = $cell;
}
else {
} else {
$row->cells[] = '?';
$row->cells[] = '';
}
@ -650,7 +664,7 @@ class mod_attforblock_renderer extends plugin_renderer_base {
$table->attributes['class'] = 'generaltable attwidth';
// user picture
// User picture.
$table->head[] = '';
$table->align[] = 'left';
$table->size[] = '1px';
@ -663,8 +677,9 @@ class mod_attforblock_renderer extends plugin_renderer_base {
$sesstext = userdate($sess->sessdate, get_string('strftimedm', 'attforblock'));
$sesstext .= html_writer::empty_tag('br');
$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::empty_tag('br');
$sesstext .= $sess->groupid ? $reportdata->groups[$sess->groupid]->name : get_string('commonsession', 'attforblock');
@ -672,7 +687,7 @@ class mod_attforblock_renderer extends plugin_renderer_base {
$table->align[] = 'center';
$table->size[] = '1px';
}
foreach ($reportdata->statuses as $status) {
$table->head[] = $status->acronym;
$table->align[] = 'center';
@ -694,11 +709,12 @@ class mod_attforblock_renderer extends plugin_renderer_base {
$row->cells = array_merge($row->cells, $cellsgenerator->get_cells());
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;
else
// no attendance data for this $status => no statistic for this status
} else {
// No attendance data for this $status => no statistic for this status.
$row->cells[] = 0;
}
}
if ($reportdata->gradable) {
@ -738,15 +754,17 @@ 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('newdescription', 30, 30);
$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::input_hidden_params($prefdata->url(array(), false));
$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');
return $o;
}
@ -770,8 +788,7 @@ class mod_attforblock_renderer extends plugin_renderer_base {
$showhideicon = $OUTPUT->action_icon(
$prefdata->url($params),
new pix_icon("t/hide", get_string('hide')));
}
else {
} else {
$params = array(
'action' => att_preferences_page_params::ACTION_SHOW,
'statusid' => $st->id);
@ -786,8 +803,9 @@ class mod_attforblock_renderer extends plugin_renderer_base {
$deleteicon = $OUTPUT->action_icon(
$prefdata->url($params),
new pix_icon("t/delete", get_string('delete')));
} else {
$deleteicon = '';
}
else $deleteicon = '';
return $showhideicon . $deleteicon;
}

85
renderhelpers.php

@ -54,21 +54,19 @@ class user_sessions_cells_generator {
if ($this->user->enrolmentstart > $sess->sessdate) {
$starttext = get_string('enrolmentstart', 'attforblock', userdate($this->user->enrolmentstart, '%d.%m.%Y'));
$this->construct_enrolments_info_cell($starttext);
}
elseif ($this->user->enrolmentend and $this->user->enrolmentend < $sess->sessdate) {
} else if ($this->user->enrolmentend and $this->user->enrolmentend < $sess->sessdate) {
$endtext = get_string('enrolmentend', 'attforblock', userdate($this->user->enrolmentend, '%d.%m.%Y'));
$this->construct_enrolments_info_cell($endtext);
}
// no enrolmentend and ENROL_USER_SUSPENDED
elseif (!$this->user->enrolmentend and $this->user->enrolmentstatus == ENROL_USER_SUSPENDED) {
} else if (!$this->user->enrolmentend and $this->user->enrolmentstatus == ENROL_USER_SUSPENDED) {
// No enrolmentend and ENROL_USER_SUSPENDED.
$suspendext = get_string('enrolmentsuspended', 'attforblock', userdate($this->user->enrolmentend, '%d.%m.%Y'));
$this->construct_enrolments_info_cell($suspendext);
}
else {
if ($sess->groupid == 0 or array_key_exists($sess->groupid, $this->reportdata->usersgroups[$this->user->id]))
} else {
if ($sess->groupid == 0 or array_key_exists($sess->groupid, $this->reportdata->usersgroups[$this->user->id])) {
$this->construct_not_taken_cell('?');
else
} else {
$this->construct_not_existing_for_user_session_cell('');
}
}
}
}
@ -102,13 +100,12 @@ class user_sessions_cells_generator {
}
protected function finalize_cells() {
}
}
class user_sessions_cells_html_generator extends user_sessions_cells_generator {
private $cell;
protected function construct_existing_status_cell($text) {
$this->close_open_cell_if_needed();
$this->cells[] = $text;
@ -122,25 +119,24 @@ class user_sessions_cells_html_generator extends user_sessions_cells_generator {
if (is_null($this->cell)) {
$this->cell = new html_table_cell($text);
$this->cell->colspan = 1;
}
else {
} else {
if ($this->cell->text != $text) {
$this->cells[] = $this->cell;
$this->cell = new html_table_cell($text);
$this->cell->colspan = 1;
}
else
} else {
$this->cell->colspan++;
}
}
}
private function close_open_cell_if_needed(){
private function close_open_cell_if_needed() {
if ($this->cell) {
$this->cells[] = $this->cell;
$this->cell = null;
}
}
protected function construct_not_taken_cell($text) {
$this->close_open_cell_if_needed();
$this->cells[] = $text;
@ -152,8 +148,9 @@ class user_sessions_cells_html_generator extends user_sessions_cells_generator {
}
protected function finalize_cells() {
if ($this->cell)
if ($this->cell) {
$this->cells[] = $this->cell;
}
}
}
@ -168,9 +165,9 @@ class user_sessions_cells_text_generator extends user_sessions_cells_generator {
if ($this->enrolments_info_cell_text != $text) {
$this->enrolments_info_cell_text = $text;
$this->cells[] = $text;
}
else
} else {
$this->cells[] = '←';
}
}
}
@ -190,11 +187,11 @@ function construct_session_full_date_time($datetime, $duration) {
function construct_user_data_stat($stat, $statuses, $gradable, $grade, $maxgrade, $decimalpoints) {
global $OUTPUT;
$stattable = new html_table();
$stattable->attributes['class'] = 'attlist';
$row = new html_table_row();
$row->cells[] = get_string('sessionscompleted','attforblock').':';
$row->cells[] = get_string('sessionscompleted', 'attforblock').':';
$row->cells[] = $stat['completed'];
$stattable->data[] = $row;
@ -208,12 +205,13 @@ function construct_user_data_stat($stat, $statuses, $gradable, $grade, $maxgrade
if ($gradable) {
$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;
$stattable->data[] = $row;
$row = new html_table_row();
$row->cells[] = get_string('attendancepercent','attforblock') . ':';
$row->cells[] = get_string('attendancepercent', 'attforblock') . ':';
if ($maxgrade == 0) {
$percent = 0;
} else {
@ -227,26 +225,25 @@ function construct_user_data_stat($stat, $statuses, $gradable, $grade, $maxgrade
}
function construct_full_user_stat_html_table($attforblock, $course, $user) {
global $CFG;
$gradeable = $attforblock->grade > 0;
$statuses = att_get_statuses($attforblock->id);
$userstatusesstat = att_get_user_statuses_stat($attforblock->id, $course->startdate, $user->id);
$stat['completed'] = att_get_user_taken_sessions_count($attforblock->id, $course->startdate, $user->id);
$stat['statuses'] = $userstatusesstat;
if ($gradeable) {
$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);
if (!$decimalpoints = grade_get_setting($course->id, 'decimalpoints')) {
$decimalpoints = $CFG->grade_decimalpoints;
}
}
else {
$grade = 0;
$maxgrade = 0;
$decimalpoints = 0;
global $CFG;
$gradeable = $attforblock->grade > 0;
$statuses = att_get_statuses($attforblock->id);
$userstatusesstat = att_get_user_statuses_stat($attforblock->id, $course->startdate, $user->id);
$stat['completed'] = att_get_user_taken_sessions_count($attforblock->id, $course->startdate, $user->id);
$stat['statuses'] = $userstatusesstat;
if ($gradeable) {
$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);
if (!$decimalpoints = grade_get_setting($course->id, 'decimalpoints')) {
$decimalpoints = $CFG->grade_decimalpoints;
}
} else {
$grade = 0;
$maxgrade = 0;
$decimalpoints = 0;
}
return construct_user_data_stat($stat, $statuses,
$gradeable, $grade, $maxgrade, $decimalpoints);
return construct_user_data_stat($stat, $statuses,
$gradeable, $grade, $maxgrade, $decimalpoints);
}

18
report.php

@ -28,11 +28,11 @@ require_once(dirname(__FILE__).'/locallib.php');
$pageparams = new att_report_page_params();
$id = required_param('id', PARAM_INT);
$from = optional_param('from', NULL, PARAM_ACTION);
$pageparams->view = optional_param('view', NULL, PARAM_INT);
$pageparams->curdate = optional_param('curdate', NULL, PARAM_INT);
$pageparams->group = optional_param('group', null, PARAM_INT);
$pageparams->sort = optional_param('sort', null, PARAM_INT);
$from = optional_param('from', null, PARAM_ACTION);
$pageparams->view = optional_param('view', null, PARAM_INT);
$pageparams->curdate = optional_param('curdate', null, PARAM_INT);
$pageparams->group = optional_param('group', null, PARAM_INT);
$pageparams->sort = optional_param('sort', null, PARAM_INT);
$cm = get_coursemodule_from_id('attforblock', $id, 0, false, MUST_EXIST);
$course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST);
@ -47,11 +47,11 @@ $att->perm->require_view_reports_capability();
$PAGE->set_url($att->url_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_cacheable(true);
$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');
$tabs = new attforblock_tabs($att, attforblock_tabs::TAB_REPORT);
@ -61,10 +61,10 @@ $reportdata = new attforblock_report_data($att);
global $USER;
$att->log('report viewed', null, $USER->firstname.' '.$USER->lastname);
/// Output starts here
// Output starts here.
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($filtercontrols);
echo $output->render($reportdata);

83
sessions.php

@ -54,39 +54,39 @@ $formparams = array('course' => $course, 'cm' => $cm, 'modcontext' => $PAGE->con
switch ($att->pageparams->action) {
case att_sessions_page_params::ACTION_ADD:
$url = $att->url_sessions(array('action' => att_sessions_page_params::ACTION_ADD));
$mform = new mod_attforblock_add_form($url, $formparams);
$mform = new mod_attforblock_add_form($url, $formparams);
if ($formdata = $mform->get_data()) {
$sessions = construct_sessions_data_for_add($formdata);
$att->add_sessions($sessions);
redirect($url, get_string('sessionsgenerated','attforblock'));
redirect($url, get_string('sessionsgenerated', 'attforblock'));
}
break;
case att_sessions_page_params::ACTION_UPDATE:
$sessionid = required_param('sessionid', PARAM_INT);
$sessionid = required_param('sessionid', PARAM_INT);
$url = $att->url_sessions(array('action' => att_sessions_page_params::ACTION_UPDATE, 'sessionid' => $sessionid));
$formparams['sessionid'] = $sessionid;
$mform = new mod_attforblock_update_form($url, $formparams);
if ($mform->is_cancelled()) {
redirect($att->url_manage());
}
$mform = new mod_attforblock_update_form($url, $formparams);
if ($mform->is_cancelled()) {
redirect($att->url_manage());
}
if ($formdata = $mform->get_data()) {
$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;
case att_sessions_page_params::ACTION_DELETE:
$sessionid = required_param('sessionid', PARAM_INT);
$confirm = optional_param('confirm', NULL, PARAM_INT);
$sessionid = required_param('sessionid', PARAM_INT);
$confirm = optional_param('confirm', null, PARAM_INT);
if (isset($confirm)) {
$att->delete_sessions(array($sessionid));
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);
@ -100,26 +100,27 @@ switch ($att->pageparams->action) {
$params = array('action' => $att->pageparams->action, 'sessionid' => $sessionid, 'confirm' => 1);
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->footer();
exit;
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)) {
$sessionsids = required_param('sessionsids', PARAM_ALPHANUMEXT);
$sessionsids = required_param('sessionsids', PARAM_ALPHANUMEXT);
$sessionsids = explode('_', $sessionsids);
$att->delete_sessions($sessionsids);
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();
// nothing selected
if (!isset($fromform->sessid))
$fromform = data_submitted();
// Nothing selected.
if (!isset($fromform->sessid)) {
print_error ('nosessionsselected', 'attforblock', $att->url_manage());
}
$sessionsinfo = $att->get_sessions_info($fromform->sessid);
@ -136,31 +137,32 @@ switch ($att->pageparams->action) {
$params = array('action' => $att->pageparams->action, 'sessionsids' => $sessionsids, 'confirm' => 1);
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->footer();
exit;
case att_sessions_page_params::ACTION_CHANGE_DURATION:
$fromform = data_submitted();
$fromform = data_submitted();
$slist = isset($fromform->sessid) ? implode('_', $fromform->sessid) : '';
$url = $att->url_sessions(array('action' => att_sessions_page_params::ACTION_CHANGE_DURATION));
$formparams['ids'] = $slist;
$mform = new mod_attforblock_duration_form($url, $formparams);
$mform = new mod_attforblock_duration_form($url, $formparams);
if ($mform->is_cancelled()) {
redirect($att->url_manage());
}
if ($mform->is_cancelled()) {
redirect($att->url_manage());
}
if ($formdata = $mform->get_data()) {
$sessionsids = explode('_', $fromform->ids);
$duration = $formdata->durtime['hours']*HOURSECS + $formdata->durtime['minutes']*MINSECS;
$att->update_sessions_duration($sessionsids, $duration);
redirect($att->url_manage(), get_string('sessionupdated','attforblock'));
redirect($att->url_manage(), get_string('sessionupdated', 'attforblock'));
}
if ($slist === '') {
print_error('nosessionsselected', 'attforblock', $att->url_manage());
}
if ($slist === '')
print_error ('nosessionsselected','attforblock', $att->url_manage());
break;
}
@ -168,7 +170,7 @@ switch ($att->pageparams->action) {
$output = $PAGE->get_renderer('mod_attforblock');
$tabs = new attforblock_tabs($att, attforblock_tabs::TAB_ADD);
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);
$mform->display();
@ -185,17 +187,19 @@ function construct_sessions_data_for_add($formdata) {
if (isset($formdata->addmultiply)) {
$startdate = $formdata->sessiondate;
$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);
// Getting first day of week
// Getting first day of week.
$sdate = $startdate;
$dinfo = usergetdate($sdate);
if ($CFG->calendar_startwday === '0') { //week start from sunday
$startweek = $startdate - $dinfo['wday'] * DAYSECS; //call new variable
if ($CFG->calendar_startwday === '0') { // Week start from sunday.
$startweek = $startdate - $dinfo['wday'] * DAYSECS; // Call new variable.
} else {
$wday = $dinfo['wday'] === 0 ? 7 : $dinfo['wday'];
$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');
while ($sdate < $enddate) {
if($sdate < $startweek + WEEKSECS) {
if ($sdate < $startweek + WEEKSECS) {
$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->sessdate = usergetmidnight($sdate) + $starttime;
$sess->duration = $duration;
@ -243,8 +247,7 @@ function fill_groupid($formdata, &$sessions, $sess) {
$sess = clone $sess;
$sess->groupid = 0;
$sessions[] = $sess;
}
else {
} else {
foreach ($formdata->groups as $groupid) {
$sess = clone $sess;
$sess->groupid = $groupid;

6
take.php

@ -30,7 +30,7 @@ $pageparams = new att_take_page_params();
$id = required_param('id', PARAM_INT);
$pageparams->sessionid = required_param('sessionid', PARAM_INT);
$pageparams->grouptype = required_param('grouptype', PARAM_INT);
$pageparams->sort = optional_param('sort', null, PARAM_INT);
$pageparams->sort = optional_param('sort', null, PARAM_INT);
$pageparams->copyfrom = optional_param('copyfrom', null, PARAM_INT);
$pageparams->viewmode = optional_param('viewmode', null, PARAM_INT);
$pageparams->gridcols = optional_param('gridcols', null, PARAM_INT);
@ -66,10 +66,10 @@ $output = $PAGE->get_renderer('mod_attforblock');
$tabs = new attforblock_tabs($att);
$sesstable = new attforblock_take_data($att);
/// Output starts here
// Output starts here.
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($sesstable);

28
update_form.php

@ -26,8 +26,7 @@
require_once($CFG->libdir.'/formslib.php');
class mod_attforblock_update_form extends moodleform {
function definition() {
public function definition() {
global $CFG, $DB;
$mform =& $this->_form;
@ -48,39 +47,28 @@ class mod_attforblock_update_form extends moodleform {
'durtime' => array('hours' => $dhours, 'minutes' => $dmins),
'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('date_time_selector', 'sessiondate', get_string('newdate','attforblock'));
$mform->addElement('static', 'olddate', get_string('olddate', 'attforblock'),
userdate($sess->sessdate, get_string('strftimedmyhm', 'attforblock')));
$mform->addElement('date_time_selector', 'sessiondate', get_string('newdate', 'attforblock'));
for ($i=0; $i<=23; $i++) {
$hours[$i] = sprintf("%02d",$i);
$hours[$i] = sprintf("%02d", $i);
}
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', '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->setType('sdescription', PARAM_RAW);
$mform->setDefaults($data);
//-------------------------------------------------------------------------------
// buttons
$submit_string = get_string('update', 'attforblock');
$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
*/
$module->version = 2012120700; // The current module version (Date: YYYYMMDDXX)
$module->version = 2012120700;
$module->requires = 2012120300;
$module->release = '2.4.1';
$module->maturity = MATURITY_ALPHA;
$module->cron = 0; // Period for cron to check this module (secs)
$module->component = 'mod_attforblock'; // Full name of the plugin (used for diagnostics)
$module->cron = 0;
$module->component = 'mod_attforblock';

13
view.php

@ -29,10 +29,10 @@ require_once(dirname(__FILE__).'/locallib.php');
$pageparams = new att_view_page_params();
$id = required_param('id', 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->view = optional_param('view', NULL, PARAM_INT);
$pageparams->curdate = optional_param('curdate', 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->view = optional_param('view', null, PARAM_INT);
$pageparams->curdate = optional_param('curdate', null, PARAM_INT);
$cm = get_coursemodule_from_id('attforblock', $id, 0, false, 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);
// Not specified studentid for displaying attendance?
// Redirect to appropriate page if can
// Redirect to appropriate page if can.
if (!$pageparams->studentid) {
if ($att->perm->can_manage() || $att->perm->can_take() || $att->perm->can_change()) {
redirect($att->url_manage());
}
elseif ($att->perm->can_view_reports()) {
} else if ($att->perm->can_view_reports()) {
redirect($att->url_report());
}
}

Loading…
Cancel
Save