/** * Returns an array of user stats, sorted according to the given criterion * and in the given order. Includes a cache lookup. * * @param crit Criterion to sorty by * @param ord Order to sort in (ascending/descending) */ public static function getTopData($crit, $ord, $manual) { $topEntries = TopEntry::getUnsortedTopData($manual); $nick = array(); $numWords = array(); $numChars = array(); $date = array(); foreach ($topEntries as $topEntry) { $nick[] = $topEntry->userNick; $numWords[] = $topEntry->numDefinitions; $numChars[] = $topEntry->numChars; $date[] = $topEntry->timestamp; } $ord = (int) $ord; if ($crit == CRIT_CHARS) { array_multisort($numChars, SORT_NUMERIC, $ord, $nick, SORT_ASC, $topEntries); } else { if ($crit == CRIT_WORDS) { array_multisort($numWords, SORT_NUMERIC, $ord, $nick, SORT_ASC, $topEntries); } else { if ($crit == CRIT_NICK) { array_multisort($nick, $ord, $topEntries); } else { array_multisort($date, SORT_NUMERIC, $ord, $nick, SORT_ASC, $topEntries); } } } return $topEntries; }
$userData = array(); $user->email = StringUtil::scrambleEmail($user->email); // Find the rank of this user by number of words and number of characters $topWords = TopEntry::getTopData(CRIT_WORDS, SORT_DESC, true); $numUsers = count($topWords); $rankWords = 0; while ($rankWords < $numUsers && $topWords[$rankWords]->userNick != $nick) { $rankWords++; } $userData['rank_words'] = $rankWords + 1; if ($rankWords < $numUsers) { $topEntry = $topWords[$rankWords]; $userData['last_submission'] = $topEntry->timestamp; $userData['num_words'] = $topEntry->numDefinitions; $userData['num_chars'] = $topEntry->numChars; } $topChars = TopEntry::getTopData(CRIT_CHARS, SORT_DESC, true); $numUsers = count($topChars); $rankChars = 0; while ($rankChars < $numUsers && $topChars[$rankChars]->userNick != $nick) { $rankChars++; } $userData['rank_chars'] = $rankChars + 1; SmartyWrap::assign('medals', Medal::loadForUser($user)); if (util_isModerator(PRIV_ADMIN)) { // Admins can grant/revoke medals SmartyWrap::assign('allMedals', Medal::$DATA); } SmartyWrap::assign('user', $user); SmartyWrap::assign('userData', $userData); SmartyWrap::display('user.tpl');
<?php require_once "../phplib/util.php"; smarty_assign('manualData', TopEntry::getTopData(CRIT_CHARS, SORT_DESC, true)); smarty_assign('bulkData', TopEntry::getTopData(CRIT_CHARS, SORT_DESC, false)); smarty_assign('page_title', 'Topul voluntarilor'); smarty_displayCommonPageWithSkin('top.ihtml');