public function undoSetEncounter($roundId, $encId)
 {
     $enc = new EliminationEncounter($this->tournamentId, $roundId, $encId, false);
     // do not allow encounters with byes to be reset
     if ($enc->getPlayer1id() < 0 || $enc->getPlayer2id() < 0) {
         return false;
     }
     // do not create encounters if it is the final match
     if ($roundId <= $this->roundCount() - 2) {
         $nextEnc = new EliminationEncounter($this->tournamentId, $roundId + 1, (int) $enc->getAlias() / 2, false);
         if (!$this->isNextEncUndoable($nextEnc)) {
             return false;
         }
         $resetThird = false;
         if ($this->thirdplayoff && $roundId == $this->roundCount() - 2) {
             $resetThird = true;
             $thirdPlayoff = new EliminationEncounter($this->tournamentId, $roundId + 1, 1, false);
             if (!$this->isNextEncUndoable($thirdPlayoff)) {
                 return false;
             }
         }
         // reset encounters
         $firstAtNext = $enc->getAlias() % 2 == 0;
         if ($firstAtNext) {
             $nextEnc->setPlayer1id(0);
             if ($resetThird) {
                 $thirdPlayoff->setPlayer1id(0);
             }
         } else {
             $nextEnc->setPlayer2id(0);
             if ($resetThird) {
                 $thirdPlayoff->setPlayer2id(0);
             }
         }
     }
     $enc->unsetPoints();
     return true;
 }
Esempio n. 2
0
 function encounter($roundId, $encId)
 {
     global $breadcrumbs, $template_dir, $smarty, $tournamentList, $notify, $lang;
     $tournament = $tournamentList->getTournament($this->tournamentId);
     $smarty->assign('tournament', $tournament);
     $enc = new EliminationEncounter($this->tournamentId, $roundId, $encId);
     foreach ($this->participants as $participant) {
         if ($participant->getId() == $enc->getPlayer1id()) {
             $player1 = $participant;
         }
         if ($participant->getId() == $enc->getPlayer2id()) {
             $player2 = $participant;
         }
     }
     if (!isset($player1) || !isset($player2)) {
         $notify->add($lang->get('encounter'), $lang->get('ntfy_submit_err_player'));
     } else {
         $breadcrumbs->addElement($player1->getName() . " vs. " . $player2->getName(), makeURL('tournament', array('tournamentid' => $_GET['tournamentid'], 'encid' => $_GET['encid'], 'roundid' => $_GET['roundid'], 'mode' => 'view')));
         $smarty->assign('path', $template_dir . "/eliminationencounter_detail.tpl");
         $smarty->assign('player1', array('name' => $player1->getName(), 'url' => $player1->getUrl()));
         $smarty->assign('player2', array('name' => $player2->getName(), 'url' => $player2->getUrl()));
         $enc_arr['points1'] = $enc->getPoints1();
         $enc_arr['points2'] = $enc->getPoints2();
         $enc_arr['finished'] = $enc->isFinished();
         $enc_arr['winner'] = $enc->getPoints1() > $enc->getPoints2() ? 1 : 2;
         $enc_arr['map'] = $this->getMap($_GET['roundid'] + 1);
         if ($enc->getStart() != 0) {
             $enc_arr['start'] = $enc->getStart() > time() ? timeLeft($enc->getStart()) : formatTime($enc->getStart());
             $tEnd = $enc->getStart() + $enc->getDuration();
             $enc_arr['end'] = $enc->getStart() < time() && $tEnd > time() ? timeLeft($tEnd) : formatTime($tEnd);
             $enc_arr['duration'] = $enc->getDuration();
         }
         $smarty->assign('enc', $enc_arr);
         $smarty->assign('user_can_submit', $this->checkSubmitRights($enc, $player1, $player2));
     }
     $smarty->assign('path', $template_dir . "/eliminationencounter_detail.tpl");
     $smarty->assign('_GET', $_GET);
 }
 public function undoSetEncounter($roundId, $encId)
 {
     $enc = new EliminationEncounter($this->tournamentId, $roundId, $encId, false);
     // do not allow encounters with byes to be reset
     if ($enc->getPlayer1id() < 0 || $enc->getPlayer2id() < 0) {
         return false;
     }
     if ($roundId < $this->lastRound() - 1) {
         // normal and looser tier not merged yet
         if ($enc->getId() >= $this->lowerEncOffset()) {
             // in looser tier
             if ($roundId == $this->lastRound() - 2) {
                 // winner will get in first final match
                 $nextEnc = new EliminationEncounter($this->tournamentId, $roundId + 1, 0);
                 $firstAtNext = false;
             } else {
                 if ($roundId % 2 == 0) {
                     $nextEnc = new EliminationEncounter($this->tournamentId, $roundId + 1, $enc->getId());
                     $firstAtNext = false;
                 } else {
                     $nextEnc = new EliminationEncounter($this->tournamentId, $roundId + 1, (int) $enc->getAlias() / 2 + $this->lowerEncOffset());
                     $firstAtNext = $enc->getAlias() % 2 == 0;
                 }
             }
         } else {
             // in winner tier
             if ($roundId == 1) {
                 $nextEnc = new EliminationEncounter($this->tournamentId, $roundId + 1, (int) $enc->getAlias() / 2);
                 $firstAtNext = $enc->getAlias() % 2 == 0;
                 $loserNextEnc = new EliminationEncounter($this->tournamentId, $roundId + 1, (int) $enc->getAlias() / 2 + $this->lowerEncOffset());
                 $loserFirstAtNext = $enc->getAlias() % 2 == 0;
             } else {
                 $nextEnc = new EliminationEncounter($this->tournamentId, $roundId + 2, (int) $enc->getAlias() / 2);
                 $firstAtNext = $enc->getAlias() % 2 == 0;
                 $loserNextEnc = new EliminationEncounter($this->tournamentId, $roundId + 1, (int) $enc->getAlias() + $this->lowerEncOffset());
                 $loserFirstAtNext = true;
             }
         }
     } else {
         if ($roundId == $this->lastRound() - 1) {
             // create second final match
             $nextEnc = new EliminationEncounter($this->tournamentId, $roundId + 1, 0, false);
             $loserNextEnc = $nextEnc;
             $firstAtNext = true;
             $loserFirstAtNext = false;
         } else {
             // final match
         }
     }
     // Check if the encounters are undoable
     if (isset($nextEnc)) {
         if (!$this->isNextEncUndoable($nextEnc)) {
             return false;
         }
     }
     if (isset($loserNextEnc)) {
         if (!$this->isNextEncUndoable($loserNextEnc)) {
             return false;
         }
     }
     if (isset($nextEnc)) {
         if ($firstAtNext) {
             $nextEnc->setPlayer1id(0);
         } else {
             $nextEnc->setPlayer2id(0);
         }
     }
     if (isset($loserNextEnc)) {
         if ($loserFirstAtNext) {
             $loserNextEnc->setPlayer1id(0);
         } else {
             $loserNextEnc->setPlayer2id(0);
         }
     }
     $enc->unsetPoints();
     return true;
 }