PageRenderTime 53ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/com_joomleague/components/com_joomleague/views/matchreport/view.html.php

https://gitlab.com/julienv/joomleague
PHP | 538 lines | 506 code | 26 blank | 6 comment | 41 complexity | badbb24da6eaef4d1241391b5c543e35 MD5 | raw file
  1. <?php defined('_JEXEC') or die('Restricted access');
  2. jimport('joomla.application.component.view');
  3. jimport('joomla.html.pane');
  4. require_once (JLG_PATH_ADMIN .DS.'models'.DS.'match.php');
  5. require_once(JPATH_COMPONENT.DS.'models'.DS.'results.php');
  6. class JoomleagueViewMatchReport extends JLGView
  7. {
  8. function display($tpl=null)
  9. {
  10. // Get a refrence of the page instance in joomla
  11. $document = JFactory::getDocument();
  12. $version = urlencode(JoomleagueHelper::getVersion());
  13. $css='components/com_joomleague/assets/css/tabs.css?v='.$version;
  14. $document->addStyleSheet($css);
  15. $model = $this->getModel();
  16. $config=$model->getTemplateConfig($this->getName());
  17. $project=$model->getProject();
  18. $match=$model->getMatch();
  19. $this->assignRef('project',$project);
  20. $this->assignRef('overallconfig',$model->getOverallConfig());
  21. $this->assignRef('config',$config);
  22. $this->assignRef('match',$match);
  23. $ret=$model->getMatchText($match->new_match_id);
  24. $this->assignRef('newmatchtext',$ret->text);
  25. $ret=$model->getMatchText($match->old_match_id);
  26. $this->assignRef('oldmatchtext',$ret->text);
  27. $this->assignRef('round',$model->getRound());
  28. $this->assignRef('team1',$model->getTeaminfo($this->match->projectteam1_id));
  29. $this->assignRef('team2',$model->getTeaminfo($this->match->projectteam2_id));
  30. $this->assignRef('team1_club',$model->getClubinfo($this->team1->club_id));
  31. $this->assignRef('team2_club',$model->getClubinfo($this->team2->club_id));
  32. $this->assignRef('matchplayerpositions',$model->getMatchPlayerPositions());
  33. $this->assignRef('matchplayers',$model->getMatchPlayers());
  34. $this->assignRef('matchstaffpositions',$model->getMatchStaffPositions());
  35. $this->assignRef('matchstaffs',$model->getMatchStaff());
  36. $this->assignRef('matchrefereepositions',$model->getMatchRefereePositions());
  37. $this->assignRef('matchreferees',$model->getMatchReferees());
  38. $this->assignRef('substitutes',$model->getSubstitutes());
  39. $this->assignRef('eventtypes',$model->getEventTypes());
  40. $sortEventsDesc = isset($this->config['sort_events_desc']) ? $this->config['sort_events_desc'] : '1';
  41. $this->assignRef('matchevents',$model->getMatchEvents($this->match->id,1,$sortEventsDesc));
  42. $this->assignRef('playground',$model->getPlayground($this->match->playground_id));
  43. $this->assignRef('stats',$model->getProjectStats());
  44. $this->assignRef('playerstats',$model->getMatchStats());
  45. $this->assignRef('staffstats',$model->getMatchStaffStats());
  46. $this->assignRef('model',$model);
  47. $xmlfile=JPATH_COMPONENT_ADMINISTRATOR.DS.'assets'.DS.'extended'.DS.'match.xml';
  48. $jRegistry = new JRegistry;
  49. $jRegistry->loadString($match->extended, 'ini');
  50. $extended =& JForm::getInstance('extended', $xmlfile, array('control'=> 'extended'), false, '/config');
  51. $extended->bind($jRegistry);
  52. $this->assignRef( 'extended', $extended);
  53. // Set page title
  54. $titleInfo = JoomleagueHelper::createTitleInfo(JText::_('COM_JOOMLEAGUE_MATCHREPORT_PAGE_TITLE'));
  55. if (!empty($this->team1))
  56. {
  57. $titleInfo->team1Name = $this->team1->name;
  58. }
  59. if (!empty($this->team2))
  60. {
  61. $titleInfo->team2Name = $this->team2->name;
  62. }
  63. if (!empty($this->round))
  64. {
  65. $titleInfo->roundName = $this->round->name;
  66. }
  67. if (!empty($this->project))
  68. {
  69. $titleInfo->projectName = $this->project->name;
  70. $titleInfo->leagueName = $this->project->league_name;
  71. $titleInfo->seasonName = $this->project->season_name;
  72. }
  73. $division = $model->getDivision(JRequest::getInt('division',0));
  74. if (!empty( $division ) && $division->id != 0)
  75. {
  76. $titleInfo->divisionName = $division->name;
  77. }
  78. $this->assignRef('pagetitle', JoomleagueHelper::formatTitle($titleInfo, $this->config["page_title_format"]));
  79. $document->setTitle($this->pagetitle);
  80. parent::display($tpl);
  81. }
  82. function showLegresult($team=0)
  83. {
  84. if($this->match->alt_decision==0) {
  85. if ($team!=0)
  86. {
  87. if ($team==1)
  88. {
  89. $result=$this->match->team1_result_split;
  90. }
  91. else
  92. {
  93. $result=$this->match->team2_result_split;
  94. }
  95. $legresult=explode(";",$result);
  96. $string=" (";
  97. foreach ($legresult as $temp){$string .= $temp.' : ';}
  98. $string=substr_replace($string,'',-2);
  99. $string.=') ';
  100. return $string;
  101. }
  102. else
  103. {
  104. $legresult1=str_replace(";","",$this->match->team1_result_split);
  105. $legresult2=str_replace(";","",$this->match->team2_result_split);
  106. if (($legresult1=="") && ($legresult2==""))
  107. {
  108. return false;
  109. }
  110. return true;
  111. }
  112. }
  113. }
  114. function showOvertimeResult()
  115. {
  116. if(isset($this->match->team1_result_ot) || isset($this->match->team2_result_ot))
  117. {
  118. $result=$this->match->team1_result_ot.' : '.$this->match->team2_result_ot;
  119. return $result;
  120. }
  121. return false;
  122. }
  123. function showShotoutResult()
  124. {
  125. if(isset($this->match->team1_result_so) || isset($this->match->team2_result_so))
  126. {
  127. $result=$this->match->team1_result_so.' : '.$this->match->team2_result_so;
  128. return $result;
  129. }
  130. return false;
  131. }
  132. function showMatchresult($decision,$team)
  133. {
  134. if ($decision==1)
  135. {
  136. if ($team==1)
  137. {
  138. $result=$this->match->team1_result_decision;
  139. }
  140. else
  141. {
  142. $result=$this->match->team2_result_decision;
  143. }
  144. }
  145. else
  146. if ($team==1)
  147. {
  148. $result=$this->match->team1_result;
  149. }
  150. else
  151. {
  152. $result=$this->match->team2_result;
  153. }
  154. return $result;
  155. }
  156. function showSubstitution($sub)
  157. {
  158. $pic_time='images/com_joomleague/database/events/'.$this->project->fs_sport_type_name.'/playtime.gif';
  159. $pic_out='images/com_joomleague/database/events/'.$this->project->fs_sport_type_name.'/out.png';
  160. $pic_in='images/com_joomleague/database/events/'.$this->project->fs_sport_type_name.'/in.png';
  161. //$imgTitle=JText::_('COM_JOOMLEAGUE_MATCHREPORT_MINUTE');
  162. //$imgTitle2=array(' title' => $imgTitle);
  163. //$result=JHtml::image($pic_time,$imgTitle,$imgTitle2).'&nbsp;'.$sub->in_out_time;
  164. $result='<b>'.$sub->in_out_time.'. '. JText::_('COM_JOOMLEAGUE_MATCHREPORT_MINUTE') .'</b>';
  165. $result .= '<br />';
  166. $outName = JoomleagueHelper::formatName(null, $sub->out_firstname, $sub->out_nickname, $sub->out_lastname, $this->config["name_format"]);
  167. if($outName != '') {
  168. $imgTitle=JText::_('COM_JOOMLEAGUE_MATCHREPORT_SUBSTITUTION_WENT_OUT');
  169. $imgTitle2=array(' title' => $imgTitle);
  170. $result .= JHtml::image($pic_out,$imgTitle,$imgTitle2).'&nbsp;';
  171. $isFavTeam = in_array( $sub->team_id, explode(",",$this->project->fav_team));
  172. if ( ($this->config['show_player_profile_link'] == 1) || (($this->config['show_player_profile_link'] == 2) && ($isFavTeam)) )
  173. {
  174. $result .= JHtml::link(JoomleagueHelperRoute::getPlayerRoute($this->project->id,$sub->team_id,$sub->out_person_id),$outName);
  175. } else {
  176. $result .= $outName;
  177. }
  178. if($sub->out_position!='') {
  179. $result .= '&nbsp;('.JText::_($sub->out_position).')';
  180. }
  181. $result .= '<br />';
  182. }
  183. $inName = JoomleagueHelper::formatName(null, $sub->firstname, $sub->nickname, $sub->lastname, $this->config["name_format"]);
  184. if($inName!='') {
  185. $imgTitle=JText::_('COM_JOOMLEAGUE_MATCHREPORT_SUBSTITUTION_CAME_IN');
  186. $imgTitle2=array(' title' => $imgTitle);
  187. $result .= JHtml::image($pic_in,$imgTitle,$imgTitle2).'&nbsp;';
  188. $isFavTeam = in_array( $sub->team_id, explode(",",$this->project->fav_team));
  189. if ( ($this->config['show_player_profile_link'] == 1) || (($this->config['show_player_profile_link'] == 2) && ($isFavTeam)) )
  190. {
  191. $result .= JHtml::link(JoomleagueHelperRoute::getPlayerRoute($this->project->id,$sub->team_id,$sub->person_id),$inName);
  192. } else {
  193. $result .= $inName;
  194. }
  195. if($sub->in_position!='') {
  196. $result .= '&nbsp;('.JText::_($sub->in_position).')';
  197. }
  198. $result .= '<br /><br />';
  199. }
  200. return $result;
  201. }
  202. function showEvents($eventid=0,$projectteamid=0)
  203. {
  204. $result='';
  205. $txt_tab='';
  206. // Make event table
  207. foreach ($this->matchevents AS $me)
  208. {
  209. if ($me->event_type_id==$eventid && $me->ptid==$projectteamid)
  210. {
  211. $result .= '<dt class="list">';
  212. if ($this->config['show_event_minute'] == 1 && $me->event_time > 0)
  213. {
  214. $prefix = str_pad($me->event_time, 2 ,'0', STR_PAD_LEFT)."' ";
  215. } else {
  216. $prefix = null;
  217. }
  218. $match_player = JoomleagueHelper::formatName($prefix, $me->firstname1, $me->nickname1, $me->lastname1, $this->config["name_format"]);
  219. if ($this->config['event_link_player'] == 1 && $me->playerid != 0)
  220. {
  221. $player_link=JoomleagueHelperRoute::getPlayerRoute($this->project->slug,$me->team_id,$me->playerid);
  222. $match_player = JHtml::link($player_link,$match_player);
  223. }
  224. $result .= $match_player;
  225. if($this->config['show_event_team_name']) {
  226. $result .= ' (' . $me->team_name . ')';
  227. }
  228. // only show event sum and match notice when set to on in template cofig
  229. if($this->config['show_event_sum'] == 1 || $this->config['show_event_notice'] == 1)
  230. {
  231. if (($this->config['show_event_sum'] == 1 && $me->event_sum > 0) || ($this->config['show_event_notice'] == 1 && strlen($me->notice) > 0))
  232. {
  233. $result .= ' (';
  234. if ($this->config['show_event_sum'] == 1 && $me->event_sum > 0)
  235. {
  236. $result .= $me->event_sum;
  237. }
  238. if (($this->config['show_event_sum'] == 1 && $me->event_sum > 0) && ($this->config['show_event_notice'] == 1 && strlen($me->notice) > 0))
  239. {
  240. $result .= ' | ';
  241. }
  242. if ($this->config['show_event_notice'] == 1 && strlen($me->notice) > 0)
  243. {
  244. $result .= $me->notice;
  245. }
  246. $result .= ')';
  247. }
  248. }
  249. $result .= '</dt>';
  250. }
  251. }
  252. return $result;
  253. }
  254. /** timeline */
  255. function getTimelineMatchTime()
  256. {
  257. $result_type=$this->match->match_result_type;
  258. switch ($result_type) {
  259. case 0:
  260. /** Ordinary time */
  261. $matchtime=$this->project->game_regular_time;
  262. break;
  263. case 1:
  264. /** Overtime time */
  265. $matchtime=$this->project->game_regular_time + $this->project->add_time;
  266. break;
  267. case 2:
  268. /** Shotout time */
  269. if ( $this->showOvertimeResult() ) {
  270. /** First overtime, then Shotout? */
  271. $matchtime=$this->project->game_regular_time + $this->project->add_time; }
  272. else {
  273. $matchtime=$this->project->game_regular_time; }
  274. break;
  275. }
  276. return $matchtime;
  277. }
  278. function getEventsTimes()
  279. {
  280. $eventstimecounter = array();
  281. foreach ($this->matchevents AS $me)
  282. {
  283. $eventstimecounter[] = $me->event_time;
  284. }
  285. return $eventstimecounter;
  286. }
  287. function showSubstitution_Timelines1($sub=0)
  288. {
  289. $result='';
  290. $substitutioncounter = array();
  291. $eventstimecounter = $this->getEventsTimes();
  292. foreach ( $this->substitutes as $sub ) {
  293. if ($sub->ptid == $this->match->projectteam1_id) {
  294. if (in_array($sub->in_out_time, $eventstimecounter) || in_array($sub->in_out_time, $substitutioncounter))
  295. {
  296. $result .= JoomleagueViewMatchReport::_formatTimelineSubstitution($sub,$sub->firstname,$sub->nickname,$sub->lastname,$sub->out_firstname,$sub->out_nickname,$sub->out_lastname,1);
  297. }
  298. else {
  299. $result .= JoomleagueViewMatchReport::_formatTimelineSubstitution($sub,$sub->firstname,$sub->nickname,$sub->lastname,$sub->out_firstname,$sub->out_nickname,$sub->out_lastname,0);
  300. }
  301. $substitutioncounter[] = $sub->in_out_time;
  302. }
  303. }
  304. return $result;
  305. }
  306. function showSubstitution_Timelines2($sub=0)
  307. {
  308. $result='';
  309. $substitutioncounter = array();
  310. $eventstimecounter = $this->getEventsTimes();
  311. foreach ( $this->substitutes as $sub ) {
  312. if ($sub->ptid == $this->match->projectteam2_id) {
  313. if (in_array($sub->in_out_time, $eventstimecounter) || in_array($sub->in_out_time, $substitutioncounter))
  314. {
  315. $result .= JoomleagueViewMatchReport::_formatTimelineSubstitution($sub,$sub->firstname,$sub->nickname,$sub->lastname,$sub->out_firstname,$sub->out_nickname,$sub->out_lastname,2);
  316. }
  317. else {
  318. $result .= JoomleagueViewMatchReport::_formatTimelineSubstitution($sub,$sub->firstname,$sub->nickname,$sub->lastname,$sub->out_firstname,$sub->out_nickname,$sub->out_lastname,0);
  319. }
  320. $substitutioncounter[] = $sub->in_out_time;
  321. }
  322. }
  323. return $result;
  324. }
  325. function _formatTimelineSubstitution($sub,$firstname,$nickname,$lastname,$out_firstname,$out_nickname,$out_lastname,$two_substitutions_per_minute=0)
  326. {
  327. $pic_out='images/com_joomleague/database/events/'.$this->project->fs_sport_type_name.'/out.png';
  328. $pic_in='images/com_joomleague/database/events/'.$this->project->fs_sport_type_name.'/in.png';
  329. $pic_time='images/com_joomleague/database/events/'.$this->project->fs_sport_type_name.'/change.png';
  330. $time=$sub->in_out_time;
  331. $matchtime=$this->getTimelineMatchTime();
  332. $time2=($time / $matchtime) *100;
  333. $tiptext=JText::_('COM_JOOMLEAGUE_MATCHREPORT_TIMELINE_SUBSTITUTION_MIN').' ';
  334. $tiptext .= $time;
  335. $tiptext .= ' ::';
  336. $tiptext .= JoomleagueViewMatchReport::getHtmlImageForTips($pic_in);
  337. $tiptext .= JoomleagueHelper::formatName(null, $firstname, $nickname, $lastname, $this->config["name_format"]);
  338. $tiptext .= ' &lt;br&gt; ';
  339. $tiptext .= JoomleagueViewMatchReport::getHtmlImageForTips($pic_out);
  340. $tiptext .= JoomleagueHelper::formatName(null, $out_firstname, $out_nickname, $out_lastname, $this->config["name_format"]);
  341. $result='';
  342. if ($two_substitutions_per_minute == 1) // there were two substitutions in one minute in timelinetop
  343. {
  344. $result .= "\n".'<img class="imgzev" style="position: absolute; left: '.$time2.'%; top: -25px;"';
  345. }
  346. elseif ($two_substitutions_per_minute == 2) // there were two substitutions in one minute in timelinebottom
  347. {
  348. $result .= "\n".'<img class="imgzev" style="position: absolute; left: '.$time2.'%; top: 25px;"';
  349. }
  350. else
  351. {
  352. $result .= "\n".'<img class="imgzev" style="position: absolute; left: '.$time2.'%;"';
  353. }
  354. $result .= ' src="'.$pic_time.'" alt="'.$tiptext.'" title="'.$tiptext;
  355. $result .= '" />';
  356. return $result;
  357. }
  358. function showEvents_Timelines1($eventid=0,$projectteamid=0)
  359. {
  360. $result='';
  361. $eventcounter = array();
  362. foreach ($this->eventtypes AS $event)
  363. {
  364. foreach ($this->matchevents AS $me)
  365. {
  366. if ($me->event_type_id==$event->id && $me->ptid==$this->match->projectteam1_id)
  367. {
  368. $placeholder = JoomleagueHelper::getDefaultPlaceholder("player");
  369. // set teamplayer picture
  370. if ( ($me->tppicture1 != $placeholder) && (!empty($me->tppicture1)) )
  371. {
  372. $picture = $me->tppicture1;
  373. }
  374. // when teamplayer picture is empty or a placeholder icon look for the general player picture
  375. elseif
  376. ( ( ($me->tppicture1 == $placeholder) || (empty($me->tppicture1)) ) &&
  377. ( ($me->picture1 != $placeholder) && (!empty($me->picture1)) )
  378. )
  379. {
  380. $picture = $me->picture1;
  381. }
  382. else {
  383. $picture = '';
  384. }
  385. if (in_array($me->event_time, $eventcounter))
  386. {
  387. $result .= JoomleagueViewMatchReport::_formatTimelineEvent($me,$event,$me->firstname1,$me->nickname1,$me->lastname1,$picture,1);
  388. }
  389. else {
  390. $result .= JoomleagueViewMatchReport::_formatTimelineEvent($me,$event,$me->firstname1,$me->nickname1,$me->lastname1,$picture,0);
  391. }
  392. $eventcounter[] = $me->event_time;
  393. }
  394. }
  395. }
  396. return $result;
  397. }
  398. function showEvents_Timelines2($eventid=0,$projectteamid=0)
  399. {
  400. $result='';
  401. $eventcounter = array();
  402. foreach ($this->eventtypes AS $event)
  403. {
  404. foreach ($this->matchevents AS $me)
  405. {
  406. if ($me->event_type_id==$event->id && $me->ptid==$this->match->projectteam2_id)
  407. {
  408. $placeholder = JoomleagueHelper::getDefaultPlaceholder("player");
  409. // set teamplayer picture
  410. if ( ($me->tppicture1 != $placeholder) && (!empty($me->tppicture1)) )
  411. {
  412. $picture = $me->tppicture1;
  413. }
  414. // when teamplayer picture is empty or a placeholder icon look for the general player picture
  415. elseif
  416. ( ( ($me->tppicture1 == $placeholder) || (empty($me->tppicture1)) ) &&
  417. ( ($me->picture1 != $placeholder) && (!empty($me->picture1)) )
  418. )
  419. {
  420. $picture = $me->picture1;
  421. }
  422. else {
  423. $picture = '';
  424. }
  425. if (in_array($me->event_time, $eventcounter))
  426. {
  427. $result .= JoomleagueViewMatchReport::_formatTimelineEvent($me,$event,$me->firstname1,$me->nickname1,$me->lastname1,$picture,2);
  428. }
  429. else {
  430. $result .= JoomleagueViewMatchReport::_formatTimelineEvent($me,$event,$me->firstname1,$me->nickname1,$me->lastname1,$picture,0);
  431. }
  432. $eventcounter[] = $me->event_time;
  433. }
  434. }
  435. }
  436. return $result;
  437. }
  438. function _formatTimelineEvent($matchEvent,$event,$firstname,$nickname,$lastname,$picture,$two_events_per_minute=0)
  439. {
  440. $result='';
  441. if(empty($event->icon)) {
  442. $event->icon = JUri::Base() . "media/com_joomleague/jl_images/same.png";
  443. }
  444. $tiptext=JText::_($event->name).' '.JText::_('COM_JOOMLEAGUE_MATCHREPORT_MINUTE_SHORT').' '.$matchEvent->event_time;
  445. $tiptext .= ' ::';
  446. if (file_exists($picture))
  447. {
  448. $tiptext .= JoomleagueViewMatchReport::getHtmlImageForTips($picture,
  449. $this->config['player_picture_width'],
  450. $this->config['player_picture_height']);
  451. }
  452. $tiptext .= '&lt;br /&gt;'.JoomleagueHelper::formatName(null, $firstname, $nickname, $lastname, $this->config["name_format"]);
  453. $time=($matchEvent->event_time / $this->getTimelineMatchTime()) *100;
  454. if ($two_events_per_minute == 1) // there were two events in one minute in timelinetop
  455. {
  456. $result .= "\n".'<img class="imgzev" style="position: absolute;left: '.$time.'%; top: -25px;" src="'.$event->icon.'" alt="'.$tiptext.'" title="'.$tiptext;
  457. }
  458. elseif ($two_events_per_minute == 2) // there were two events in one minute in timelinebottom
  459. {
  460. $result .= "\n".'<img class="imgzev" style="position: absolute;left: '.$time.'%; top: 25px;" src="'.$event->icon.'" alt="'.$tiptext.'" title="'.$tiptext;
  461. }
  462. else
  463. {
  464. $result .= "\n".'<img class="imgzev" style="position: absolute;left: '.$time.'%;" src="'.$event->icon.'" alt="'.$tiptext.'" title="'.$tiptext;
  465. }
  466. if ($this->config['use_tabs_events'] == 2) {
  467. $result.= '" onclick="gotoevent('.$matchEvent->event_id .')';
  468. }
  469. $result.= '" />';
  470. return $result;
  471. }
  472. function getHtmlImageForTips($picture,$width=0,$height=0)
  473. {
  474. $picture = JUri::root(true).'/'.str_replace(JPATH_SITE.DS, "", $picture);
  475. if($width > 0 && $height==0) {
  476. return '&lt;img src=\''.$picture.'\' width=\''.$width.'\' /&gt;';
  477. }
  478. if($height>0 && $width==0) {
  479. return '&lt;img src=\''.$picture.'\' height=\''.$height.'\' /&gt;';
  480. }
  481. if($height > 0 && $width > 0) {
  482. return '&lt;img src=\''.$picture.'\' height=\''.$height.'\' width=\''.$width.'\' /&gt;';
  483. }
  484. return '&lt;img src=\''.$picture.'\' /&gt;';
  485. }
  486. }
  487. ?>