PageRenderTime 25ms CodeModel.GetById 16ms app.highlight 7ms RepoModel.GetById 1ms app.codeStats 0ms

/com_joomleague/components/com_joomleague/models/statsranking.php

https://gitlab.com/volleyuisp/joomleague
PHP | 150 lines | 96 code | 20 blank | 34 comment | 7 complexity | 815edf2568463aa031a28dc461419ab9 MD5 | raw file
  1<?php
  2/**
  3 * @copyright	Copyright (C) 2006-2014 joomleague.at. All rights reserved.
  4 * @license		GNU/GPL,see LICENSE.php
  5 * Joomla! is free software. This version may have been modified pursuant
  6 * to the GNU General Public License,and as distributed it includes or
  7 * is derivative of works licensed under the GNU General Public License or
  8 * other free or open source software licenses.
  9 * See COPYRIGHT.php for copyright notices and details.
 10 */
 11
 12// Check to ensure this file is included in Joomla!
 13defined('_JEXEC') or die('Restricted access');
 14
 15jimport( 'joomla.application.component.model');
 16
 17require_once( JLG_PATH_SITE . DS . 'models' . DS . 'project.php' );
 18
 19class JoomleagueModelStatsRanking extends JoomleagueModelProject
 20{
 21	/**
 22	 * players total
 23	 *
 24	 * @var integer
 25	 */
 26	var $_total = null;
 27
 28	/**
 29	 * Pagination object
 30	 *
 31	 * @var object
 32	 */
 33	var $_pagination = null;
 34	
 35	var $order = null;
 36	var $divisionid = 0;
 37	var $teamid = 0;
 38	
 39	function __construct( )
 40	{
 41		parent::__construct( );
 42
 43		$this->projectid	= JRequest::getInt( 'p', 0 );
 44		$this->divisionid	= JRequest::getInt( 'division', 0 );
 45		$this->teamid		= JRequest::getInt( 'tid', 0 );
 46		$this->setStatid(JRequest::getVar( 'sid', 0 ));
 47		$config = $this->getTemplateConfig($this->getName());
 48		// TODO: the default value for limit should be updated when we know if there is more than 1 statistics type to be shown
 49		if ( $this->stat_id != 0 )
 50		{
 51			$this->limit = JRequest::getInt( 'limit', $config["max_stats"] );
 52		}
 53		else
 54		{
 55			$this->limit = JRequest::getInt( 'limit', $config["count_stats"] );
 56		}
 57		$this->limitstart = JRequest::getInt( 'limitstart', 0 );
 58		$this->setOrder(JRequest::getVar('order'));
 59	}
 60	
 61	function getDivision()
 62	{
 63		$division = null;
 64		if ($this->divisionid != 0)
 65		{
 66			$division = parent::getDivision($this->divisionid);
 67		}
 68		return $division;
 69	}
 70
 71	function getTeamId()
 72	{
 73		return $this->teamid;
 74	}
 75
 76	/**
 77	 * set order (asc or desc)
 78	 * @param string $order
 79	 * @return string order
 80	 */
 81	function setOrder($order)
 82	{
 83		if (strcasecmp($order, 'asc') === 0 || strcasecmp($order, 'desc') === 0) {
 84			$this->order = strtolower($order);
 85		}
 86		return $this->order;
 87	}
 88
 89	function getLimit( )
 90	{
 91		return $this->limit;
 92	}
 93
 94	function getLimitStart( )
 95	{
 96		return $this->limitstart;
 97	}
 98
 99	function setStatid($statid)
100	{
101		// Allow for multiple statistics IDs, arranged in a single parameters (sid) as string
102		// with "|" as separator
103		$sidarr = explode("|", $statid);
104		$this->stat_id = array();
105		foreach ($sidarr as $sid)
106		{
107			$this->stat_id[] = (int)$sid;	// The cast gets rid of the slug
108		}
109		// In case 0 was (part of) the sid string, make sure all stat types are loaded)
110		if (in_array(0, $this->stat_id))
111		{
112			$this->stat_id = 0;
113		}
114	}
115
116	// return unique stats assigned to project
117	/**
118	 * (non-PHPdoc)
119	 * @see components/com_joomleague/models/JoomleagueModelProject#getProjectStats($statid, $positionid)
120	 */
121	function getProjectUniqueStats()
122	{
123		$pos_stats = $this->getProjectStats($this->stat_id);
124		
125		$allstats = array();
126		foreach ($pos_stats as $pos => $stats) 
127		{
128			foreach ($stats as $stat) {
129				$allstats[$stat->id] = $stat;
130			} 
131		}
132		return $allstats;
133	}
134	
135	function getPlayersStats($order=null)
136	{
137		$stats = &$this->getProjectUniqueStats();
138		$order = ($order ? $order : $this->order);
139		
140		$results = array();
141		foreach ($stats as $stat) 
142		{
143			$results[$stat->id] = $stat->getPlayersRanking($this->projectid, $this->divisionid, $this->teamid, $this->getLimit(), $this->getLimitStart(), $order);
144		}
145		
146		return $results;
147	}
148
149}
150?>