Skip to content

Commit

Permalink
digedag/cfc_league#99 Add judo as sports
Browse files Browse the repository at this point in the history
  • Loading branch information
digedag committed Mar 10, 2024
1 parent be95562 commit ca4da58
Show file tree
Hide file tree
Showing 6 changed files with 424 additions and 7 deletions.
2 changes: 2 additions & 0 deletions Classes/Table/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use System25\T3sports\Table\Football\Table as FootballTable;
use System25\T3sports\Table\Handball\Table as HandballTable;
use System25\T3sports\Table\Icehockey\Table as IcehockeyTable;
use System25\T3sports\Table\Judo\Table as JudoTable;
use System25\T3sports\Table\Volleyball\Table as VolleyballTable;
use tx_rnbase;

Expand Down Expand Up @@ -64,6 +65,7 @@ public static function createTableType($type)
FootballTable::TABLE_TYPE => FootballTable::class,
HandballTable::TABLE_TYPE => HandballTable::class,
IcehockeyTable::TABLE_TYPE => IcehockeyTable::class,
JudoTable::TABLE_TYPE => JudoTable::class,
VolleyballTable::TABLE_TYPE => VolleyballTable::class,
];

Expand Down
98 changes: 98 additions & 0 deletions Classes/Table/Judo/Configurator.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
<?php

namespace System25\T3sports\Table\Judo;

use Exception;
use System25\T3sports\Table\Football\Comparator;
use System25\T3sports\Table\Football\Configurator as FootballConfigurator;
use System25\T3sports\Table\IComparator;
use tx_rnbase;

/***************************************************************
* Copyright notice
*
* (c) 2008-2024 Rene Nitzsche ([email protected])
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project is
* free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
*
* This script is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/

/**
* Configurator for handball league tables.
*/
class Configurator extends FootballConfigurator
{
/**
* Whether or not loose points are count.
*
* @return bool
*/
public function isCountLoosePoints()
{
return false;
}

/**
* 0- 2-Punktsystem.
*/
public function getPointSystem()
{
return $this->cfgPointSystem;
}

/**
* @return IComparator
*/
public function getComparator(): IComparator
{
$compareClass = $this->cfgComparatorClass ? $this->cfgComparatorClass : Comparator::class;
$comparator = tx_rnbase::makeInstance($compareClass);
if (!is_object($comparator)) {
throw new Exception('Could not instanciate comparator: '.$compareClass);
}
if (!($comparator instanceof IComparator)) {
throw new Exception('Comparator is no instance of tx_cfcleaguefe_table_football_IComparator: '.get_class($comparator));
}

return $comparator;
}

protected function init()
{
// Der TableScope wirkt sich auf die betrachteten Spiele (Hin-Rückrunde) aus
$parameters = $this->configurations->getParameters();
$this->cfgTableScope = $this->getConfValue('tablescope');
// Wir bleiben mit den alten falschen TS-Einstellungen kompatibel und fragen
// beide Einstellungen ab
if ($this->configurations->get('tabletypeSelectionInput') || $this->getConfValue('tablescopeSelectionInput')) {
$this->cfgTableScope = $parameters->offsetGet('tablescope') ? $parameters->offsetGet('tablescope') : $this->cfgTableScope;
}

// tabletype means home or away matches only
$this->cfgTableType = $this->getConfValue('tabletype');
if ($this->configurations->get('tabletypeSelectionInput') || $this->getConfValue('tabletypeSelectionInput')) {
$this->cfgTableType = $parameters->offsetGet('tabletype') ? $parameters->offsetGet('tabletype') : $this->cfgTableType;
}

$this->cfgPointSystem = $this->getCompetition()->getProperty('point_system');
if ($this->configurations->get('pointSystemSelectionInput') || $this->getConfValue('pointSystemSelectionInput')) {
$this->cfgPointSystem = is_string($parameters->offsetGet('pointsystem')) ? intval($parameters->offsetGet('pointsystem')) : $this->cfgPointSystem;
}
$this->cfgLiveTable = (int) $this->getConfValue('showLiveTable');
$this->cfgComparatorClass = $this->getStrategyValue('comparator');
}
}
246 changes: 246 additions & 0 deletions Classes/Table/Judo/Table.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,246 @@
<?php

namespace System25\T3sports\Table\Judo;

use System25\T3sports\Model\Fixture;
use System25\T3sports\Table\Football\Table as FootballTable;
use System25\T3sports\Table\IConfigurator;
use System25\T3sports\Table\ITeam;
use System25\T3sports\Utility\MatchSets;
use tx_rnbase;

