function _assignMatchesDo() { // Check for request forgeries JRequest::checkToken() or die('Invalid Token'); // Turnierdaten! $tournament = new CLMTournament($this->id, true); // $tournament->data->typ if ($tournament->data->tl != clm_core::$access->getJid() and $clmAccess->access('BE_tournament_edit_round') !== true or $clmAccess->access('BE_tournament_edit_round') === false) { //if (clm_core::$access->getType() != 'admin' AND clm_core::$access->getType() != 'tl') { JError::raiseWarning(500, JText::_('TOURNAMENT_NO_ACCESS')); return false; } if ($tournament->data->typ == 2) { // Volturnier nur via Rundenerstellung! JError::raiseWarning(500, CLMText::errortext(JText::_('MATCHES_ASSIGN'), 'IMPOSSIBLE')); return false; } elseif ($tournament->data->typ == 3) { // KO // maximal bestätige Runde holen - ist hier MIN(nr) $query = 'SELECT MIN(nr) FROM #__clm_turniere_rnd_termine' . ' WHERE turnier = ' . $this->id . ' AND tl_ok = 1'; $this->_db->setQuery($query); if ($tlokMin = $this->_db->loadResult()) { $roundToDraw = $tlokMin - 1; } else { $roundToDraw = $tournament->data->runden; } // nächste zu vervollständigende Runde ermittelt if ($roundToDraw == 0) { // dann gibt es nichts mehr zu tun JError::raiseWarning(500, JText::_('NO_ROUND_LEFT')); return false; } // Frage: sind in dieser Runde schon Partien angesetzt? $query = 'SELECT COUNT(*)' . ' FROM #__clm_turniere_rnd_spl' . ' WHERE turnier = ' . $this->id . ' AND runde = ' . $roundToDraw . ' AND ((spieler >= 1 AND gegner >= 1) OR ergebnis = 8)'; $this->_db->setQuery($query); $matchesAssigned = $this->_db->loadResult(); if ($matchesAssigned > 0) { // bereits Matches angelegt JError::raiseWarning(500, JText::_('MATCHES_ASSIGNED_ALREADY')); return false; } // OKay, jetzt kann angesetzt werden // alle Spieler, die 'in' sind holen $query = "SELECT snr " . " FROM #__clm_turniere_tlnr" . " WHERE turnier = " . $this->id . " AND koStatus = '1'"; $this->_db->setQuery($query); $playersIn = $this->_db->loadAssocList('snr'); // wieviele Matches werden benötigt? // Spielerzahl - (maximale Matches der Runde / 2) // maximale Matches der Runde: 2^Runde $neededMatches = count($playersIn) - pow(2, $roundToDraw) / 2; // TODO: Sicherheitscheck, ob diese Boards wirklich vorhanden! // jetzt setzen wir an jedes Board eine Zufallspaarung // Matches zusammenstellen $sid = $tournament->data->sid; for ($m = 1; $m <= $neededMatches; $m++) { // Spieler 1 $player1 = array_rand($playersIn); unset($playersIn[$player1]); // Spieler 2 $player2 = array_rand($playersIn); unset($playersIn[$player2]); // SQL $query = "UPDATE #__clm_turniere_rnd_spl" . " SET tln_nr = " . $player1 . ", spieler = " . $player1 . ", gegner = " . $player2 . " WHERE turnier = " . $this->id . " AND runde = " . $roundToDraw . " AND brett = " . $m . " AND heim = '1'"; $this->_db->setQuery($query); if (!$this->_db->query()) { JError::raiseError(500, JText::_('MATCH: ') . $m . ": " . $this->_db->getErrorMsg()); } $query = "UPDATE #__clm_turniere_rnd_spl" . " SET tln_nr = " . $player2 . ", spieler = " . $player2 . ", gegner = " . $player1 . " WHERE turnier = " . $this->id . " AND runde = " . $roundToDraw . " AND brett = " . $m . " AND heim = '0'"; $this->_db->setQuery($query); if (!$this->_db->query()) { JError::raiseError(500, JText::_('MATCH: ') . $m . ": " . $this->_db->getErrorMsg()); } } $app = JFactory::getApplication(); $app->enqueueMessage(JText::_('ROUND_KO_' . $roundToDraw) . ": " . JText::_('TOURNAMENT_MATCHES_ASSIGNED')); // Log $clmLog = new CLMLog(); $clmLog->aktion = JText::_('ROUND_KO_' . $roundToDraw) . ": " . JText::_('TOURNAMENT_MATCHES_ASSIGNED'); $clmLog->params = array('sid' => $tournament->data->sid, 'tid' => $this->id, 'rnd' => $roundToDraw); // TurnierID wird als LigaID gespeichert $clmLog->write(); } elseif ($tournament->data->typ == 1) { // CH JError::raiseWarning(500, CLMText::errortext(JText::_('MATCHES_ASSIGN'), 'NOTIMPLEMENTED')); return false; } }