Browse Source

Move attendance class into proper class

also adjust attendance grading function to pass full attendance class
to minimse db calls.
MOODLE_29_STABLE
Dan Marsden 9 years ago
parent
commit
d18786886f
  1. 14
      add_form.php
  2. 2
      attendance.php
  3. 1149
      classes/structure.php
  4. 2
      export.php
  5. 1157
      locallib.php
  6. 2
      manage.php
  7. 4
      preferences.php
  8. 16
      renderables.php
  9. 4
      renderer.php
  10. 2
      report.php
  11. 8
      sessions.php
  12. 2
      take.php
  13. 2
      temp_form.php
  14. 2
      tempedit.php
  15. 2
      tempedit_form.php
  16. 2
      tempmerge.php
  17. 4
      tempusers.php
  18. 2
      view.php

14
add_form.php

@ -54,26 +54,26 @@ class mod_attendance_add_form extends moodleform {
$mform->addElement('static', 'sessiontypedescription', get_string('sessiontype', 'attendance'), $mform->addElement('static', 'sessiontypedescription', get_string('sessiontype', 'attendance'),
get_string('commonsession', 'attendance')); get_string('commonsession', 'attendance'));
$mform->addHelpButton('sessiontypedescription', 'sessiontype', 'attendance'); $mform->addHelpButton('sessiontypedescription', 'sessiontype', 'attendance');
$mform->addElement('hidden', 'sessiontype', attendance::SESSION_COMMON); $mform->addElement('hidden', 'sessiontype', mod_attendance_structure::SESSION_COMMON);
$mform->setType('sessiontype', PARAM_INT); $mform->setType('sessiontype', PARAM_INT);
break; break;
case SEPARATEGROUPS: case SEPARATEGROUPS:
$mform->addElement('static', 'sessiontypedescription', get_string('sessiontype', 'attendance'), $mform->addElement('static', 'sessiontypedescription', get_string('sessiontype', 'attendance'),
get_string('groupsession', 'attendance')); get_string('groupsession', 'attendance'));
$mform->addHelpButton('sessiontypedescription', 'sessiontype', 'attendance'); $mform->addHelpButton('sessiontypedescription', 'sessiontype', 'attendance');
$mform->addElement('hidden', 'sessiontype', attendance::SESSION_GROUP); $mform->addElement('hidden', 'sessiontype', mod_attendance_structure::SESSION_GROUP);
$mform->setType('sessiontype', PARAM_INT); $mform->setType('sessiontype', PARAM_INT);
break; break;
case VISIBLEGROUPS: case VISIBLEGROUPS:
$radio = array(); $radio = array();
$radio[] = &$mform->createElement('radio', 'sessiontype', '', $radio[] = &$mform->createElement('radio', 'sessiontype', '',
get_string('commonsession', 'attendance'), attendance::SESSION_COMMON); get_string('commonsession', 'attendance'), mod_attendance_structure::SESSION_COMMON);
$radio[] = &$mform->createElement('radio', 'sessiontype', '', $radio[] = &$mform->createElement('radio', 'sessiontype', '',
get_string('groupsession', 'attendance'), attendance::SESSION_GROUP); get_string('groupsession', 'attendance'), mod_attendance_structure::SESSION_GROUP);
$mform->addGroup($radio, 'sessiontype', get_string('sessiontype', 'attendance'), ' ', false); $mform->addGroup($radio, 'sessiontype', get_string('sessiontype', 'attendance'), ' ', false);
$mform->setType('sessiontype', PARAM_INT); $mform->setType('sessiontype', PARAM_INT);
$mform->addHelpButton('sessiontype', 'sessiontype', 'attendance'); $mform->addHelpButton('sessiontype', 'sessiontype', 'attendance');
$mform->setDefault('sessiontype', attendance::SESSION_COMMON); $mform->setDefault('sessiontype', mod_attendance_structure::SESSION_COMMON);
break; break;
} }
if ($groupmode == SEPARATEGROUPS or $groupmode == VISIBLEGROUPS) { if ($groupmode == SEPARATEGROUPS or $groupmode == VISIBLEGROUPS) {
@ -89,7 +89,7 @@ class mod_attendance_add_form extends moodleform {
} }
$select = &$mform->addElement('select', 'groups', get_string('groups', 'group'), $selectgroups); $select = &$mform->addElement('select', 'groups', get_string('groups', 'group'), $selectgroups);
$select->setMultiple(true); $select->setMultiple(true);
$mform->disabledIf('groups', 'sessiontype', 'neq', attendance::SESSION_GROUP); $mform->disabledIf('groups', 'sessiontype', 'neq', mod_attendance_structure::SESSION_GROUP);
} else { } else {
if ($groupmode == VISIBLEGROUPS) { if ($groupmode == VISIBLEGROUPS) {
$mform->updateElementAttr($radio, array('disabled' => 'disabled')); $mform->updateElementAttr($radio, array('disabled' => 'disabled'));
@ -187,7 +187,7 @@ class mod_attendance_add_form extends moodleform {
$errors['sessionenddate'] = get_string('invalidsessionenddate', 'attendance'); $errors['sessionenddate'] = get_string('invalidsessionenddate', 'attendance');
} }
if ($data['sessiontype'] == attendance::SESSION_GROUP and empty($data['groups'])) { if ($data['sessiontype'] == mod_attendance_structure::SESSION_GROUP and empty($data['groups'])) {
$errors['groups'] = get_string('errorgroupsnotselected', 'attendance'); $errors['groups'] = get_string('errorgroupsnotselected', 'attendance');
} }

2
attendance.php

@ -40,7 +40,7 @@ $course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST)
require_login($course, true, $cm); require_login($course, true, $cm);
$pageparams->sessionid = $id; $pageparams->sessionid = $id;
$att = new attendance($attendance, $cm, $course, $PAGE->context, $pageparams); $att = new mod_attendance_structure($attendance, $cm, $course, $PAGE->context, $pageparams);
// Require that a session key is passed to this page. // Require that a session key is passed to this page.
require_sesskey(); require_sesskey();

1149
classes/structure.php

File diff suppressed because it is too large

2
export.php

@ -39,7 +39,7 @@ require_login($course, true, $cm);
$context = context_module::instance($cm->id); $context = context_module::instance($cm->id);
require_capability('mod/attendance:export', $context); require_capability('mod/attendance:export', $context);
$att = new attendance($att, $cm, $course, $context); $att = new mod_attendance_structure($att, $cm, $course, $context);
$PAGE->set_url($att->url_export()); $PAGE->set_url($att->url_export());
$PAGE->set_title($course->shortname. ": ".$att->name); $PAGE->set_title($course->shortname. ": ".$att->name);

1157
locallib.php

File diff suppressed because it is too large

2
manage.php

@ -50,7 +50,7 @@ if (!has_any_capability($capabilities, $context)) {
} }
$pageparams->init($cm); $pageparams->init($cm);
$att = new attendance($att, $cm, $course, $context, $pageparams); $att = new mod_attendance_structure($att, $cm, $course, $context, $pageparams);
// If teacher is coming from block, then check for a session exists for today. // If teacher is coming from block, then check for a session exists for today.
if ($from === 'block') { if ($from === 'block') {

4
preferences.php

@ -47,7 +47,7 @@ if ($pageparams->statusset > $maxstatusset + 1) {
$pageparams->statusset = $maxstatusset + 1; $pageparams->statusset = $maxstatusset + 1;
} }
$att = new attendance($att, $cm, $course, $context, $pageparams); $att = new mod_attendance_structure($att, $cm, $course, $context, $pageparams);
$PAGE->set_url($att->url_preferences()); $PAGE->set_url($att->url_preferences());
$PAGE->set_title($course->shortname. ": ".$att->name.' - '.get_string('settings', 'attendance')); $PAGE->set_title($course->shortname. ": ".$att->name.' - '.get_string('settings', 'attendance'));
@ -123,7 +123,7 @@ switch ($att->pageparams->action) {
$errors[$id] = $att->update_status($status, $acronym[$id], $description[$id], $grade[$id], null); $errors[$id] = $att->update_status($status, $acronym[$id], $description[$id], $grade[$id], null);
} }
if ($att->grade > 0) { if ($att->grade > 0) {
attendance_update_all_users_grades($att->id, $att->course, $att->context, $cm); attendance_update_all_users_grades($att, $cm);
} }
break; break;
} }

