]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/wikilens/Buddy.php
Activated Id substitution for Subversion
[SourceForge/phpwiki.git] / lib / wikilens / Buddy.php
1 <?php //-*-php-*-
2 rcs_id('$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                 . " GROUP BY raterpage"
60                 . " ORDER BY numrating"
61                 . " LIMIT 10";
62             $result = $dbh->query($query);
63         } else {
64             // from 10 random raters of this page (non-SQL)
65             ;
66         }
67
68     }
69     $result = array();
70     if (is_array($buddies_array))
71       foreach ($buddies_array as $userid) { 
72         $result[] = new RatingsUser($userid);
73       }
74     return $result;
75 }
76
77 function CoAgreement($dbi, $page, $users, $active_userid){
78         //Returns a "yes" 1, "no" -1, or "unsure" 0 for whether 
79         //the group agrees on the page based on their ratings
80         $cur_page = $page;
81         
82         $my_ratings_iter = $dbi->get_rating(0, $active_userid, $page);
83         $my_ratings_single = $my_ratings_iter->next();
84         $cur_rating = $my_ratings_single['ratingvalue'];
85         
86         $MIDDLE_RATING = 3;
87         
88         if($cur_rating >= $MIDDLE_RATING){
89                 $agreePos = 1;
90         } else {
91                 $agreePos = 0;
92         }
93         foreach($users as $buddy){
94                 $buddy_rating_iter = $dbi->get_rating(0, $buddy, $cur_page);
95                 $buddy_rating_array = $buddy_rating_iter->next();
96                 $buddy_rating = $buddy_rating_array['ratingvalue'];
97                 if($buddy_rating == ""){
98                         $agree = 1;
99                 }else if($agreePos && $buddy_rating >= $MIDDLE_RATING){
100                         $agree = 1;
101                 } else if(!$agreePos && $buddy_rating < $MIDDLE_RATING){
102                         $agree = 1;
103                 } else {
104                         $agree = 0;
105                         break;
106                 }       
107         }
108         if($agree && $agreePos){
109                 return 1;
110         } else if($agree && !$agreePos){
111                 return -1;
112         } else {
113                 return 0;
114         }
115 }
116
117 function MinMisery($dbi, $page, $users, $active_userid){
118     //Returns the minimum rating for the page
119     //from all the users.
120         
121     $cur_page = $page;
122         
123     $my_ratings_iter = $dbi->get_rating(0, $active_userid, $page);
124     $my_ratings_single = $my_ratings_iter->next();
125     $cur_rating = $my_ratings_single['ratingvalue'];
126         
127     $min = $cur_rating;
128     foreach($users as $buddy){
129         $buddy_rating_iter = $dbi->get_rating(0, $buddy, $cur_page);
130         $buddy_rating_array = $buddy_rating_iter->next();
131         $buddy_rating = $buddy_rating_array['ratingvalue'];
132         if($buddy_rating != "" && $buddy_rating < $min){
133             $min = $buddy_rating;       
134         }
135     }
136     return $min;
137 }
138
139 function AverageRating($dbi, $page, $users, $active_userid){
140     //Returns the average rating for the page
141     //from all the users.
142         
143     $cur_page = $page;
144         
145     $my_ratings_iter = $dbi->get_rating(0, $active_userid, $page);
146     $my_ratings_single = $my_ratings_iter->next();
147     $cur_rating = $my_ratings_single['ratingvalue'];
148     if($cur_rating != ""){
149         $total = $cur_rating;
150         $count = 1;
151     } else {
152         $total = 0;
153         $count = 0;
154     }
155     foreach($users as $buddy){
156         $buddy_rating_iter = $dbi->get_rating(0, $buddy, $cur_page);
157         $buddy_rating_array = $buddy_rating_iter->next();
158         $buddy_rating = $buddy_rating_array['ratingvalue'];
159         if($buddy_rating != ""){                
160             $total = $total + $buddy_rating;
161             $count++;   
162         }
163     }
164     if($count == 0){
165         return 0;
166     } else {
167         return $total / $count;
168     }
169 }
170
171 // $Log: not supported by cvs2svn $
172 // Revision 1.3  2004/11/21 11:59:26  rurban
173 // remove final \n to be ob_cache independent
174 //
175 // Revision 1.2  2004/11/15 16:00:02  rurban
176 // enable RateIt imgPrefix: '' or 'Star' or 'BStar',
177 // enable blue prediction icons,
178 // enable buddy predictions.
179 //
180 // Revision 1.1  2004/06/18 14:42:17  rurban
181 // added wikilens libs (not yet merged good enough, some work for DanFr)
182 // 
183
184 // Local Variables:
185 // mode: php
186 // tab-width: 8
187 // c-basic-offset: 4
188 // c-hanging-comment-ender-p: nil
189 // indent-tabs-mode: nil
190 // End:
191 ?>