private function getResponses($result) { $outputar = array("matchno;date;time;category;group;playground;teamA;teamB"); /* @var $match MatchPlan */ foreach ($result['matches'] as $match) { $schedule = Date::getDateTime($match->getDate(), $match->getTime()); $date = date_format($schedule, "j-n-Y"); $time = date_format($schedule, "G.i"); $outputstr = $match->getMatchno() . ';' . $date . ';' . $time . ';"' . $match->getCategory()->getName() . '";"' . $match->getGroup()->getName() . '";"' . $match->getPlayground()->getNo() . '";"' . str_replace('"', "'", $match->getTeamA()->getName()) . " (" . $match->getTeamA()->getCountry() . ")" . '";"' . str_replace('"', "'", $match->getTeamB()->getName()) . " (" . $match->getTeamB()->getCountry() . ")" . '"'; $outputar[] = $outputstr; } if (count($result['unassigned']) > 0) { $outputar[] = ";;;;;;;"; foreach ($result['unassigned'] as $match) { $outputstr = ';;;"' . $match->getCategory()->getName() . '";"' . $match->getGroup()->getName() . '";;"' . str_replace('"', "'", $match->getTeamA()->getName()) . " (" . $match->getTeamA()->getCountry() . ")" . '";"' . str_replace('"', "'", $match->getTeamB()->getName()) . " (" . $match->getTeamB()->getCountry() . ")" . '"'; $outputar[] = $outputstr; } } $outputar[] = ";;;;;;;"; $tid = array(); foreach ($result['matches'] as $match) { if (!isset($tid[$match->getTeamA()->getId()])) { $outputstr = '"' . $match->getCategory()->getName() . '";"' . $match->getGroup()->getName() . '";"' . str_replace('"', "'", $match->getTeamA()->getName()) . " (" . $match->getTeamA()->getCountry() . ")" . '"'; $tid[$match->getTeamA()->getId()] = $match->getTeamA()->getName(); $outputar[] = $outputstr; } } return $outputar; }
public function getSchedule() { return Date::getDateTime($this->date); }
public function listMatchCalendar($tournamentid) { $qb = $this->em->createQuery("select distinct a.date " . "from " . $this->entity->getRepositoryPath('PlaygroundAttribute') . " a, " . $this->entity->getRepositoryPath('Playground') . " p, " . $this->entity->getRepositoryPath('Site') . " s " . "where s.tournament=:tournament and p.site=s.id and a.playground=p.id"); $qb->setParameter('tournament', $tournamentid); $matchList = array(); foreach ($qb->getResult() as $date) { $matchdate = Date::getDateTime($date['date']); $matchList[] = $matchdate; } return $matchList; }
public function getEndSchedule() { return Date::getDateTime($this->date, $this->end); }
private function copyEventForm(Event $event) { $eventForm = new EventForm(); $eventForm->setId($event->getId()); $eventForm->setPid($event->getTournament()->getId()); $eventForm->setEvent($event->getEvent()); $dateformat = $this->get('translator')->trans('FORMAT.DATE'); $eventdate = Date::getDateTime($event->getDate()); $eventForm->setDate(date_format($eventdate, $dateformat)); return $eventForm; }
private function copyMatchForm(Match $match) { $matchForm = new MatchForm(); $matchForm->setId($match->getId()); $matchForm->setPid($match->getGroup()->getId()); $matchForm->setMatchno($match->getMatchno()); $matchdate = Date::getDateTime($match->getDate(), $match->getTime()); $dateformat = $this->get('translator')->trans('FORMAT.DATE'); $matchForm->setDate(date_format($matchdate, $dateformat)); $timeformat = $this->get('translator')->trans('FORMAT.TIME'); $matchForm->setTime(date_format($matchdate, $timeformat)); $matchForm->setPlayground($match->getPlayground()); /* @var $homeRel QMatchRelation */ $homeRel = $this->get('match')->getQMatchRelationByMatch($match->getId(), false); if ($homeRel != null) { $matchForm->setGroupA($homeRel->getGroup()->getId()); $matchForm->setRankA($homeRel->getRank()); } /* @var $awayRel QMatchRelation */ $awayRel = $this->get('match')->getQMatchRelationByMatch($match->getId(), true); if ($awayRel != null) { $matchForm->setGroupB($awayRel->getGroup()->getId()); $matchForm->setRankB($awayRel->getRank()); } return $matchForm; }
public function listNewsByTournament($tournamentid) { $qb = $this->em->createQuery("select n.id as nid,n.date,n.newstype,n.newsno,n.language,n.title,n.context," . "t.id,t.name,t.division,c.name as club,c.country," . "m.id as mid,m.matchno,m.date as matchdate,m.time as matchtime " . "from " . $this->entity->getRepositoryPath('News') . " n " . "left outer join " . $this->entity->getRepositoryPath('Match') . " m " . "with n.match=m.id " . "left outer join " . $this->entity->getRepositoryPath('Team') . " t " . "with n.team=t.id " . "left outer join " . $this->entity->getRepositoryPath('Club') . " c " . "with t.club=c.id " . "where n.tournament=:tournament " . "order by n.newsno asc"); $qb->setParameter('tournament', $tournamentid); $newsList = array(); foreach ($qb->getResult() as $news) { $newsdate = Date::getDateTime($news['date']); $news['schedule'] = $newsdate; $newsList[] = $news; } return $newsList; }
private function copyMatchForm(Match $match) { $matchForm = new MatchForm(); $matchForm->setId($match->getId()); $matchForm->setGroup($match->getGroup()); $matchForm->setMatchno($match->getMatchno()); $matchdate = Date::getDateTime($match->getDate(), $match->getTime()); $dateformat = $this->get('translator')->trans('FORMAT.DATE'); $matchForm->setDate(date_format($matchdate, $dateformat)); $timeformat = $this->get('translator')->trans('FORMAT.TIME'); $matchForm->setTime(date_format($matchdate, $timeformat)); $matchForm->setPlayground($match->getPlayground()); $matchForm->setTeamA($this->get('match')->getMatchHomeTeam($match->getId())); $matchForm->setTeamB($this->get('match')->getMatchAwayTeam($match->getId())); return $matchForm; }
private function copyNewsForm(News $news) { $newsForm = new NewsForm(); $newsForm->setId($news->getId()); $newsForm->setTournament($news->getTournament()); $newsForm->setNewsno($news->getNewsno()); $newsForm->setNewstype($news->getNewstype()); $newsForm->setLanguage($news->getLanguage()); $newsForm->setTitle($news->getTitle()); $newsForm->setContext($news->getContext()); $dateformat = $this->get('translator')->trans('FORMAT.DATE'); $eventdate = Date::getDateTime($news->getDate()); $newsForm->setDate(date_format($eventdate, $dateformat)); $newsForm->setTeam($news->getTeam()); $newsForm->setMatch($news->getMatch()); return $newsForm; }
private function getOverviewResponse($tournament, $date, Request $request) { /* @var $utilService Util */ $utilService = $this->get('util'); $utilService->setTournamentKey($tournament); $tournament = $utilService->getTournament(); if ($tournament == null) { return $this->redirect($this->generateUrl('_tournament_select')); } /* @var $matchDate DateTime */ $matchDate = $this->get('match')->getMatchDate($tournament->getId(), $date); if (!$matchDate) { // No match dates have been defined - use currect date to avoid exception $matchDate = new DateTime(); } $pattrs = $this->get('logic')->listPlaygroundAttributesByTournament($tournament->getId()); $pattrList = array(); /* @var $pattr PlaygroundAttribute */ foreach ($pattrs as $pattr) { $pattrList[$pattr->getPlayground()->getId()][] = $pattr; } $newsStream = $this->get('tmnt')->listNewsByTournament($tournament->getId()); $newsRef = array(); $newsRefTeam = array(); $newsGeneral = array(); $today = new DateTime(); foreach ($newsStream as $news) { $news['newsdate'] = Date::getDateTime($news['date']); if ($news['id'] > 0) { $newsRefTeam[$news['id']][$news['newsno']][$news['language']] = $news; continue; } if ($news['mid'] > 0) { $newsRef[$news['mid']][$news['newsno']][$news['language']] = $news; continue; } /* @var $diff \DateInterval */ $diff = $today->diff($news['newsdate']); if ($news['newstype'] == News::$TYPE_PERMANENT || $diff->days < 2) { $newsGeneral[$news['newsno']][$news['language']] = $news; } } $matches = $this->get('match')->listMatchesByDate($tournament->getId(), $matchDate); $matchList = array(); foreach ($matches as $match) { $matchNews = array(); if (array_key_exists($match['id'], $newsRef)) { $matchNews = array_merge($matchNews, $this->getNews($newsRef[$match['id']], $request)); } if (array_key_exists($match['home']['id'], $newsRefTeam)) { $matchNews = array_merge($matchNews, $this->getNews($newsRefTeam[$match['home']['id']], $request)); } if (array_key_exists($match['away']['id'], $newsRefTeam)) { $matchNews = array_merge($matchNews, $this->getNews($newsRefTeam[$match['away']['id']], $request)); } $match['news'] = $matchNews; $slotid = 0; foreach ($pattrList[$match['playground']['id']] as $pattr) { $diffstart = $pattr->getStartSchedule()->getTimestamp() - $match['schedule']->getTimestamp(); $diffend = $pattr->getEndSchedule()->getTimestamp() - $match['schedule']->getTimestamp(); if ($diffend >= 0 && $diffstart <= 0) { $match['timeslot'] = $pattr->getTimeslot(); $matchList[] = $match; $slotid = $pattr->getTimeslot()->getId(); break; } } if (!$slotid) { $match['timeslot'] = new Timeslot(); $matchList[] = $match; } } usort($matchList, function ($match1, $match2) { $p1 = $match2['timeslot']->getId() - $match1['timeslot']->getId(); $p2 = $match2['playground']['no'] - $match1['playground']['no']; $p3 = $match2['schedule']->getTimestamp() - $match1['schedule']->getTimestamp(); $p4 = 0; if ($p1 == 0 && $p2 == 0 && $p3 == 0 && $p4 == 0) { return 0; } elseif ($p1 < 0 || $p1 == 0 && $p2 < 0 || $p1 == 0 && $p2 == 0 && $p3 < 0 || $p1 == 0 && $p2 == 0 && $p3 == 0 && $p4 < 0) { return 1; } else { return -1; } }); $teaserList = array(array('titletext' => 'FORM.TEASER.TOURNAMENT.GROUPS.TITLE', 'text' => 'FORM.TEASER.TOURNAMENT.GROUPS.DESC', 'path' => $this->generateUrl('_tournament_categories', array('tournament' => $tournament->getKey()))), array('titletext' => 'FORM.TEASER.TOURNAMENT.PLAYGROUNDS.TITLE', 'text' => 'FORM.TEASER.TOURNAMENT.PLAYGROUNDS.DESC', 'path' => $this->generateUrl('_tournament_playgrounds', array('tournament' => $tournament->getKey()))), array('titletext' => 'FORM.TEASER.TOURNAMENT.TEAMS.TITLE', 'text' => 'FORM.TEASER.TOURNAMENT.TEAMS.DESC', 'path' => $this->generateUrl('_tournament_clubs', array('tournament' => $tournament->getKey()))), array('titletext' => 'FORM.TEASER.TOURNAMENT.WINNERS.TITLE', 'text' => 'FORM.TEASER.TOURNAMENT.WINNERS.DESC', 'path' => $this->generateUrl('_tournament_winners', array('tournament' => $tournament->getKey()))), array('titletext' => 'FORM.TEASER.TOURNAMENT.STATISTICS.TITLE', 'text' => 'FORM.TEASER.TOURNAMENT.STATISTICS.DESC', 'path' => $this->generateUrl('_tournament_statistics', array('tournament' => $tournament->getKey())))); $thisDate = DateTime::createFromFormat(DateTime::ATOM, $matchDate->format(DateTime::ATOM)); $nextDate = $thisDate->add(new DateInterval("P1D")); $nextMatchDate = $this->get('match')->getMatchDate($tournament->getId(), $nextDate); if ($nextMatchDate) { /* @var $diff DateInterval */ $diff = $nextMatchDate->diff($matchDate); if ($diff->days > 0) { array_unshift($teaserList, array('titletext' => 'FORM.TEASER.TOURNAMENT.MOREMATCHES.TITLE', 'text' => 'FORM.TEASER.TOURNAMENT.MOREMATCHES.DESC', 'path' => $this->generateUrl('_tournament_overview_date', array('tournament' => $tournament->getKey(), 'date' => date_format($nextMatchDate, "d-m-Y"))))); } } $host = $tournament->getHost(); return array('host' => $host, 'tournament' => $tournament, 'matchdate' => $matchDate, 'newsstream' => $newsStream, 'newsgeneral' => $this->getNews($newsGeneral, $request), 'matchlist' => $matchList, 'teaserlist' => $teaserList); }
/** * List qualifying match schedules ordered by match time ascending * Unassigned match schedules are sorted at the end of the list * @param Tournament $tournament * @return array sorted match schedule list */ public function listQMatchSchedules(Tournament $tournament) { $qmatchschedules = $this->entity->getQMatchScheduleRepo()->findBy(array('tournament' => $tournament->getId())); usort($qmatchschedules, function (QMatchSchedule $ms1, QMatchSchedule $ms2) { if ($ms1->getPlan() && $ms2->getPlan()) { $schedule1 = Date::getDateTime($ms1->getPlan()->getPlaygroundAttribute()->getDate(), $ms1->getPlan()->getMatchstart()); $schedule2 = Date::getDateTime($ms2->getPlan()->getPlaygroundAttribute()->getDate(), $ms2->getPlan()->getMatchstart()); return min(1, max(-1, $schedule1->getTimestamp() - $schedule2->getTimestamp())); } return (!$ms2->getPlan() ? 0 : 1) - (!$ms1->getPlan() ? 0 : 1); }); return $qmatchschedules; }
private function checkForm($form, ResultForm $resultForm) { if (!$form->isValid()) { return false; } /* * Check for blank fields */ if ($resultForm->getMatchno() == null || trim($resultForm->getMatchno()) == '') { $form->addError(new FormError($this->get('translator')->trans('FORM.RESULTREPORT.NONO', array(), 'tournament'))); } if ($resultForm->getEvent() == ResultForm::$EVENT_MATCH_PLAYED) { if ($resultForm->getScoreA() == null || trim($resultForm->getScoreA()) == '') { $form->addError(new FormError($this->get('translator')->trans('FORM.RESULTREPORT.NOHOMESCORE', array(), 'tournament'))); } if ($resultForm->getScoreB() == null || trim($resultForm->getScoreB()) == '') { $form->addError(new FormError($this->get('translator')->trans('FORM.RESULTREPORT.NOAWAYSCORE', array(), 'tournament'))); } } if (!$form->isValid()) { return false; } /* * Check for valid contents */ if ($resultForm->getEvent() == ResultForm::$EVENT_MATCH_PLAYED) { if ($resultForm->getScoreA() > 100 || $resultForm->getScoreA() < 0) { $form->addError(new FormError($this->get('translator')->trans('FORM.RESULTREPORT.INVALIDHOMESCORE', array(), 'tournament'))); } if ($resultForm->getScoreB() > 100 || $resultForm->getScoreB() < 0) { $form->addError(new FormError($this->get('translator')->trans('FORM.RESULTREPORT.INVALIDAWAYSCORE', array(), 'tournament'))); } } /* @var $match Match */ $match = $this->get('match')->getMatchByNo($resultForm->getTournament(), $resultForm->getMatchno()); if ($match == null) { $form->addError(new FormError($this->get('translator')->trans('FORM.RESULTREPORT.INVALIDMATCHNO', array(), 'tournament'))); } else { if (!$this->isMatchValid($match)) { $form->addError(new FormError($this->get('translator')->trans('FORM.RESULTREPORT.MATCHNOTREADY', array(), 'tournament'))); } else { if ($this->get('match')->isMatchResultValid($match->getId())) { $form->addError(new FormError($this->get('translator')->trans('FORM.RESULTREPORT.CANTCHANGE', array(), 'tournament'))); } else { $today = new DateTime(); $matchdate = Date::getDateTime($match->getDate(), $match->getTime()); if ($matchdate > $today) { $form->addError(new FormError($this->get('translator')->trans('FORM.RESULTREPORT.TOOEARLY', array(), 'tournament'))); } } } } return $form->isValid(); }