/** * Method to get the list * * @access public * @return array */ function getData(&$params) { global $mainframe; if (!class_exists('JoomleagueModelRanking')) { require_once JLG_PATH_SITE . '/models/ranking.php'; } $model = JLGModel::getInstance('project', 'JoomleagueModel'); $model->setProjectId($params->get('p')); $project = $model->getProject(); $ranking = JLGRanking::getInstance($project); $ranking->setProjectId($params->get('p')); $divisionid = explode(':', $params->get('division_id', 0)); $divisionid = $divisionid[0]; $res = $ranking->getRanking(null, null, $divisionid); $teams = $model->getTeamsIndexedByPtid(); $list = array(); foreach ($res as $ptid => $t) { $t->team = $teams[$ptid]; $list[] = $t; } if ($params->get('visible_team') != '') { $exParam = explode(':', $params->get('visible_team')); $list = modJLGRankingHelper::getShrinkedDataAroundOneTeam($list, $exParam[0], $params->get('limit', 5)); } $colors = array(); if ($params->get('show_rank_colors', 0)) { $mdlRanking = JLGModel::getInstance("Ranking", "JoomleagueModel"); $mdlRanking->setProjectid($params->get('p')); $config = $mdlRanking->getTemplateConfig("ranking"); $colors = $mdlRanking->getColors($config["colors"]); } return array('project' => $project, 'ranking' => $list, 'colors' => $colors); }
/** * Method to get the list * * @access private * @return array */ private function _getData() { $mainframe = JFactory::getApplication(); if (!class_exists('JoomleagueModelRanking')) { require_once JLG_PATH_SITE . DS . 'models' . DS . 'ranking.php'; } $project_id = (JRequest::getVar('option', '') == 'com_joomleague' and JRequest::getInt('p', 0) > 0 and $this->params->get('usepfromcomponent', 0) == 1) ? JRequest::getInt('p') : $this->params->get('project_ids'); if (is_array($project_id)) { $project_id = $project_id[0]; } if ($project_id) { $model =& JLGModel::getInstance('project', 'JoomleagueModel'); $model->setProjectId($project_id); $this->project =& $model->getProject(); $ranking =& JLGRanking::getInstance($this->project); $ranking->setProjectId($project_id); $divisionid = explode(':', $this->params->get('division_id', 0)); $divisionid = $divisionid[0]; $this->ranking = $ranking->getRanking(null, null, $divisionid); if ($this->params->get('logotype') == 'logo_small') { $teams = $model->getTeamsIndexedByPtid(); } else { unset($model); if (!class_exists('JoomleagueModelTeams')) { require_once JLG_PATH_SITE . DS . 'models' . DS . 'teams.php'; } $model =& JLGModel::getInstance('teams', 'JoomleagueModel'); $model->setProjectId($project_id); $teams = $model->getTeams($divisionid); } $this->buildData($teams); unset($teams); unset($model); } }
function _getRanking() { if (empty($this->ranking)) { $project = $this->getProject(); $division = $this->divisionid; $ranking = JLGRanking::getInstance($project); $ranking->setProjectId($project->id); $this->ranking = $ranking->getRanking(0, $this->getCurrentRound(), $division); } return $this->ranking; }
/** * get ranking of current team in a project * @param int projectid * @param int division_id * @return array */ function getTeamRanking($projectid, $division_id) { $rank = array(); $model = JLGModel::getInstance('Project', 'JoomleagueModel'); $model->setProjectID($projectid); $project = $model->getProject(); $tableconfig = $model->getTemplateConfig("ranking"); $ranking = JLGRanking::getInstance($project); $ranking->setProjectId($project->id); $this->ranking = $ranking->getRanking(0, $model->getCurrentRound(), $division_id); foreach ($this->ranking as $ptid => $value) { if ($value->getPtid() == $this->projectteamid) { $rank['rank'] = $value->rank; $rank['games'] = $value->cnt_matches; $rank['points'] = $value->getPoints(); $rank['series'] = $value->cnt_won . "/" . $value->cnt_draw . "/" . $value->cnt_lost; $rank['goals'] = $value->sum_team1_result . ":" . $value->sum_team2_result; break; } else { if ($value->getTeamId() == $this->teamid) { $rank['rank'] = $value->rank; $rank['games'] = $value->cnt_matches; $rank['points'] = $value->getPoints(); $rank['series'] = $value->cnt_won . "/" . $value->cnt_draw . "/" . $value->cnt_lost; $rank['goals'] = $value->sum_team1_result . ":" . $value->sum_team2_result; break; } } } return $rank; }
function getDataByDivision($division = 0) { $project = $this->getProject(); $rounds = $this->getRounds(); $teams = $this->getTeamsIndexedByPtid($division); $rankinghelper = JLGRanking::getInstance($project); $rankinghelper->setProjectId($project->id); $mdlRounds = JModel::getInstance("Rounds", "JoomleagueModel"); $mdlRounds->setProjectId($project->id); $firstRound = $mdlRounds->getFirstRound($project->id); $firstRoundId = $firstRound['id']; $rankings = array(); foreach ($rounds as $r) { $rankings[$r->id] = $rankinghelper->getRanking($firstRoundId, $r->id, $division); } foreach ($teams as $ptid => $team) { if ($team->is_in_score == 0) { continue; } $team_rankings = array(); foreach ($rankings as $roundcode => $t) { if (empty($t[$ptid])) { continue; } $team_rankings[] = $t[$ptid]->rank; } $teams[$ptid]->rankings = $team_rankings; } return $teams; }
/** * computes the ranking * */ function computeRanking() { $mainframe = JFactory::getApplication(); $project =& $this->getProject(); $mdlRound = JModel::getInstance("Round", "JoomleagueModel"); $mdlRounds = JModel::getInstance("Rounds", "JoomleagueModel"); $mdlRounds->setProjectId($project->id); $firstRound = $mdlRounds->getFirstRound($project->id); $lastRound = $mdlRounds->getLastRound($project->id); // url if no sef link comes along (ranking form) $url = JoomleagueHelperRoute::getRankingRoute($this->projectid); $tableconfig = $this->getTemplateConfig("ranking"); $this->round = $this->round == 0 ? $this->getCurrentRound() : $this->round; $this->rounds = $this->getRounds(); if ($this->part == 1) { $this->from = $firstRound['id']; // diddipoeler: das ist ein bug //$this->to = $this->rounds[intval(count($this->rounds)/2)]->id; $this->to = $this->rounds[intval(count($this->rounds) / 2) - 1]->id; } elseif ($this->part == 2) { // diddipoeler: das ist ein bug //$this->from = $this->rounds[intval(count($this->rounds)/2)+1]->id; $this->from = $this->rounds[intval(count($this->rounds) / 2)]->id; $this->to = $lastRound['id']; } else { $this->from = JRequest::getInt('from', $firstRound['id']); $this->to = JRequest::getInt('to', $this->round, $lastRound['id']); } if ($this->part > 0) { $url .= '&part=' . $this->part; } elseif ($this->from != 1 || $this->to != $this->round) { $url .= '&from=' . $this->from . '&to=' . $this->to; } $this->type = JRequest::getInt('type', 0); if ($this->type > 0) { $url .= '&type=' . $this->type; } $this->divLevel = 0; //echo 'computeRanking this->part -> '.'<pre>'.print_r($this->part,true).'</pre>'; //echo 'computeRanking this->from -> '.'<pre>'.print_r($this->from,true).'</pre>'; //echo 'computeRanking this->to-> '.'<pre>'.print_r($this->to,true).'</pre>'; //echo 'computeRanking this->rounds -> '.'<pre>'.print_r($this->rounds,true).'</pre>'; //$mainframe->enqueueMessage(JText::_('computeRanking this->part -> '.'<pre>'.print_r($this->part,true).'</pre>' ),''); //$mainframe->enqueueMessage(JText::_('computeRanking this->from -> '.'<pre>'.print_r($this->from,true).'</pre>' ),''); //$mainframe->enqueueMessage(JText::_('computeRanking this->to-> '.'<pre>'.print_r($this->to,true).'</pre>' ),''); //$mainframe->enqueueMessage(JText::_('computeRanking this->rounds -> '.'<pre>'.print_r($this->rounds,true).'</pre>' ),''); //for sub division ranking tables if ($project->project_type == 'DIVISIONS_LEAGUE') { $selDivision = JRequest::getInt('division', 0); $this->divLevel = JRequest::getInt('divLevel', $tableconfig['default_division_view']); if ($selDivision > 0) { $url .= '&division=' . $selDivision; $divisions = array($selDivision); } else { // check if division level view is allowed. if not, replace with default if ($this->divLevel == 0 && $tableconfig['show_project_table'] == 0 || $this->divLevel == 1 && $tableconfig['show_level1_table'] == 0 || $this->divLevel == 2 && $tableconfig['show_level2_table'] == 0) { $this->divLevel = $tableconfig['default_division_view']; } $url .= '&divLevel=' . $this->divLevel; if ($this->divLevel) { $divisions = $this->getDivisionsId($this->divLevel); // print_r( $divisions); } else { $divisions = array(0); } } } else { $divisions = array(0); //project } $selectedvalue = 0; $last = JRequest::getInt('last', 0); if ($last > 0) { $url .= '&last=' . $last; } if (JRequest::getInt('sef', 0) == 1) { $mainframe->redirect(JRoute::_($url)); } /** * create ranking object * */ $ranking = JLGRanking::getInstance($project); $ranking->setProjectId($this->projectid); foreach ($divisions as $division) { //away rank if ($this->type == 2) { $this->currentRanking[$division] = $ranking->getRankingAway($this->from, $this->to, $division); } else { if ($this->type == 1) { $this->currentRanking[$division] = $ranking->getRankingHome($this->from, $this->to, $division); } else { $this->currentRanking[$division] = $ranking->getRanking($this->from, $this->to, $division); $this->homeRank[$division] = $ranking->getRankingHome($this->from, $this->to, $division); $this->awayRank[$division] = $ranking->getRankingAway($this->from, $this->to, $division); } } $this->_sortRanking($this->currentRanking[$division]); //previous rank if ($tableconfig['last_ranking'] == 1) { if ($this->to == 1 || $this->to == $this->from) { $this->previousRanking[$division] =& $this->currentRanking[$division]; } else { //away rank if ($this->type == 2) { $this->previousRanking[$division] = $ranking->getRankingAway($this->from, $this->_getPreviousRoundId($this->to), $division); } else { if ($this->type == 1) { $this->previousRanking[$division] = $ranking->getRankingHome($this->from, $this->_getPreviousRoundId($this->to), $division); } else { $this->previousRanking[$division] = $ranking->getRanking($this->from, $this->_getPreviousRoundId($this->to), $division); } } $this->_sortRanking($this->previousRanking[$division]); } } } $this->current_round = $this->round; return; }