]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/wikilens/Buddy.php
Remove rcs_id
[SourceForge/phpwiki.git] / lib / wikilens / Buddy.php
1 <?php //-*-php-*-
2 // $Id$
3
4 // It is anticipated that when userid support is added to phpwiki,
5 // this object will hold much more information (e-mail,
6 // home(wiki)page, etc.) about the user.
7
8 // There seems to be no clean way to "log out" a user when using HTTP
9 // authentication. So we'll hack around this by storing the currently
10 // logged in username and other state information in a cookie.
11
12 // 2002-09-08 11:44:04 rurban
13 // Todo: Fix prefs cookie/session handling:
14 //       _userid and _homepage cookie/session vars still hold the
15 //       serialized string.
16 //       If no homepage, fallback to prefs in cookie as in 1.3.3.
17
18
19 /**
20
21 */
22 require_once (dirname(__FILE__)."/Utils.php");
23
24 /*
25 class Buddy extends WikiUserNew {}
26 */
27
28 function addBuddy($user, $buddy, $dbi)
29 {
30     $START_DELIM = _("Buddies:");
31     // the delimiter is really a comma, but include a space to make it look
32     // nicer (getBuddies strips out extra spaces when extracting buddies)
33     $DELIM = ", ";
34
35     addPageTextData($user, $dbi, $buddy, $START_DELIM, $DELIM);
36 }
37
38 function getBuddies($fromUser, $dbi, $thePage = ""){
39     $START_DELIM = $thePage . _("Buddies:");
40     $DELIM = ",";
41     $buddies_array = getPageTextData($fromUser, $dbi, $START_DELIM, $DELIM);
42     if (count($buddies_array) == 0 and $thePage !== "") {
43         $buddies_array = getPageTextData($fromUser, $dbi, _("Buddies:"), $DELIM);
44     }
45     if (empty($buddies_array)) {
46         // 1. calculate buddies automatically from the 10 top raters with the most numratings (min. 5 ratings).
47         //    of all pages (only SQL)
48         // or 2. from 10 random raters of this page (non-SQL)
49         // or 3. from all members of your group (department) if <= 20
50         $rdbi = RatingsDb::getTheRatingsDb();
51         $dimension = '';
52         if (RATING_STORAGE == 'SQL') {
53             //$result = $this->_sql_get_rating_result($dimension, null, null, 'numrating', "rater");
54             $dbh = &$rdbi->_sqlbackend;
55             extract($dbh->_table_names);
56             $query = "SELECT raterpage, COUNT(rateepage) as numrating"
57                 . " FROM $rating_tbl r, $page_tbl p "
58 //              . " WHERE ratingvalue > 0 AND numrating > 5"
59                 . " WHERE ratingvalue > 0"
60                 . " GROUP BY raterpage"
61                 . " ORDER BY numrating"
62                 . " LIMIT 10";
63             $result = $dbh->_dbh->query($query);
64         } else {
65             // from 10 random raters of this page (non-SQL)
66             ;
67         }
68
69     }
70     $result = array();
71     if (is_array($buddies_array))
72       foreach ($buddies_array as $userid) { 
73         $result[] = new RatingsUser($userid);
74       }
75     return $result;
76 }
77
78 function CoAgreement($dbi, $page, $users, $active_userid){
79         //Returns a "yes" 1, "no" -1, or "unsure" 0 for whether 
80         //the group agrees on the page based on their ratings
81         $cur_page = $page;
82         
83         $my_ratings_iter = $dbi->get_rating(0, $active_userid, $page);
84         $my_ratings_single = $my_ratings_iter->next();
85         $cur_rating = $my_ratings_single['ratingvalue'];
86         
87         $MIDDLE_RATING = 3;
88         
89         if($cur_rating >= $MIDDLE_RATING){
90                 $agreePos = 1;
91         } else {
92                 $agreePos = 0;
93         }
94         foreach($users as $buddy){
95                 $buddy_rating_iter = $dbi->get_rating(0, $buddy, $cur_page);
96                 $buddy_rating_array = $buddy_rating_iter->next();
97                 $buddy_rating = $buddy_rating_array['ratingvalue'];
98                 if($buddy_rating == ""){
99                         $agree = 1;
100                 }else if($agreePos && $buddy_rating >= $MIDDLE_RATING){
101                         $agree = 1;
102                 } else if(!$agreePos && $buddy_rating < $MIDDLE_RATING){
103                         $agree = 1;
104                 } else {
105                         $agree = 0;
106                         break;
107                 }       
108         }
109         if($agree && $agreePos){
110                 return 1;
111         } else if($agree && !$agreePos){
112                 return -1;
113         } else {
114                 return 0;
115         }
116 }
117
118 function MinMisery($dbi, $page, $users, $active_userid){
119     //Returns the minimum rating for the page
120     //from all the users.
121         
122     $cur_page = $page;
123         
124     $my_ratings_iter = $dbi->get_rating(0, $active_userid, $page);
125     $my_ratings_single = $my_ratings_iter->next();
126     $cur_rating = $my_ratings_single['ratingvalue'];
127         
128     $min = $cur_rating;
129     foreach($users as $buddy){
130         $buddy_rating_iter = $dbi->get_rating(0, $buddy, $cur_page);
131         $buddy_rating_array = $buddy_rating_iter->next();
132         $buddy_rating = $buddy_rating_array['ratingvalue'];
133         if($buddy_rating != "" && $buddy_rating < $min){
134             $min = $buddy_rating;       
135         }
136     }
137     return $min;
138 }
139
140 function AverageRating($dbi, $page, $users, $active_userid){
141     //Returns the average rating for the page
142     //from all the users.
143         
144     $cur_page = $page;
145         
146     $my_ratings_iter = $dbi->get_rating(0, $active_userid, $page);
147     $my_ratings_single = $my_ratings_iter->next();
148     $cur_rating = $my_ratings_single['ratingvalue'];
149     if($cur_rating != ""){
150         $total = $cur_rating;
151         $count = 1;
152     } else {
153         $total = 0;
154         $count = 0;
155     }
156     foreach($users as $buddy){
157         $buddy_rating_iter = $dbi->get_rating(0, $buddy, $cur_page);
158         $buddy_rating_array = $buddy_rating_iter->next();
159         $buddy_rating = $buddy_rating_array['ratingvalue'];
160         if($buddy_rating != ""){                
161             $total = $total + $buddy_rating;
162             $count++;   
163         }
164     }
165     if($count == 0){
166         return 0;
167     } else {
168         return $total / $count;
169     }
170 }
171
172 // Local Variables:
173 // mode: php
174 // tab-width: 8
175 // c-basic-offset: 4
176 // c-hanging-comment-ender-p: nil
177 // indent-tabs-mode: nil
178 // End:
179 ?>