From 54e42e0bf28f0fba34e6c49c75ea8f3957bbed9a Mon Sep 17 00:00:00 2001 From: Andrew Davis Date: Tue, 16 Mar 2010 08:57:57 +0000 Subject: [PATCH] rating MDL-21657 Switched from table ratings to rating --- lib/db/upgrade.php | 12 ++++++------ lib/db/upgradelib.php | 2 +- rating/ratinglib.php | 8 ++++---- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/lib/db/upgrade.php b/lib/db/upgrade.php index 2368a55b23d..5a58cb8630d 100644 --- a/lib/db/upgrade.php +++ b/lib/db/upgrade.php @@ -3052,10 +3052,10 @@ WHERE gradeitemid IS NOT NULL AND grademax IS NOT NULL"); } if ($result && $oldversion < 2010031600) { - //create the ratings table (replaces module specific ratings implementations) - $table = new xmldb_table('ratings'); + //create the rating table (replaces module specific rating implementations) + $table = new xmldb_table('rating'); - /// Adding fields to table ratings + /// Adding fields to table rating $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); $table->add_field('contextid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); @@ -3067,12 +3067,12 @@ WHERE gradeitemid IS NOT NULL AND grademax IS NOT NULL"); $table->add_field('timecreated', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); $table->add_field('timemodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); - /// Adding keys to table ratings + /// Adding keys to table rating $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); $table->add_key('contextid', XMLDB_KEY_FOREIGN, array('contextid'), 'context', array('id')); $table->add_key('userid', XMLDB_KEY_FOREIGN, array('userid'), 'user', array('id')); - /// Adding indexes to table ratings + /// Adding indexes to table rating $table->add_index('itemid', XMLDB_INDEX_NOTUNIQUE, array('itemid')); /// Create table for ratings @@ -3080,7 +3080,7 @@ WHERE gradeitemid IS NOT NULL AND grademax IS NOT NULL"); $dbman->create_table($table); } - //migrate ratings out of the modules into the central ratings table + //migrate ratings out of the modules into the central rating table //migrate forumratings //forum ratings only have a single time column so use it for both time created and modified diff --git a/lib/db/upgradelib.php b/lib/db/upgradelib.php index fdfe3355cc6..a9dc74310ca 100644 --- a/lib/db/upgradelib.php +++ b/lib/db/upgradelib.php @@ -433,7 +433,7 @@ where m.name=:modulename and cm.instance=:moduleinstanceid and cxt.contextlevel= $rating->timecreated = $old_rating->timecreated; $rating->timemodified = $old_rating->timemodified; - $result = $result && $DB->insert_record('ratings', $rating); + $result = $result && $DB->insert_record('rating', $rating); } //$ratings->close(); diff --git a/rating/ratinglib.php b/rating/ratinglib.php index 61680f5a725..c72bc110dc9 100644 --- a/rating/ratinglib.php +++ b/rating/ratinglib.php @@ -67,7 +67,7 @@ function update_rating($rating) { global $DB; $data = new stdclass(); - $table = 'ratings'; + $table = 'rating'; $item = new stdclass(); $item->id = $this->itemid; @@ -153,7 +153,7 @@ public static function load_ratings_for_item($context, $itemid, $sort) { $sql = "SELECT r.id, r.rating, r.itemid, r.userid, r.timemodified, u.firstname, u.lastname, u.imagealt, u.picture -FROM {ratings} r +FROM {rating} r LEFT JOIN {user} u ON r.userid = u.id WHERE r.contextid = :contextid AND @@ -202,8 +202,8 @@ public static function load_ratings($context, $items, $aggregate=RATING_AGGREGAT $aggregatestr(r.rating) AS aggrrating, COUNT(r.rating) AS numratings, ur.rating AS usersrating -FROM {ratings} r -LEFT JOIN {ratings} ur ON ur.contextid = r.contextid AND +FROM {rating} r +LEFT JOIN {rating} ur ON ur.contextid = r.contextid AND ur.itemid = r.itemid AND ur.userid = :userid WHERE