]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/wikilens/Buddy.php
Cleanup. fixed sql_get_users_rated, add metadata_get_users_rated
[SourceForge/phpwiki.git] / lib / wikilens / Buddy.php
1 <?php //-*-php-*-
2 rcs_id('$Id: Buddy.php,v 1.3 2004-11-21 11:59:26 rurban Exp $');
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     
42     $buddies_array = getPageTextData($fromUser, $dbi, $START_DELIM, $DELIM);
43     if (count($buddies_array) == 0 and $thePage !== "") {
44         $buddies_array = getPageTextData($fromUser, $dbi, _("Buddies:"), $DELIM);
45     }
46     return $buddies_array;
47 }
48
49 function CoAgreement($dbi, $page, $users, $active_userid){
50         //Returns a "yes" 1, "no" -1, or "unsure" 0 for whether 
51         //the group agrees on the page based on their ratings
52         $cur_page = $page;
53         
54         $my_ratings_iter = $dbi->get_rating(0, $active_userid, $page);
55         $my_ratings_single = $my_ratings_iter->next();
56         $cur_rating = $my_ratings_single['ratingvalue'];
57         
58         $MIDDLE_RATING = 3;
59         
60         if($cur_rating >= $MIDDLE_RATING){
61                 $agreePos = 1;
62         } else {
63                 $agreePos = 0;
64         }
65         foreach($users as $buddy){
66                 $buddy_rating_iter = $dbi->get_rating(0, $buddy, $cur_page);
67                 $buddy_rating_array = $buddy_rating_iter->next();
68                 $buddy_rating = $buddy_rating_array['ratingvalue'];
69                 if($buddy_rating == ""){
70                         $agree = 1;
71                 }else if($agreePos && $buddy_rating >= $MIDDLE_RATING){
72                         $agree = 1;
73                 } else if(!$agreePos && $buddy_rating < $MIDDLE_RATING){
74                         $agree = 1;
75                 } else {
76                         $agree = 0;
77                         break;
78                 }       
79         }
80         if($agree && $agreePos){
81                 return 1;
82         } else if($agree && !$agreePos){
83                 return -1;
84         } else {
85                 return 0;
86         }
87 }
88
89 function MinMisery($dbi, $page, $users, $active_userid){
90     //Returns the minimum rating for the page
91     //from all the users.
92         
93     $cur_page = $page;
94         
95     $my_ratings_iter = $dbi->get_rating(0, $active_userid, $page);
96     $my_ratings_single = $my_ratings_iter->next();
97     $cur_rating = $my_ratings_single['ratingvalue'];
98         
99     $min = $cur_rating;
100     foreach($users as $buddy){
101         $buddy_rating_iter = $dbi->get_rating(0, $buddy, $cur_page);
102         $buddy_rating_array = $buddy_rating_iter->next();
103         $buddy_rating = $buddy_rating_array['ratingvalue'];
104         if($buddy_rating != "" && $buddy_rating < $min){
105             $min = $buddy_rating;       
106         }
107     }
108     return $min;
109 }
110
111 function AverageRating($dbi, $page, $users, $active_userid){
112     //Returns the average rating for the page
113     //from all the users.
114         
115     $cur_page = $page;
116         
117     $my_ratings_iter = $dbi->get_rating(0, $active_userid, $page);
118     $my_ratings_single = $my_ratings_iter->next();
119     $cur_rating = $my_ratings_single['ratingvalue'];
120     if($cur_rating != ""){
121         $total = $cur_rating;
122         $count = 1;
123     } else {
124         $total = 0;
125         $count = 0;
126     }
127     foreach($users as $buddy){
128         $buddy_rating_iter = $dbi->get_rating(0, $buddy, $cur_page);
129         $buddy_rating_array = $buddy_rating_iter->next();
130         $buddy_rating = $buddy_rating_array['ratingvalue'];
131         if($buddy_rating != ""){                
132             $total = $total + $buddy_rating;
133             $count++;   
134         }
135     }
136     if($count == 0){
137         return 0;
138     } else {
139         return $total / $count;
140     }
141 }
142
143 // $Log: not supported by cvs2svn $
144 // Revision 1.2  2004/11/15 16:00:02  rurban
145 // enable RateIt imgPrefix: '' or 'Star' or 'BStar',
146 // enable blue prediction icons,
147 // enable buddy predictions.
148 //
149 // Revision 1.1  2004/06/18 14:42:17  rurban
150 // added wikilens libs (not yet merged good enough, some work for DanFr)
151 // 
152
153 // Local Variables:
154 // mode: php
155 // tab-width: 8
156 // c-basic-offset: 4
157 // c-hanging-comment-ender-p: nil
158 // indent-tabs-mode: nil
159 // End:
160 ?>