コード例 #1
0
ファイル: UserRatings.php プロジェクト: pombredanne/tuleap
 function run($dbi, $argstr, &$request, $basepage)
 {
     extract($this->getArgs($argstr, $request));
     // XXX: fix to reflect multi-user ratings?
     $caption = _("Displaying %d ratings:");
     $active_user = $request->getUser();
     $active_userid = $active_user->_userid;
     // check for request to display a category's ratings
     if (isset($category) && is_string($category) && strlen($category)) {
         $pageids = array();
         $category_page = $dbi->getPage($category);
         $iter = $category_page->getLinks();
         while ($item = $iter->next()) {
             array_push($pageids, $item->getName());
         }
         // XXX: is there a way to retrieve the preferred plural
         // representation of a category name?
         // XXX: should the category text be a link?  can it be one easily?
         $caption = sprintf(_("Showing all %ss (%%d):"), $category);
     } elseif (!isset($pageids) || !is_array($pageids)) {
         // XXX: need support for sorted ratings
         // bug: pages excluded from the PageList via the "exclude" argument
         // count toward the limit!
         $pageids = array();
         $active_user_ratings_user =& RatingsUserFactory::getUser($active_user->getId());
         $current_user_ratings = $active_user_ratings_user->get_ratings();
         if ($userPage) {
             //we're on a user's homepage, get *their* ratings
             $this_page_user =& RatingsUserFactory::getUser($userPage);
             $caption = _("Here are {$userPage}" . "'s %d page ratings:");
             $ratings = $this_page_user->get_ratings();
         } else {
             $caption = _("Here are your %d page ratings:");
             $ratings = $current_user_ratings;
         }
         $i = 0;
         foreach ($ratings as $pagename => $page_ratings) {
             // limit is currently only honored for "own" ratings
             if ($limit > 0 && $i >= $limit) {
                 break;
             }
             if (isset($page_ratings[$dimension])) {
                 array_push($pageids, $pagename);
                 $i++;
             }
         }
         // $caption = _("Here are your %d page ratings:");
         //make $ratings the user's ratings again if it had been treated as the current page
         // name's ratings
         $ratings = $current_user_ratings;
     }
     // if userids is null or empty, fill it with just the active user
     if (!isset($userids) || !is_array($userids) || !count($userids)) {
         // TKL: moved getBuddies call inside if statement because it was
         // causing the userids[] parameter to be ignored
         if (is_string($active_userid) && strlen($active_userid) && $active_user->isSignedIn() && !$userPage) {
             if (isset($category_page)) {
                 $userids = getBuddies($active_userid, $dbi, $category_page->getName());
             } else {
                 $userids = getBuddies($active_userid, $dbi);
             }
         } elseif ($userPage) {
             //we're on a user page, show that user's ratings as the only column
             $userids = array();
             array_push($userids, $userPage);
         } else {
             $userids = array();
             // XXX: this wipes out the category caption...
             // $caption = _("You must be logged in to view ratings.");
         }
     }
     // find out which users we should show ratings for
     // users allowed in the prediction calculation
     $allowed_users = array();
     // users actually allowed to be shown to the user
     $allowed_users_toshow = array();
     foreach ($userids as $userid) {
         $user =& RatingsUserFactory::getUser($userid);
         if ($user->allow_view_ratings($active_user)) {
             array_push($allowed_users_toshow, $user);
         }
         // all users should be allowed in calculation
         array_push($allowed_users, $user);
         // This line ensures $user is not a reference type after this loop
         // If it is a reference type, that can produce very unexpected behavior!
         unset($user);
     }
     // if no buddies, use allusers in prediction calculation
     if (count($userids) == 0 || $userPage) {
         $allowed_users = array();
         //$people_iter = $dbi->get_users_rated();
         $people_dbi = RatingsDb::getTheRatingsDb();
         $people_iter = $people_dbi->sql_get_users_rated();
         while ($people_array = $people_iter->next()) {
             $userid = $people_array['pagename'];
             $user =& RatingsUserFactory::getUser($userid);
             array_push($allowed_users, $user);
         }
     }
     $columns = $info ? explode(",", $info) : array();
     // build our table...
     $pagelist = new PageList($columns, $exclude, array('dimension' => $dimension, 'users' => $allowed_users_toshow));
     // augment columns
     //$preds = new _PageList_Column_prediction('prediction', _("Pred"), 'right', $dimension, $allowed_users);
     $preds = array('_PageList_column_prediction', 'custom:prediction', _("Pred"), 'right', ' ', $allowed_users);
     $pagelist->addColumnObject($preds);
     //$widget = new _PageList_Column_ratingwidget('ratingwidget', _("Rate"), 'left', $dimension);
     $widget = array('_PageList_column_ratingwidget', 'custom:ratingwidget', _("Rate"), 'center');
     $pagelist->addColumnObject($widget);
     $noRatingUsers = array();
     if (!$nobuds) {
         foreach ($allowed_users_toshow as $idx => $user) {
             // For proper caching behavior, get a ref, don't user $user
             $u =& $allowed_users_toshow[$idx];
             //$col = new _PageList_Column_ratingvalue('ratingvalue', $u->getId(), 'right', $dimension, $u);
             $col = array('_PageList_Column_ratingvalue', 'custom:ratingvalue', $u->getId(), 'right', ' ', $u);
             $pagelist->addColumnObject($col);
             unset($u);
         }
     }
     // add rows -- each row represents an item (page)
     foreach ($pageids as $pagename) {
         // addPage can deal with cases where it is passed a string
         $pagelist->addPage($pagename);
     }
     if (!$noheader) {
         $pagelist->setCaption(_($caption));
     }
     return $pagelist;
 }
コード例 #2
0
ファイル: RatingsDb.php プロジェクト: pombredanne/tuleap
 /**
  * TODO: slow item-based recommendation engine, similar to suggest RType=2.
  *       Only the SUGGEST_EstimateAlpha part
  * Take wikilens/RatingsUser.php for the php methods.
  */
 function php_prediction($userid = null, $pagename = null, $dimension = null)
 {
     if (is_null($dimension)) {
         $dimension = $this->dimension;
     }
     if (is_null($userid)) {
         $userid = $this->userid;
     }
     if (is_null($pagename)) {
         $pagename = $this->pagename;
     }
     if (empty($this->buddies)) {
         require_once "lib/wikilens/RatingsUser.php";
         require_once "lib/wikilens/Buddy.php";
         $user = RatingsUserFactory::getUser($userid);
         $this->buddies = getBuddies($user, $GLOBALS['request']->_dbi);
     }
     return $user->knn_uu_predict($pagename, $this->buddies, $dimension);
 }
コード例 #3
0
ファイル: PageListColumns.php プロジェクト: nterray/tuleap
 function _PageList_Column_prediction($params)
 {
     global $request;
     $active_user = $request->getUser();
     // This needs to be a reference so things aren't recomputed for this user
     $this->_active_ratings_user =& RatingsUserFactory::getUser($active_user->getId());
     $this->_pagelist =& $params[3];
     $this->_PageList_Column($params[0], $params[1], $params[2]);
     $this->_dimension = $this->_pagelist->getOption('dimension');
     $this->_users = $this->_pagelist->getOption('users');
 }