PageRenderTime 51ms CodeModel.GetById 21ms RepoModel.GetById 1ms app.codeStats 0ms

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

https://gitlab.com/julienv/joomleague
PHP | 279 lines | 240 code | 23 blank | 16 comment | 43 complexity | d16c12eef284d2212cf9c9404c96b5c6 MD5 | raw file
  1. <?php defined( '_JEXEC' ) or die( 'Restricted access' );
  2. jimport( 'joomla.application.component.view');
  3. require_once( JLG_PATH_SITE.DS."assets".DS."classes".DS."open-flash-chart".DS."open-flash-chart.php" );
  4. class JoomleagueViewCurve extends JLGView
  5. {
  6. function display($tpl = null)
  7. {
  8. $option = JRequest::getCmd('option');
  9. // Get a reference of the page instance in joomla
  10. $document = JFactory::getDocument();
  11. $uri = JFactory::getURI();
  12. $js = $this->baseurl . '/components/'.$option.'/assets/js/json2.js';
  13. $document->addScript($js);
  14. $js = $this->baseurl . '/components/'.$option.'/assets/js/swfobject.js';
  15. $document->addScript($js);
  16. $division = JRequest::getInt('division', 0);
  17. $model = $this->getModel();
  18. $rankingconfig = $model->getTemplateConfig( "ranking" );
  19. $flashconfig = $model->getTemplateConfig( "flash" );
  20. $config = $model->getTemplateConfig($this->getName());
  21. $this->assignRef( 'project', $model->getProject() );
  22. $this->assignRef( 'division', $model->getDivision($division) );
  23. if ( isset( $this->project ) )
  24. {
  25. $teamid1 = $model->teamid1;
  26. $teamid2 = $model->teamid2;
  27. $options = array( JHtml::_( 'select.option', '0', JText::_('COM_JOOMLEAGUE_CURVE_CHOOSE_TEAM') ) );
  28. $divisions = $model->getDivisions();
  29. if (count($divisions)>0 && $division == 0)
  30. {
  31. foreach ($divisions as $d)
  32. {
  33. $options = array();
  34. $teams = $model->getTeams($d->id);
  35. $i=0;
  36. foreach ((array) $teams as $t) {
  37. $options[] = JHtml::_( 'select.option', $t->id, $t->name );
  38. if($i==0) {
  39. $teamid1=$t->id;
  40. }
  41. if($i==1) {
  42. $teamid2=$t->id;
  43. }
  44. $i++;
  45. }
  46. $team1select[$d->id] = JHtml::_('select.genericlist', $options, 'tid1_'.$d->id, 'onchange="reload_curve_chart_'.$d->id.'()" class="inputbox" style="font-size:9px;"','value', 'text', $teamid1);
  47. $team2select[$d->id] = JHtml::_('select.genericlist', $options, 'tid2_'.$d->id, 'onchange="reload_curve_chart_'.$d->id.'()" class="inputbox" style="font-size:9px;"','value', 'text', $teamid2);
  48. }
  49. }
  50. else
  51. {
  52. $divisions = array();
  53. $team1select = array();
  54. $team2select = array();
  55. $div = $model->getDivision($division);
  56. if(empty($div)) {
  57. $div = new stdClass();
  58. $div->id = 0;
  59. $div->name = '';
  60. }
  61. $divisions[0] = $div;
  62. $teams = $model->getTeams($division);
  63. $i=0;
  64. foreach ((array) $teams as $t) {
  65. $options[] = JHtml::_( 'select.option', $t->id, $t->name );
  66. if($i==0 && $teamid1==0) {
  67. $teamid1=$t->id;
  68. }
  69. if($i==1 && $teamid2==0) {
  70. $teamid2=$t->id;
  71. }
  72. $i++;
  73. }
  74. $team1select[$div->id] = JHtml::_('select.genericlist', $options, 'tid1_'.$div->id, 'onchange="reload_curve_chart_'.$div->id.'()" class="inputbox" style="font-size:9px;"','value', 'text', $teamid1);
  75. $team2select[$div->id] = JHtml::_('select.genericlist', $options, 'tid2_'.$div->id, 'onchange="reload_curve_chart_'.$div->id.'()" class="inputbox" style="font-size:9px;"','value', 'text', $teamid2);
  76. }
  77. $this->assignRef( 'overallconfig', $model->getOverallConfig() );
  78. if ( !isset( $this->overallconfig['seperator'] ) )
  79. {
  80. $this->overallconfig['seperator'] = ":";
  81. }
  82. $this->assignRef( 'config', $config );
  83. $this->assignRef( 'model', $model);
  84. $this->assignRef( 'colors', $model->getColors($rankingconfig['colors']) );
  85. $this->assignRef( 'divisions', $divisions );
  86. $this->assignRef( 'division', $model->getDivision($division) );
  87. $this->assignRef( 'favteams', $model->getFavTeams() );
  88. $this->assignRef( 'team1', $model->getTeam1() );
  89. $this->assignRef( 'team2', $model->getTeam2() );
  90. $this->assignRef( 'allteams', $model->getTeams($division) );
  91. $this->assignRef( 'team1select', $team1select );
  92. $this->assignRef( 'team2select', $team2select );
  93. $this->_setChartdata(array_merge($flashconfig, $rankingconfig));
  94. }
  95. // Set page title
  96. $titleInfo = JoomleagueHelper::createTitleInfo(JText::_('COM_JOOMLEAGUE_CURVE_PAGE_TITLE'));
  97. if (!empty($this->team1))
  98. {
  99. $titleInfo->team1Name = $this->team1->name;
  100. }
  101. if (!empty($this->team2))
  102. {
  103. $titleInfo->team2Name = $this->team2->name;
  104. }
  105. if (!empty($this->project))
  106. {
  107. $titleInfo->projectName = $this->project->name;
  108. $titleInfo->leagueName = $this->project->league_name;
  109. $titleInfo->seasonName = $this->project->season_name;
  110. }
  111. if (!empty($this->division))
  112. {
  113. $titleInfo->divisionName = $this->division->name;
  114. }
  115. $this->assignRef('pagetitle', JoomleagueHelper::formatTitle($titleInfo, $this->config["page_title_format"]));
  116. $document->setTitle($this->pagetitle);
  117. parent::display( $tpl );
  118. }
  119. /**
  120. * assign the chartdata object for open flash chart library
  121. * @param $config
  122. * @return unknown_type
  123. */
  124. function _setChartdata($config)
  125. {
  126. $model = $this->getModel();
  127. $rounds = $this->get('Rounds');
  128. $round_labels = array();
  129. foreach ($rounds as $r) {
  130. $round_labels[] = $r->name;
  131. }
  132. //$data = $this->get('Data');
  133. $divisions = $this->divisions;
  134. //create a line
  135. $length = (count($rounds)-0.5);
  136. $linewidth = $config['color_legend_line_width'];
  137. $lines = array();
  138. foreach ($divisions as $division)
  139. {
  140. $data = $model->getDataByDivision($division->id);
  141. $allteams = $model->getTeams($division->id);
  142. if(empty($allteams) || count($allteams)==0) continue;
  143. $chart = new open_flash_chart();
  144. //$title = $division->name;
  145. //$chart->set_title( $title );
  146. $chart->set_bg_colour($config['bg_colour']);
  147. //colors defined for ranking table lines
  148. //todo: add support for more than 2 lines
  149. foreach( $this->colors as $color )
  150. {
  151. foreach ( $rounds AS $r )
  152. {
  153. for ( $n = $color['from']; $n <= $color['to']; $n++ )
  154. {
  155. $lines[$color['color']][$n][] = $n;
  156. }
  157. }
  158. }
  159. //set lines on the graph
  160. foreach( $lines AS $key => $value )
  161. {
  162. foreach( $value AS $line =>$key2 )
  163. {
  164. $chart->add_element( hline($key,$length,$line,$linewidth) );
  165. }
  166. }
  167. $team1id = 0;
  168. //load team1, first team in the dropdown
  169. foreach ($allteams as $t) {
  170. if(empty($data[$t->projectteamid])) continue;
  171. $team = $data[$t->projectteamid];
  172. if(($t->division_id == $division->id
  173. && $t->team_id != $team1id
  174. && $model->teamid1 == 0)
  175. || ($model->teamid1 != 0 && $model->teamid1 == $t->team_id)
  176. ) {
  177. $team1id = $team->team_id;
  178. $d = new $config['dotstyle_1']();
  179. $d->size((int) $config['line1_dot_strength']);
  180. $d->halo_size(1);
  181. $d->colour($config['line1']);
  182. $d->tooltip('Rank: #val#');
  183. $line = new line();
  184. $line->set_default_dot_style($d);
  185. $line->set_values( $team->rankings );
  186. $line->set_width( (int) $config['line1_strength'] );
  187. $line->set_key($team->name, 12);
  188. $line->set_colour( $config['line1'] );
  189. $line->on_show(new line_on_show($config['l_animation_1'], $config['l_cascade_1'], $config['l_delay_1']));
  190. $chart->add_element($line);
  191. break;
  192. }
  193. }
  194. if($model->teamid1!=0) {
  195. $team1id = $model->teamid1;
  196. }
  197. //load team2, second team in the dropdown
  198. foreach ($allteams as $t) {
  199. if(empty($data[$t->projectteamid])) continue;
  200. $team = $data[$t->projectteamid];
  201. if(($t->division_id == $division->id
  202. && $t->team_id != $team1id
  203. && $model->teamid2 == 0)
  204. || ($model->teamid2 != 0 && $model->teamid2 == $t->team_id)
  205. ) {
  206. $d = new $config['dotstyle_2']();
  207. $d->size((int) $config['line2_dot_strength']);
  208. $d->halo_size(1);
  209. $d->colour($config['line2']);
  210. $d->tooltip('Rank: #val#');
  211. $line = new line();
  212. $line->set_default_dot_style($d);
  213. $line->set_values( $team->rankings );
  214. $line->set_width( (int) $config['line2_strength'] );
  215. $line->set_key($team->name, 12);
  216. $line->set_colour( $config['line2'] );
  217. $line->on_show(new line_on_show($config['l_animation_2'], $config['l_cascade_2'], $config['l_delay_2']));
  218. $chart->add_element($line);
  219. break;
  220. }
  221. }
  222. $x = new x_axis();
  223. if ($config['x_axis_label']==1)
  224. {
  225. $xlabels = new x_axis_labels();
  226. $xlabels->set_labels($round_labels);
  227. $xlabels->set_vertical();
  228. }
  229. $x->set_labels($xlabels);
  230. $x->set_colours($config['x_axis_colour'], $config['x_axis_colour_inner']);
  231. $chart->set_x_axis( $x );
  232. $x_legend = new x_legend( JText::_('COM_JOOMLEAGUE_CURVE_ROUNDS') );
  233. $x_legend->set_style( '{font-size: 15px; color: #778877}' );
  234. $chart->set_x_legend( $x_legend );
  235. $y = new y_axis();
  236. $y->set_range( count($data), 1, -1);
  237. $y->set_colours($config['x_axis_colour'], $config['x_axis_colour_inner']);
  238. $chart->set_y_axis( $y );
  239. $y_legend = new y_legend( JText::_('COM_JOOMLEAGUE_CURVE_RANK') );
  240. $y_legend->set_style( '{font-size: 15px; color: #778877}' );
  241. $chart->set_y_legend( $y_legend );
  242. $this->assignRef( 'chartdata_'.$division->id, $chart);
  243. unset($chart);
  244. }
  245. }
  246. }
  247. function hline($color, $length, $ypoint, $linewidth)
  248. {
  249. $hline = new shape( $color );
  250. $hline->append_value( new shape_point( -0.5, $ypoint) );
  251. $hline->append_value( new shape_point( -0.5, $ypoint + $linewidth ) );
  252. $hline->append_value( new shape_point( $length, $ypoint + $linewidth) );
  253. $hline->append_value( new shape_point( $length, $ypoint ) );
  254. return $hline;
  255. }
  256. ?>