/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. // Check to ensure this file is included in Joomla!
  12. defined('_JEXEC') or die('Restricted access');
  13. jimport( 'joomla.application.component.model');
  14. require_once( JLG_PATH_SITE . DS . 'models' . DS . 'project.php' );
  15. class JoomleagueModelStatsRanking extends JoomleagueModelProject
  16. {
  17. /**
  18. * players total
  19. *
  20. * @var integer
  21. */
  22. var $_total = null;
  23. /**
  24. * Pagination object
  25. *
  26. * @var object
  27. */
  28. var $_pagination = null;
  29. var $order = null;
  30. var $divisionid = 0;
  31. var $teamid = 0;
  32. function __construct( )
  33. {
  34. parent::__construct( );
  35. $this->projectid = JRequest::getInt( 'p', 0 );
  36. $this->divisionid = JRequest::getInt( 'division', 0 );
  37. $this->teamid = JRequest::getInt( 'tid', 0 );
  38. $this->setStatid(JRequest::getVar( 'sid', 0 ));
  39. $config = $this->getTemplateConfig($this->getName());
  40. // TODO: the default value for limit should be updated when we know if there is more than 1 statistics type to be shown
  41. if ( $this->stat_id != 0 )
  42. {
  43. $this->limit = JRequest::getInt( 'limit', $config["max_stats"] );
  44. }
  45. else
  46. {
  47. $this->limit = JRequest::getInt( 'limit', $config["count_stats"] );
  48. }
  49. $this->limitstart = JRequest::getInt( 'limitstart', 0 );
  50. $this->setOrder(JRequest::getVar('order'));
  51. }
  52. function getDivision()
  53. {
  54. $division = null;
  55. if ($this->divisionid != 0)
  56. {
  57. $division = parent::getDivision($this->divisionid);
  58. }
  59. return $division;
  60. }
  61. function getTeamId()
  62. {
  63. return $this->teamid;
  64. }
  65. /**
  66. * set order (asc or desc)
  67. * @param string $order
  68. * @return string order
  69. */
  70. function setOrder($order)
  71. {
  72. if (strcasecmp($order, 'asc') === 0 || strcasecmp($order, 'desc') === 0) {
  73. $this->order = strtolower($order);
  74. }
  75. return $this->order;
  76. }
  77. function getLimit( )
  78. {
  79. return $this->limit;
  80. }
  81. function getLimitStart( )
  82. {
  83. return $this->limitstart;
  84. }
  85. function setStatid($statid)
  86. {
  87. // Allow for multiple statistics IDs, arranged in a single parameters (sid) as string
  88. // with "|" as separator
  89. $sidarr = explode("|", $statid);
  90. $this->stat_id = array();
  91. foreach ($sidarr as $sid)
  92. {
  93. $this->stat_id[] = (int)$sid; // The cast gets rid of the slug
  94. }
  95. // In case 0 was (part of) the sid string, make sure all stat types are loaded)
  96. if (in_array(0, $this->stat_id))
  97. {
  98. $this->stat_id = 0;
  99. }
  100. }
  101. // return unique stats assigned to project
  102. /**
  103. * (non-PHPdoc)
  104. * @see components/com_joomleague/models/JoomleagueModelProject#getProjectStats($statid, $positionid)
  105. */
  106. function getProjectUniqueStats()
  107. {
  108. $pos_stats = $this->getProjectStats($this->stat_id);
  109. $allstats = array();
  110. foreach ($pos_stats as $pos => $stats)
  111. {
  112. foreach ($stats as $stat) {
  113. $allstats[$stat->id] = $stat;
  114. }
  115. }
  116. return $allstats;
  117. }
  118. function getPlayersStats($order=null)
  119. {
  120. $stats = &$this->getProjectUniqueStats();
  121. $order = ($order ? $order : $this->order);
  122. $results = array();
  123. foreach ($stats as $stat)
  124. {
  125. $results[$stat->id] = $stat->getPlayersRanking($this->projectid, $this->divisionid, $this->teamid, $this->getLimit(), $this->getLimitStart(), $order);
  126. }
  127. return $results;
  128. }
  129. }
  130. ?>