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:");
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);
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();
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"
62 $result = $dbh->query($query);
64 // from 10 random raters of this page (non-SQL)
70 if (is_array($buddies_array))
71 foreach ($buddies_array as $userid) {
72 $result[] = new RatingsUser($userid);
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
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'];
88 if($cur_rating >= $MIDDLE_RATING){
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 == ""){
99 }else if($agreePos && $buddy_rating >= $MIDDLE_RATING){
101 } else if(!$agreePos && $buddy_rating < $MIDDLE_RATING){
108 if($agree && $agreePos){
110 } else if($agree && !$agreePos){
117 function MinMisery($dbi, $page, $users, $active_userid){
118 //Returns the minimum rating for the page
119 //from all the users.
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'];
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;
139 function AverageRating($dbi, $page, $users, $active_userid){
140 //Returns the average rating for the page
141 //from all the users.
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;
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;
167 return $total / $count;
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
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.
180 // Revision 1.1 2004/06/18 14:42:17 rurban
181 // added wikilens libs (not yet merged good enough, some work for DanFr)
188 // c-hanging-comment-ender-p: nil
189 // indent-tabs-mode: nil