Skip to content

Commit

Permalink
#35 integrate fixture search by tags
Browse files Browse the repository at this point in the history
  • Loading branch information
digedag committed Oct 4, 2024
1 parent fd705db commit 29c73f3
Show file tree
Hide file tree
Showing 10 changed files with 225 additions and 46 deletions.
21 changes: 13 additions & 8 deletions Classes/Command/CalculateSeriesCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,14 +106,19 @@ public function matchesLoaded(Collection $matches): void
public function clubProcessed(Club $club, SeriesBag $seriesBag): void
{
$this->clubProgress->advance();
$firstMatch = $seriesBag->getBestSeriesFixtures()[0];
$lastMatch = $seriesBag->getBestSeriesFixtures()[count($seriesBag->getBestSeriesFixtures()) - 1];
$this->output->section()->writeln(sprintf('<info>Club (%s) %d series length: %d from %s to %s</info>',
$club->getName(),
$club->getUid(), count($seriesBag->getBestSeriesFixtures()),
date('d.m.Y', $firstMatch->getProperty('date')),
date('d.m.Y', $lastMatch->getProperty('date'))
));
$bestSeriesFixtures = $seriesBag->getBestSeriesFixtures();
if (!empty($bestSeriesFixtures)) {
$firstMatch = $bestSeriesFixtures[0];
$lastMatch = $bestSeriesFixtures[count($bestSeriesFixtures) - 1];
$this->output->section()->writeln(sprintf('<info>Club (%s) %d series length: %d from %s to %s</info>',
$club->getName(),
$club->getUid(), count($bestSeriesFixtures),
date('d.m.Y', $firstMatch->getProperty('date')),
date('d.m.Y', $lastMatch->getProperty('date'))
));
} else {
$this->output->section()->writeln('<info>No series found.</info>');
}
}

public function matchProcessed(Fixture $match): void
Expand Down
11 changes: 11 additions & 0 deletions Classes/Hooks/Search.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ public function getTableMappingMatch(&$params, $parent)
$params['tableMapping']['PLAYERSTAT'] = 'tx_t3sportstats_players';
$params['tableMapping']['COACHSTAT'] = 'tx_t3sportstats_coachs';
$params['tableMapping']['REFEREESTAT'] = 'tx_t3sportstats_referees';
$params['tableMapping']['TAG'] = 'tx_t3sportstats_tags';
$params['tableMapping']['TAGMM'] = 'tx_t3sportstats_tags_mm';
}

public function getJoinsMatch(&$params, $parent)
Expand All @@ -51,5 +53,14 @@ public function getJoinsMatch(&$params, $parent)
if (isset($params['tableAliases']['REFEREESTAT'])) {
$params['join'][] = new Join('MATCH', 'tx_t3sportstats_referees', 'MATCH.uid = REFEREESTAT.t3match', 'REFEREESTAT');
}
if (isset($params['tableAliases']['TAG']) || isset($params['tableAliases']['TAGMM'])) {
if (!isset($params['tableAliases']['COMPETITION'])) {
$params['join'][] = new Join('MATCH', 'tx_cfcleague_competition', 'MATCH.competition = COMPETITION.uid', 'COMPETITION');
}
$params['join'][] = new Join('COMPETITION', 'tx_t3sportstats_tags_mm', 'COMPETITION.UID = TAGMM.uid_local AND TAGMM.tablenames = \'tx_cfcleague_competition\' ', 'TAGMM');
}
if (isset($params['tableAliases']['TAG'])) {
$params['join'][] = new Join('TAGMM', 'tx_t3sportstats_tags', 'TAGMM.uid_foreign = TAG.uid', 'TAG');
}
}
}
36 changes: 36 additions & 0 deletions Classes/Model/Tag.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

namespace System25\T3sports\Model;

use Sys25\RnBase\Domain\Model\BaseModel;

/***************************************************************
* Copyright notice
*
* (c) 2010-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!
***************************************************************/

class Tag extends BaseModel
{
public function getTableName()
{
return 'tx_t3sportstats_tags';
}
}
40 changes: 40 additions & 0 deletions Classes/Repository/TagRepository.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

namespace System25\T3sports\Repository;

use Sys25\RnBase\Domain\Repository\PersistenceRepository;
use System25\T3sports\Search\TagSearch;

/***************************************************************
* Copyright notice
*
* (c) 2017-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!
***************************************************************/

/**
* @author Rene Nitzsche
*/
class TagRepository extends PersistenceRepository
{
public function getSearchClass()
{
return TagSearch::class;
}
}
27 changes: 2 additions & 25 deletions Classes/Search/SeriesSearch.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace System25\T3sports\Search;

