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; }
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; }