Exemple #1
0
 function &getUser($season_id, $rounds, $show_detail)
 {
     // load the season
     $db =& JFactory::getDBO();
     $season = new jSeason($db);
     $season->load($season_id);
     $current_round_id = $season->getCurrentRound();
     //		echo "<br>CURRENT ROUND ID: " .$current_round_id;
     // get the round number for the current round
     $query = "SELECT round FROM #__jtips_rounds WHERE id = " . $db->Quote($current_round_id);
     $db->setQuery($query);
     $current_round_number = $db->loadResult();
     //		echo "<br>CURRENT ROUND NUM: " .$current_round_number;
     // is the current round a multiple of $rounds?
     $mod = $current_round_number % $rounds;
     //		echo "<br>MOD = " .$mod;
     // upper limit
     $upper = $current_round_number - $mod;
     if ($upper < 0) {
         $upper = 0;
     }
     //		echo "<br>UPPER = " .$upper;
     // lower limit
     $lower = $upper - $rounds + 1;
     if ($lower < 0) {
         $lower = 0;
     }
     //		echo "<br>LOWER = " .$lower;
     // get the round numbers for all the rounds between
     $round_numbers = array();
     for ($i = $lower; $i <= $upper; $i++) {
         $round_numbers[] = $i;
     }
     // get the ids for these rounds
     $query = "SELECT id FROM #__jtips_rounds WHERE round IN (" . implode(", ", $round_numbers) . ") AND season_id = " . $db->Quote($season_id);
     $db->setQuery($query);
     $ids = $db->loadResultArray();
     // get the scores for the rounds between the lower and upper limits
     $query = " SELECT user_id, SUM(points) AS total FROM #__jtips_history " . " WHERE round_id IN (" . implode(", ", $ids) . ") " . " GROUP BY user_id ORDER BY total DESC";
     //		echo $query;
     $db->setQuery($query, 0, 1);
     $win = $db->loadObject();
     $jTipsUser = new jTipsUser($db);
     $jTipsUser->load($win->user_id);
     $data = array('who' => $jTipsUser, 'points' => $win->total);
     if ($show_detail) {
         $query = "SELECT #__jtips_rounds.round, #__jtips_history.points, #__jtips_history.rank FROM #__jtips_history " . " JOIN #__jtips_rounds ON #__jtips_history.round_id = #__jtips_rounds.id " . " WHERE user_id = {$win->user_id} AND #__jtips_history.round_id IN (" . implode(", ", $ids) . ") " . " ORDER BY #__jtips_rounds.round ASC";
         $db->setQuery($query);
         $data['results'] = $db->loadAssocList();
     } else {
         $data['results'] = array();
     }
     return $data;
 }
if (is_numeric($season_id)) {
    $jSeason->load($season_id);
} else {
    $date = gmdate('Y-m-d');
    //Bug 33.4 - Extended params array to default to season for current user
    $objParams = array('end_time' => array('type' => 'query', 'query' => "> '{$date}'"), 'left_join' => array('type' => 'left_join', 'join_table' => '#__jtips_users', 'lhs_table' => '#__jtips_seasons', 'lhs_key' => 'id', 'rhs_table' => '#__jtips_users', 'rhs_key' => 'season_id'));
    if (isset($jTipsUser->user_id) and !empty($jTipsUser->user_id)) {
        $objParams['#__jtips_users.user_id'] = $jTipsUser->user_id;
    }
    $jSeasons = forceArray($jSeason->loadByParams($objParams));
    if (count($jSeasons) > 0) {
        $jSeason =& array_shift($jSeasons);
    }
}
$jRound = new jRound($database);
$round_id = $jSeason->getCurrentRound();
$jRound->load($round_id);
if ($jRound->scored == 0) {
    $prev_round_id = $jSeason->getLastRound();
    $prev_round = new jRound($database);
    $prev_round->load($prev_round_id);
    $jRound =& $prev_round;
    $load_round = $prev_round_id;
} else {
    $load_round = $jRound->id;
}
$jHistory = new jHistory($database);
$jTipsUsers = $jHistory->getLadder($jTips['NumDefault'], $load_round);
?>
<table width='100%' cellspacing="0">
	<thead>
Exemple #3
0
 function getSummaryScores()
 {
     global $database;
     $season_ids = $this->getSeasons();
     $scores = array();
     foreach ($season_ids as $season_id) {
         $jSeason = new jSeason($database);
         $jSeason->load($season_id);
         $round_id = $jSeason->getCurrentRound();
         $jRound = new jRound($database);
         $jRound->load($round_id);
         $last_round_id = $jRound->getPrev();
         $jHistory = new jHistory($database);
         if (is_integer($last_round_id)) {
             $params = array('user_id' => $this->user_id, 'round_id' => $round_id);
             $jHistory->loadByParams($params);
         }
         $jTipsUser_season = new jTipsUser($database);
         $params = array('user_id' => $this->user_id, 'season_id' => $season_id);
         $jTipsUser_season->loadByParams($params);
         $jRound->load($last_round_id);
         $total = $jHistory->getTotal($this, 'points');
         if (!isset($total)) {
             $total = 0;
         }
         $average = $total / (is_numeric($jRound->round) && $jRound->round > 0 ? $jRound->round : 1);
         if (!isset($average)) {
             $average = 0;
         }
         $scores[$season_id] = array('total_points' => $total, 'total_precision' => $jHistory->getTotal($this, 'precision'), 'average' => $average, 'doubleup' => $jTipsUser_season->doubleup, 'paid' => $jTipsUser_season->paid);
     }
     return $scores;
 }