2 rcs_id('$Id: Buddy.php,v 1.3 2004-11-21 11:59:26 rurban Exp $');
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.
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.
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
16 // If no homepage, fallback to prefs in cookie as in 1.3.3.
22 require_once (dirname(__FILE__)."/Utils.php");
25 class Buddy extends WikiUserNew {}
28 function addBuddy($user, $buddy, $dbi)
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)
35 addPageTextData($user, $dbi, $buddy, $START_DELIM, $DELIM);
38 function getBuddies($fromUser, $dbi, $thePage = ""){
39 $START_DELIM = $thePage . _("Buddies:");
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);
46 return $buddies_array;
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
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'];
60 if($cur_rating >= $MIDDLE_RATING){
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 == ""){
71 }else if($agreePos && $buddy_rating >= $MIDDLE_RATING){
73 } else if(!$agreePos && $buddy_rating < $MIDDLE_RATING){
80 if($agree && $agreePos){
82 } else if($agree && !$agreePos){
89 function MinMisery($dbi, $page, $users, $active_userid){
90 //Returns the minimum rating for the page
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'];
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;
111 function AverageRating($dbi, $page, $users, $active_userid){
112 //Returns the average rating for the page
113 //from all the users.
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;
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;
139 return $total / $count;
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.
149 // Revision 1.1 2004/06/18 14:42:17 rurban
150 // added wikilens libs (not yet merged good enough, some work for DanFr)
157 // c-hanging-comment-ender-p: nil
158 // indent-tabs-mode: nil