Ejemplo n.º 1
0
 function getRoundScore($field, $round_id)
 {
     global $database;
     if (!isset($this->{$field})) {
         $jHistory = new jHistory($database);
         $params = array('round_id' => $round_id, 'user_id' => $this->id);
         $jHistory->loadByParams($params);
         if ($jHistory->exists()) {
             $this->{$field} = $jHistory->{$field};
         } else {
             $this->{$field} = 0;
         }
     }
     return $this->{$field};
 }
Ejemplo n.º 2
0
 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);
 }
Ejemplo n.º 3
0
 /**
  * Delete all history related to this round
  */
 function clearHistory()
 {
     global $database;
     $params = array('round_id' => $this->id);
     $jHistory = new jHistory($database);
     $jHistories = forceArray($jHistory->loadByParams($params));
     foreach ($jHistories as $jHistory) {
         $jHistory->destroy();
     }
 }
Ejemplo n.º 4
0
 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++;
     }
 }
Ejemplo n.º 5
0
/**
 * For the given user and column, fetch the correct data to be displayed.
 * Returns the details from the users history for the selected column, eg, total score
 *
 * @param $jTipsUser The jTipsUser object to access data from/for
 * @param $jRound The round to be used as a reference for locating scores
 * @param $column The name of the column to fetch data for
 * @param $isModule True is being called from a module, false otherwise. Default is false
 * @return string The data for the user and field
 */
