1
|
|
|
<?php |
2
|
|
|
declare(strict_types=1); |
3
|
|
|
/** |
4
|
|
|
* Created by PhpStorm. |
5
|
|
|
* User: benedikt |
6
|
|
|
* Date: 1/2/18 |
7
|
|
|
* Time: 2:34 PM |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
namespace Tfboe\FmLib\Service\RankingSystem; |
11
|
|
|
|
12
|
|
|
|
13
|
|
|
use Doctrine\ORM\Query; |
14
|
|
|
use Doctrine\ORM\QueryBuilder; |
15
|
|
|
use Tfboe\FmLib\Entity\GameInterface; |
16
|
|
|
use Tfboe\FmLib\Entity\RankingSystemInterface; |
|
|
|
|
17
|
|
|
use Tfboe\FmLib\Helpers\Level; |
18
|
|
|
|
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Class GameRankingSystemService |
22
|
|
|
* @package Tfboe\FmLib\Service\RankingSystemService |
23
|
|
|
*/ |
24
|
|
|
abstract class GameRankingSystemService extends RankingSystemService implements GameRankingSystemInterface |
25
|
|
|
{ |
26
|
|
|
//<editor-fold desc="Protected Methods"> |
27
|
|
|
/** |
28
|
|
|
* @inheritDoc |
29
|
|
|
*/ |
30
|
|
|
protected function getEntitiesQueryBuilder(RankingSystemInterface $ranking, \DateTime $from, \DateTime $to): QueryBuilder |
31
|
|
|
{ |
32
|
|
|
// query all relevant games |
33
|
|
|
$query = $this->getEntityManager()->createQueryBuilder(); |
34
|
|
|
$query |
35
|
|
|
->from(GameInterface::class, 'g') |
36
|
|
|
->select('g') |
37
|
|
|
->leftJoin('g.rankingSystems', 'grs', Query\Expr\Join::WITH, $query->expr()->eq('grs', ':ranking')) |
38
|
|
|
->innerJoin('g.match', 'm') |
39
|
|
|
->leftJoin('m.rankingSystems', 'mrs', Query\Expr\Join::WITH, $query->expr()->eq('mrs', ':ranking')) |
40
|
|
|
->innerJoin('m.phase', 'p') |
41
|
|
|
->leftJoin('p.rankingSystems', 'prs', Query\Expr\Join::WITH, $query->expr()->eq('prs', ':ranking')) |
42
|
|
|
->innerJoin('p.competition', 'c') |
43
|
|
|
->leftJoin('c.rankingSystems', 'crs', Query\Expr\Join::WITH, $query->expr()->eq('crs', ':ranking')) |
44
|
|
|
->innerJoin('c.tournament', 't') |
45
|
|
|
->leftJoin('t.rankingSystems', 'trs', Query\Expr\Join::WITH, $query->expr()->eq('trs', ':ranking')) |
46
|
|
|
->setParameter('ranking', $ranking) |
47
|
|
|
->andWhere("COALESCE(g.endTime, g.startTime, m.endTime, m.startTime, p.endTime, p.startTime, c.endTime, " . |
48
|
|
|
"c.startTime, t.endTime, t.startTime, t.updatedAt) > :from") |
49
|
|
|
->setParameter('from', $from) |
50
|
|
|
->andWhere("COALESCE(g.endTime, g.startTime, m.endTime, m.startTime, p.endTime, p.startTime, c.endTime, " . |
51
|
|
|
"c.startTime, t.endTime, t.startTime, t.updatedAt) <= :to") |
52
|
|
|
->setParameter('to', $to) |
53
|
|
|
->andWhere($query->expr()->orX( |
54
|
|
|
$query->expr()->isNotNull('grs.id'), |
55
|
|
|
$query->expr()->isNotNull('mrs.id'), |
56
|
|
|
$query->expr()->isNotNull('prs.id'), |
57
|
|
|
$query->expr()->isNotNull('crs.id'), |
58
|
|
|
$query->expr()->isNotNull('trs.id') |
59
|
|
|
)); |
60
|
|
|
|
61
|
|
|
return $query; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* @inheritDoc |
66
|
|
|
*/ |
67
|
|
|
protected function getLevel(): int |
68
|
|
|
{ |
69
|
|
|
return Level::GAME; |
70
|
|
|
} |
71
|
|
|
//</editor-fold desc="Protected Methods"> |
72
|
|
|
|
73
|
|
|
} |
Let’s assume that you have a directory layout like this:
and let’s assume the following content of
Bar.php
:If both files
OtherDir/Foo.php
andSomeDir/Foo.php
are loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php
However, as
OtherDir/Foo.php
does not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php
, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: