PageRenderTime 44ms CodeModel.GetById 12ms RepoModel.GetById 1ms app.codeStats 0ms

/com_joomleague/components/com_joomleague/modules/mod_joomleague_calendar/connectors/joomleague_legacy.php

https://gitlab.com/julienv/joomleague
PHP | 328 lines | 300 code | 24 blank | 4 comment | 56 complexity | 5266ede1de6a04cf9a1c4072a01d79b9 MD5 | raw file
  1. <?php
  2. class JoomleagueConnector extends JLCalendar{
  3. var $xparams;
  4. var $prefix;
  5. function getEntries ( &$caldates, &$params, &$matches ) {
  6. $m = array();
  7. $b = array();
  8. $this->xparams = $params;
  9. $this->prefix = $params->prefix;
  10. if($this->xparams->get('joomleague_use_favteams', 0) == 1){
  11. $this->favteams = JoomleagueConnector::getFavs();
  12. }
  13. if ($this->xparams->get('jlmatches', 0) == 1) {
  14. $rows = JoomleagueConnector::getMatches($caldates);
  15. $m = JoomleagueConnector::formatMatches($rows, $matches);
  16. }
  17. if ($this->xparams->get('jlbirthdays', 1) == 1) {
  18. $birthdays = JoomleagueConnector::getBirthdays ( $caldates, $this->params, $this->matches );
  19. $b = JoomleagueConnector::formatBirthdays($birthdays, $matches, $caldates);
  20. }
  21. return array_merge($m, $b);
  22. }
  23. function getFavs() {
  24. $query = "SELECT fav_team FROM #__joomleague WHERE fav_team != ''";
  25. $projectid = $this->xparams->get('project_ids') ;
  26. if ($projectid != '') {
  27. $projectids = explode( ',', $projectid );
  28. JArrayHelper::toInteger( $projectids );
  29. $query .= " AND id IN(".implode(', ', $projectids).")";
  30. }
  31. $query = ($this->prefix != '') ? str_replace('#__', $this->prefix, $query) : $query;
  32. $database = JFactory::getDbo();
  33. $database->setQuery($query);
  34. $fav=$database->loadColumn();
  35. return implode(',', $fav);
  36. }
  37. function getBirthdays ( $caldates, $ordering='ASC' ) {
  38. $teamCondition = '';
  39. $clubCondition = '';
  40. $favCondition = '';
  41. $limitingcondition = '';
  42. $limitingconditions = array();
  43. $database = JFactory::getDbo();
  44. $customteam = JRequest::getVar('jlcteam',0,'default','POST');
  45. $teamid = $this->xparams->get('team_ids') ;
  46. $teamid = ($customteam > 0) ? $customteam : $teamid;
  47. if ($teamid) {
  48. $teamids = explode( ',', $teamid );
  49. JArrayHelper::toInteger( $teamids );
  50. $teamCondition = '(pt.team_id IN ('.implode(', ', $teamids).'))';
  51. $limitingconditions[] = $teamCondition;
  52. }
  53. if($this->xparams->get('joomleague_use_favteams', 0) == 1 && $customteam == 0) {
  54. $favCondition .= "(pt.team_id IN (".$this->favteams."))";
  55. $limitingconditions[] = $favCondition;
  56. }
  57. if (count($limitingconditions) > 0) {
  58. $limitingcondition .=' AND (';
  59. $limitingcondition .= implode(' OR ', $limitingconditions);
  60. $limitingcondition .=')';
  61. }
  62. $query="SELECT p.id, p.firstname, p.lastname, p.default_picture, p.nation,
  63. DATE_FORMAT(p.birthday, '%m-%d') AS month_day,
  64. YEAR( CURRENT_DATE( ) ) as year,
  65. DATE_FORMAT('".$caldates['start']."', '%Y') - YEAR( p.birthday ) AS age,
  66. DATE_FORMAT(p.birthday,'%Y-%m-%d') AS date_of_birth,
  67. 'showplayer' AS func_to_call,
  68. pt.project_id,
  69. 'pid' AS id_to_append,
  70. team.name AS teamname, team.short_name, pro.name AS pname
  71. FROM #__joomleague_players AS p
  72. LEFT JOIN #__joomleague_playertool AS pt ON (p.id = pt.player_id)
  73. LEFT JOIN #__joomleague_teams AS team ON (pt.team_id = team.id)";
  74. $query .= " LEFT JOIN #__joomleague AS pro ON (pro.id = pt.project_id)";
  75. //$query .= " LEFT JOIN #__joomleague AS pro ON (pro.id = pt.project_id OR pro.id = crew.project_id OR pro.season_id = pt.season_id OR pro.season_id = crew.season_id)";
  76. $query .= " WHERE p.birthday != '0000-00-00' and DATE_FORMAT(p.birthday, '%m') = DATE_FORMAT('".$caldates['start']."', '%m') ";
  77. $projectid = $this->xparams->get('project_ids') ;
  78. if ($projectid != '') {
  79. $projectids = explode( ',', $projectid );
  80. JArrayHelper::toInteger( $projectids );
  81. $query .= " AND (pt.project_id IN (".implode(', ', $projectids).")";
  82. $query .= ") ";
  83. }
  84. $query .= $limitingcondition;
  85. $query .= " GROUP BY p.id ";
  86. $query .= " ORDER BY p.birthday ASC";
  87. $query = ($this->prefix != '') ? str_replace('#__', $this->prefix, $query) : $query;
  88. $database->setQuery($query);
  89. if (!$players=$database->loadObjectList()) $players = array();
  90. return $players;
  91. }
  92. function formatBirthdays( $rows, &$matches, $dates ) {
  93. $newrows = array();
  94. $year = substr($dates['start'], 0, 4);
  95. foreach ($rows AS $key => $row) {
  96. $newrows[$key]['type'] = 'jlb';
  97. $newrows[$key]['homepic'] = '';
  98. $newrows[$key]['awaypic'] = '';
  99. $newrows[$key]['date'] = $year.'-'.$row->month_day;
  100. $newrows[$key]['age'] = '('.$row->age.')';
  101. $newrows[$key]['headingtitle'] = $this->xparams->get('birthday_text', 'Birthday');
  102. $newrows[$key]['name'] = '';
  103. $newrows[$key]['team'] = '';
  104. global $mainframe;
  105. if ($this->xparams->get('jlbirthdaypix', 0) == 1 AND $row->default_picture != '' AND file_exists($mainframe->getCfg('absolute_path').DS.str_replace('/', DS, $row->default_picture))) {
  106. $linkit = 1;
  107. $newrows[$key]['image'] = '<img src="'.(JUri::root(true).'/'.parent::jl_utf8_convert ($row->default_picture, 'iso-8859-1', 'utf-8'))
  108. .'" alt="" style="height:40px; vertical-align:middle;margin:0 5px;" />';
  109. }
  110. JoomleagueConnector::build_url($row);
  111. $newrows[$key]['link'] = JRoute::_($row->link);
  112. $newrows[$key]['name'] = parent::jl_utf8_convert ($row->firstname, 'iso-8859-1', 'utf-8').' ';
  113. $newrows[$key]['name'] .= parent::jl_utf8_convert ($row->lastname, 'iso-8859-1', 'utf-8');
  114. if (isset($row->teamname)) {
  115. $newrows[$key]['team'] = '<acronym title="'.parent::jl_utf8_convert ($row->teamname.' '.$row->pname, 'iso-8859-1', 'utf-8').'">'
  116. . parent::jl_utf8_convert ($row->short_name, 'iso-8859-1', 'utf-8').'</acronym>';
  117. }
  118. //$newrows[$key]['name'] .= ' ('..')';
  119. $newrows[$key]['matchcode'] = 0;
  120. $newrows[$key]['project_id'] = 0;
  121. $matches[] = $newrows[$key];
  122. }
  123. return $newrows;
  124. }
  125. function formatMatches( $rows, &$matches ) {
  126. $newrows = array();
  127. $teamnames = $this->xparams->get('team_names', 'short_name');
  128. $teams = JoomleagueConnector::getTeamsFromMatches( $rows );
  129. $teams[0]->name = $teams[0]->$teamnames = $teams[0]->logo_small = $teams[0]->logo_middle = $teams[0]->logo_big = '';
  130. foreach ($rows AS $key => $row) {
  131. $newrows[$key]['type'] = 'jlm';
  132. $newrows[$key]['homepic'] = (isset($teams[$row->matchpart1])) ? JoomleagueConnector::buildImage($teams[$row->matchpart1]) : '';
  133. $newrows[$key]['awaypic'] = (isset($teams[$row->matchpart2])) ? JoomleagueConnector::buildImage($teams[$row->matchpart2]) : '';
  134. $newrows[$key]['date'] = JoomleagueHelper::getMatchStartTimestamp($row);
  135. $newrows[$key]['result'] = (!is_null($row->matchpart1_result)) ? $row->matchpart1_result . ':' . $row->matchpart2_result : '-:-';
  136. $newrows[$key]['headingtitle'] = parent::jl_utf8_convert ($row->name.'-'.$row->roundname, 'iso-8859-1', 'utf-8');
  137. $newrows[$key]['homename'] = (isset($teams[$row->matchpart1])) ? JoomleagueConnector::formatTeamName($teams[$row->matchpart1]) : 'n/a';;
  138. $newrows[$key]['awayname'] = (isset($teams[$row->matchpart2])) ? JoomleagueConnector::formatTeamName($teams[$row->matchpart2]) : 'n/a';;
  139. $newrows[$key]['matchcode'] = $row->matchcode;
  140. $newrows[$key]['project_id'] = $row->project_id;
  141. $matches[] = $newrows[$key];
  142. if (isset($teams[$row->matchpart1])) {
  143. parent::addTeam($row->matchpart1, parent::jl_utf8_convert ($teams[$row->matchpart1]->name, 'iso-8859-1', 'utf-8'), $newrows[$key]['homepic']);
  144. }
  145. if (isset($teams[$row->matchpart2])) {
  146. parent::addTeam($row->matchpart2, parent::jl_utf8_convert ($teams[$row->matchpart2]->name, 'iso-8859-1', 'utf-8'),$newrows[$key]['awaypic']);
  147. }
  148. }
  149. return $newrows;
  150. }
  151. function formatTeamName($team) {
  152. $teamnames = $this->xparams->get('team_names', 'short_name');
  153. switch ($teamnames) {
  154. case '-':
  155. return '';
  156. break;
  157. case 'short_name':
  158. $teamname = '<acronym title="'.parent::jl_utf8_convert ($team->name, 'iso-8859-1', 'utf-8').'">'
  159. .parent::jl_utf8_convert ($team->short_name, 'iso-8859-1', 'utf-8')
  160. .'</acronym>';
  161. break;
  162. default:
  163. if (!isset($team->$teamnames) OR (is_null($team->$teamnames) OR trim($team->$teamnames)=='')) {
  164. $teamname = parent::jl_utf8_convert ($team->name, 'iso-8859-1', 'utf-8');
  165. }
  166. else {
  167. $teamname = parent::jl_utf8_convert ($team->$teamnames, 'iso-8859-1', 'utf-8');
  168. }
  169. break;
  170. }
  171. return $teamname;
  172. }
  173. function buildImage($team) {
  174. global $mainframe;
  175. $image = $this->xparams->get('team_logos', 'logo_small');
  176. if ($image == '-') { return ''; }
  177. $logo = '';
  178. if ($team->$image != '' && file_exists($mainframe->getCfg('absolute_path').'/'.$team->$image)){
  179. $h = $this->xparams->get('logo_height', 20);
  180. $logo = '<img src="'.JUri::root(true).'/'.$team->$image.'" alt="'
  181. .parent::jl_utf8_convert ($team->short_name, 'iso-8859-1', 'utf-8').'" title="'
  182. .parent::jl_utf8_convert ($team->name, 'iso-8859-1', 'utf-8').'"';
  183. if ($h > 0) {
  184. $logo .= ' style="height:'.$h.'px;"';
  185. }
  186. $logo .= ' />';
  187. }
  188. return $logo;
  189. }
  190. function getMatches($caldates, $ordering='ASC'){
  191. $database = JFactory::getDbo();
  192. $teamCondition = '';
  193. $clubCondition = '';
  194. $favCondition = '';
  195. $limitingcondition = '';
  196. $limitingconditions = array();
  197. $customteam = JRequest::getVar('jlcteam',0,'default','POST');
  198. $teamid = $this->xparams->get('team_ids') ;
  199. $teamid = ($customteam > 0) ? $customteam : $teamid;
  200. if ($teamid) {
  201. $teamids = explode( ',', $teamid );
  202. JArrayHelper::toInteger( $teamids );
  203. $teamCondition = '(matchpart1 IN ('.implode(', ', $teamids).') or matchpart2 IN ('.implode(', ', $teamids).'))';
  204. $limitingconditions[] = $teamCondition;
  205. }
  206. $clubid = $this->xparams->get('club_ids') ;
  207. if ($clubid && $customteam == 0) {
  208. $clubids = explode( ',', $clubid );
  209. JArrayHelper::toInteger( $clubids );
  210. $clubCondition = '(teams.club_id IN ('.implode(', ', $clubids).') AND (matchpart1 = teams.id or matchpart2 = teams.id))';
  211. $limitingconditions[] = $clubCondition;
  212. }
  213. if($this->xparams->get('joomleague_use_favteams', 0) == 1 && $customteam == 0) {
  214. $favCondition .= "(m.matchpart1 IN (".$this->favteams.") OR m.matchpart2 IN (".$this->favteams."))";
  215. $limitingconditions[] = $favCondition;
  216. }
  217. if (count($limitingconditions) > 0) {
  218. $limitingcondition .=' AND (';
  219. $limitingcondition .= implode(' OR ', $limitingconditions);
  220. $limitingcondition .=')';
  221. }
  222. $limit = (isset($caldates['limitstart'])&&isset($caldates['limitend'])) ? ' LIMIT '.$caldates['limitstart'].', '.$caldates['limitend'] :'';
  223. $query = "SELECT m.*,p.*,
  224. DATE_FORMAT(match_date, '%Y-%m-%d') AS caldate,
  225. r.matchcode, r.name AS roundname, r.round_date_first, r.round_date_last
  226. FROM #__joomleague_matches m
  227. LEFT JOIN #__joomleague_rounds r ON m.round_id = r.id
  228. LEFT JOIN #__joomleague p ON p.id = m.project_id
  229. LEFT JOIN #__joomleague_teams teams ON (teams.id = m.matchpart1 OR teams.id = m.matchpart2) ";
  230. $where = " WHERE m.published = 1
  231. AND p.published = 1 ";
  232. if (isset($caldates['start'])) $where .= " AND m.match_date >= '".$caldates['start']."'";
  233. if (isset($caldates['end'])) $where .= " AND m.match_date <= '".$caldates['end']."'";
  234. if (isset($caldates['matchcode'])) $where .= " AND r.matchcode = '".$caldates['matchcode']."'";
  235. $projectid = $this->xparams->get('project_ids') ;
  236. if ($projectid) {
  237. $projectids = explode( ',', $projectid );
  238. JArrayHelper::toInteger( $projectids );
  239. $where .= " AND m.project_id IN (".implode(', ', $projectids).")";
  240. }
  241. if(isset($caldates['resultsonly']) && $caldates['resultsonly']== 1) $where .= " AND m.matchpart1_result IS NOT NULL";
  242. $where .= $limitingcondition;
  243. $where .= " GROUP BY m.match_id";
  244. $where .=" ORDER BY m.match_date ".$ordering;
  245. $query = ($this->prefix != '') ? str_replace('#__', $this->prefix, $query) : $query;
  246. $database->setQuery($query.$where.$limit);
  247. $result = $database->loadObjectList();
  248. if ($result)
  249. {
  250. foreach ($result as $match)
  251. {
  252. JoomleagueHelper::convertMatchDateToTimezone($match);
  253. }
  254. }
  255. return $result;
  256. }
  257. function getTeamsFromMatches( &$games ){
  258. $database = JFactory::getDbo();
  259. //if ($my->id == 62) explain_array($games);
  260. //$project_id = $games[0]->project_id;
  261. if ( !count ($games) ) return Array();
  262. foreach ( $games as $m ) {
  263. $teamsId[] = $m->matchpart1;
  264. $teamsId[] = $m->matchpart2;
  265. }
  266. $listTeamId = implode( ",", array_unique($teamsId) );
  267. $query = "SELECT tl.id AS teamtoolid, tl.division_id, tl.standard_playground, tl.admin, tl.start_points,
  268. tl.info, tl.team_id, tl.checked_out, tl.checked_out_time, tl.picture, tl.project_id,
  269. t.id, t.name, t.short_name, t.middle_name, t.description, t.club_id,
  270. pg1.id AS tt_pg_id, pg1.name AS tt_pg_name, pg1.short_name AS tt_pg_short_name,
  271. pg2.id AS club_pg_id, pg2.name AS club_pg_name, pg2.short_name AS club_pg_short_name,
  272. u.username, u.email,
  273. c.logo_small, c.logo_middle, c.logo_big, c.country,
  274. CONCAT('images/joomleague/flags/', LOWER(ctry.countries_iso_code_2), '.png') AS logo_country,
  275. d.name AS division_name, d.shortname AS division_shortname,
  276. p.name AS project_name
  277. FROM #__joomleague_teams t
  278. LEFT JOIN #__joomleague_team_joomleague tl on tl.team_id = t.id ";
  279. $query .= "LEFT JOIN #__users u on tl.admin = u.id
  280. LEFT JOIN #__joomleague_clubs c on t.club_id = c.id
  281. LEFT JOIN #__joomleague_countries ctry on ctry.countries_id = c.country
  282. LEFT JOIN #__joomleague_divisions d on d.id = tl.division_id
  283. LEFT JOIN #__joomleague p on p.id = tl.project_id
  284. LEFT JOIN #__joomleague_playgrounds pg1 ON pg1.id = tl.standard_playground
  285. LEFT JOIN #__joomleague_playgrounds pg2 ON pg2.id = c.standard_playground
  286. WHERE t.id IN (".$listTeamId.") AND tl.project_id = p.id";
  287. $query = ($this->prefix != '') ? str_replace('#__', $this->prefix, $query) : $query;
  288. $database->setQuery($query);
  289. if ( !$result = $database->loadObjectList('team_id') ) $result = Array();
  290. return $result;
  291. }
  292. function build_url( &$row ) {
  293. $row->link = ($this->xparams->get('linkbirthday', 0) == 1) ? 'index.php?option=com_joomleague&amp;p='.$row->project_id.'&amp;func='.$row->func_to_call.'&amp;pid='.$row->id : '';
  294. }
  295. function getGlobalTeams () {
  296. $teamnames = $this->xparams->get('team_names', 'short_name');
  297. $database = JFactory::getDbo();
  298. $query = "SELECT t.".$teamnames." AS name, t.id AS value
  299. FROM #__joomleague_teams t, #__joomleague p
  300. WHERE t.id IN(p.fav_team)";
  301. $database->setQuery($query);
  302. $result = $database->loadObjectList();
  303. }
  304. }