function getUserLadderField(&$jTipsUser, &$jRound, $column, $isModule = false)
{
    global $mainframe, $database, $jTips, $jLang, $mosConfig_live_site, $Itemid, $mosConfig_absolute_path;
    jTipsLogger::_log('fetching user ladder data for user ' . $jTipsUser->id . ' and column ' . $column, 'INFO');
    switch ($column) {
        case 'rank':
            //return $jTipsUser->getRank($jRound->id);
            $params = array('round_id' => $jRound->id, 'user_id' => $jTipsUser->id);
            $jHistory = new jHistory($database);
            $jHistory->loadByParams($params);
            return $jHistory->rank;
            break;
        case 'user':
            global $option;
            global $Itemid;
            if ($option == 'com_jtips') {
                $suffix = '&Itemid=' . $Itemid;
            } else {
                $suffix = '&season=' . $jTipsUser->season_id;
            }
            $name = $jTipsUser->getName();
            if ($jTips['EnableShowTips'] == 1 and $jRound->roundOver() and (!isset($jTips['SocialIntegration']) or empty($jTips['SocialIntegration']))) {
                //Link is to popup
                if (isJoomla15()) {
                    $width = $jTips['ShowTipsWidth'];
                    $height = $jTips['ShowTipsHeight'];
                    $title = $jLang['_LADDER_VIEW_TIPS_FOR'] . " " . $name;
                    //$showTipsUrl = jTipsRoute("index2.php?option=com_jtips&view=CompetitionLadder&menu=0&action=ShowTips&uid={$jTipsUser->id}&rid={$jRound->id}".$suffix);
                    /*$link = <<<EOF
                    				    <a class="modal" rel="{handler: 'iframe', size: {x: {$width}, y: {$height}}}" title="$title" href="$showTipsUrl">{$name}</a>
                    EOF;*/
                    // load the modal popul helper
                    JHTML::_('behavior.modal');
                    $showTipsUrl = jTipsRoute("index.php?option=com_jtips&view=CompetitionLadder&Itemid={$Itemid}&tmpl=component&menu=0&action=ShowTips&uid={$jTipsUser->id}&rid={$jRound->id}" . $suffix);
                    $rel = json_encode(array('size' => array('x' => $width, 'y' => $height)));
                    $attribs = array('class' => 'modal', 'rel' => str_replace('"', "'", $rel), 'title' => $title);
                    $link = JHTML::link($showTipsUrl, $name, $attribs);
                } else {
                    global $Itemid;
                    $data = "&Itemid={$Itemid}";
                    $link = "<a href='javascript:void(0);' onclick='loadTipsPopup(" . $jTipsUser->id . ", " . $jRound->id . ", this, \"{$data}\");' title='" . $jLang['_LADDER_VIEW_TIPS_FOR'] . " " . $name . "' id='userLadderLink_" . $jTipsUser->id . "'>" . $name . "</a>";
                }
            } else {
                //BUG 283 - Better fallback when CB enabled but not installed
                if (isset($jTips['SocialIntegration']) and !empty($jTips['SocialIntegration'])) {
                    if ($jTips['SocialIntegration'] == 'cb') {
                        // Link is to CB Pofile
                        $img = getCommunityBuilderAvatar($jTipsUser->user_id);
                    } else {
                        // Link to JomSocial Profile and get avatar
                        $img = getJomSocialAvatar($jTipsUser->user_id);
                    }
                    $alt = $name;
                    if (!empty($img)) {
                        //$img = preg_replace('/>|\/>/', "align='absmiddle' />", $img);
                        $name = "<img src='{$img}' border='0' align='absmiddle' />&nbsp;{$name}";
                    }
                    if ($jTips['EnableShowTips'] == 1) {
                        if (isJoomla15()) {
                            $width = $jTips['ShowTipsWidth'];
                            $height = $jTips['ShowTipsHeight'];
                            // BUG 312 - only display the user's name in the title of the link
                            $title = $jLang['_LADDER_VIEW_TIPS_FOR'] . " " . $jTipsUser->getName();
                            $showTipsUrl = jTipsRoute("index.php?option=com_jtips&view=CompetitionLadder&Itemid={$Itemid}&menu=0&action=ShowTips&uid={$jTipsUser->id}&rid={$jRound->id}" . $suffix);
                            $link = <<<EOF
\t\t\t\t\t\t\t    <a class="modal" rel="{handler: 'iframe', size: {x: {$width}, y: {$height}}}" title="{$title}" href="{$showTipsUrl}">{$name}</a>
EOF;
                        } else {
                            $data = "&Itemid={$Itemid}";
                            $link = "<a href='javascript:void(0);' onclick='loadTipsPopup(" . $jTipsUser->id . ", " . $jRound->id . ", this, \"{$data}\");' title='" . $jLang['_LADDER_VIEW_TIPS_FOR'] . " " . $alt . "' id='userLadderLink_" . $jTipsUser->id . "'>" . $name . "</a>";
                        }
                    } else {
                        // Get Community Builder Link
                        if ($jTips['SocialIntegration'] == 'cb') {
                            $link = "<a href='" . jTipsRoute("index.php?option=com_comprofiler&amp;task=userProfile&amp;user="******"'";
                        } else {
                            $ccLink = getJomSocialProfileLink($jTipsUser->user_id);
                            $link = "<a href='" . jTipsRoute($ccLink) . "'";
                        }
                        $link .= " title='View Profile' id='userLadderLink_" . $jTipsUser->id . "'>" . $name . "</a>";
                    }
                } else {
                    $link = $name;
                }
            }
            return $link;
            break;
        case 'points':
            return $jTipsUser->getRoundScore('points', $jRound->id);
            break;
        case 'pointst':
            //return $jTipsUser->getTotalScore('points');
            $jHistory = new jHistory($database);
            return $jHistory->getProgressScore($jTipsUser, $jRound->id);
            break;
        case 'prec':
            return $jTipsUser->getRoundScore('precision', $jRound->id);
            break;
        case 'prect':
            //return $jTipsUser->getTotalScore('precision');
            $jHistory = new jHistory($database);
            return $jHistory->getProgressScore($jTipsUser, $jRound->id, 'precision');
            break;
        case 'comment':
            $params = array('user_id' => $jTipsUser->id, 'round_id' => $jRound->id);
            $jComment = new jComment($database);
            $jComment->loadByParams($params);
            /*if (strlen($jComment->comment) > 40) {
            			$name = $jTipsUser->getName(). "'s Comment";
            			$comment = "<span style='cursor:pointer; cursor:hand;' " .AddOverlibCall($jComment->comment, $name). ">" .substr($jComment->comment, 0, 40). "...</span>";
            		} else */
            if (!empty($jComment->comment)) {
                $comment = "<div style='font-weight:normal;text-align:left;'>" . jTipsStripslashes($jComment->comment) . "</div>";
            } else {
                return "";
            }
            return $comment;
            break;
        case 'moved':
            $prev_id = $jRound->getPrev();
            //BUG 171 & 172 Don't know why this is here... was causing problems
            /*if (!jTipsGetParam($_REQUEST, 'round_id', false)) {
            			$prevRound = new jRound($database);
            			$prevRound->load($prev_id);
            			$prev_id = $prevRound->getPrev();
            		}*/
            if ($prev_id < 0) {
                $prev_id = 0;
            }
            $params = array('round_id' => $jRound->id, 'user_id' => $jTipsUser->id);
            $jHistory = new jHistory($database);
            $jHistory->loadByParams($params);
            $curr_rank = $jHistory->rank;
            jTipsLogger::_log('CURRENT: ' . $curr_rank . ' HID: ' . $jHistory->id, 'ERROR');
            $params['round_id'] = $prev_id;
            $jHistory->loadByParams($params);
            $prev_rank = $jHistory->rank;
            jTipsLogger::_log('PREV: ' . $prev_rank . ' HID: ' . $jHistory->id, 'ERROR');
            if ($curr_rank > $prev_rank) {
                $arrow = 'down';
            } else {
                if ($curr_rank < $prev_rank) {
                    $arrow = 'up';
                } else {
                    $arrow = 'none';
                    return '&nbsp;';
                }
            }
            //Bug 125 - Added mosConfig_live_site to path
            return "<img src='" . $mosConfig_live_site . "/components/com_jtips/images/" . $arrow . ".png' alt='" . $arrow . "' border='0' title='" . ucfirst($arrow) . " " . abs($curr_rank - $prev_rank) . "' />";
            break;
        case 'doubleup':
            if ($jTipsUser->doubleup == $jRound->id) {
                return "<img src='{$mosConfig_live_site}/administrator/images/tick.png' border='0' alt='Yes' align='absmiddle' />";
            } else {
                return "&nbsp;";
            }
            break;
        default:
            return '-';
            break;
    }
}