コード例 #1
0
ファイル: ListPages.php プロジェクト: pombredanne/tuleap
 function run($dbi, $argstr, &$request, $basepage)
 {
     $args = $this->getArgs($argstr, $request);
     extract($args);
     // If the ratings table does not exist, or on dba it will break otherwise.
     // Check if Theme isa 'wikilens'
     if ($info == 'pagename' and isa($GLOBALS['WikiTheme'], 'wikilens')) {
         $info .= ",top3recs";
     }
     if ($info) {
         $info = split(',', $info);
     } else {
         $info = array();
     }
     if (in_array('top3recs', $info)) {
         require_once 'lib/wikilens/Buddy.php';
         require_once 'lib/wikilens/PageListColumns.php';
         $active_user = $request->getUser();
         $active_userid = $active_user->_userid;
         // 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) and strlen($active_userid) and $active_user->isSignedIn()) {
                 $userids = getBuddies($active_userid, $dbi);
             } 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
         $allowed_users = array();
         foreach ($userids as $userid) {
             $user = new RatingsUser($userid);
             if ($user->allow_view_ratings($active_user)) {
                 array_push($allowed_users, $user);
             }
             // PHP's silly references... (the behavior with this line commented
             // out is... odd)
             unset($user);
         }
         $options = array('dimension' => $dimension, 'users' => $allowed_users);
         $args = array_merge($options, $args);
     }
     if (empty($pages) and $pages != '0') {
         return '';
     }
     if (in_array('numbacklinks', $info)) {
         $args['types']['numbacklinks'] = new _PageList_Column_ListPages_count('numbacklinks', _("#"), true);
     }
     if (in_array('numpagelinks', $info)) {
         $args['types']['numpagelinks'] = new _PageList_Column_ListPages_count('numpagelinks', _("#"));
     }
     $pagelist = new PageList($info, $exclude, $args);
     $pages_array = is_string($pages) ? explodePageList($pages) : (is_array($pages) ? $pages : array());
     $pagelist->addPageList($pages_array);
     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
ファイル: 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;
 }