/***************************************************************
* Copyright notice
*
* (c) 2011-2024 Rene Nitzsche ([email protected])
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project is
* free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
*
* This script is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/

/**
* Computes league tables for judo.
* TODO: implement
* Rules:
* We will count points, sets and balls
* team 1: 2:0, 2:1, 43:41
* 2 point for winner.
*/
class Table extends FootballTable
{
public const TABLE_TYPE = 'judo';

/**
* @return Configurator
*/
public function getConfigurator($forceNew = false): IConfigurator
{
if ($forceNew || !is_object($this->configurator)) {
$configuratorClass = $this->getConfValue('configuratorClass');
$configuratorClass = $configuratorClass ? $configuratorClass : Configurator::class;
$this->configurator = tx_rnbase::makeInstance($configuratorClass, $this->getMatchProvider()->getBaseCompetition(), $this->configuration, $this->confId);
}

return $this->configurator;
}

/**
* Zählt die Punkte für eine normale Tabelle.
*
* @param Fixture $match
* @param int $toto
* @param IConfigurator $configurator
*/
protected function countStandard($match, $toto, IConfigurator $configurator)
{
// Anzahl Spiele aktualisieren
$home = $match->getHome();
$guest = $match->getGuest();
$this->addMatchCount($home);
$this->addMatchCount($guest);

// Für H2H modus das Spielergebnis merken
$this->addResult($home, $guest, $match->getResult());

if (0 == $toto) { // Unentschieden
$this->addPoints($home, $configurator->getPointsDraw());
$this->addPoints($guest, $configurator->getPointsDraw());
if ($configurator->isCountLoosePoints()) {
$this->addPoints2($home, $configurator->getPointsDraw());
$this->addPoints2($guest, $configurator->getPointsDraw());
}

$this->addDrawCount($home);
$this->addDrawCount($guest);
} elseif (1 == $toto) { // Heimsieg
// Für die
$this->addPoints($home, $configurator->getPointsWin($match->getGoalsHome(), $match->getGoalsGuest()));
$this->addPoints($guest, $configurator->getPointsLoose($match->getGoalsHome(), $match->getGoalsGuest()));

if ($configurator->isCountLoosePoints()) {
$this->addPoints2($guest, $configurator->getPointsLoose($match->getGoalsHome(), $match->getGoalsGuest()));
}

$this->addWinCount($home);
$this->addLoseCount($guest);
} else { // Auswärtssieg
$this->addPoints($home, $configurator->getPointsLoose($match->getGoalsHome(), $match->getGoalsGuest()));
$this->addPoints($guest, $configurator->getPointsWin($match->getGoalsHome(), $match->getGoalsGuest()));

if ($configurator->isCountLoosePoints()) {
$this->addPoints2($home, $configurator->getPointsWin($match->getGoalsHome(), $match->getGoalsGuest()));
}
$this->addLoseCount($home);
$this->addWinCount($guest);
}

// $ballsHome = MatchSets::countSetPointsHome($match);
// $ballsGuest = MatchSets::countSetPointsGuest($match);
// $this->addBalls($home, $ballsHome, $ballsGuest);
// $this->addBalls($guest, $ballsGuest, $ballsHome);

// Jetzt die Tore summieren
$this->addSets($home, $match->getGoalsHome(), $match->getGoalsGuest());
$this->addSets($guest, $match->getGoalsGuest(), $match->getGoalsHome());
}

protected function initTeam(ITeam $team)
{
$this->_teamData->setTeamData($team, 'balls1', 0);
$this->_teamData->setTeamData($team, 'balls2', 0);
$this->_teamData->setTeamData($team, 'balls_diff', 0);
$this->_teamData->setTeamData($team, 'sets1', 0);
$this->_teamData->setTeamData($team, 'sets2', 0);
$this->_teamData->setTeamData($team, 'sets_diff', 0);
}

/**
* Addiert Sätze zu einem Team.
*/
protected function addSets(ITeam $team, $sets1, $sets2)
{
$data = $this->_teamData->getTeamData($team->getTeamId());
$newSets1 = $data['sets1'] + $sets1;
$newSets2 = $data['sets2'] + $sets2;
$this->_teamData->setTeamData($team, 'sets1', $newSets1);
$this->_teamData->setTeamData($team, 'sets2', $newSets2);
$this->_teamData->setTeamData($team, 'sets_diff', $newSets1 - $newSets2);
// TODO: Muss hier ggf. gerundet werden??
$this->_teamData->setTeamData($team, 'sets_quot', $newSets1 / ($newSets2 > 0 ? $newSets2 : 1));
}

/**
* Addiert Bälle zu einem Team.
*/
protected function addBalls(ITeam $team, $balls1, $balls2)
{
$data = $this->_teamData->getTeamData($team->getTeamId());
$newBalls1 = $data['balls1'] + $balls1;
$newBalls2 = $data['balls2'] + $balls2;
$this->_teamData->setTeamData($team, 'balls1', $newBalls1);
$this->_teamData->setTeamData($team, 'balls2', $newBalls2);
$this->_teamData->setTeamData($team, 'balls_diff', $newBalls1 - $newBalls2);
$this->_teamData->setTeamData($team, 'balls_quot', $newBalls1 / ($newBalls2 > 0 ? $newBalls2 : 1));
}

/**
* Zählt die Punkte für eine Heimspieltabelle. Die Ergebnisse werden als nur für die
* Heimmannschaft gewertet.
*
* @param Fixture $match
* @param int $toto
* @param IConfigurator $configurator
*/
protected function countHome($match, $toto, IConfigurator $configurator)
{
$home = $match->getHome();
$guest = $match->getGuest();

// Anzahl Spiele aktualisieren
$this->addMatchCount($home);
$this->addResult($home, $guest, $match->getGuest());

if (0 == $toto) { // Unentschieden
$this->addPoints($home, $configurator->getPointsDraw());
if ($configurator->isCountLoosePoints()) {
$this->addPoints2($home, $configurator->getPointsDraw());
}
$this->addDrawCount($home);
} elseif (1 == $toto) { // Heimsieg
$this->addPoints($home, $configurator->getPointsWin($match->isExtraTime(), $match->isPenalty()));
$this->addWinCount($home);
} else { // Auswärtssieg
$this->addPoints($home, $configurator->getPointsLoose($match->isExtraTime(), $match->isPenalty()));
if ($configurator->isCountLoosePoints()) {
$this->addPoints2($home, $configurator->getPointsWin($match->isExtraTime(), $match->isPenalty()));
}
$this->addLoseCount($home);
}
// $ballsHome = MatchSets::countSetPointsHome($match);
// $ballsGuest = MatchSets::countSetPointsGuest($match);
// $this->addBalls($home, $ballsHome, $ballsGuest);

// Jetzt die Sätze summieren
$this->addSets($home, $match->getGoalsHome(), $match->getGoalsGuest());
}

/**
* Zählt die Punkte für eine Auswärtstabelle. Die Ergebnisse werden als nur für die
* Gastmannschaft gewertet.
*
* @param Fixture $match
* @param int $toto
* @param IConfigurator $configurator
*/
protected function countGuest($match, $toto, IConfigurator $configurator)
{
$home = $match->getHome();
$guest = $match->getGuest();
// Anzahl Spiele aktualisieren
$this->addMatchCount($guest);
$this->addResult($home, $guest, $match->getGuest());

if (0 == $toto) { // Unentschieden
$this->addPoints($guest, $configurator->getPointsDraw());
if ($configurator->isCountLoosePoints()) {
$this->addPoints2($guest, $configurator->getPointsDraw());
}
$this->addDrawCount($guest);
} elseif (1 == $toto) { // Heimsieg
$this->addPoints($guest, $configurator->getPointsLoose($match->isExtraTime(), $match->isPenalty()));
if ($configurator->isCountLoosePoints()) {
$this->addPoints2($guest, $configurator->getPointsWin($match->isExtraTime(), $match->isPenalty()));
}
$this->addLoseCount($guest);
} else { // Auswärtssieg
$this->addPoints($guest, $configurator->getPointsWin($match->isExtraTime(), $match->isPenalty()));
$this->addWinCount($guest);
}

$ballsHome = MatchSets::countSetPointsHome($match);
$ballsGuest = MatchSets::countSetPointsGuest($match);
$this->addBalls($guest, $ballsGuest, $ballsHome);

// Jetzt die Tore summieren
$this->addSets($guest, $match->getGoalsGuest(), $match->getGoalsHome());
}

public function getTypeID(): string
{
return self::TABLE_TYPE;
}
}
4 changes: 0 additions & 4 deletions Classes/Table/Volleyball/Comparator.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,7 @@
/***************************************************************
* Copyright notice
*
<<<<<<< HEAD
* (c) 2011-2024 Rene Nitzsche ([email protected])
=======
* (c) 2011-2023 Rene Nitzsche ([email protected])
>>>>>>> master
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project is
Expand Down
6 changes: 3 additions & 3 deletions Classes/Table/Volleyball/Configurator.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,13 @@ public function getComparator()
{
$comparatorClass = $this->cfgComparatorClass;
if (!$comparatorClass) {
$compareClass = self::POINT_SYSTEM_2POINT == $this->getPointSystem() ?
$comparatorClass = self::POINT_SYSTEM_2POINT == $this->getPointSystem() ?
Comparator::class :
Comparator3Point::class;
}
$comparator = tx_rnbase::makeInstance($compareClass);
$comparator = tx_rnbase::makeInstance($comparatorClass);
if (!is_object($comparator)) {
throw new Exception('Could not instanciate comparator: '.$compareClass);
throw new Exception('Could not instanciate comparator: '.$comparatorClass);
}
if (!($comparator instanceof IComparator)) {
throw new Exception('Comparator is no instance of tx_cfcleaguefe_table_volleyball_IComparator: '.get_class($comparator));
Expand Down
Loading

0 comments on commit ca4da58

Please sign in to comment.