PageRenderTime 39ms CodeModel.GetById 10ms RepoModel.GetById 1ms app.codeStats 0ms

/com_joomleague/components/com_joomleague/modules/mod_joomleague_navigation_menu/helper.php

https://gitlab.com/julienv/joomleague
PHP | 417 lines | 305 code | 51 blank | 61 comment | 33 complexity | 72a3113159d6db09fde245aa877afdcb MD5 | raw file
  1. <?php
  2. /**
  3. * @version $Id: helper.php 4905 2010-01-30 08:51:33Z and_one $
  4. * @package Joomleague
  5. * @subpackage Joomleague navigation module
  6. * @copyright Copyright (C) 2005-2014 joomleague.at. All rights reserved.
  7. * @license GNU/GPL, see LICENSE.php
  8. * Joomla! is free software. This version may have been modified pursuant to the
  9. * GNU General Public License, and as distributed it includes or is derivative
  10. * of works licensed under the GNU General Public License or other free or open
  11. * source software licenses. See COPYRIGHT.php for copyright notices and
  12. * details.
  13. */
  14. // no direct access
  15. defined('_JEXEC') or die('Restricted access');
  16. class modJoomleagueNavigationMenuHelper {
  17. protected $_params;
  18. protected $_db;
  19. protected $_project_id;
  20. protected $_team_id;
  21. protected $_division_id=0;
  22. protected $_round_id=null;
  23. protected $_teamoptions;
  24. protected $_project;
  25. public function __construct($params)
  26. {
  27. $this->_params = $params;
  28. $this->_db = JFactory::getDbo();
  29. if (JRequest::getCmd('option') == 'com_joomleague') {
  30. $p = JRequest::getInt('p', $params->get('default_project_id'));
  31. }
  32. else {
  33. $p = $params->get('default_project_id');
  34. }
  35. $this->_project_id = intval($p);
  36. $this->_project = $this->getProject();
  37. $this->_round_id = JRequest::getInt('r');
  38. $this->_division_id = JRequest::getInt('division',0);
  39. $this->_team_id = JRequest::getInt('tid',0);
  40. }
  41. public function getSeasonId()
  42. {
  43. if ($this->getProject()) {
  44. return $this->getProject()->season_id;
  45. }
  46. else {
  47. return 0;
  48. }
  49. }
  50. public function getLeagueId()
  51. {
  52. if ($this->getProject()) {
  53. return $this->getProject()->league_id;
  54. }
  55. else {
  56. return 0;
  57. }
  58. }
  59. public function getDivisionId()
  60. {
  61. return $this->_division_id;
  62. }
  63. public function getTeamId()
  64. {
  65. return $this->_team_id;
  66. }
  67. /**
  68. * returns the selector for season
  69. *
  70. * @return string html select
  71. */
  72. public function getSeasonSelect()
  73. {
  74. $options = array(JHtml::_('select.option', 0, JText::_($this->getParam('seasons_text'))));
  75. $query = ' SELECT s.id AS value, s.name AS text '
  76. . ' FROM #__joomleague_season AS s '
  77. ;
  78. $this->_db->setQuery($query);
  79. $res = $this->_db->loadObjectList();
  80. if ($res) {
  81. $options = array_merge($options, $res);
  82. }
  83. return JHtml::_('select.genericlist', $options, 's', 'class="jlnav-select"', 'value', 'text', $this->getSeasonId());
  84. }
  85. /**
  86. * returns the selector for division
  87. *
  88. * @return string html select
  89. */
  90. public function getDivisionSelect()
  91. {
  92. $project = $this->getProject();
  93. if(!is_object($project)) return false;
  94. if(!$this->_project_id && !($this->_project_id>0) && $project->project_type!='DIVISION_LEAGUE') {
  95. return false;
  96. }
  97. $options = array(JHtml::_('select.option', 0, JText::_($this->getParam('divisions_text'))));
  98. $query = ' SELECT d.id AS value, d.name AS text '
  99. . ' FROM #__joomleague_division AS d '
  100. . ' WHERE d.project_id = ' . $project->id
  101. . ($this->getParam("show_only_subdivisions", 0) ? ' AND parent_id > 0' : '')
  102. . ' ORDER BY d.name'
  103. ;
  104. $this->_db->setQuery($query);
  105. $res = $this->_db->loadObjectList();
  106. if ($res) {
  107. $options = array_merge($options, $res);
  108. }
  109. return JHtml::_('select.genericlist', $options, 'd', 'class="jlnav-division"', 'value', 'text', $this->getDivisionId());
  110. }
  111. /**
  112. * returns the selector for league
  113. *
  114. * @return string html select
  115. */
  116. public function getLeagueSelect()
  117. {
  118. $options = array(JHtml::_('select.option', 0, JText::_($this->getParam('leagues_text'))));
  119. $query = ' SELECT id AS value, name AS text '
  120. . ' FROM #__joomleague_league AS l '
  121. ;
  122. $this->_db->setQuery($query);
  123. $res = $this->_db->loadObjectList();
  124. if ($res) {
  125. $options = array_merge($options, $res);
  126. }
  127. return JHtml::_('select.genericlist', $options, 'l', 'class="jlnav-select"', 'value', 'text', $this->getLeagueId());
  128. }
  129. /**
  130. * returns the selector for project
  131. *
  132. * @return string html select
  133. */
  134. public function getProjectSelect()
  135. {
  136. $options = array(JHtml::_('select.option', 0, JText::_($this->getParam('text_project_dropdown'))));
  137. $query_base = ' SELECT p.id AS value, p.name AS text, s.name AS season_name, st.name as sports_type_name '
  138. . ' FROM #__joomleague_project AS p '
  139. . ' INNER JOIN #__joomleague_season AS s on s.id = p.season_id '
  140. . ' INNER JOIN #__joomleague_league AS l on l.id = p.league_id '
  141. . ' INNER JOIN #__joomleague_sports_type AS st on st.id = p.sports_type_id '
  142. . ' WHERE p.published = 1 ';
  143. $query = $query_base;
  144. if ($this->getParam('show_project_dropdown') == 'season' && $this->getProject())
  145. {
  146. $query .= ' AND p.season_id = '. $this->getProject()->season_id;
  147. $query .= ' AND p.league_id = '. $this->getProject()->league_id;
  148. }
  149. $query .= ' GROUP BY p.id ';
  150. switch ($this->getParam('project_ordering', 0))
  151. {
  152. case 0:
  153. $query .= ' ORDER BY p.ordering ASC';
  154. break;
  155. case 1:
  156. $query .= ' ORDER BY p.ordering DESC';
  157. break;
  158. case 2:
  159. $query .= ' ORDER BY s.ordering ASC, l.ordering ASC, p.ordering ASC';
  160. break;
  161. case 3:
  162. $query .= ' ORDER BY s.ordering DESC, l.ordering DESC, p.ordering DESC';
  163. break;
  164. case 4:
  165. $query .= ' ORDER BY p.name ASC';
  166. break;
  167. case 5:
  168. $query .= ' ORDER BY p.name DESC';
  169. break;
  170. case 6:
  171. $query .= ' ORDER BY l.ordering ASC, p.ordering ASC, s.ordering ASC';
  172. break;
  173. case 7:
  174. $query .= ' ORDER BY l.ordering DESC, p.ordering DESC, s.ordering DESC';
  175. break;
  176. }
  177. $this->_db->setQuery($query);
  178. $res = $this->_db->loadObjectList();
  179. if ($res)
  180. {
  181. switch ($this->getParam('project_include_season_name', 0))
  182. {
  183. case 2:
  184. foreach ($res as $p)
  185. {
  186. $stText = ($this->getParam('project_include_sports_type_name', 0) ==1) ? ' ('.JText::_($p->sports_type_name). ')': '';
  187. $options[] = JHtml::_('select.option', $p->value, $p->text.' - '.$p->season_name . $stText);
  188. }
  189. break;
  190. case 1:
  191. foreach ($res as $p)
  192. {
  193. $stText = ($this->getParam('project_include_sports_type_name', 0) ==1) ? ' ('.JText::_($p->sports_type_name). ')': '';
  194. $options[] = JHtml::_('select.option', $p->value, $p->season_name .' - '. $p->text. $stText);
  195. }
  196. break;
  197. case 0:
  198. default:
  199. foreach ($res as $p)
  200. {
  201. $stText = ($this->getParam('project_include_sports_type_name', 0) ==1) ? ' ('.JText::_($p->sports_type_name). ')': '';
  202. $options[] = JHtml::_('select.option', $p->value, $p->text. $stText);
  203. }
  204. }
  205. }
  206. return JHtml::_('select.genericlist', $options, 'p', 'class="jlnav-project"', 'value', 'text', $this->_project_id);
  207. }
  208. /**
  209. * returns the selector for teams
  210. *
  211. * @return string html select
  212. */
  213. public function getTeamSelect()
  214. {
  215. if (!$this->_project_id) {
  216. return false;
  217. }
  218. $options = array(JHtml::_('select.option', 0, JText::_($this->getParam('text_teams_dropdown'))));
  219. $res = $this->getTeamsOptions();
  220. if ($res)
  221. {
  222. $options = array_merge($options, $res);
  223. }
  224. return JHtml::_('select.genericlist', $options, 'tid', 'class="jlnav-team"', 'value', 'text', $this->getTeamId());
  225. }
  226. /**
  227. * returns select for project teams
  228. *
  229. * @return string html select
  230. */
  231. protected function getTeamsOptions()
  232. {
  233. if (empty($this->_teamoptions))
  234. {
  235. if (!$this->_project_id) {
  236. return false;
  237. }
  238. $query = ' SELECT t.id AS value, t.name AS text '
  239. . ' FROM #__joomleague_project_team AS pt '
  240. . ' INNER JOIN #__joomleague_team AS t ON t.id = pt.team_id '
  241. . ' WHERE pt.project_id = '.intval($this->_project_id)
  242. . ($this->_division_id ? ' AND pt.division_id = '.intval($this->_division_id) : '')
  243. . ' ORDER BY t.name ASC '
  244. ;
  245. $this->_db->setQuery($query);
  246. $res = $this->_db->loadObjectList();
  247. if (!$res) {
  248. Jerror::raiseWarning(0, $this->_db->getErrorMsg());
  249. }
  250. $this->_teamoptions = $res;
  251. }
  252. return $this->_teamoptions;
  253. }
  254. /**
  255. * return info for current project
  256. *
  257. * @return object
  258. */
  259. public function getProject()
  260. {
  261. if (!$this->_project)
  262. {
  263. if (!$this->_project_id) {
  264. return false;
  265. }
  266. $query = ' SELECT p.id, p.name, p.season_id, p.league_id '
  267. . ' FROM #__joomleague_project AS p '
  268. . ' WHERE id = ' . $this->_project_id;
  269. $this->_db->setQuery($query);
  270. $this->_project = $this->_db->loadObject();
  271. }
  272. return $this->_project;
  273. }
  274. /**
  275. * return link for specified view - allow seo consistency
  276. *
  277. * @param string $view
  278. * @return string url
  279. */
  280. public function getLink($view)
  281. {
  282. if (!$this->_project_id) {
  283. return false;
  284. }
  285. switch ($view)
  286. {
  287. case "calendar":
  288. $link = JoomleagueHelperRoute::getTeamPlanRoute( $this->_project_id, $this->_team_id, $this->_division_id );
  289. break;
  290. case "curve":
  291. $link = JoomleagueHelperRoute::getCurveRoute( $this->_project_id, $this->_team_id, 0, $this->_division_id );
  292. break;
  293. case "eventsranking":
  294. $link = JoomleagueHelperRoute::getEventsRankingRoute( $this->_project_id, $this->_division_id, $this->_team_id );
  295. break;
  296. case "matrix":
  297. $link = JoomleagueHelperRoute::getMatrixRoute( $this->_project_id, $this->_division_id );
  298. break;
  299. case "referees":
  300. $link = JoomleagueHelperRoute::getRefereesRoute( $this->_project_id );
  301. break;
  302. case "results":
  303. $link = JoomleagueHelperRoute::getResultsRoute( $this->_project_id, $this->_round_id, $this->_division_id );
  304. break;
  305. case "resultsmatrix":
  306. $link = JoomleagueHelperRoute::getResultsMatrixRoute( $this->_project_id, $this->_round_id, $this->_division_id );
  307. break;
  308. case "resultsranking":
  309. $link = JoomleagueHelperRoute::getResultsRankingRoute( $this->_project_id, $this->_round_id, $this->_division_id );
  310. break;
  311. case "resultsrankingmatrix":
  312. $link = JoomleagueHelperRoute::getResultsRankingMatrixRoute( $this->_project_id, $this->_round_id, $this->_division_id );
  313. break;
  314. case "roster":
  315. if (!$this->_team_id) {
  316. return false;
  317. }
  318. $link = JoomleagueHelperRoute::getPlayersRoute( $this->_project_id, $this->_team_id, null, $this->_division_id );
  319. break;
  320. case "stats":
  321. $link = JoomleagueHelperRoute::getStatsRoute( $this->_project_id, $this->_division_id );
  322. break;
  323. case "statsranking":
  324. $link = JoomleagueHelperRoute::getStatsRankingRoute( $this->_project_id, $this->_division_id );
  325. break;
  326. case "teaminfo":
  327. if (!$this->_team_id) {
  328. return false;
  329. }
  330. $link = JoomleagueHelperRoute::getTeamInfoRoute( $this->_project_id, $this->_team_id );
  331. break;
  332. case "teamplan":
  333. if (!$this->_team_id) {
  334. return false;
  335. }
  336. $link = JoomleagueHelperRoute::getTeamPlanRoute( $this->_project_id, $this->_team_id, $this->_division_id );
  337. break;
  338. case "teamstats":
  339. if (!$this->_team_id) {
  340. return false;
  341. }
  342. $link = JoomleagueHelperRoute::getTeamStatsRoute( $this->_project_id, $this->_team_id );
  343. break;
  344. case "treetonode":
  345. $link = JoomleagueHelperRoute::getBracketsRoute( $this->_project_id );
  346. break;
  347. case "separator":
  348. return false;
  349. default:
  350. case "ranking":
  351. $link = JoomleagueHelperRoute::getRankingRoute( $this->_project_id, $this->_round_id,null,null,0,$this->_division_id );
  352. }
  353. return $link;
  354. }
  355. /**
  356. * return param value or default if not found
  357. *
  358. * @param string $name
  359. * @param mixed $default
  360. * @return mixed
  361. */
  362. protected function getParam($name, $default = null)
  363. {
  364. return $this->_params->get($name, $default);
  365. }
  366. }