16
renderables.php

@ -56,7 +56,7 @@ class attendance_tabs implements renderable {
* @param attendance $att instance * @param attendance $att instance
* @param $currenttab - one of attendance_tabs constants * @param $currenttab - one of attendance_tabs constants
*/ */
public function __construct(attendance $att, $currenttab=null) { public function __construct(mod_attendance_structure $att, $currenttab=null) {
$this->att = $att; $this->att = $att;
$this->currenttab = $currenttab; $this->currenttab = $currenttab;
} }
@ -130,7 +130,7 @@ class attendance_filter_controls implements renderable {
private $att; private $att;
public function __construct(attendance $att, $report = false) { public function __construct(mod_attendance_structure $att, $report = false) {
global $PAGE; global $PAGE;
$this->pageparams = $att->pageparams; $this->pageparams = $att->pageparams;
@ -230,7 +230,7 @@ class attendance_manage_data implements renderable {
* *
* @param attendance $att instance * @param attendance $att instance
*/ */
public function __construct(attendance $att) { public function __construct(mod_attendance_structure $att) {
$this->sessions = $att->get_filtered_sessions(); $this->sessions = $att->get_filtered_sessions();
@ -275,7 +275,7 @@ class attendance_take_data implements renderable {
private $urlparams; private $urlparams;
private $att; private $att;
public function __construct(attendance $att) { public function __construct(mod_attendance_structure $att) {
if ($att->pageparams->grouptype) { if ($att->pageparams->grouptype) {
$this->users = $att->get_users($att->pageparams->grouptype, $att->pageparams->page); $this->users = $att->get_users($att->pageparams->grouptype, $att->pageparams->page);
} else { } else {
@ -359,7 +359,7 @@ class attendance_user_data implements renderable {
private $urlpath; private $urlpath;
private $urlparams; private $urlparams;
public function __construct(attendance $att, $userid) { public function __construct(mod_attendance_structure $att, $userid) {
global $CFG; global $CFG;
$this->user = $att->get_user($userid); $this->user = $att->get_user($userid);
@ -465,7 +465,7 @@ class attendance_report_data implements renderable {
public $att; public $att;
public function __construct(attendance $att) { public function __construct(mod_attendance_structure $att) {
global $CFG; global $CFG;
$currenttime = time(); $currenttime = time();
@ -549,7 +549,7 @@ class attendance_preferences_data implements renderable {
public $errors; public $errors;
public function __construct(attendance $att, $errors) { public function __construct(mod_attendance_structure $att, $errors) {
$this->statuses = $att->get_statuses(false); $this->statuses = $att->get_statuses(false);
$this->errors = $errors; $this->errors = $errors;
@ -575,7 +575,7 @@ class attendance_set_selector implements renderable {
private $att; private $att;
public function __construct(attendance $att, $maxstatusset) { public function __construct(mod_attendance_structure $att, $maxstatusset) {
$this->att = $att; $this->att = $att;
$this->maxstatusset = $maxstatusset; $this->maxstatusset = $maxstatusset;
} }

4
renderer.php

@ -395,7 +395,7 @@ class mod_attendance_renderer extends plugin_renderer_base {
$controls = ''; $controls = '';
$context = context_module::instance($takedata->cm->id); $context = context_module::instance($takedata->cm->id);
$group = 0; $group = 0;
if ($takedata->pageparams->grouptype != attendance::SESSION_COMMON) { if ($takedata->pageparams->grouptype != mod_attendance_structure::SESSION_COMMON) {
$group = $takedata->pageparams->grouptype; $group = $takedata->pageparams->grouptype;
} else { } else {
if ($takedata->pageparams->group) { if ($takedata->pageparams->group) {
@ -434,7 +434,7 @@ class mod_attendance_renderer extends plugin_renderer_base {
} }
} }
if ($takedata->pageparams->grouptype == attendance::SESSION_COMMON and if ($takedata->pageparams->grouptype == mod_attendance_structure::SESSION_COMMON and
($takedata->groupmode == VISIBLEGROUPS or ($takedata->groupmode == VISIBLEGROUPS or
($takedata->groupmode and has_capability('moodle/site:accessallgroups', $context)))) { ($takedata->groupmode and has_capability('moodle/site:accessallgroups', $context)))) {
$controls .= groups_print_activity_menu($takedata->cm, $takedata->url(), true); $controls .= groups_print_activity_menu($takedata->cm, $takedata->url(), true);

2
report.php

@ -46,7 +46,7 @@ $context = context_module::instance($cm->id);
require_capability('mod/attendance:viewreports', $context); require_capability('mod/attendance:viewreports', $context);
$pageparams->init($cm); $pageparams->init($cm);
$att = new attendance($attrecord, $cm, $course, $context, $pageparams); $att = new mod_attendance_structure($attrecord, $cm, $course, $context, $pageparams);
$PAGE->set_url($att->url_report()); $PAGE->set_url($att->url_report());
$PAGE->set_pagelayout('report'); $PAGE->set_pagelayout('report');

8
sessions.php

@ -53,7 +53,7 @@ require_login($course, true, $cm);
$context = context_module::instance($cm->id); $context = context_module::instance($cm->id);
require_capability('mod/attendance:manageattendances', $context); require_capability('mod/attendance:manageattendances', $context);
$att = new attendance($att, $cm, $course, $context, $pageparams); $att = new mod_attendance_structure($att, $cm, $course, $context, $pageparams);
$PAGE->set_url($att->url_sessions(array('action' => $pageparams->action))); $PAGE->set_url($att->url_sessions(array('action' => $pageparams->action)));
$PAGE->set_title($course->shortname. ": ".$att->name); $PAGE->set_title($course->shortname. ": ".$att->name);
@ -114,7 +114,7 @@ switch ($att->pageparams->action) {
if (isset($confirm) && confirm_sesskey()) { if (isset($confirm) && confirm_sesskey()) {
$att->delete_sessions(array($sessionid)); $att->delete_sessions(array($sessionid));
if ($att->grade > 0) { if ($att->grade > 0) {
attendance_update_all_users_grades($att->id, $att->course, $att->context, $cm); attendance_update_all_users_grades($att, $cm);
} }
redirect($att->url_manage(), get_string('sessiondeleted', 'attendance')); redirect($att->url_manage(), get_string('sessiondeleted', 'attendance'));
} }
@ -143,7 +143,7 @@ switch ($att->pageparams->action) {
$att->delete_sessions($sessionsids); $att->delete_sessions($sessionsids);
if ($att->grade > 0) { if ($att->grade > 0) {
attendance_update_all_users_grades($att->id, $att->course, $att->context, $cm); attendance_update_all_users_grades($att, $cm);
} }
redirect($att->url_manage(), get_string('sessiondeleted', 'attendance')); redirect($att->url_manage(), get_string('sessiondeleted', 'attendance'));
} }
@ -302,7 +302,7 @@ function construct_sessions_data_for_add($formdata) {
} }
function fill_groupid($formdata, &$sessions, $sess) { function fill_groupid($formdata, &$sessions, $sess) {
if ($formdata->sessiontype == attendance::SESSION_COMMON) { if ($formdata->sessiontype == mod_attendance_structure::SESSION_COMMON) {
$sess = clone $sess; $sess = clone $sess;
$sess->groupid = 0; $sess->groupid = 0;
$sessions[] = $sess; $sessions[] = $sess;

2
take.php

@ -48,7 +48,7 @@ require_capability('mod/attendance:takeattendances', $context);
$pageparams->group = groups_get_activity_group($cm, true); $pageparams->group = groups_get_activity_group($cm, true);
$pageparams->init($course->id); $pageparams->init($course->id);
$att = new attendance($att, $cm, $course, $PAGE->context, $pageparams); $att = new mod_attendance_structure($att, $cm, $course, $PAGE->context, $pageparams);
$allowedgroups = groups_get_activity_allowed_groups($cm); $allowedgroups = groups_get_activity_allowed_groups($cm);
if (!empty($pageparams->grouptype) && !array_key_exists($pageparams->grouptype, $allowedgroups)) { if (!empty($pageparams->grouptype) && !array_key_exists($pageparams->grouptype, $allowedgroups)) {

2
temp_form.php

@ -57,7 +57,7 @@ class temp_form extends moodleform {
public function validation($data, $files) { public function validation($data, $files) {
$errors = parent::validation($data, $files); $errors = parent::validation($data, $files);
if ($err = attendance::check_existing_email($data['temail'])) { if ($err = mod_attendance_structure::check_existing_email($data['temail'])) {
$errors['temail'] = $err; $errors['temail'] = $err;
} }

2
tempedit.php

@ -37,7 +37,7 @@ $course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST)
$att = $DB->get_record('attendance', array('id' => $cm->instance), '*', MUST_EXIST); $att = $DB->get_record('attendance', array('id' => $cm->instance), '*', MUST_EXIST);
$tempuser = $DB->get_record('attendance_tempusers', array('id' => $userid), '*', MUST_EXIST); $tempuser = $DB->get_record('attendance_tempusers', array('id' => $userid), '*', MUST_EXIST);
$att = new attendance($att, $cm, $course); $att = new mod_attendance_structure($att, $cm, $course);
$params = array('userid' => $tempuser->id); $params = array('userid' => $tempuser->id);
if ($action) { if ($action) {

2
tempedit_form.php

@ -63,7 +63,7 @@ class tempedit_form extends moodleform {
public function validation($data, $files) { public function validation($data, $files) {
$errors = parent::validation($data, $files); $errors = parent::validation($data, $files);
if ($err = attendance::check_existing_email($data['temail'], $data['userid'])) { if ($err = mod_attendance_structure::check_existing_email($data['temail'], $data['userid'])) {
$errors['temail'] = $err; $errors['temail'] = $err;
} }
return $errors; return $errors;

2
tempmerge.php

@ -36,7 +36,7 @@ $course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST)
$att = $DB->get_record('attendance', array('id' => $cm->instance), '*', MUST_EXIST); $att = $DB->get_record('attendance', array('id' => $cm->instance), '*', MUST_EXIST);
$tempuser = $DB->get_record('attendance_tempusers', array('id' => $userid), '*', MUST_EXIST); $tempuser = $DB->get_record('attendance_tempusers', array('id' => $userid), '*', MUST_EXIST);
$att = new attendance($att, $cm, $course); $att = new mod_attendance_structure($att, $cm, $course);
$params = array('userid' => $tempuser->id); $params = array('userid' => $tempuser->id);
$PAGE->set_url($att->url_tempmerge($params)); $PAGE->set_url($att->url_tempmerge($params));

4
tempusers.php

@ -33,7 +33,7 @@ $cm = get_coursemodule_from_id('attendance', $id, 0, false, MUST_EXIST);
$course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST); $course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST);
$att = $DB->get_record('attendance', array('id' => $cm->instance), '*', MUST_EXIST); $att = $DB->get_record('attendance', array('id' => $cm->instance), '*', MUST_EXIST);
$att = new attendance($att, $cm, $course); $att = new mod_attendance_structure($att, $cm, $course);
$PAGE->set_url($att->url_managetemp()); $PAGE->set_url($att->url_managetemp());
require_login($course, true, $cm); require_login($course, true, $cm);
@ -94,7 +94,7 @@ if ($tempusers) {
echo '</div>'; echo '</div>';
echo $output->footer($course); echo $output->footer($course);
function print_tempusers($tempusers, attendance $att) { function print_tempusers($tempusers, mod_attendance_structure $att) {
echo '<p></p>'; echo '<p></p>';
echo '<table border="1" bordercolor="#EEEEEE" style="background-color:#fff" cellpadding="2" align="center"'. echo '<table border="1" bordercolor="#EEEEEE" style="background-color:#fff" cellpadding="2" align="center"'.
'width="80%" summary="'.get_string('temptable', 'attendance').'"><tr>'; 'width="80%" summary="'.get_string('temptable', 'attendance').'"><tr>';

2
view.php

@ -43,7 +43,7 @@ $context = context_module::instance($cm->id);
require_capability('mod/attendance:view', $context); require_capability('mod/attendance:view', $context);
$pageparams->init($cm); $pageparams->init($cm);
$att = new attendance($attendance, $cm, $course, $context, $pageparams); $att = new mod_attendance_structure($attendance, $cm, $course, $context, $pageparams);
// Not specified studentid for displaying attendance? // Not specified studentid for displaying attendance?
// Redirect to appropriate page if can. // Redirect to appropriate page if can.

Loading…
Cancel
Save