function getTotalScore($field) { global $database; /* if (!isset($this->$field)) { $jHistory = new jHistory($database); $this->$field = $jHistory->getTotal($this, $field); } return $this->$field; */ $jHistory = new jHistory($database); return $jHistory->getTotal($this, $field); }
$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> <tr class='sectiontableheader jtableheader'> <th>#</th> <th><?php echo $jLang['_COM_TIP_LADDER_USER']; ?> </th> <th><?php echo $jLang['_COM_TIP_LADDER_LAST']; ?> </th> <th><?php
function getUserLadder($num_to_show, $page = 0, $field = 'points', $dir = 'desc', $round_id = FALSE) { global $database, $jTips; $org_round_id = $round_id; if ($round_id === FALSE) { $round_id = $this->getLatestRound(); } $jHistory = new jHistory($database); $this->getUsers($round_id); $jTipsUsers = array(); $start_from = $num_to_show * $page; $go_to = min($start_from + $num_to_show, count($this->users)); for ($i = $start_from; $i < $go_to; $i++) { $jTipsUser =& $this->users[$i]; $params = array('user_id' => $this->users[$i]->id, 'round_id' => $round_id, 'left_join' => array('type' => 'left_join', 'join_table' => '#__jtips_rounds', 'lhs_table' => '#__jtips_history', 'rhs_table' => '#__jtips_rounds', 'lhs_key' => 'round_id', 'rhs_key' => 'id', 'supplement' => 'AND #__jtips_rounds.scored = 1')); $jHistory->loadByParams($params); if (is_property($jHistory, $field)) { $jTipsUser->{$field} = $jHistory->{$field}; } else { if ($field == 'pointst') { $jTipsUser->{$field} = $jTipsUser->getTotalScore('points'); } else { if ($field == 'prect') { $jTipsUser->{$field} = $jTipsUser->getTotalScore('precision'); } else { if ($field == 'rank') { $jTipsUser->{$field} = $jTipsUser->getRank($org_round_id); } else { if ($field == 'comment') { $jComment = new jComment($database); $params = array('user_id' => $jTipsUser->id, 'round_id' => $round_id); $jComment->loadByParams($params); $jTipsUser->{$field} = !empty($jComment->comment) ? $jComment->comment : ""; } else { $jTipsUser->{$field} = $jTipsUser->getName(); } } } } } array_push($jTipsUsers, $jTipsUser); } //jTipsSortArrayObjects($jTipsUsers, $field, $dir); //return $jTipsUsers; return jTipsUser::sort($jTipsUsers, $field, $dir); }
//should columns be hidden? $hideRaw = jTipsGetParam($_REQUEST, 'hide'); if ($hideRaw) { //BUG 231 - Add a fallback in case we are using PHP < 5.2.0 if (!function_exists('json_decode')) { $hideColumns = array('result', 'actual', 'awarded'); } else { // TODO: need to ensure json_decode returns an array here $hideColumns = json_decode(jTipsStripslashes(rawurldecode($hideRaw))); } // BUG 371 - use a fallback if something went wrong if (!$hideColumns) { $hideColumns = array('result', 'actual', 'awarded'); } $render->assign('stats', false); } else { $hideColumns = array(); //should the extra stats be calculated $jHistory = new jHistory($database); if ($jTips['ShowTipsStats']) { //ok, here we go! $stats = array('tips' => array('round' => $jTipsUser->getTipsAccuracy($jRound->id), 'overall' => $jTipsUser->getTipsAccuracy()), 'score' => array('round' => $jTipsUser->getRoundScore('precision', $jRound->id), 'overall' => $jHistory->getProgressScore($jTipsUser, $jRound->id, 'precision'))); $render->assign('stats', $stats); } else { $render->assign('stats', false); } } $render->display($hideColumns); if (!isJoomla15()) { die; }
function setRanks($round_id, $force = false) { global $database; if (!$round_id) { jTipsLogger::_log('setRanks - no round_id passed in!', 'ERROR'); return; } //optimizing //only process this round if the number of users in the round (in history) does not equal the outof $query = "SELECT COUNT(*) total, outof from #__jtips_history WHERE round_id = " . $database->Quote($round_id) . " GROUP BY round_id"; //jTipsDebug($query); $database->setQuery($query); $rows = $database->loadAssocList(); $row = array_shift($rows); //jTipsDebug($row); //die(); if (!$force and $row['total'] == $row['outof']) { //no need to reprocess this round! jTipsLogger::_log('setRanks: round does not need to be processed'); return; } ////////////////////////////// // BUG 87 - Incorrect User Ranks and Scores // //$query = "SELECT user_id, SUM(`points`) AS total_points, SUM(`precision`) AS total_precision " . //"FROM #__jtips_history GROUP BY user_id ORDER BY total_points DESC, total_precision ASC"; $getSeasonQuery = "SELECT season_id, `round` FROM #__jtips_rounds WHERE id = {$round_id}"; $database->setQuery($getSeasonQuery); $rounds = $database->loadAssocList(); $round = array_shift($rounds); $roundIDQuery = "SELECT id FROM #__jtips_rounds WHERE season_id = '" . $round['season_id'] . "' AND `round` <= '" . $round['round'] . "'"; //$roundIDQuery = "SELECT id FROM #__jtips_rounds WHERE season_id = '" .$round['season_id']. "' AND start_time <= '" .$round['start_time']. "'"; $database->setQuery($roundIDQuery); $round_ids_array = $database->loadResultArray(); if (empty($round_ids_array)) { jTipsLogger::_log('setRanks - no rounds found! Something went wrong!', 'ERROR'); return; } $round_ids = implode(', ', $round_ids_array); $query = "SELECT user_id, SUM(points) AS total_points, SUM(`precision`) AS total_precision " . "FROM #__jtips_history WHERE round_id IN ({$round_ids}) GROUP BY user_id " . "ORDER BY total_points DESC, total_precision ASC"; // END BUG 87 ////////////////////////////////// jTipsLogger::_log("SETRANKS QUERY: " . $query); $database->setQuery($query); $rows = $database->loadResultArray(); $outof = count($rows); $rank = 1; foreach ($rows as $id) { $params = array('user_id' => $id, 'round_id' => $round_id); $jHistory = new jHistory($database); $jHistory->loadByParams($params); $jHistory->rank = $rank; $jHistory->outof = $outof; if (!$id) { jTipsLogger::_log("NO USER ID!: U:{$id} R:{$rank} O:{$outof} Q:{$query}"); } jTipsLogger::_log("Setting rank for user {$id} to {$rank} out of {$outof}"); //jTipsLogger::_log($jHistory); $jHistory->save(); if (!empty($jHistory->_error)) { jTipsLogger::_log($jHistory->_error, 'ERROR'); } $rank++; } }
function process() { global $database, $jTips, $mosConfig_absolute_path; $this->clearHistory(); $params = array('round_id' => $this->id); $jSeason = new jSeason($database); $jSeason->load($this->season_id); $jGame = new jGame($database); $jGames = forceArray($jGame->loadByParams($params)); $params = array('season_id' => $this->season_id); $jTipsUser = new jTipsUser($database); $jTipsUsers = forceArray($jTipsUser->loadByParams($params)); $noTips = $scores = $worst_precision = array(); $played = count($jGames); foreach ($jTipsUsers as $jTipsUser) { jTipsLogger::_log("Processing scores for user " . $jTipsUser->id); $score = $matching = $precision = $allAwayScore = 0; if ($jTipsUser->hasTipped($this->id)) { jTipsLogger::_log($jTipsUser->id . " has tipped in round " . $this->id); foreach ($jGames as $jGame) { jTipsLogger::_log("Processing game " . $jGame->id); $params = array('user_id' => $jTipsUser->id, 'game_id' => $jGame->id); $jTip = new jTip($database); $jTip->loadByParams($params); // make sure this is not a bye game if (!$jGame->home_id or !$jGame->away_id or !$jGame->winner_id) { jTipsLogger::_log('attempting to process tips on a bye game, skipping', 'INFO'); continue; } /* * Feature Request 101 - Team Starts * Determine the winner when we take the starts into account * We only care about the starts for picking the winner/draw * For picking the margins and scores, use the actual winner */ if ($jSeason->team_starts) { jTipsLogger::_log('processing team starts'); $homeScore = $awayScore = 0; $homeScore = $jGame->home_score + ($jGame->home_start + 0); $awayScore = $jGame->away_score + ($jGame->away_start + 0); if ($homeScore > $awayScore) { $winnerID = $jGame->home_id; } else { if ($homeScore < $awayScore) { $winnerID = $jGame->away_id; } else { if ($homeScore == $awayScore) { $winnerID = -1; } } } jTipsLogger::_log('feature 101: With starts, the winner is ' . $winnerID . ', otherwise the winner is ' . $jGame->winner_id . " HOME {$homeScore} v AWAY {$awayScore}"); } else { $winnerID = $jGame->winner_id; } if ($jTip->tip_id == $winnerID) { //User tipped right! jTipsLogger::_log("CORRECT TIP by " . $jTipsUser->id . " in round_id " . $this->id . " in game_id " . $jGame->id); //BUG 248 - Add ToughScore if enabled if ($jSeason->tough_score and $jGame->tough_score) { $score += $jGame->tough_score; } if ($winnerID == -1) { $score += isset($jSeason->user_draw) ? $jSeason->user_draw : 0; jTipsLogger::_log("Draw correctly picked!"); } else { $score += isset($jSeason->user_correct) ? $jSeason->user_correct : 0; } $matching++; } if ($winnerID == $jGame->away_id) { $allAwayScore += $jSeason->user_correct; } //Check for correct margins and handle precision score gathering if ($jSeason->pick_margin == 1 and $jGame->has_margin == 1) { $margin = abs($jGame->home_score - $jGame->away_score); if ($jTip->margin == $margin) { $score += isset($jSeason->user_pick_margin) ? $jSeason->user_pick_margin : 0; jTipsLogger::_log("correct margin picked!"); } if ($jSeason->precision_score == 1) { if ($jGame->winner_id == $jTip->tip_id) { $margin_offset = abs($margin - $jTip->margin); } else { $margin_offset = abs($margin + $jTip->margin); } if (isset($worst_precision[$jGame->id]) && $margin_offset > $worst_precision[$jGame->id] || empty($worst_precision[$jGame->id])) { $worst_precision[$jGame->id] = $margin_offset; } $precision += $margin_offset; jTipsLogger::_log("PICK_MARGIN: Adding {$margin_offset} to precision of {$precision}"); } } //Check for correct scores and handle precision score gathering if ($jSeason->pick_score == 1 and $jGame->has_score == 1) { $margin = abs($jGame->home_score - $jGame->away_score); if ($jTip->home_score == $jGame->home_score and $jTip->away_score == $jGame->away_score) { $score += isset($jSeason->user_pick_score) ? $jSeason->user_pick_score : 0; jTipsLogger::_log("Correct scores picked!"); } if ($jSeason->precision_score == 1) { $pickedScoreMargin = abs($jTip->home_score - $jTips->away_score); if ($jGame->winner_id == $jTip->tip_id) { $score_offset = abs($margin - $pickedScoreMargin); } else { $score_offset = abs($margin + $pickedScoreMargin); } if (isset($worst_precision[$jGame->id]) and $score_offset > $worst_precision[$jGame->id] or empty($worst_precision[$jGame->id])) { $worst_precision[$jGame->id] = $score_offset; } $precision += $score_offset; jTipsLogger::_log("PICK_SCORE: Adding {$score_offset} to precision of {$precision}"); jTipsLogger::_log("PREC DEBUG: {$jTipsUser->id}-{$jTipsUser->user_id} Picked Margin: {$pickedScoreMargin}. Actual Margin: {$margin}. Applied Precision: {$score_offset}. Running Precision: {$precision}", 'INFO'); } } //Check for a bonus team selection if ($jSeason->pick_bonus >= 1 and $jGame->has_bonus == 1) { if ($jTip->bonus_id == $jGame->bonus_id && $jGame->bonus_id != -1) { $score += isset($jSeason->user_pick_bonus) ? $jSeason->user_pick_bonus : 0; } } } //was a perfect round picked? if ($matching == $played) { $score += isset($jSeason->user_bonus) ? $jSeason->user_bonus : 0; } //did the user use their 'doubleup' if ($jTipsUser->doubleup == $this->id and $jTips['DoubleUp'] == 1) { $score = $score * 2; } $scores[] = $score; //Save the data to the history object $jHistory = new jHistory($database); $jHistory->user_id = $jTipsUser->id; $jHistory->round_id = $this->id; jTipsLogger::_log("Score for user_id " . $jTipsUser->id . " in round_id " . $this->id . " is {$score}"); $jHistory->points = $score; //Update rank after all users have been saved $jHistory->outof = count($jTipsUsers); //$jHistory->comment = $jTipsUser->comment; if ($jSeason->precision_score == 1) { jTipsLogger::_log("setting precision to {$precision} for user_id " . $jTipsUser->id . " in round_id " . $this->id); $jHistory->precision = $precision; } else { $jHistory->precision = 0; } if ($jHistory->save() !== false) { $results[] = 1; } else { jTipsLogger::_log("Error saving history: " . $jHistory->_error); $results[] = 0; } //remove the current comment $jTipsUser->comment = null; $jTipsUser->save(); // Check if the AlphaUserPoints config option is set if (isJoomla15()) { $api_AUP = JPATH_SITE . DS . 'components' . DS . 'com_alphauserpoints' . DS . 'helper.php'; } else { $api_AUP = $mosConfig_absolute_path . 'components/com_alphauserpoints/helper.php'; } if (!$this->scored and $jTips['AlphaUserPoints'] and jTipsFileExists($api_AUP)) { require_once $api_AUP; jTipsLogger::_log('sending ' . $score . ' points for user ' . $jTipsUser->user_id, 'INFO'); $refID = AlphaUserPointsHelper::getAnyUserReferreID($jTipsUser->user_id); AlphaUserPointsHelper::newpoints('plgaup_jtips_total_points', $refID, '', '', $score); } if (!$this->scored and $jTips['JomSocialActivities'] and $jTips['JomSocialUserResults']) { global $mosConfig_absolute_path; require_once $mosConfig_absolute_path . '/administrator/components/com_jtips/utils/jTipsJomSocial.php'; jTipsJomSocial::writeRoundResult($jSeason, $this, $jTipsUser->user_id, $score); } } else { $noTips[] = $jTipsUser; } } if (count($noTips) > 0) { ///////////////////////////////////////////////// // Feature Request 71 // Allow users that did not to be assigned // all the away teams // /*if ($jSeason->user_none != -1) { $thisRound = $jSeason->user_none; } else if (is_array($scores) && count($scores) > 0) { $thisRound = min($scores); } else { $thisRound = 0; }*/ if ($jSeason->user_none == -2) { //handle all away teams $thisRound = $allAwayScore; jTipsLogger::_log("didn't tip? You'll be stuck with the away teams. You got {$thisRound}"); } else { if ($jSeason->user_none == -1) { //handle lowest possible score if (is_array($scores) and count($scores) > 0) { $thisRound = min($scores); jTipsLogger::_log("didn't tip? You'll be stuck with the lowest score this round, {$thisRound}"); } else { $thisRound = 0; jTipsLogger::_log("didn't tip? You'll be stuck {$thisRound}"); } } else { //handle allocated score $thisRound = $jSeason->user_none; jTipsLogger::_log("didn't tip? You're getting {$thisRound}"); } } // // END Feature Request 71 //////////////////////////////////////////////////// foreach ($noTips as $jTipsUser) { $jHistory = new jHistory($database); $jHistory->user_id = $jTipsUser->id; $jHistory->round_id = $this->id; $jHistory->points = $thisRound; $jHistory->precision = array_sum($worst_precision); //$jHistory->outof = count($jTipsUsers); //$jHistory->comment = $jTipsUser->comment; if ($jHistory->save() !== false) { $results[] = 1; } else { $results[] = 0; } $jTipsUser->save(); // Check if the AlphaUserPoints config option is set if (isJoomla15()) { $api_AUP = JPATH_SITE . DS . 'components' . DS . 'com_alphauserpoints' . DS . 'helper.php'; } else { $api_AUP = $mosConfig_absolute_path . 'components/com_alphauserpoints/helper.php'; } if (!$this->scored and $jTips['AlphaUserPoints'] and jTipsFileExists($api_AUP)) { require_once $api_AUP; jTipsLogger::_log('sending ' . $score . ' points for user ' . $jTipsUser->user_id, 'INFO'); $refID = AlphaUserPointsHelper::getAnyUserReferreID($jTipsUser->user_id); AlphaUserPointsHelper::newpoints('plgaup_jtips_total_points', $refID, '', '', $thisRound); } if (!$this->scored and $jTips['JomSocialActivities']) { global $mosConfig_absolute_path; require_once $mosConfig_absolute_path . '/administrator/components/com_jtips/utils/jTipsJomSocial.php'; if ($jTips['JomSocialUserResults']) { jTipsJomSocial::writeRoundResult($jSeason, $this, $jTipsUser->user_id, $score); } if ($jTips['JomSocialOnNoTips']) { jTipsJomSocial::writeOnNoTips($jTipsUser->user_id, $jSeason, $this); } } } } $jHistory = new jHistory($database); $jHistory->setRanks($this->id, true); if (!$this->scored and $jTips['JomSocialActivities']) { // find out who won the round and write it to the JomSocial stream $winners = $this->getRoundWinners(); jTipsJomSocial::writeRoundWinners($winners, $this, $jSeason); } $this->scored = 1; $result = $this->save(); //if ($this->scored != 1) { jTeam::updateLadder($this, $jSeason); //} //$this->scored = 1; //return $this->save(); return $result; }
function getLastRoundSummaryDetail(&$jTipsUser, $col) { global $jTips, $jLang, $database; $jSeason = new jSeason($database); $jSeason->load($jTipsUser->season_id); switch ($col) { case 'season': return $jSeason->name; break; case 'last_won': //return $jTipsUser->getName(); // BUG 313 - Social Integration on Last Round Summary dashlet if (isset($jTips['SocialIntegration']) and !empty($jTips['SocialIntegration'])) { // which type of integration if ($jTips['SocialIntegration'] == 'cb') { // Community Builder $link = jTipsRoute("index.php?option=com_comprofiler&task=userProfile&user="******"<img src='{$img}' alt='Avatar' title='" . $jTipsUser->getName() . "' align='absmiddle' /> <a href='{$link}'>" . $jTipsUser->getName() . "</a>"; return "<div style='text-align:left;'>{$html}</div>"; } else { return $jTipsUser->getName(); } break; case 'last_prec': $jHistory = new jHistory($database); return $jHistory->getLast($jTipsUser, 'precision'); break; case 'last_round': $jHistory = new jHistory($database); return $jHistory->getLast($jTipsUser); break; case 'last_prect': return $jTipsUser->getTotalScore('precision'); break; case 'last_tot': return $jTipsUser->getTotalScore('points'); break; case 'last_comm': $jComment = new jComment($database); $params = array('user_id' => $jTipsUser->id, 'round_id' => $jSeason->getLastRound()); $jComment->loadByParams($params); return jTipsStripslashes($jComment->comment); break; default: return '-'; } }
$jRound->load($round_id); if ($jRound->scored != 1) { $prev_id = $jRound->getPrev(); if ($prev_id !== false) { $jRound->load($prev_id); } } } $render->assign('jRound', $jRound); $jTipsCurrentUserParams = array('season_id' => $jSeason->id, 'status' => 1); $total = $jTipsCurrentUser->getCount($jTipsCurrentUserParams); //Better pagination $start = jTipsGetParam($_REQUEST, 'start', jTipsGetParam($_REQUEST, 'limitstart', 0)); $limit = jTipsGetParam($_REQUEST, 'limit', $jTips['NumMax']); //BUG 238 - Busted page calculations filter down to select queries $page = $start > 0 ? $start / $limit : 0; $pageNav = new mosPageNav($total, $start, $limit); $render->assign('pageNav', $pageNav); if ($limit == 0) { $limit = false; } $direction = jTipsGetParam($_REQUEST, 'filter_order_Dir', 'asc'); $jHistory = new jHistory($database); $jTipsUsers = $jHistory->getLadder($limit, $jRound->id, $page, jTipsGetParam($_REQUEST, 'filter_order', 'rank'), $direction, $jRound->id); $render->assign('jTipsUsers', $jTipsUsers); //build season dropdown $jSeasonParams = array('end_time' => array('type' => 'query', 'query' => "> '" . gmdate('Y-m-d H:i:s') . "'")); $jSeasons = forceArray($jSeason->loadByParams($jSeasonParams)); $render->assign('jSeasons', $jSeasons); $render->display(); //return jtips_HTML::jtips_ladder($jTipsUsers, $jSeason, $jRound, $pageNav);
?> <th class="sectiontableheader" style="text-align:center"><?php echo $fieldOptions[$user_field]; ?> </th> <?php } ?> </tr> </thead> <tbody> <?php $round_id = $jSeason->getLastRound(); $jRound = new jRound($database); $jRound->load($round_id); $jHistory = new jHistory($database); $orderField = ($user_field != 'moved' and $user_field != '-1') ? $user_field : 'pointst'; if ($orderField == 'points' or $orderField == 'comment') { $order = 'desc'; } else { if ($orderField == 'rank' or $orderField == 'pointst') { $order = 'asc'; } else { $order = 'default'; } } $userLadder = $jHistory->getLadder($numtoshow, $round_id, 0, $orderField, $order); $i = 1; foreach ($userLadder as $jUser) { ?> <tr class="sectiontableentry<?php