Skip to content

Commit

Permalink
#35 wip calculate home, away and obligation series
Browse files Browse the repository at this point in the history
  • Loading branch information
digedag committed Oct 1, 2024
1 parent ac7bd26 commit 4c23a03
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 5 deletions.
7 changes: 7 additions & 0 deletions Classes/Model/Series.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@
*/
class Series extends BaseModel
{
public const MATCHTYPE_HOME = 'home';
public const MATCHTYPE_AWAY = 'away';
public const MATCHTYPE_ALL = 'all';
public const OBLIGATION_YES = 'yes';
public const OBLIGATION_NO = 'no';
public const OBLIGATION_ALL = 'all';

public function getTableName()
{
return 'tx_t3sportstats_series';
Expand Down
22 changes: 18 additions & 4 deletions Classes/Series/SeriesCalculator.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ public function calculate(int $seriesUid, SeriesCalculationVisitorInterface $vis
);
$clubs = $clubs->map(function ($item) { return $item['uid']; })->toArray();
$ageGroup = $series->getProperty('agegroup');
$matchType = $series->getProperty('matchtype');
$obligation = $series->getProperty('obligation');

if ($visitor) {
$visitor->seriesLoaded($series, $clubs);
Expand All @@ -111,7 +113,7 @@ public function calculate(int $seriesUid, SeriesCalculationVisitorInterface $vis
foreach ($clubs as $clubUid) {
$club = $this->clubRepo->findByUid($clubUid);
$seriesBag = new SeriesBag($club);
$matches = $this->lookupMatches($clubUid, $ageGroup);
$matches = $this->lookupMatches($clubUid, $ageGroup, $matchType, $obligation);
if ($visitor) {
$visitor->matchesLoaded($matches);
}
Expand Down Expand Up @@ -264,14 +266,26 @@ private function isTeamHome($match, $clubUid, $ageGroupUid): bool
throw new TeamNotFoundException(sprintf('Team for club %d not found in match %d', $clubUid, $match->getUid()));
}

private function lookupMatches($clubUid, $ageGroupUid): Collection
private function lookupMatches($clubUid, $ageGroupUid, string $matchType, string $obligation): Collection
{
$builder = $this->matchService->getMatchTableBuilder();
$builder->setStatus(Fixture::MATCH_STATUS_FINISHED);
$builder->setAgeGroups($ageGroupUid);
$builder->setClubs(''.$clubUid);
if ($matchType === Series::MATCHTYPE_HOME) {
$builder->setHomeClubs(''.$clubUid);
} elseif ($matchType === Series::MATCHTYPE_HOME) {
$builder->setGuestClubs(''.$clubUid);
} else {
$builder->setClubs(''.$clubUid);
}
$builder->setOrderByDate(false);
$builder->setCompetitionObligation(1);
if ($obligation === Series::OBLIGATION_ALL) {
$builder->setCompetitionObligation(0);
} elseif ($obligation === Series::OBLIGATION_NO) {
$builder->setCompetitionObligation(2);
} else {
$builder->setCompetitionObligation(1);
}

$fields = $options = [];
$builder->getFields($fields, $options);
Expand Down
37 changes: 36 additions & 1 deletion Configuration/TCA/tx_t3sportstats_series.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,41 @@
],
],
],
'matchtype' => [
'exclude' => 1,
'label' => 'LLL:EXT:t3sportstats/Resources/Private/Language/locallang_db.xlf:tx_t3sportstats_series_matchtype',
'config' => [
'type' => 'select',
'renderType' => 'selectSingle',
'items' => [
['LLL:EXT:t3sportstats/Resources/Private/Language/locallang_db.xlf:tx_t3sportstats_series_matchtype_all', 'all'],
['LLL:EXT:t3sportstats/Resources/Private/Language/locallang_db.xlf:tx_t3sportstats_series_matchtype_home', 'home'],
['LLL:EXT:t3sportstats/Resources/Private/Language/locallang_db.xlf:tx_t3sportstats_series_matchtype_away', 'away'],
],
'size' => 1,
'minitems' => 0,
'maxitems' => 1,
'default' => 'all',
],
],
'obligation' => [
'exclude' => 1,
'label' => 'LLL:EXT:t3sportstats/Resources/Private/Language/locallang_db.xlf:tx_t3sportstats_series_obligation',
'config' => [
'type' => 'select',
'renderType' => 'selectSingle',
'items' => [
['LLL:EXT:t3sportstats/Resources/Private/Language/locallang_db.xlf:tx_t3sportstats_series_obligation_yes', 'yes'],
['LLL:EXT:t3sportstats/Resources/Private/Language/locallang_db.xlf:tx_t3sportstats_series_obligation_no', 'no'],
['LLL:EXT:t3sportstats/Resources/Private/Language/locallang_db.xlf:tx_t3sportstats_series_obligation_all', 'all'],
],
'size' => 1,
'minitems' => 0,
'maxitems' => 1,
'default' => 'yes',
],
],

'rules' => [
'label' => 'LLL:EXT:t3sportstats/Resources/Private/Language/locallang_db.xlf:tx_t3sportstats_series_rules',
'description' => 'field description',
Expand Down Expand Up @@ -163,7 +198,7 @@
],
'types' => [
'0' => [
'showitem' => 'hidden,name,label,saison,competitiontag,competition,agegroup,club,
'showitem' => 'hidden,name,label,saison,competitiontag,competition,agegroup,club,matchtype,obligation,
--div--;LLL:EXT:t3sportstats/Resources/Private/Language/locallang_db.xlf:tx_t3sportstats_series_rules,rules,
--div--;LLL:EXT:t3sportstats/Resources/Private/Language/locallang_db.xlf:tx_t3sportstats_series_results,results
',
Expand Down
24 changes: 24 additions & 0 deletions Resources/Private/Language/locallang_db.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,30 @@
<trans-unit id="tx_t3sportstats_series_results" xml:space="preserve">
<source>Results</source>
</trans-unit>
<trans-unit id="tx_t3sportstats_series_matchtype" xml:space="preserve">
<source>Match type</source>
</trans-unit>
<trans-unit id="tx_t3sportstats_series_matchtype_home" xml:space="preserve">
<source>Home series</source>
</trans-unit>
<trans-unit id="tx_t3sportstats_series_matchtype_away" xml:space="preserve">
<source>Away series</source>
</trans-unit>
<trans-unit id="tx_t3sportstats_series_matchtype_all" xml:space="preserve">
<source>Both</source>
</trans-unit>
<trans-unit id="tx_t3sportstats_series_obligation" xml:space="preserve">
<source>Obligation</source>
</trans-unit>
<trans-unit id="tx_t3sportstats_series_obligation_yes" xml:space="preserve">
<source>Yes</source>
</trans-unit>
<trans-unit id="tx_t3sportstats_series_obligation_no" xml:space="preserve">
<source>No</source>
</trans-unit>
<trans-unit id="tx_t3sportstats_series_obligation_all" xml:space="preserve">
<source>Both</source>
</trans-unit>

<trans-unit id="tx_t3sportstats_series_rule" xml:space="preserve">
<source>Series Rule</source>
Expand Down
2 changes: 2 additions & 0 deletions ext_tables.sql
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,8 @@ CREATE TABLE tx_t3sportstats_series (
club int(11) DEFAULT '0' NOT NULL,
competition int(11) DEFAULT '0' NOT NULL,
competitiontag int(11) DEFAULT '0' NOT NULL,
matchtype varchar(10) DEFAULT '' NOT NULL,
obligation varchar(10) DEFAULT '' NOT NULL,

rules int(11) DEFAULT '0' NOT NULL,
results int(11) DEFAULT '0' NOT NULL,
Expand Down

0 comments on commit 4c23a03

Please sign in to comment.