From 747d96944e4bd87ede7d51272102e22a5c9f9c91 Mon Sep 17 00:00:00 2001 From: Artem Andreev Date: Sat, 18 Jun 2011 12:51:26 +0400 Subject: [PATCH] We don't need courseid fields in attendance_sessions and attendance_statuses because of now we can create more than one attendances per course --- db/install.xml | 24 ++++++++++-------------- db/upgrade.php | 24 ++++++++++++++++++++++-- locallib.php | 15 ++++++--------- version.php | 4 ++-- 4 files changed, 40 insertions(+), 27 deletions(-) diff --git a/db/install.xml b/db/install.xml index 3e9cc60..195512e 100644 --- a/db/install.xml +++ b/db/install.xml @@ -20,11 +20,10 @@ - - - - - + + + + @@ -36,10 +35,9 @@ - - - - + + +
@@ -64,9 +62,8 @@
- - - + + @@ -77,8 +74,7 @@ - - + diff --git a/db/upgrade.php b/db/upgrade.php index ea5e161..edb4e59 100644 --- a/db/upgrade.php +++ b/db/upgrade.php @@ -279,7 +279,7 @@ function xmldb_attforblock_upgrade($oldversion=0) { upgrade_mod_savepoint(true, 2010123003, 'attforblock'); } - if ($oldversion < 2011053006) { + if ($oldversion < 2011061800) { $table = new xmldb_table('attendance_sessions'); $field = new xmldb_field('description'); @@ -304,7 +304,27 @@ function xmldb_attforblock_upgrade($oldversion=0) { $rs->close(); } - upgrade_mod_savepoint(true, 2011053006, 'attforblock'); + // now we can create more than one attendances per course + // thus sessions and statuses belongs to attendance + // so we don't need courseid fields in attendance_sessions and attendance_statuses + $index = new xmldb_index('courseid', XMLDB_INDEX_NOTUNIQUE, array('courseid')); + if ($dbman->index_exists($table, $index)) { + $dbman->drop_index($table, $index); + } + $field = new xmldb_field('courseid'); + if ($dbman->field_exists($table, $field)) { + $dbman->drop_field($table, $field); + } + + $table = new xmldb_table('attendance_statuses'); + if ($dbman->index_exists($table, $index)) { + $dbman->drop_index($table, $index); + } + if ($dbman->field_exists($table, $field)) { + $dbman->drop_field($table, $field); + } + + upgrade_mod_savepoint(true, 2011061800, 'attforblock'); } return $result; } diff --git a/locallib.php b/locallib.php index bbb7235..c7054a7 100644 --- a/locallib.php +++ b/locallib.php @@ -452,9 +452,8 @@ class attforblock { public function get_hidden_sessions_count() { global $DB; - $where = "courseid = :cid AND attendanceid = :aid AND sessdate < :csdate"; + $where = "attendanceid = :aid AND sessdate < :csdate"; $params = array( - 'cid' => $this->course->id, 'aid' => $this->id, 'csdate'=> $this->course->startdate); @@ -465,15 +464,14 @@ class attforblock { global $DB; if ($this->pageparams->startdate && $this->pageparams->enddate) { - $where = "courseid=:cid AND attendanceid = :aid AND sessdate >= :csdate AND sessdate >= :sdate AND sessdate < :edate"; + $where = "attendanceid = :aid AND sessdate >= :csdate AND sessdate >= :sdate AND sessdate < :edate"; } else { - $where = "courseid=:cid AND attendanceid = :aid AND sessdate >= :csdate"; + $where = "attendanceid = :aid AND sessdate >= :csdate"; } if ($this->get_current_group() > attforblock::SELECTOR_ALL) { $where .= " AND groupid=:cgroup"; } $params = array( - 'cid' => $this->course->id, 'aid' => $this->id, 'csdate' => $this->course->startdate, 'sdate' => $this->pageparams->startdate, @@ -914,10 +912,10 @@ class attforblock { global $DB; if ($this->pageparams->startdate && $this->pageparams->enddate) { - $where = "ats.courseid=:cid AND ats.attendanceid = :aid AND - ats.sessdate >= :csdate AND ats.sessdate >= :sdate AND ats.sessdate < :edate"; + $where = "ats.attendanceid = :aid AND ats.sessdate >= :csdate AND + ats.sessdate >= :sdate AND ats.sessdate < :edate"; } else { - $where = "AND ats.courseid=:cid AND ats.attendanceid = :aid AND ats.sessdate >= :csdate"; + $where = "AND ats.attendanceid = :aid AND ats.sessdate >= :csdate"; } $sql = "SELECT ats.id, ats.sessdate, ats.duration, ats.description, al.statusid, al.remarks @@ -929,7 +927,6 @@ class attforblock { $params = array( 'uid' => $userid, - 'cid' => $this->course->id, 'aid' => $this->id, 'csdate' => $this->course->startdate, 'sdate' => $this->pageparams->startdate, diff --git a/version.php b/version.php index ca6c978..8da40a6 100644 --- a/version.php +++ b/version.php @@ -5,7 +5,7 @@ /// This fragment is called by moodle_needs_upgrading() and /admin/index.php ///////////////////////////////////////////////////////////////////////////////// -$module->version = 2011053006; // The current module version (Date: YYYYMMDDXX) -$module->release = '2.3.1'; +$module->version = 2011061800; // The current module version (Date: YYYYMMDDXX) +$module->release = '2.4.0'; $module->cron = 0; // Period for cron to check this module (secs) ?>