use Sys25\RnBase\Database\Query\Join;
use Sys25\RnBase\Search\SearchBase;
use Sys25\RnBase\Utility\Misc;
use System25\T3sports\Model\Series;
Expand Down Expand Up @@ -39,10 +38,8 @@ class SeriesSearch extends SearchBase
protected function getTableMappings()
{
$tableMapping = [];
$tableMapping['SERIES'] = 'tx_t3sportstats_series';
$tableMapping['MATCH'] = 'tx_cfcleague_games';
$tableMapping['COMPETITION'] = 'tx_cfcleague_competition';
$tableMapping['CLUB'] = 'tx_cfcleague_club';
$tableMapping['SERIES'] = $this->getBaseTable();

// Hook to append other tables
Misc::callHook('t3sportstats', 'search_Series_getTableMapping_hook', [
'tableMapping' => &$tableMapping,
Expand All @@ -51,11 +48,6 @@ protected function getTableMappings()
return $tableMapping;
}

protected function useAlias()
{
return true;
}

protected function getBaseTableAlias()
{
return 'SERIES';
Expand All @@ -74,21 +66,6 @@ public function getWrapperClass()
protected function getJoins($tableAliases)
{
$join = [];
if (isset($tableAliases['MATCH'])) {
$join[] = new Join('COACHSTAT', 'tx_cfcleague_games', 'MATCH.uid = COACHSTAT.t3match', 'MATCH');
}
if (isset($tableAliases['COACH'])) {
$join[] = new Join('COACHSTAT', 'tx_cfcleague_profiles', 'COACH.uid = COACHSTAT.coach', 'COACH');
}
if (isset($tableAliases['COMPETITION'])) {
$join[] = new Join('COACHSTAT', 'tx_cfcleague_competition', 'COMPETITION.uid = COACHSTAT.competition', 'COMPETITION');
}
if (isset($tableAliases['CLUB'])) {
$join[] = new Join('COACHSTAT', 'tx_cfcleague_club', 'CLUB.uid = COACHSTAT.club', 'CLUB');
}
if (isset($tableAliases['CLUBOPP'])) {
$join[] = new Join('COACHSTAT', 'tx_cfcleague_club', 'CLUBOPP.uid = COACHSTAT.clubopp', 'CLUBOPP');
}

// Hook to append other tables
Misc::callHook('t3sportstats', 'search_Series_getJoins_hook', [
Expand Down
88 changes: 88 additions & 0 deletions Classes/Search/TagSearch.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
<?php

namespace System25\T3sports\Search;

use Sys25\RnBase\Database\Query\Join;
use Sys25\RnBase\Search\SearchBase;
use Sys25\RnBase\Utility\Misc;
use System25\T3sports\Model\Tag;

/***************************************************************
* Copyright notice
*
* (c) 2010-2024 Rene Nitzsche
* Contact: [email protected]
* All rights reserved
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
***************************************************************/

/**
* Class to search player stats from database.
*
* @author Rene Nitzsche
*/
class TagSearch extends SearchBase
{
protected function getTableMappings()
{
$tableMapping = [];
$tableMapping['TAG'] = $this->getBaseTable();
$tableMapping['SERIES_SCOPE_MM'] = 'tx_t3sportstats_series_scope_mm';
$tableMapping['SERIES'] = 'tx_t3sportstats_series';

// Hook to append other tables
Misc::callHook('t3sportstats', 'search_Tags_getTableMapping_hook', [
'tableMapping' => &$tableMapping,
], $this);

return $tableMapping;
}

protected function getBaseTableAlias()
{
return 'TAG';
}

protected function getBaseTable()
{
return 'tx_t3sportstats_tags';
}

public function getWrapperClass()
{
return Tag::class;
}

protected function getJoins($tableAliases)
{
$join = [];
if (isset($tableAliases['SERIES']) || isset($tableAliases['SERIES_SCOPE_MM'])) {
$join[] = new Join('TAG', 'tx_t3sportstats_series_scope_mm', 'TAG.uid = SERIES_SCOPE_MM.uid_foreign AND SERIES_SCOPE_MM.tablenames=\'tx_t3sportstats_tags\'', 'SERIES_SCOPE_MM');
}

if (isset($tableAliases['SERIES'])) {
$join[] = new Join('SERIES_SCOPE_MM', 'tx_t3sportstats_series', 'SERIES.uid = SERIES_SCOPE_MM.uid_local', 'SERIES');
}

// Hook to append other tables
Misc::callHook('t3sportstats', 'search_Tags_getJoins_hook', [
'join' => &$join,
'tableAliases' => $tableAliases,
], $this);

return $join;
}
}
4 changes: 2 additions & 2 deletions Classes/Series/SeriesBag.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class SeriesBag
public function __construct(Club $club, int $bestBagSize = 3)
{
$this->club = $club;
$this->bestBagSize = $bestBagSize;
$this->bestBagSize = $bestBagSize ?: 1;
}

public function appendToSeries(Fixture $match)
Expand Down Expand Up @@ -91,7 +91,7 @@ public function breakSeries()
*/
public function getBestSeriesFixtures(): array
{
return $this->bestSeries[0];
return $this->bestSeries[0] ?? [];
}

public function getClub(): ?Club
Expand Down
Loading

0 comments on commit 29c73f3

Please sign in to comment.