3 // It is anticipated that when userid support is added to phpwiki,
4 // this object will hold much more information (e-mail,
5 // home(wiki)page, etc.) about the user.
7 // There seems to be no clean way to "log out" a user when using HTTP
8 // authentication. So we'll hack around this by storing the currently
9 // logged in username and other state information in a cookie.
11 // 2002-09-08 11:44:04 rurban
12 // Todo: Fix prefs cookie/session handling:
13 // _userid and _homepage cookie/session vars still hold the
15 // If no homepage, fallback to prefs in cookie as in 1.3.3.
17 require_once (dirname(__FILE__) . "/Utils.php");
19 function addBuddy($user, $buddy, $dbi)
21 $START_DELIM = _("Buddies:");
22 // the delimiter is really a comma, but include a space to make it look
23 // nicer (getBuddies strips out extra spaces when extracting buddies)
26 addPageTextData($user, $dbi, $buddy, $START_DELIM, $DELIM);
29 function getBuddies($fromUser, $dbi, $thePage = "")
31 $START_DELIM = $thePage . _("Buddies:");
33 $buddies_array = getPageTextData($fromUser, $dbi, $START_DELIM, $DELIM);
34 if (count($buddies_array) == 0 and $thePage !== "") {
35 $buddies_array = getPageTextData($fromUser, $dbi, _("Buddies:"), $DELIM);
37 if (empty($buddies_array)) {
38 // 1. calculate buddies automatically from the 10 top raters with the most numratings (min. 5 ratings).
39 // of all pages (only SQL)
40 // or 2. from 10 random raters of this page (non-SQL)
41 // or 3. from all members of your group (department) if <= 20
42 $rdbi = RatingsDb::getTheRatingsDb();
44 if (RATING_STORAGE == 'SQL') {
45 //$result = $this->_sql_get_rating_result($dimension, null, null, 'numrating', "rater");
46 $dbh = &$rdbi->_sqlbackend;
47 extract($dbh->_table_names);
48 $query = "SELECT raterpage, COUNT(rateepage) as numrating"
49 . " FROM $rating_tbl r, $page_tbl p "
50 // . " WHERE ratingvalue > 0 AND numrating > 5"
51 . " WHERE ratingvalue > 0"
52 . " GROUP BY raterpage"
53 . " ORDER BY numrating"
55 $result = $dbh->_dbh->query($query);
57 // from 10 random raters of this page (non-SQL)
63 if (is_array($buddies_array))
64 foreach ($buddies_array as $userid) {
65 $result[] = new RatingsUser($userid);
70 function CoAgreement($dbi, $page, $users, $active_userid)
72 //Returns a "yes" 1, "no" -1, or "unsure" 0 for whether
73 //the group agrees on the page based on their ratings
76 $my_ratings_iter = $dbi->get_rating(0, $active_userid, $page);
77 $my_ratings_single = $my_ratings_iter->next();
78 $cur_rating = $my_ratings_single['ratingvalue'];
82 if ($cur_rating >= $MIDDLE_RATING) {
87 foreach ($users as $buddy) {
88 $buddy_rating_iter = $dbi->get_rating(0, $buddy, $cur_page);
89 $buddy_rating_array = $buddy_rating_iter->next();
90 $buddy_rating = $buddy_rating_array['ratingvalue'];
91 if ($buddy_rating == "") {
93 } elseif ($agreePos && $buddy_rating >= $MIDDLE_RATING) {
95 } elseif (!$agreePos && $buddy_rating < $MIDDLE_RATING) {
102 if ($agree && $agreePos) {
104 } elseif ($agree && !$agreePos) {
111 function MinMisery($dbi, $page, $users, $active_userid)
113 //Returns the minimum rating for the page
114 //from all the users.
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'];
123 foreach ($users as $buddy) {
124 $buddy_rating_iter = $dbi->get_rating(0, $buddy, $cur_page);
125 $buddy_rating_array = $buddy_rating_iter->next();
126 $buddy_rating = $buddy_rating_array['ratingvalue'];
127 if ($buddy_rating != "" && $buddy_rating < $min) {
128 $min = $buddy_rating;
134 function AverageRating($dbi, $page, $users, $active_userid)
136 //Returns the average rating for the page
137 //from all the users.
141 $my_ratings_iter = $dbi->get_rating(0, $active_userid, $page);
142 $my_ratings_single = $my_ratings_iter->next();
143 $cur_rating = $my_ratings_single['ratingvalue'];
144 if ($cur_rating != "") {
145 $total = $cur_rating;
151 foreach ($users as $buddy) {
152 $buddy_rating_iter = $dbi->get_rating(0, $buddy, $cur_page);
153 $buddy_rating_array = $buddy_rating_iter->next();
154 $buddy_rating = $buddy_rating_array['ratingvalue'];
155 if ($buddy_rating != "") {
156 $total = $total + $buddy_rating;
163 return $total / $count;
171 // c-hanging-comment-ender-p: nil
172 // indent-tabs-mode: nil