PageRenderTime 23ms CodeModel.GetById 7ms RepoModel.GetById 0ms app.codeStats 0ms

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

https://gitlab.com/julienv/joomleague
PHP | 170 lines | 136 code | 23 blank | 11 comment | 11 complexity | c7c450c2fbbd05299d1a290733ad6044 MD5 | raw file
  1. <?php defined( '_JEXEC' ) or die( 'Restricted access' );
  2. jimport( 'joomla.application.component.view');
  3. class JoomleagueViewTeamStats extends JLGView
  4. {
  5. function display($tpl = null)
  6. {
  7. // Get a refrence of the page instance in joomla
  8. $document= JFactory::getDocument();
  9. $model = $this->getModel();
  10. $config = $model->getTemplateConfig($this->getName());
  11. $tableconfig = $model->getTemplateConfig( "ranking" );
  12. $eventsconfig = $model->getTemplateConfig( "eventsranking" );
  13. $flashconfig = $model->getTemplateConfig( "flash" );
  14. $this->assignRef( 'project', $model->getProject() );
  15. if ( isset( $this->project ) )
  16. {
  17. $this->assignRef( 'overallconfig', $model->getOverallConfig() );
  18. if ( !isset( $this->overallconfig['seperator'] ) )
  19. {
  20. $this->overallconfig['seperator'] = ":";
  21. }
  22. $this->assignRef( 'config', $config );
  23. $this->assignRef( 'tableconfig', $tableconfig );
  24. $this->assignRef( 'eventsconfig', $eventsconfig );
  25. $this->assignRef( 'actualround', $model->getCurrentRound() );
  26. $this->assignRef( 'team', $model->getTeam() );
  27. $this->assignRef( 'highest_home', $model->getHighestHome( ) );
  28. $this->assignRef( 'highest_away', $model->getHighestAway( ) );
  29. $this->assignRef( 'highestdef_home', $model->getHighestDefHome( ) );
  30. $this->assignRef( 'highestdef_away', $model->getHighestDefAway( ) );
  31. $this->assignRef( 'totalshome', $model->getSeasonTotalsHome( ) );
  32. $this->assignRef( 'totalsaway', $model->getSeasonTotalsAway( ) );
  33. $this->assignRef( 'matchdaytotals', $model->getMatchDayTotals( ) );
  34. $this->assignRef( 'totalrounds', $model->getTotalRounds( ) );
  35. $this->assignRef( 'totalattendance', $model->getTotalAttendance() );
  36. $this->assignRef( 'bestattendance', $model->getBestAttendance() );
  37. $this->assignRef( 'worstattendance', $model->getWorstAttendance() );
  38. $this->assignRef( 'averageattendance', $model->getAverageAttendance() );
  39. $this->assignRef( 'chart_url', $model->getChartURL( ) );
  40. $this->assignRef( 'nogoals_against', $model->getNoGoalsAgainst( ) );
  41. $this->assignRef( 'logo', $model->getLogo( ) );
  42. $this->assignRef( 'results', $model->getResults());
  43. $this->_setChartdata(array_merge($flashconfig, $config));
  44. }
  45. // Set page title
  46. $titleInfo = JoomleagueHelper::createTitleInfo(JText::_('COM_JOOMLEAGUE_TEAMSTATS_PAGE_TITLE'));
  47. if (!empty($this->team))
  48. {
  49. $titleInfo->team1Name = $this->team->name;
  50. }
  51. if (!empty($this->project))
  52. {
  53. $titleInfo->projectName = $this->project->name;
  54. $titleInfo->leagueName = $this->project->league_name;
  55. $titleInfo->seasonName = $this->project->season_name;
  56. }
  57. $division = $model->getDivision(JRequest::getInt('division',0));
  58. if (!empty( $division ) && $division->id != 0)
  59. {
  60. $titleInfo->divisionName = $division->name;
  61. }
  62. $this->assignRef('pagetitle', JoomleagueHelper::formatTitle($titleInfo, $this->config["page_title_format"]));
  63. $document->setTitle($this->pagetitle);
  64. parent::display( $tpl );
  65. }
  66. /**
  67. * assign the chartdata object for open flash chart library
  68. * @param $config
  69. * @return unknown_type
  70. */
  71. function _setChartdata($config)
  72. {
  73. require_once( JLG_PATH_SITE.DS."assets".DS."classes".DS."open-flash-chart".DS."open-flash-chart.php" );
  74. $data = $this->get('ChartData');
  75. // Calculate Values for Chart Object
  76. $forSum = array();
  77. $againstSum = array();
  78. $matchDayGoalsCount = array();
  79. $matchDayGoalsCount[] = 0;
  80. $round_labels = array();
  81. $matchDayGoalsCountMax = 0;
  82. foreach( $data as $rw )
  83. {
  84. if (!$rw->goalsfor) $rw->goalsfor = 0;
  85. if (!$rw->goalsagainst) $rw->goalsagainst = 0;
  86. $forSum[] = intval($rw->goalsfor);
  87. $againstSum[] = intval($rw->goalsagainst);
  88. // check, if both results are missing and avoid drawing the flatline of "0" goals for not played games yet
  89. if ((!$rw->goalsfor) && (!$rw->goalsagainst))
  90. {
  91. $matchDayGoalsCount[] = 0;
  92. }
  93. else
  94. {
  95. $matchDayGoalsCount[] = intval($rw->goalsfor + $rw->goalsagainst);
  96. }
  97. $round_labels[] = $rw->roundcode;
  98. }
  99. $chart = new open_flash_chart();
  100. //$chart->set_title( $title );
  101. $chart->set_bg_colour($config['bg_colour']);
  102. $barfor = new $config['bartype_1']();
  103. $barfor->set_values( $forSum );
  104. $barfor->set_tooltip( JText::_('COM_JOOMLEAGUE_TEAMSTATS_GOALS_FOR'). ": #val#" );
  105. $barfor->set_colour( $config['bar1'] );
  106. $barfor->set_on_show(new bar_on_show($config['animation_1'], $config['cascade_1'], $config['delay_1']));
  107. $barfor->set_key(JText::_('COM_JOOMLEAGUE_TEAMSTATS_GOALS_FOR'), 12);
  108. $baragainst = new $config['bartype_2']();
  109. $baragainst->set_values( $againstSum );
  110. $baragainst->set_tooltip( JText::_('COM_JOOMLEAGUE_TEAMSTATS_GOALS_AGAINST'). ": #val#" );
  111. $baragainst->set_colour( $config['bar2'] );
  112. $baragainst->set_on_show(new bar_on_show($config['animation_2'], $config['cascade_2'], $config['delay_2']));
  113. $baragainst->set_key(JText::_('COM_JOOMLEAGUE_TEAMSTATS_GOALS_AGAINST'), 12);
  114. $chart->add_element($barfor);
  115. $chart->add_element($baragainst);
  116. // total
  117. $d = new $config['dotstyle_3']();
  118. $d->size((int)$config['line3_dot_strength']);
  119. $d->halo_size(1);
  120. $d->colour($config['line3']);
  121. $d->tooltip(JText::_('COM_JOOMLEAGUE_TEAMSTATS_TOTAL2').' #val#');
  122. $line = new line();
  123. $line->set_default_dot_style($d);
  124. $line->set_values(array_slice( $matchDayGoalsCount,1) );
  125. $line->set_width( (int) $config['line3_strength'] );
  126. $line->set_key(JText::_('COM_JOOMLEAGUE_TEAMSTATS_TOTAL'), 12);
  127. $line->set_colour( $config['line3'] );
  128. $line->on_show(new line_on_show($config['l_animation_3'], $config['l_cascade_3'], $config['l_delay_3']));
  129. $chart->add_element($line);
  130. $x = new x_axis();
  131. $x->set_colours($config['x_axis_colour'], $config['x_axis_colour_inner']);
  132. $x->set_labels_from_array($round_labels);
  133. $chart->set_x_axis( $x );
  134. $x_legend = new x_legend( JText::_('COM_JOOMLEAGUE_TEAMSTATS_ROUNDS') );
  135. $x_legend->set_style( '{font-size: 15px; color: #778877}' );
  136. $chart->set_x_legend( $x_legend );
  137. $y = new y_axis();
  138. $y->set_range( 0, max($matchDayGoalsCount)+2, $config['y_axis_steps']);
  139. $y->set_colours($config['y_axis_colour'], $config['y_axis_colour_inner']);
  140. $chart->set_y_axis( $y );
  141. $y_legend = new y_legend( JText::_('COM_JOOMLEAGUE_TEAMSTATS_GOALS') );
  142. $y_legend->set_style( '{font-size: 15px; color: #778877}' );
  143. $chart->set_y_legend( $y_legend );
  144. $this->assignRef( 'chartdata', $chart);
  145. }
  146. }
  147. ?>