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