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