From: Dan F <dfr...@us...> - 2004-06-30 20:05:46
|
Update of /cvsroot/phpwiki/phpwiki/lib/wikilens In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9107 Modified Files: RatingsDb.php Log Message: + Add getTheRatingsDb() singleton. + Remove defaulting of dimension, userid, pagename in getRating-- it didn't work + Fix typo in get_rating. + Fix _sql_get_rating_result + Fix sql_rate(). It's now not transactionally safe yet, but at least it works. Index: RatingsDb.php =================================================================== RCS file: /cvsroot/phpwiki/phpwiki/lib/wikilens/RatingsDb.php,v retrieving revision 1.2 retrieving revision 1.3 diff -u -2 -b -p -d -r1.2 -r1.3 --- RatingsDb.php 19 Jun 2004 10:22:41 -0000 1.2 +++ RatingsDb.php 30 Jun 2004 20:05:36 -0000 1.3 @@ -32,4 +32,5 @@ define('RATING_STORAGE','SQL'); class RatingsDb extends WikiDB { + function RatingsDb() { global $request; @@ -50,8 +51,19 @@ class RatingsDb extends WikiDB { } + // this is a singleton. It ensures there is only 1 ratingsDB. + function &getTheRatingsDb(){ + static $_theRatingsDb; + + if (!isset($_theRatingsDb)){ + $_theRatingsDb = new RatingsDb(); + } + //echo "rating db is $_theRatingsDb"; + return $_theRatingsDb; + } + + /// ************************************************************************************* // FIXME // from Reini Urban's RateIt plugin - function addRating($rating, $userid, $pagename, $dimension) { if (RATING_STORAGE == 'SQL') { @@ -77,7 +89,4 @@ class RatingsDb extends WikiDB { function getRating($userid=null, $pagename=null, $dimension=null) { - if (is_null($dimension)) $dimension = $this->dimension; - if (is_null($userid)) $userid = $this->userid; - if (is_null($pagename)) $pagename = $this->pagename; if (RATING_STORAGE == 'SQL') { $ratings_iter = $this->sql_get_rating($dimension, $userid, $pagename); @@ -149,11 +158,12 @@ class RatingsDb extends WikiDB { $orderby = null, $pageinfo = "ratee") { if (RATING_STORAGE == 'SQL') { - $ratings_iter = $this->sql_get_rating($dimension, $userid, $pagename); + $ratings_iter = $this->sql_get_rating($dimension, $rater, $pagename); if ($rating = $ratings_iter->next()) { return $rating['ratingvalue']; } else return false; + // return $ratings_iter; } else { - return $this->metadata_get_rating($userid, $pagename, $dimension); + return $this->metadata_get_rating($rater, $pagename, $dimension); } /* @@ -404,5 +414,4 @@ class RatingsDb extends WikiDB { if (($pageinfo != "ratee") && ($pageinfo != "rater")) return; - $dbi = &$this->_dbi->_backend; //$dbh = &$this->_dbi; @@ -426,5 +435,5 @@ class RatingsDb extends WikiDB { if (isset($rater) or isset($ratee)) $what = '*'; // same as _get_users_rated_result() - else $what = 'DISTINCT p.pagename'; + else $what = 'DISTINCT p.pagename, r.ratingvalue, r.dimension'; $query = "SELECT $what" @@ -432,5 +441,4 @@ class RatingsDb extends WikiDB { . $where . $orderbyStr; - $result = $dbi->_dbh->query($query); return $result; @@ -492,14 +500,12 @@ class RatingsDb extends WikiDB { assert($raterid); assert($rateeid); + //we changed back to delete and insert because update didn't work if it was a new rating + + $dbi->_dbh->query("DELETE from $rating_tbl WHERE dimension=$dimension AND raterpage=$raterid AND rateepage=$rateeid"); $where = "WHERE raterpage='$raterid' AND rateepage='$rateeid'"; - if (isset($dimension)) $where .= " AND dimension='$dimension'"; - // atomic transaction: - $dbi->_dbh->query("UPDATE $rating_tbl SET ratingvalue='$rating', rateeversion='$rateeversion' $where"); - /* - $dbi->_dbh->query("DELETE FROM $rating_tbl $where"); - // NOTE: Leave tstamp off the insert, and MySQL automatically updates it (only if MySQL is used) - $dbi->_dbh->query("INSERT INTO $rating_tbl (dimension, raterpage, rateepage, ratingvalue, rateeversion) VALUES ('$dimension', $raterid, $rateeid, '$rating', '$rateeversion')"); - */ + $insert = "INSERT INTO $rating_tbl (dimension, raterpage, rateepage, ratingvalue, rateeversion) VALUES ('$dimension', $raterid, $rateeid, '$rating', '$rateeversion')"; + $dbi->_dbh->query($insert); + //$dbi->unlock(); return true; @@ -656,4 +662,13 @@ extends WikiDB_backend_PearDB { // $Log$ +// Revision 1.3 2004/06/30 20:05:36 dfrankow +// + Add getTheRatingsDb() singleton. +// + Remove defaulting of dimension, userid, pagename in getRating-- +// it didn't work +// + Fix typo in get_rating. +// + Fix _sql_get_rating_result +// + Fix sql_rate(). It's now not transactionally safe yet, but at least it +// works. +// // Revision 1.2 2004/06/19 10:22:41 rurban // outcomment the pear specific methods to let all pages load |