]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/wikilens/RatingsDb.php
various unit test fixes: print error backtrace on _DEBUG_TRACE; allusers fix; new...
[SourceForge/phpwiki.git] / lib / wikilens / RatingsDb.php
1 <?php // -*-php-*-
2 rcs_id('$Id: RatingsDb.php,v 1.5 2004-07-08 13:50:33 rurban Exp $');
3
4 /*
5  * @author:  Dan Frankowski (wikilens author), Reini Urban (as plugin)
6  *
7  * TODO: 
8  * - fix RATING_STORAGE = WIKIPAGE
9  * - fix smart caching
10  * - finish mysuggest.c (external engine with data from mysql)
11  * - add php_prediction
12  * - add the various show modes (esp. TopN queries in PHP)
13  */
14 /*
15  CREATE TABLE rating (
16         dimension INT(4) NOT NULL,
17         raterpage INT(11) NOT NULL,
18         rateepage INT(11) NOT NULL,
19         ratingvalue FLOAT NOT NULL,
20         rateeversion INT(11) NOT NULL,
21         isPrivate ENUM('yes','no'),
22         tstamp TIMESTAMP(14) NOT NULL,
23         PRIMARY KEY (dimension, raterpage, rateepage)
24  );
25 */
26
27 //define('RATING_STORAGE','WIKIPAGE');   // not fully supported yet
28 define('RATING_STORAGE','SQL');          // only for mysql yet.
29 // leave undefined for internal, slow php engine.
30 //define('RATING_EXTERNAL',PHPWIKI_DIR . 'suggest.exe');
31
32 class RatingsDb extends WikiDB {
33
34        
35     function RatingsDb() {
36         global $request;
37         $this->_dbi = &$request->_dbi;
38         $this->_backend = &$this->_dbi->_backend;
39         if (isa($this->_backend, 'WikiDB_backend_PearDB'))
40             $this->dbtype = "PearDB";
41         else
42             $this->dbtype = "ADODB";
43         $this->iter_class = "WikiDB_backend_".$this->dbtype."_generic_iter";
44         
45         extract($this->_backend->_table_names);
46         if (empty($rating_tbl)) {
47             $rating_tbl = (!empty($GLOBALS['DBParams']['prefix']) 
48                            ? $GLOBALS['DBParams']['prefix'] : '') . 'rating';
49             $request->_dbi->_backend->_table_names['rating_tbl'] = $rating_tbl;
50         }
51     }
52     
53     // this is a singleton.  It ensures there is only 1 ratingsDB.
54     function &getTheRatingsDb(){
55         static $_theRatingsDb;
56         
57         if (!isset($_theRatingsDb)){
58             $_theRatingsDb = new RatingsDb();
59         } 
60         //echo "rating db is $_theRatingsDb";
61         return $_theRatingsDb;
62     }
63    
64
65 /// *************************************************************************************
66 // FIXME    
67 // from Reini Urban's RateIt plugin
68     function addRating($rating, $userid, $pagename, $dimension) {
69         if (RATING_STORAGE == 'SQL') {
70             $page = $this->_dbi->getPage($pagename);
71             $current = $page->getCurrentRevision();
72             $rateeversion = $current->getVersion();
73             $this->sql_rate($userid, $pagename, $rateeversion, $dimension, $rating);
74         } else {
75             $this->metadata_set_rating($userid, $pagename, $dimension, $rating);
76         }
77     }
78
79     function deleteRating($userid=null, $pagename=null, $dimension=null) {
80         if (is_null($dimension)) $dimension = $this->dimension;
81         if (is_null($userid))    $userid = $this->userid; 
82         if (is_null($pagename))  $pagename = $this->pagename;
83         if (RATING_STORAGE == 'SQL') {
84             $this->sql_delete_rating($userid, $pagename, $dimension);
85         } else {
86             $this->metadata_set_rating($userid, $pagename, $dimension, -1);
87         }
88     }
89     
90     function getRating($userid=null, $pagename=null, $dimension=null) {
91         if (RATING_STORAGE == 'SQL') {
92             $ratings_iter = $this->sql_get_rating($dimension, $userid, $pagename);
93             if ($rating = $ratings_iter->next()) {
94                 return $rating['ratingvalue'];
95             } else 
96                 return false;
97         } else {
98             return $this->metadata_get_rating($userid, $pagename, $dimension);
99         }
100     }
101
102     function getUsersRated($dimension=null, $orderby = null) {
103         if (is_null($dimension)) $dimension = $this->dimension;
104         if (is_null($userid))    $userid = $this->userid; 
105         if (is_null($pagename))  $pagename = $this->pagename;
106         if (RATING_STORAGE == 'SQL') {
107             $ratings_iter = $this->sql_get_users_rated($dimension, $orderby);
108             if ($rating = $ratings_iter->next()) {
109                 return $rating['ratingvalue'];
110             } else 
111                 return false;
112         } else {
113             return $this->metadata_get_users_rated($dimension, $orderby);
114         }
115     }
116    
117     
118     /**
119      * Get ratings.
120      *
121      * @param dimension  The rating dimension id.
122      *                   Example: 0
123      *                   [optional]
124      *                   If this is null (or left off), the search for ratings
125      *                   is not restricted by dimension.
126      *
127      * @param rater  The page id of the rater, i.e. page doing the rating.
128      *               This is a Wiki page id, often of a user page.
129      *               Example: "DanFr"
130      *               [optional]
131      *               If this is null (or left off), the search for ratings
132      *               is not restricted by rater.
133      *               TODO: Support an array
134      *
135      * @param ratee  The page id of the ratee, i.e. page being rated.
136      *               Example: "DudeWheresMyCar"
137      *               [optional]
138      *               If this is null (or left off), the search for ratings
139      *               is not restricted by ratee.
140      *
141      * @param orderby An order-by clause with fields and (optionally) ASC
142      *                or DESC.
143      *               Example: "ratingvalue DESC"
144      *               [optional]
145      *               If this is null (or left off), the search for ratings
146      *               has no guaranteed order
147      *
148      * @param pageinfo The type of page that has its info returned (i.e.,
149      *               'pagename', 'hits', and 'pagedata') in the rows.
150      *               Example: "rater"
151      *               [optional]
152      *               If this is null (or left off), the info returned
153      *               is for the 'ratee' page (i.e., thing being rated).
154      *
155      * @return DB iterator with results 
156      */
157     function get_rating($dimension=null, $rater=null, $ratee=null,
158                         $orderby = null, $pageinfo = "ratee") {
159         if (RATING_STORAGE == 'SQL') {
160             $ratings_iter = $this->sql_get_rating($dimension, $rater, $pagename);
161             if ($rating = $ratings_iter->next()) {
162                 return $rating['ratingvalue'];
163             } else 
164                 return false;
165                // return $ratings_iter;
166         } else {
167             return $this->metadata_get_rating($rater, $pagename, $dimension);
168         }
169         /*
170         return $this->_backend->get_rating($dimension, $rater, $ratee,
171                                            $orderby, $pageinfo);
172         */
173     }
174     
175     function get_users_rated($dimension=null, $orderby = null) {
176         if (RATING_STORAGE == 'SQL') {
177             $ratings_iter = $this->sql_get_users_rated($dimension, $orderby);
178             if ($rating = $ratings_iter->next()) {
179                return $rating['ratingvalue'];
180             } else 
181                 return false;
182         } else {
183             return $this->metadata_get_users_rated($dimension, $orderby);
184         }
185         /*
186         return $this->_backend->get_users_rated($dimension, $orderby);
187         */
188     }
189
190     /**
191      * Like get_rating(), but return a WikiDB_PageIterator
192      * FIXME!
193      */
194     function get_rating_page($dimension=null, $rater=null, $ratee=null,
195                         $orderby = null, $pageinfo = "ratee") {
196         $result = $this->_backend->get_rating_page($dimension, $rater, $ratee,
197                                                    $orderby, $pageinfo);
198         return new WikiDB_PageIterator($this, $result);
199     }
200
201     /**
202      * Delete a rating.
203      *
204      * @param rater  The page id of the rater, i.e. page doing the rating.
205      *               This is a Wiki page id, often of a user page.
206      * @param ratee  The page id of the ratee, i.e. page being rated.
207      * @param dimension  The rating dimension id.
208      *
209      * @access public
210      *
211      * @return true upon success
212      */
213     function delete_rating($rater, $ratee, $dimension) {
214         if (RATING_STORAGE == 'SQL') {
215             $this->sql_delete_rating($userid, $pagename, $dimension);
216         } else {
217             $this->metadata_set_rating($userid, $pagename, $dimension, -1);
218         }
219         /*
220         return $this->_backend->delete_rating($rater, $ratee, $dimension);
221         */
222     }
223
224     /**
225      * Rate a page.
226      *
227      * @param rater  The page id of the rater, i.e. page doing the rating.
228      *               This is a Wiki page id, often of a user page.
229      * @param ratee  The page id of the ratee, i.e. page being rated.
230      * @param rateeversion  The version of the ratee page.
231      * @param dimension  The rating dimension id.
232      * @param rating The rating value (a float).
233      *
234      * @access public
235      *
236      * @return true upon success
237      */
238     function rate($rater, $ratee, $rateeversion, $dimension, $rating) {
239         if (RATING_STORAGE == 'SQL') {
240             $page = $this->_dbi->getPage($pagename);
241             $current = $page->getCurrentRevision();
242             $rateeversion = $current->getVersion();
243             $this->sql_rate($userid, $pagename, $rateeversion, $dimension, $rating);
244         } else {
245             $this->metadata_set_rating($userid, $pagename, $dimension, $rating);
246         }
247         /*
248         return $this->_backend->rate($rater, $ratee, $rateeversion, $dimension, $rating);
249         */
250     }
251     
252     //function getUsersRated(){}
253     
254 //*******************************************************************************
255     // TODO:
256     // Use wikilens/RatingsUser.php for the php methods.
257     //
258     // Old:
259     // Currently we have to call the "suggest" CGI
260     //   http://www-users.cs.umn.edu/~karypis/suggest/
261     // until we implement a simple recommendation engine.
262     // Note that "suggest" is only free for non-profit organizations.
263     // I am currently writing a binary CGI using suggest, which loads 
264     // data from mysql.
265     function getPrediction($userid=null, $pagename=null, $dimension=null) {
266         if (is_null($dimension)) $dimension = $this->dimension;
267         if (is_null($userid))    $userid   = $this->userid; 
268         if (is_null($pagename))  $pagename = $this->pagename;
269
270         if (RATING_STORAGE == 'SQL') {
271             $dbi = &$this->_dbi->_backend;
272             if (isset($pagename))
273                 $page = $dbi->_get_pageid($pagename);
274             else 
275                 return 0;
276             if (isset($userid))
277                 $user = $dbi->_get_pageid($userid);
278             else 
279                 return 0;
280         }
281         if (defined('RATING_EXTERNAL') and RATING_EXTERNAL) {
282             // how call suggest.exe? as CGI or natively
283             //$rating = HTML::Raw("<!--#include virtual=".RATING_ENGINE." -->");
284             $args = "-u$user -p$page -malpha"; // --top 10
285             if (isset($dimension))
286                 $args .= " -d$dimension";
287             $rating = passthru(RATING_EXTERNAL . " $args");
288         } else {
289             $rating = $this->php_prediction($userid, $pagename, $dimension);
290         }
291         return $rating;
292     }
293
294     /**
295      * TODO: slow item-based recommendation engine, similar to suggest RType=2.
296      *       Only the SUGGEST_EstimateAlpha part
297      * Take wikilens/RatingsUser.php for the php methods.
298      */
299     function php_prediction($userid=null, $pagename=null, $dimension=null) {
300         if (is_null($dimension)) $dimension = $this->dimension;
301         if (is_null($userid))    $userid   = $this->userid; 
302         if (is_null($pagename))  $pagename = $this->pagename;
303         if (RATING_STORAGE == 'SQL') {
304             $rating = 0;
305         } else {
306             $rating = 0;
307         }
308         return $rating;
309     }
310     
311     function getNumUsers($pagename=null, $dimension=null) {
312         if (is_null($dimension)) $dimension = $this->dimension;
313         if (is_null($pagename))  $pagename = $this->pagename;
314         if (RATING_STORAGE == 'SQL') {
315             $ratings_iter = $this->sql_get_rating($dimension, null, $pagename,
316                                                   null, "ratee");
317             return $ratings_iter->count();
318         } else {
319             $page = $this->_dbi->getPage($pagename);
320             $data = $page->get('rating');
321             if (!empty($data[$dimension]))
322                 return count($data[$dimension]);
323             else 
324                 return 0;
325         }
326     }
327     // TODO: metadata method
328     function getAvg($pagename=null, $dimension=null) {
329         if (is_null($dimension)) $dimension = $this->dimension;
330         if (is_null($pagename))  $pagename = $this->pagename;
331         if (RATING_STORAGE == 'SQL') {
332             $dbi = &$this->_dbi->_backend;
333             $where = "WHERE 1";
334             if (isset($pagename)) {
335                 $raterid = $dbi->_get_pageid($pagename, true);
336                 $where .= " AND raterpage=$raterid";
337             }
338             if (isset($dimension)) {
339                 $where .= " AND dimension=$dimension";
340             }
341             //$dbh = &$this->_dbi;
342             extract($dbi->_table_names);
343             $query = "SELECT AVG(ratingvalue) as avg"
344                    . " FROM $rating_tbl r, $page_tbl p "
345                    . $where. " GROUP BY raterpage";
346             $result = $dbi->_dbh->query($query);
347             $iter = new $this->iter_class($this,$result);
348             $row = $iter->next();
349             return $row['avg'];
350         } else {
351             return 2.5;
352         }
353     }
354 //*******************************************************************************
355
356     /**
357      * Get ratings.
358      *
359      * @param dimension  The rating dimension id.
360      *                   Example: 0
361      *                   [optional]
362      *                   If this is null (or left off), the search for ratings
363      *                   is not restricted by dimension.
364      *
365      * @param rater  The page id of the rater, i.e. page doing the rating.
366      *               This is a Wiki page id, often of a user page.
367      *               Example: "DanFr"
368      *               [optional]
369      *               If this is null (or left off), the search for ratings
370      *               is not restricted by rater.
371      *               TODO: Support an array
372      *
373      * @param ratee  The page id of the ratee, i.e. page being rated.
374      *               Example: "DudeWheresMyCar"
375      *               [optional]
376      *               If this is null (or left off), the search for ratings
377      *               is not restricted by ratee.
378      *               TODO: Support an array
379      *
380      * @param orderby An order-by clause with fields and (optionally) ASC
381      *                or DESC.
382      *               Example: "ratingvalue DESC"
383      *               [optional]
384      *               If this is null (or left off), the search for ratings
385      *               has no guaranteed order
386      *
387      * @param pageinfo The type of page that has its info returned (i.e.,
388      *               'pagename', 'hits', and 'pagedata') in the rows.
389      *               Example: "rater"
390      *               [optional]
391      *               If this is null (or left off), the info returned
392      *               is for the 'ratee' page (i.e., thing being rated).
393      *
394      * @return DB iterator with results 
395      */
396     function sql_get_rating($dimension=null, $rater=null, $ratee=null,
397                             $orderby=null, $pageinfo = "ratee") {
398         if (empty($dimension)) $dimension=null;
399         $result = $this->_sql_get_rating_result($dimension, $rater, $ratee, $orderby, $pageinfo);
400         return new $this->iter_class($this, $result);
401     }
402
403     function sql_get_users_rated($dimension=null, $orderby=null) {
404         if (empty($dimension)) $dimension=null;
405         $result = $this->_sql_get_rating_result($dimension, null, null, $orderby, "rater");
406         return new $this->iter_class($this, $result);
407     }
408
409     /**
410      * @access private
411      * @return result ressource, suitable to the iterator
412      */
413     function _sql_get_rating_result($dimension=null, $rater=null, $ratee=null,
414                                     $orderby=null, $pageinfo = "ratee") {
415         // pageinfo must be 'rater' or 'ratee'
416         if (($pageinfo != "ratee") && ($pageinfo != "rater"))
417             return;
418         $dbi = &$this->_dbi->_backend;
419         //$dbh = &$this->_dbi;
420         extract($dbi->_table_names);
421         $where = "WHERE r." . $pageinfo . "page = p.id";
422         if (isset($dimension)) {
423             $where .= " AND dimension=$dimension";
424         }
425         if (isset($rater)) {
426             $raterid = $dbi->_get_pageid($rater, true);
427             $where .= " AND raterpage=$raterid";
428         }
429         if (isset($ratee)) {
430             if(is_array($ratee)){
431                         $where .= " AND (";
432                         for($i = 0; $i < count($ratee); $i++){
433                                 $rateeid = $dbi->_get_pageid($ratee[$i], true);
434                         $where .= "rateepage=$rateeid";
435                                 if($i != (count($ratee) - 1)){
436                                         $where .= " OR ";
437                                 }
438                         }
439                         $where .= ")";
440                 } else {
441                         $rateeid = $dbi->_get_pageid($ratee, true);
442                 $where .= " AND rateepage=$rateeid";
443                 }
444         }
445         $orderbyStr = "";
446         if (isset($orderby)) {
447             $orderbyStr = " ORDER BY " . $orderby;
448         }
449         if (isset($rater) or isset($ratee)) $what = '*';
450         // same as _get_users_rated_result()
451         else $what = 'DISTINCT p.pagename';
452
453         $query = "SELECT $what"
454                . " FROM $rating_tbl r, $page_tbl p "
455                . $where
456                . $orderbyStr;
457         $result = $dbi->_dbh->query($query);
458         return $result;
459     }
460
461     /**
462      * Delete a rating.
463      *
464      * @param rater  The page id of the rater, i.e. page doing the rating.
465      *               This is a Wiki page id, often of a user page.
466      * @param ratee  The page id of the ratee, i.e. page being rated.
467      * @param dimension  The rating dimension id.
468      *
469      * @access public
470      *
471      * @return true upon success
472      */
473     function sql_delete_rating($rater, $ratee, $dimension) {
474         //$dbh = &$this->_dbi;
475         $dbi = &$this->_dbi->_backend;
476         extract($dbi->_table_names);
477
478         $dbi->lock();
479         $raterid = $dbi->_get_pageid($rater, true);
480         $rateeid = $dbi->_get_pageid($ratee, true);
481         $where = "WHERE raterpage=$raterid and rateepage=$rateeid";
482         if (isset($dimension)) {
483             $where .= " AND dimension=$dimension";
484         }
485         $dbi->_dbh->query("DELETE FROM $rating_tbl $where");
486         $dbi->unlock();
487         return true;
488     }
489
490     /**
491      * Rate a page.
492      *
493      * @param rater  The page id of the rater, i.e. page doing the rating.
494      *               This is a Wiki page id, often of a user page.
495      * @param ratee  The page id of the ratee, i.e. page being rated.
496      * @param rateeversion  The version of the ratee page.
497      * @param dimension  The rating dimension id.
498      * @param rating The rating value (a float).
499      *
500      * @access public
501      *
502      * @return true upon success
503      */
504     //               ($this->userid, $this->pagename, $this->dimension, $rating);
505     function sql_rate($rater, $ratee, $rateeversion, $dimension, $rating) {
506         $dbi = &$this->_dbi->_backend;
507         extract($dbi->_table_names);
508         if (empty($rating_tbl))
509             $rating_tbl = $this->_dbi->getParam('prefix') . 'rating';
510
511         //$dbi->lock();
512         $raterid = $dbi->_get_pageid($rater, true);
513         $rateeid = $dbi->_get_pageid($ratee, true);
514         assert($raterid);
515         assert($rateeid);
516         //we changed back to delete and insert because update didn't work if it was a new rating
517         
518         $dbi->_dbh->query("DELETE from $rating_tbl WHERE dimension=$dimension AND raterpage=$raterid AND rateepage=$rateeid");
519         $where = "WHERE raterpage='$raterid' AND rateepage='$rateeid'";
520
521         $insert = "INSERT INTO $rating_tbl (dimension, raterpage, rateepage, ratingvalue, rateeversion) VALUES ('$dimension', $raterid, $rateeid, '$rating', '$rateeversion')";
522         $dbi->_dbh->query($insert);
523         
524         //$dbi->unlock();
525         return true;
526     }
527
528     function metadata_get_rating($userid, $pagename, $dimension) {
529         $page = $this->_dbi->getPage($pagename);
530         $data = $page->get('rating');
531         if (!empty($data[$dimension][$userid]))
532             return (float)$data[$dimension][$userid];
533         else 
534             return false;
535     }
536
537     function metadata_set_rating($userid, $pagename, $dimension, $rating = -1) {
538         $page = $this->_dbi->getPage($pagename);
539         $data = $page->get('rating');
540         if ($rating == -1)
541             unset($data[$dimension][$userid]);
542         else {
543             if (empty($data[$dimension][$userid]))
544                 $data[$dimension] = array($userid => (float)$rating);
545             else
546                 $data[$dimension][$userid] = $rating;
547         }
548         $page->set('rating',$data);
549     }
550    
551 }
552
553 /*
554 class RatingsDB_backend_PearDB 
555 extends WikiDB_backend_PearDB {
556     function get_rating($dimension=null, $rater=null, $ratee=null,
557                         $orderby=null, $pageinfo = "ratee") {
558         $result = $this->_get_rating_result(
559                          $dimension, $rater, $ratee, $orderby, $pageinfo);
560         return new WikiDB_backend_PearDB_generic_iter($this, $result);
561     }
562     
563     function get_users_rated($dimension=null, $orderby=null) {
564         $result = $this->_get_users_rated_result(
565                          $dimension, $orderby);
566         return new WikiDB_backend_PearDB_generic_iter($this, $result);
567     }
568
569     function get_rating_page($dimension=null, $rater=null, $ratee=null,
570                              $orderby=null, $pageinfo = "ratee") {
571         $result = $this->_get_rating_result(
572                          $dimension, $rater, $ratee, $orderby, $pageinfo);
573         return new WikiDB_backend_PearDB_iter($this, $result);
574     }
575
576     function _get_rating_result($dimension=null, $rater=null, $ratee=null,
577                                 $orderby=null, $pageinfo = "ratee") {
578         // pageinfo must be 'rater' or 'ratee'
579         if (($pageinfo != "ratee") && ($pageinfo != "rater"))
580             return;
581
582         $dbh = &$this->_dbh;
583         extract($this->_table_names);
584
585         $where = "WHERE r." . $pageinfo . "page = p.id";
586         if (isset($dimension)) {
587             $where .= " AND dimension=$dimension";
588         }
589         if (isset($rater)) {
590             $raterid = $this->_get_pageid($rater, true);
591             $where .= " AND raterpage=$raterid";
592         }
593         if (isset($ratee)) {
594                 if(is_array($ratee)){
595                         $where .= " AND (";
596                         for($i = 0; $i < count($ratee); $i++){
597                                 $rateeid = $this->_get_pageid($ratee[$i], true);
598                         $where .= "rateepage=$rateeid";
599                                 if($i != (count($ratee) - 1)){
600                                         $where .= " OR ";
601                                 }
602                         }
603                         $where .= ")";
604                 } else {
605                         $rateeid = $this->_get_pageid($ratee, true);
606                 $where .= " AND rateepage=$rateeid";
607                 }
608         }
609
610         $orderbyStr = "";
611         if (isset($orderby)) {
612             $orderbyStr = " ORDER BY " . $orderby;
613         }
614
615         $query = "SELECT *"
616             . " FROM $rating_tbl r, $page_tbl p "
617             . $where
618             . $orderbyStr;
619
620         $result = $dbh->query($query);
621
622         return $result;
623     }
624     
625     function _get_users_rated_result($dimension=null, $orderby=null) {
626         $dbh = &$this->_dbh;
627         extract($this->_table_names);
628
629         $where = "WHERE p.id=r.raterpage";
630         if (isset($dimension)) {
631             $where .= " AND dimension=$dimension";
632         }
633         $orderbyStr = "";
634         if (isset($orderby)) {
635             $orderbyStr = " ORDER BY " . $orderby;
636         }
637
638         $query = "SELECT DISTINCT p.pagename"
639             . " FROM $rating_tbl r, $page_tbl p "
640             . $where
641             . $orderbyStr;
642
643         $result = $dbh->query($query);
644
645         return $result;
646     }
647     function delete_rating($rater, $ratee, $dimension) {
648         $dbh = &$this->_dbh;
649         extract($this->_table_names);
650
651         $this->lock();
652         $raterid = $this->_get_pageid($rater, true);
653         $rateeid = $this->_get_pageid($ratee, true);
654
655         $dbh->query("DELETE FROM $rating_tbl WHERE raterpage=$raterid and rateepage=$rateeid and dimension=$dimension");
656         $this->unlock();
657         return true;
658     }
659
660     function rate($rater, $ratee, $rateeversion, $dimension, $rating, $isPrivate = 'no') {
661         $dbh = &$this->_dbh;
662         extract($this->_table_names);
663
664         $this->lock();
665         $raterid = $this->_get_pageid($rater, true);
666         $rateeid = $this->_get_pageid($ratee, true);
667
668         $dbh->query("DELETE FROM $rating_tbl WHERE raterpage=$raterid and rateepage=$rateeid and dimension=$dimension and isPrivate='$isPrivate'");
669         // NOTE: Leave tstamp off the insert, and MySQL automatically updates it
670         $dbh->query("INSERT INTO $rating_tbl (dimension, raterpage, rateepage, ratingvalue, rateeversion, isPrivate) VALUES ($dimension, $raterid, $rateeid, $rating, $rateeversion, '$isPrivate')");
671         $this->unlock();
672         return true;
673     }
674
675 */
676
677 // $Log: not supported by cvs2svn $
678 // Revision 1.4  2004/07/07 19:47:36  dfrankow
679 // Fixes to get PreferencesApp to work-- thanks syilek
680 //
681 // Revision 1.3  2004/06/30 20:05:36  dfrankow
682 // + Add getTheRatingsDb() singleton.
683 // + Remove defaulting of dimension, userid, pagename in getRating--
684 //   it didn't work
685 // + Fix typo in get_rating.
686 // + Fix _sql_get_rating_result
687 // + Fix sql_rate().  It's now not transactionally safe yet, but at least it
688 //   works.
689 //
690 // Revision 1.2  2004/06/19 10:22:41  rurban
691 // outcomment the pear specific methods to let all pages load
692 //
693 // Revision 1.1  2004/06/18 14:42:17  rurban
694 // added wikilens libs (not yet merged good enough, some work for DanFr)
695 // 
696
697 // Local Variables:
698 // mode: php
699 // tab-width: 8
700 // c-basic-offset: 4
701 // c-hanging-comment-ender-p: nil
702 // indent-tabs-mode: nil
703 // End:
704 ?>