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.
18 require_once (dirname(__FILE__)."/Utils.php");
20 function addBuddy($user, $buddy, $dbi)
22 $START_DELIM = _("Buddies:");
23 // the delimiter is really a comma, but include a space to make it look
24 // nicer (getBuddies strips out extra spaces when extracting buddies)
27 addPageTextData($user, $dbi, $buddy, $START_DELIM, $DELIM);
30 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){
71 //Returns a "yes" 1, "no" -1, or "unsure" 0 for whether
72 //the group agrees on the page based on their ratings
75 $my_ratings_iter = $dbi->get_rating(0, $active_userid, $page);
76 $my_ratings_single = $my_ratings_iter->next();
77 $cur_rating = $my_ratings_single['ratingvalue'];
81 if($cur_rating >= $MIDDLE_RATING){
86 foreach($users as $buddy){
87 $buddy_rating_iter = $dbi->get_rating(0, $buddy, $cur_page);
88 $buddy_rating_array = $buddy_rating_iter->next();
89 $buddy_rating = $buddy_rating_array['ratingvalue'];
90 if($buddy_rating == ""){
92 }else if($agreePos && $buddy_rating >= $MIDDLE_RATING){
94 } else if(!$agreePos && $buddy_rating < $MIDDLE_RATING){
101 if($agree && $agreePos){
103 } else if($agree && !$agreePos){
110 function MinMisery($dbi, $page, $users, $active_userid){
111 //Returns the minimum rating for the page
112 //from all the users.
116 $my_ratings_iter = $dbi->get_rating(0, $active_userid, $page);
117 $my_ratings_single = $my_ratings_iter->next();
118 $cur_rating = $my_ratings_single['ratingvalue'];
121 foreach($users as $buddy){
122 $buddy_rating_iter = $dbi->get_rating(0, $buddy, $cur_page);
123 $buddy_rating_array = $buddy_rating_iter->next();
124 $buddy_rating = $buddy_rating_array['ratingvalue'];
125 if($buddy_rating != "" && $buddy_rating < $min){
126 $min = $buddy_rating;
132 function AverageRating($dbi, $page, $users, $active_userid){
133 //Returns the average rating for the page
134 //from all the users.
138 $my_ratings_iter = $dbi->get_rating(0, $active_userid, $page);
139 $my_ratings_single = $my_ratings_iter->next();
140 $cur_rating = $my_ratings_single['ratingvalue'];
141 if($cur_rating != ""){
142 $total = $cur_rating;
148 foreach($users as $buddy){
149 $buddy_rating_iter = $dbi->get_rating(0, $buddy, $cur_page);
150 $buddy_rating_array = $buddy_rating_iter->next();
151 $buddy_rating = $buddy_rating_array['ratingvalue'];
152 if($buddy_rating != ""){
153 $total = $total + $buddy_rating;
160 return $total / $count;
168 // c-hanging-comment-ender-p: nil
169 // indent-tabs-mode: nil