PageRenderTime 62ms CodeModel.GetById 11ms RepoModel.GetById 1ms app.codeStats 0ms

/com_joomleague/administrator/components/com_joomleague/views/match/view.html.php

https://gitlab.com/julienv/joomleague
PHP | 686 lines | 540 code | 79 blank | 67 comment | 98 complexity | 9be08d20f1ce88820b9463f37ccd3e15 MD5 | raw file
  1. <?php
  2. /**
  3. * @copyright Copyright (C) 2006-2014 joomleague.at. All rights reserved.
  4. * @license GNU/GPL,see LICENSE.php
  5. * Joomla! is free software. This version may have been modified pursuant
  6. * to the GNU General Public License,and as distributed it includes or
  7. * is derivative of works licensed under the GNU General Public License or
  8. * other free or open source software licenses.
  9. * See COPYRIGHT.php for copyright notices and details.
  10. */
  11. // Check to ensure this file is included in Joomla!
  12. defined ( '_JEXEC' ) or die ( 'Restricted access' );
  13. jimport ( 'joomla.application.component.view' );
  14. jimport ( 'joomla.filesystem.file' );
  15. JHtml::_ ( 'behavior.framework' );
  16. /**
  17. * HTML View class for the Joomleague component
  18. *
  19. * @author Marco Vaninetti <martizva@tiscali.it>
  20. * @package JoomLeague
  21. * @since 0.1
  22. */
  23. class JoomleagueViewMatch extends JLGView {
  24. function display($tpl = null) {
  25. if ($this->getLayout () == 'form') {
  26. $this->_displayForm ( $tpl );
  27. return;
  28. } elseif ($this->getLayout () == 'editevents') {
  29. $this->_displayEditevents ( $tpl );
  30. return;
  31. } elseif ($this->getLayout () == 'editeventsbb') {
  32. $this->_displayEditeventsbb ( $tpl );
  33. return;
  34. } elseif ($this->getLayout () == 'editstats') {
  35. $this->_displayEditstats ( $tpl );
  36. return;
  37. } elseif ($this->getLayout () == 'editlineup') {
  38. $this->_displayEditlineup ( $tpl );
  39. return;
  40. } elseif ($this->getLayout () == 'editreferees') {
  41. $this->_displayEditReferees ( $tpl );
  42. return;
  43. }
  44. parent::display ( $tpl );
  45. }
  46. function _displayEditReferees($tpl) {
  47. $option = JRequest::getCmd ( 'option' );
  48. $mainframe = JFactory::getApplication ();
  49. $document = JFactory::getDocument ();
  50. $project_id = $mainframe->getUserState ( $option . 'project' );
  51. $params = JComponentHelper::getParams ( $option );
  52. $default_name_format = $params->get ( "name_format" );
  53. // add the js script
  54. $version = urlencode ( JoomleagueHelper::getVersion () );
  55. $document->addScript ( JUri::base () . 'components/com_joomleague/assets/js/startinglineup.js?v=' . $version );
  56. $model = $this->getModel ();
  57. $match = $this->get ( 'data' );
  58. $allreferees = array ();
  59. $allreferees = $model->getRefereeRoster ();
  60. $inroster = array ();
  61. $projectreferees = array ();
  62. $projectreferees2 = array ();
  63. if (isset ( $allreferees )) {
  64. foreach ( $allreferees as $referee ) {
  65. $inroster [] = $referee->value;
  66. }
  67. }
  68. $projectreferees = $model->getProjectReferees ( $inroster, $project_id );
  69. if (count ( $projectreferees ) > 0) {
  70. foreach ( $projectreferees as $referee ) {
  71. $projectreferees2 [] = JHtml::_ ( 'select.option', $referee->value, JoomleagueHelper::formatName ( null, $referee->firstname, $referee->nickname, $referee->lastname, $default_name_format ) . ' - (' . strtolower ( JText::_ ( $referee->positionname ) ) . ')' );
  72. }
  73. }
  74. $lists ['team_referees'] = JHtml::_ ( 'select.genericlist', $projectreferees2, 'roster[]', 'style="font-size:12px;height:auto;min-width:15em;" ' . 'class="inputbox" multiple="true" size="' . max ( 10, count ( $projectreferees2 ) ) . '"', 'value', 'text' );
  75. $selectpositions [] = JHtml::_ ( 'select.option', '0', JText::_ ( 'COM_JOOMLEAGUE_GLOBAL_SELECT_REF_FUNCTION' ) );
  76. if ($projectpositions = $model->getProjectPositionsOptions ( 0, 3 )) {
  77. $selectpositions = array_merge ( $selectpositions, $projectpositions );
  78. }
  79. $lists ['projectpositions'] = JHtml::_ ( 'select.genericlist', $selectpositions, 'project_position_id', 'class="inputbox" size="1"', 'value', 'text' );
  80. $squad = array ();
  81. if (! $projectpositions) {
  82. JError::raiseWarning ( 440, '<br />' . JText::_ ( 'COM_JOOMLEAGUE_ADMIN_MATCH_NO_REF_POS' ) . '<br /><br />' );
  83. return;
  84. }
  85. // generate selection list for each position
  86. foreach ( $projectpositions as $key => $pos ) {
  87. // get referees assigned to this position
  88. $squad [$key] = $model->getRefereeRoster ( $pos->value );
  89. }
  90. if (count ( $squad ) > 0) {
  91. foreach ( $squad as $key => $referees ) {
  92. $temp [$key] = array ();
  93. if (isset ( $referees )) {
  94. foreach ( $referees as $referee ) {
  95. $temp [$key] [] = JHtml::_ ( 'select.option', $referee->value, JoomleagueHelper::formatName ( null, $referee->firstname, $referee->nickname, $referee->lastname, $default_name_format ) );
  96. }
  97. }
  98. $lists ['team_referees' . $key] = JHtml::_ ( 'select.genericlist', $temp [$key], 'position' . $key . '[]', 'id="testing" style="font-size:12px;height:auto;min-width:15em;" ' . 'class="inputbox position-starters" multiple="true" ', 'value', 'text' );
  99. }
  100. }
  101. $this->assignRef ( 'project_id', $project_id );
  102. $this->assignRef ( 'match', $match );
  103. $this->assignRef ( 'positions', $projectpositions );
  104. $this->assignRef ( 'lists', $lists );
  105. parent::display ( $tpl );
  106. }
  107. function _displayEditevents($tpl) {
  108. $option = JRequest::getCmd ( 'option' );
  109. $mainframe = JFactory::getApplication ();
  110. $project_id = $mainframe->getUserState ( $option . 'project' );
  111. $document = JFactory::getDocument ();
  112. $tid = JRequest::getVar ( 'team', '0' );
  113. $params = JComponentHelper::getParams ( $option );
  114. $default_name_format = $params->get ( "name_format", 14 );
  115. $default_name_dropdown_list_order = $params->get ( "cfg_be_name_dropdown_list_order", "lastname" );
  116. // add the js script
  117. $version = urlencode ( JoomleagueHelper::getVersion () );
  118. $document->addScript ( JUri::base () . 'components/com_joomleague/assets/js/editevents.js?v=' . $version );
  119. $model = $this->getModel ();
  120. $teams = $model->getMatchTeams ();
  121. if (is_null ( $teams )) {
  122. JError::raiseWarning ( 440, '<br />' . JText::_ ( 'COM_JOOMLEAGUE_ADMIN_MATCH_NO_TEAM_MATCH' ) . '<br /><br />' );
  123. return false;
  124. }
  125. $teamname = ($tid == $teams->projectteam1_id) ? $teams->team1 : $teams->team2;
  126. $this->_handlePreFillRoster ( $teams, $model, $params, $teams->projectteam1_id, $teamname );
  127. $this->_handlePreFillRoster ( $teams, $model, $params, $teams->projectteam2_id, $teamname );
  128. $homeRoster = $model->getTeamPlayers ( $teams->projectteam1_id, false, $default_name_dropdown_list_order );
  129. if (count ( $homeRoster ) == 0) {
  130. $homeRoster = $model->getGhostPlayer ();
  131. }
  132. $awayRoster = $model->getTeamPlayers ( $teams->projectteam2_id, false, $default_name_dropdown_list_order );
  133. if (count ( $awayRoster ) == 0) {
  134. $awayRoster = $model->getGhostPlayer ();
  135. }
  136. $rosters = array (
  137. 'home' => $homeRoster,
  138. 'away' => $awayRoster
  139. );
  140. $matchevents = & $model->getMatchEvents ();
  141. $project_model = $this->getModel ( 'project' );
  142. $lists = array ();
  143. // teams
  144. $teamlist = array ();
  145. $teamlist [] = JHtml::_ ( 'select.option', $teams->projectteam1_id, $teams->team1 );
  146. $teamlist [] = JHtml::_ ( 'select.option', $teams->projectteam2_id, $teams->team2 );
  147. $lists ['teams'] = JHtml::_ ( 'select.genericlist', $teamlist, 'team_id', 'class="inputbox select-team"' );
  148. // events
  149. $events = $model->getEventsOptions ( $project_id );
  150. if (! $events) {
  151. JError::raiseWarning ( 440, '<br />' . JText::_ ( 'COM_JOOMLEAGUE_ADMIN_MATCH_NO_EVENTS_POS' ) . '<br /><br />' );
  152. return false;
  153. }
  154. $eventlist = array ();
  155. $eventlist = array_merge ( $eventlist, $events );
  156. $lists ['events'] = JHtml::_ ( 'select.genericlist', $eventlist, 'event_type_id', 'class="inputbox select-event"' );
  157. $this->assignRef ( 'overall_config', $project_model->getTemplateConfig ( 'overall' ) );
  158. $this->assignRef ( 'lists', $lists );
  159. $this->assignRef ( 'rosters', $rosters );
  160. $this->assignRef ( 'teams', $teams );
  161. $this->assignRef ( 'matchevents', $matchevents );
  162. $this->assignRef ( 'default_name_format', $default_name_format );
  163. $this->assignRef ( 'default_name_dropdown_list_order', $default_name_dropdown_list_order );
  164. parent::display ( $tpl );
  165. }
  166. function _displayEditeventsbb($tpl) {
  167. $option = JRequest::getCmd ( 'option' );
  168. $mainframe = JFactory::getApplication ();
  169. $project_id = $mainframe->getUserState ( $option . 'project' );
  170. $document = JFactory::getDocument ();
  171. $params = JComponentHelper::getParams ( $option );
  172. $default_name_format = $params->get ( "name_format", 14 );
  173. $default_name_dropdown_list_order = $params->get ( "cfg_be_name_dropdown_list_order", "lastname" );
  174. $tid = JRequest::getVar ( 'team', '0' );
  175. $model = $this->getModel ();
  176. $teams = $model->getMatchTeams ();
  177. if (is_null ( $teams )) {
  178. JError::raiseWarning ( 440, '<br />' . JText::_ ( 'COM_JOOMLEAGUE_ADMIN_MATCH_NO_TEAM_MATCH' ) . '<br /><br />' );
  179. return false;
  180. }
  181. // events
  182. $events = $model->getEventsOptions ( $project_id );
  183. if (! $events) {
  184. $msg = '<br />' . JText::_ ( 'COM_JOOMLEAGUE_ADMIN_MATCH_NO_EVENTS_POS' ) . '<br /><br />';
  185. $mainframe->enqueueMessage ( $msg, 'warning' );
  186. $this->addToolbar_Editeventsbb ( false );
  187. return false;
  188. }
  189. $homeRoster = $model->getTeamPlayers ( $teams->projectteam1_id, false, $default_name_dropdown_list_order );
  190. if (count ( $homeRoster ) == 0) {
  191. $homeRoster = $model->getGhostPlayerbb ( $teams->projectteam1_id );
  192. }
  193. $awayRoster = $model->getTeamPlayers ( $teams->projectteam2_id, false, $default_name_dropdown_list_order );
  194. if (count ( $awayRoster ) == 0) {
  195. $awayRoster = $model->getGhostPlayerbb ( $teams->projectteam2_id );
  196. }
  197. $this->assignRef ( 'homeRoster', $homeRoster );
  198. $this->assignRef ( 'awayRoster', $awayRoster );
  199. $this->assignRef ( 'teams', $teams );
  200. $this->assignRef ( 'events', $events );
  201. $this->assignRef ( 'default_name_format', $default_name_format );
  202. $this->assignRef ( 'default_name_dropdown_list_order', $default_name_dropdown_list_order );
  203. $this->addToolbar_Editeventsbb ();
  204. parent::display ( $tpl );
  205. }
  206. /**
  207. * Add the page title and toolbar.
  208. *
  209. * @since 1.7
  210. */
  211. protected function addToolbar_Editeventsbb($showSave = true) {
  212. // set toolbar items for the page
  213. JToolBarHelper::title ( JText::_ ( 'COM_JOOMLEAGUE_ADMIN_MATCH_EEBB_TITLE' ), 'events' );
  214. if ($showSave) {
  215. JLToolBarHelper::apply ( 'match.saveeventbb' );
  216. }
  217. JToolBarHelper::divider ();
  218. JToolBarHelper::back ( 'back', 'index.php?option=com_joomleague&view=matches&task=match.display' );
  219. JToolBarHelper::help ( 'screen.joomleague', true );
  220. }
  221. function _displayEditstats($tpl) {
  222. $option = JRequest::getCmd ( 'option' );
  223. $mainframe = JFactory::getApplication ();
  224. $project_id = $mainframe->getUserState ( $option . 'project' );
  225. $document = JFactory::getDocument ();
  226. $params = JComponentHelper::getParams ( $option );
  227. $default_name_format = $params->get ( "name_format" );
  228. $tid = JRequest::getVar ( 'team', '0' );
  229. // add the js script
  230. $version = urlencode ( JoomleagueHelper::getVersion () );
  231. $document->addScript ( JUri::base () . 'components/com_joomleague/assets/js/editmatchstats.js?v=' . $version );
  232. $model = $this->getModel ();
  233. $match = $this->get ( 'data' );
  234. $teams = $model->getMatchTeams ();
  235. if (is_null ( $teams )) {
  236. JError::raiseWarning ( 440, '<br />' . JText::_ ( 'COM_JOOMLEAGUE_ADMIN_MATCH_NO_TEAM_MATCH' ) . '<br /><br />' );
  237. return false;
  238. }
  239. $positions = $this->get ( 'ProjectPositions' );
  240. $staffpositions = $this->get ( 'ProjectStaffPositions' );
  241. $homeRoster = $model->getMatchPlayers ( $teams->projectteam1_id );
  242. if (count ( $homeRoster ) == 0) {
  243. $homeRoster = $model->getGhostPlayerbb ( $teams->projectteam1_id );
  244. }
  245. $awayRoster = $model->getMatchPlayers ( $teams->projectteam2_id );
  246. if (count ( $awayRoster ) == 0) {
  247. $awayRoster = $model->getGhostPlayerbb ( $teams->projectteam2_id );
  248. }
  249. $homeStaff = $model->getMatchStaffs ( $teams->projectteam1_id );
  250. $awayStaff = $model->getMatchStaffs ( $teams->projectteam2_id );
  251. // stats
  252. $stats = $model->getInputStats ();
  253. if (! $stats) {
  254. JError::raiseWarning ( 440, '<br />' . JText::_ ( 'COM_JOOMLEAGUE_ADMIN_MATCH_NO_STATS_POS' ) . '<br /><br />' );
  255. return false;
  256. }
  257. $playerstats = $model->getMatchStatsInput ();
  258. $staffstats = $model->getMatchStaffStatsInput ();
  259. $this->assignRef ( 'homeRoster', $homeRoster );
  260. $this->assignRef ( 'awayRoster', $awayRoster );
  261. $this->assignRef ( 'homeStaff', $homeStaff );
  262. $this->assignRef ( 'awayStaff', $awayStaff );
  263. $this->assignRef ( 'teams', $teams );
  264. $this->assignRef ( 'stats', $stats );
  265. $this->assignRef ( 'playerstats', $playerstats );
  266. $this->assignRef ( 'staffstats', $staffstats );
  267. $this->assignRef ( 'match', $match );
  268. $this->assignRef ( 'positions', $positions );
  269. $this->assignRef ( 'staffpositions', $staffpositions );
  270. $this->assignRef ( 'default_name_format', $default_name_format );
  271. parent::display ( $tpl );
  272. }
  273. function _displayEditlineup($tpl) {
  274. $option = JRequest::getCmd ( 'option' );
  275. $mainframe = JFactory::getApplication ();
  276. $project_id = $mainframe->getUserState ( $option . 'project' );
  277. $document = JFactory::getDocument ();
  278. $tid = JRequest::getVar ( 'team', '0' );
  279. $params = JComponentHelper::getParams ( $option );
  280. $default_name_format = $params->get ( "name_format" );
  281. $default_name_dropdown_list_order = $params->get ( "cfg_be_name_dropdown_list_order", "lastname" );
  282. // add the js script
  283. $version = urlencode ( JoomleagueHelper::getVersion () );
  284. $document->addScript ( JUri::base () . 'components/com_joomleague/assets/js/startinglineup.js?v=' . $version );
  285. $model = $this->getModel ();
  286. $teams = $model->getMatchTeams ();
  287. if (is_null ( $teams )) {
  288. JError::raiseWarning ( 440, '<br />' . JText::_ ( 'COM_JOOMLEAGUE_ADMIN_MATCH_NO_TEAM_MATCH' ) . '<br /><br />' );
  289. return false;
  290. }
  291. $teamname = ($tid == $teams->projectteam1_id) ? $teams->team1 : $teams->team2;
  292. $this->_handlePreFillRoster ( $teams, $model, $params, $tid, $teamname );
  293. // get starters
  294. $starters = $model->getRoster ( $tid );
  295. $starters_id = array_keys ( $starters );
  296. // get players not already assigned to starter
  297. $not_assigned = $model->getTeamPlayers ( $tid, $starters_id, $default_name_dropdown_list_order );
  298. if (! $not_assigned && ! $starters_id) {
  299. JError::raiseWarning ( 440, '<br />' . JText::_ ( 'COM_JOOMLEAGUE_ADMIN_MATCH_NO_PLAYERS_MATCH' ) . '<br /><br />' );
  300. return false;
  301. }
  302. $projectpositions = & $model->getProjectPositions ();
  303. if (! $projectpositions) {
  304. JError::raiseWarning ( 440, '<br />' . JText::_ ( 'COM_JOOMLEAGUE_ADMIN_MATCH_NO_POS' ) . '<br /><br />' );
  305. return false;
  306. }
  307. // build select list for not assigned players
  308. $not_assigned_options = array ();
  309. foreach ( ( array ) $not_assigned as $p ) {
  310. if ($p->jerseynumber > 0) {
  311. $jerseynumber = '[' . $p->jerseynumber . '] ';
  312. } else {
  313. $jerseynumber = '';
  314. }
  315. switch ($default_name_dropdown_list_order) {
  316. case 'lastname' :
  317. case 'firstname' :
  318. $not_assigned_options [] = JHtml::_ ( 'select.option', $p->value, $jerseynumber . JoomleagueHelper::formatName ( null, $p->firstname, $p->nickname, $p->lastname, $default_name_format ) );
  319. break;
  320. case 'position' :
  321. $not_assigned_options [] = JHtml::_ ( 'select.option', $p->value, '(' . JText::_ ( $p->positionname ) . ') - ' . $jerseynumber . JoomleagueHelper::formatName ( null, $p->firstname, $p->nickname, $p->lastname, $default_name_format ) );
  322. break;
  323. }
  324. }
  325. $lists ['team_players'] = JHtml::_ ( 'select.genericlist', $not_assigned_options, 'roster[]', 'style="font-size:12px;height:auto;min-width:15em;" class="inputbox" multiple="true" size="18"', 'value', 'text' );
  326. // build position select
  327. $selectpositions [] = JHtml::_ ( 'select.option', '0', JText::_ ( 'COM_JOOMLEAGUE_GLOBAL_SELECT_IN_POSITION' ) );
  328. $selectpositions = array_merge ( $selectpositions, $model->getProjectPositionsOptions ( 0, 1 ) );
  329. $lists ['projectpositions'] = JHtml::_ ( 'select.genericlist', $selectpositions, 'project_position_id', 'class="inputbox" size="1"', 'value', 'text', NULL, false, true );
  330. // build player select for substitutions
  331. // starters + came in (because of multiple substitutions possibility in amateur soccer clubs for example)
  332. $substitutions = $model->getSubstitutions ( $tid );
  333. $starters = array_merge ( $starters, $substitutions [$tid] );
  334. // not assigned players + went out (because of multiple substitutions possibility in amateur soccer clubs for example)
  335. $not_assigned = array_merge ( $not_assigned, $substitutions [$tid] );
  336. // filter out duplicates $starters
  337. $new_starters = array ();
  338. $exclude = array (
  339. ""
  340. );
  341. for($i = 0; $i <= count ( $starters ) - 1; $i ++) {
  342. if (! in_array ( trim ( $starters [$i]->value ), $exclude )) {
  343. $new_starters [] = $starters [$i];
  344. $exclude [] = trim ( $starters [$i]->value );
  345. }
  346. }
  347. // filter out duplicates $not_assigned
  348. $new_not_assigned = array ();
  349. $exclude = array (
  350. ""
  351. );
  352. for($i = 0; $i <= count ( $not_assigned ) - 1; $i ++) {
  353. if (array_key_exists ( 'came_in', $not_assigned [$i] ) && $not_assigned [$i]->came_in == 1) {
  354. if (! in_array ( trim ( $not_assigned [$i]->in_for ), $exclude )) {
  355. $new_not_assigned [] = $not_assigned [$i];
  356. $exclude [] = trim ( $not_assigned [$i]->in_for );
  357. }
  358. } elseif (! array_key_exists ( 'came_in', $not_assigned [$i] )) {
  359. if (! in_array ( trim ( $not_assigned [$i]->value ), $exclude )) {
  360. $new_not_assigned [] = $not_assigned [$i];
  361. $exclude [] = trim ( $not_assigned [$i]->value );
  362. }
  363. }
  364. }
  365. // echo "<pre>";
  366. // echo var_dump($new_not_assigned);
  367. // echo "</pre>";
  368. $playersoptions_subs_out = array ();
  369. $playersoptions_subs_out [] = JHtml::_ ( 'select.option', '0', JText::_ ( 'COM_JOOMLEAGUE_GLOBAL_SELECT_PLAYER' ) );
  370. $i = 0;
  371. foreach ( ( array ) $new_starters as $player ) {
  372. switch ($default_name_dropdown_list_order) {
  373. case 'lastname' :
  374. case 'firstname' :
  375. if (array_key_exists ( 'came_in', $player )) {
  376. $i ++;
  377. if ($i == 1) {
  378. $playersoptions_subs_out[]=JHtml::_('select.option','0',JText::_('COM_JOOMLEAGUE_ADMIN_MATCH_ELUSUBST_SELECT_PLAYER_ALREADY_IN'));
  379. }
  380. }
  381. $playersoptions_subs_out [] = JHtml::_ ( 'select.option', $player->value, JoomleagueHelper::formatName ( null, $player->firstname, $player->nickname, $player->lastname, $default_name_format ) );
  382. break;
  383. case 'position' :
  384. if (array_key_exists ( 'came_in', $player )) {
  385. $i ++;
  386. if ($i == 1) {
  387. $playersoptions_subs_out[]=JHtml::_('select.option','0',JText::_('COM_JOOMLEAGUE_ADMIN_MATCH_ELUSUBST_SELECT_PLAYER_ALREADY_IN'));
  388. }
  389. }
  390. $playersoptions_subs_out [] = JHtml::_ ( 'select.option', $player->value, '(' . JText::_ ( $player->positionname ) . ') - ' . JoomleagueHelper::formatName ( null, $player->firstname, $player->nickname, $player->lastname, $default_name_format ) );
  391. break;
  392. }
  393. }
  394. $playersoptions_subs_in = array ();
  395. $playersoptions_subs_in [] = JHtml::_ ( 'select.option', '0', JText::_ ( 'COM_JOOMLEAGUE_GLOBAL_SELECT_PLAYER' ) );
  396. $i = 0;
  397. foreach ( ( array ) $new_not_assigned as $player ) {
  398. switch ($default_name_dropdown_list_order) {
  399. case 'lastname' :
  400. case 'firstname' :
  401. if (array_key_exists ( 'came_in', $player ) && $player->came_in == 1 && $player->in_for > 0) {
  402. $i ++;
  403. if ($i == 1) {
  404. $playersoptions_subs_in[]=JHtml::_('select.option','0',JText::_('COM_JOOMLEAGUE_ADMIN_MATCH_ELUSUBST_SELECT_PLAYER_ALREADY_OUT'));
  405. }
  406. $playersoptions_subs_in [] = JHtml::_ ( 'select.option', $player->in_for, JoomleagueHelper::formatName ( null, $player->out_firstname, $player->out_nickname, $player->out_lastname, $default_name_format ) );
  407. } elseif (! array_key_exists ( 'came_in', $player )) {
  408. $playersoptions_subs_in [] = JHtml::_ ( 'select.option', $player->value, JoomleagueHelper::formatName ( null, $player->firstname, $player->nickname, $player->lastname, $default_name_format ) );
  409. }
  410. break;
  411. case 'position' :
  412. if (array_key_exists ( 'came_in', $player ) && $player->came_in == 1 && $player->in_for > 0) {
  413. $i ++;
  414. if ($i == 1) {
  415. $playersoptions_subs_in[]=JHtml::_('select.option','0',JText::_('COM_JOOMLEAGUE_ADMIN_MATCH_ELUSUBST_SELECT_PLAYER_ALREADY_OUT'));
  416. }
  417. $playersoptions_subs_in [] = JHtml::_ ( 'select.option', $player->in_for, '(' . JText::_ ( $player->positionname_out ) . ') - ' . JoomleagueHelper::formatName ( null, $player->out_firstname, $player->out_nickname, $player->out_lastname, $default_name_format ) );
  418. } elseif (! array_key_exists ( 'came_in', $player )) {
  419. $playersoptions_subs_in [] = JHtml::_ ( 'select.option', $player->value, '(' . JText::_ ( $player->positionname ) . ') - ' . JoomleagueHelper::formatName ( null, $player->firstname, $player->nickname, $player->lastname, $default_name_format ) );
  420. }
  421. break;
  422. }
  423. }
  424. // $lists['all_players']=JHtml::_( 'select.genericlist',$playersoptions,'roster[]',
  425. // 'id="roster" style="font-size:12px;height:auto;min-width:15em;" class="inputbox" size="4"',
  426. // 'value','text');
  427. // generate selection list for each position
  428. $starters = array ();
  429. foreach ( $projectpositions as $position_id => $pos ) {
  430. // get players assigned to this position
  431. $starters [$position_id] = $model->getRoster ( $tid, $pos->pposid );
  432. }
  433. foreach ( $starters as $position_id => $players ) {
  434. $options = array ();
  435. foreach ( ( array ) $players as $p ) {
  436. if ($p->jerseynumber > 0) {
  437. $jerseynumber = '[' . $p->jerseynumber . '] ';
  438. } else {
  439. $jerseynumber = '';
  440. }
  441. $options [] = JHtml::_ ( 'select.option', $p->value, $jerseynumber . JoomleagueHelper::formatName ( null, $p->firstname, $p->nickname, $p->lastname, $default_name_format ) );
  442. }
  443. $lists ['team_players' . $position_id] = JHtml::_ ( 'select.genericlist', $options, 'position' . $position_id . '[]', 'style="font-size:12px;height:auto;min-width:15em;" size="4" class="inputbox position-starters" multiple="true" ', 'value', 'text' );
  444. }
  445. /**
  446. * staff positions
  447. */
  448. $staffpositions = & $model->getProjectStaffPositions (); // get staff not already assigned to starter
  449. // echo '<pre>'.print_r($staffpositions,true).'</pre>';
  450. // assigned staff
  451. $assigned = $model->getMatchStaffs ( $tid );
  452. $assigned_id = array_keys ( $assigned );
  453. // not assigned staff
  454. $not_assigned = $model->getTeamStaffs ( $tid, $assigned_id, $default_name_dropdown_list_order );
  455. // build select list for not assigned
  456. $not_assigned_options = array ();
  457. foreach ( ( array ) $not_assigned as $p ) {
  458. switch ($default_name_dropdown_list_order) {
  459. case 'lastname' :
  460. case 'firstname' :
  461. $not_assigned_options [] = JHtml::_ ( 'select.option', $p->value, JoomleagueHelper::formatName ( null, $p->firstname, $p->nickname, $p->lastname, $default_name_format ) );
  462. break;
  463. case 'position' :
  464. $not_assigned_options [] = JHtml::_ ( 'select.option', $p->value, '(' . JText::_ ( $p->positionname ) . ') - ' . JoomleagueHelper::formatName ( null, $p->firstname, $p->nickname, $p->lastname, $default_name_format ) );
  465. break;
  466. }
  467. }
  468. $lists ['team_staffs'] = JHtml::_ ( 'select.genericlist', $not_assigned_options, 'staff[]', 'style="font-size:12px;height:auto;min-width:15em;" size="18" class="inputbox" multiple="true" size="18"', 'value', 'text' );
  469. // generate selection list for each position
  470. $options = array ();
  471. foreach ( $staffpositions as $position_id => $pos ) {
  472. // get players assigned to this position
  473. $options = array ();
  474. foreach ( $assigned as $staff ) {
  475. if ($staff->project_position_id == $pos->pposid) {
  476. $options [] = JHtml::_ ( 'select.option', $staff->team_staff_id, JoomleagueHelper::formatName ( null, $staff->firstname, $staff->nickname, $staff->lastname, $default_name_format ) );
  477. }
  478. }
  479. $lists ['team_staffs' . $position_id] = JHtml::_ ( 'select.genericlist', $options, 'staffposition' . $position_id . '[]', 'style="font-size:12px;height:auto;min-width:15em;" size="4" class="inputbox position-staff" multiple="true" ', 'value', 'text' );
  480. }
  481. $this->assignRef ( 'match', $teams );
  482. $this->assignRef ( 'tid', $tid );
  483. $this->assignRef ( 'teamname', $teamname );
  484. $this->assignRef ( 'positions', $projectpositions );
  485. $this->assignRef ( 'staffpositions', $staffpositions );
  486. $this->assignRef ( 'substitutions', $substitutions [$tid] );
  487. $this->assignRef ( 'playersoptions_subs_out', $playersoptions_subs_out );
  488. $this->assignRef ( 'playersoptions_subs_in', $playersoptions_subs_in );
  489. $this->assignRef ( 'lists', $lists );
  490. $this->assignRef ( 'default_name_format', $default_name_format );
  491. $this->assignRef ( 'default_name_dropdown_list_order', $default_name_dropdown_list_order );
  492. parent::display ( $tpl );
  493. }
  494. function _displayForm($tpl) {
  495. $mainframe = JFactory::getApplication ();
  496. $option = JRequest::getCmd ( 'option' );
  497. $user = JFactory::getUser ();
  498. $model = $this->getModel ();
  499. $lists = array ();
  500. // get the match
  501. $match = $this->get ( 'data' );
  502. $isNew = ($match->id < 1);
  503. if ((! $match->projectteam1_id) and (! $match->projectteam2_id)) {
  504. JError::raiseWarning ( 440, '<br />' . JText::_ ( 'COM_JOOMLEAGUE_ADMIN_MATCH_NO_TEAMS' ) . '<br /><br />' );
  505. return false;
  506. }
  507. // fail if checked out not by 'me'
  508. if ($model->isCheckedOut ( $user->get ( 'id' ) )) {
  509. $msg = JText::sprintf ( 'DESCBEINGEDITTED', JText::_ ( 'COM_JOOMLEAGUE_ADMIN_MATCH_THE_MATCH' ), $match->name );
  510. $mainframe->redirect ( 'index.php?option=com_joomleague', $msg );
  511. }
  512. // Edit or Create?
  513. if (! $isNew) {
  514. $model->checkout ( $user->get ( 'id' ) );
  515. }
  516. // build the html select booleanlist for published
  517. $lists ['published'] = JHtml::_ ( 'select.booleanlist', 'published', 'class="inputbox"', $match->published );
  518. // get the home team standard playground
  519. $tblProjectHomeTeam = JTable::getInstance ( 'Projectteam', 'table' );
  520. $tblProjectHomeTeam->load ( $match->projectteam1_id );
  521. $standard_playground_id = (! empty ( $tblProjectHomeTeam->standard_playground ) && $tblProjectHomeTeam->standard_playground > 0) ? $tblProjectHomeTeam->standard_playground : null;
  522. $playground_id = (! empty ( $match->playground_id ) && ($match->playground_id > 0)) ? $match->playground_id : $standard_playground_id;
  523. // build the html select booleanlist for count match result
  524. $lists ['count_result'] = JHtml::_ ( 'select.booleanlist', 'count_result', 'class="inputbox"', $match->count_result );
  525. // build the html select booleanlist which team got the won
  526. $myoptions = array ();
  527. $myoptions [] = JHtml::_ ( 'select.option', '0', JText::_ ( 'COM_JOOMLEAGUE_ADMIN_MATCHES_NO_TEAM' ) );
  528. $myoptions [] = JHtml::_ ( 'select.option', '1', JText::_ ( 'COM_JOOMLEAGUE_ADMIN_MATCHES_HOME_TEAM' ) );
  529. $myoptions [] = JHtml::_ ( 'select.option', '2', JText::_ ( 'COM_JOOMLEAGUE_ADMIN_MATCHES_AWAY_TEAM' ) );
  530. $myoptions [] = JHtml::_ ( 'select.option', '3', JText::_ ( 'COM_JOOMLEAGUE_ADMIN_MATCHES_LOSS_BOTH_TEAMS' ) );
  531. $myoptions [] = JHtml::_ ( 'select.option', '4', JText::_ ( 'COM_JOOMLEAGUE_ADMIN_MATCHES_WON_BOTH_TEAMS' ) );
  532. $lists ['team_won'] = JHtml::_ ( 'select.genericlist', $myoptions, 'team_won', 'class="inputbox" size="1"', 'value', 'text', $match->team_won );
  533. $projectws = $this->get ( 'Data', 'project' );
  534. $model = $this->getModel ( 'project' );
  535. $overall_config = $model->getTemplateConfig ( 'overall' );
  536. $table_config = $model->getTemplateConfig ( 'ranking' );
  537. $extended = $this->getExtended ( $match->extended, 'match' );
  538. // match relation tab
  539. $mdlMatch = JModelLegacy::getInstance ( 'match', 'JoomleagueModel' );
  540. $oldmatches [] = JHtml::_ ( 'select.option', '0', JText::_ ( 'COM_JOOMLEAGUE_ADMIN_MATCH_OLD_MATCH' ) );
  541. $res = array ();
  542. $new_match_id = ($match->new_match_id) ? $match->new_match_id : 0;
  543. if ($res = & $mdlMatch->getMatchRelationsOptions ( $mainframe->getUserState ( $option . 'project', 0 ), $match->id . "," . $new_match_id )) {
  544. foreach ( $res as $m ) {
  545. $m->text = '(' . JoomleagueHelper::getMatchStartTimestamp ( $m ) . ') - ' . $m->t1_name . ' - ' . $m->t2_name;
  546. }
  547. $oldmatches = array_merge ( $oldmatches, $res );
  548. }
  549. $lists ['old_match'] = JHtml::_ ( 'select.genericlist', $oldmatches, 'old_match_id', 'class="inputbox" size="1"', 'value', 'text', $match->old_match_id );
  550. $newmatches [] = JHtml::_ ( 'select.option', '0', JText::_ ( 'COM_JOOMLEAGUE_ADMIN_MATCH_NEW_MATCH' ) );
  551. $res = array ();
  552. $old_match_id = ($match->old_match_id) ? $match->old_match_id : 0;
  553. if ($res = & $mdlMatch->getMatchRelationsOptions ( $mainframe->getUserState ( $option . 'project', 0 ), $match->id . "," . $old_match_id )) {
  554. foreach ( $res as $m ) {
  555. $m->text = '(' . JoomleagueHelper::getMatchStartTimestamp ( $m ) . ') - ' . $m->t1_name . ' - ' . $m->t2_name;
  556. }
  557. $newmatches = array_merge ( $newmatches, $res );
  558. }
  559. $lists ['new_match'] = JHtml::_ ( 'select.genericlist', $newmatches, 'new_match_id', 'class="inputbox" size="1"', 'value', 'text', $match->new_match_id );
  560. $this->assignRef ( 'overall_config', $overall_config );
  561. $this->assignRef ( 'table_config', $table_config );
  562. $this->assignRef ( 'projectws', $projectws );
  563. $this->assignRef ( 'lists', $lists );
  564. $this->assignRef ( 'match', $match );
  565. $this->assignRef ( 'extended', $extended );
  566. $form = $this->get ( 'form' );
  567. $form->setValue ( 'playground_id', null, $playground_id );
  568. $this->assignRef ( 'form', $form );
  569. parent::display ( $tpl );
  570. }
  571. protected function _handlePreFillRoster(&$teams, &$model, &$params, &$tid, &$teamname) {
  572. if ($params->get ( 'use_prefilled_match_roster' ) > 0) {
  573. $bDeleteCurrrentRoster = $params->get ( 'on_prefill_delete_current_match_roster', 0 );
  574. $prefillType = JRequest::getInt ( 'prefill', 0 );
  575. if ($prefillType == 0) {
  576. $prefillType = $params->get ( 'use_prefilled_match_roster' );
  577. }
  578. $projectteam_id = ($tid == $teams->projectteam1_id) ? $teams->projectteam1_id : $teams->projectteam2_id;
  579. if ($prefillType == 2) {
  580. $preFillSuccess = false;
  581. if (! $model->prefillMatchPlayersWithProjectteamPlayers ( $projectteam_id, $bDeleteCurrrentRoster )) {
  582. if ($model->getError () != '') {
  583. JError::raiseWarning ( 440, '<br />' . $model->getError () . '<br /><br />' );
  584. return false;
  585. } else {
  586. $preFillSuccess = false;
  587. }
  588. } else {
  589. $preFillSuccess = true;
  590. }
  591. } elseif ($prefillType == 1) {
  592. if (! $model->prefillMatchPlayersWithLastMatch ( $projectteam_id, $bDeleteCurrrentRoster )) {
  593. if ($model->getError () != '') {
  594. JError::raiseWarning ( 440, '<br />' . $model->getError () . '<br /><br />' );
  595. return false;
  596. } else {
  597. $preFillSuccess = false;
  598. }
  599. } else {
  600. $preFillSuccess = true;
  601. }
  602. }
  603. }
  604. $this->assignRef ( 'preFillSuccess', $preFillSuccess );
  605. }
  606. }
  607. ?>