1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Stu\Orm\Repository; |
6
|
|
|
|
7
|
|
|
use Doctrine\ORM\EntityRepository; |
8
|
|
|
use Stu\Component\Colony\ColonyEnum; |
9
|
|
|
use Stu\Lib\Colony\PlanetFieldHostInterface; |
10
|
|
|
use Stu\Orm\Entity\Building; |
11
|
|
|
use Stu\Orm\Entity\BuildingCommodity; |
12
|
|
|
use Stu\Orm\Entity\PlanetField; |
13
|
|
|
use Stu\Orm\Entity\PlanetFieldTypeBuilding; |
14
|
|
|
use Stu\Orm\Entity\Researched; |
15
|
|
|
use Stu\Orm\Entity\ResearchInterface; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @extends EntityRepository<Building> |
19
|
|
|
*/ |
20
|
|
|
final class BuildingRepository extends EntityRepository implements BuildingRepositoryInterface |
21
|
|
|
{ |
22
|
|
|
public function getBuildmenuBuildings( |
23
|
|
|
PlanetFieldHostInterface $host, |
24
|
|
|
int $userId, |
25
|
|
|
int $buildMenu, |
26
|
|
|
int $offset, |
27
|
|
|
int $commodityId = null |
28
|
|
|
): array { |
29
|
|
|
|
30
|
|
|
$commodityFilter = $commodityId === null ? '' : sprintf( |
31
|
|
|
'AND EXISTS (SELECT bc.id FROM %s bc WHERE bc.buildings_id = b.id AND bc.commodity_id = %d)', |
32
|
|
|
BuildingCommodity::class, |
33
|
|
|
$commodityId |
34
|
|
|
); |
35
|
|
|
|
36
|
|
|
return $this->getEntityManager() |
|
|
|
|
37
|
|
|
->createQuery( |
38
|
|
|
sprintf( |
39
|
|
|
'SELECT b FROM %s b |
40
|
|
|
WHERE b.bm_col = :buildMenu |
41
|
|
|
AND b.view = :viewState |
42
|
|
|
AND (b.research_id is null OR b.research_id IN ( |
43
|
|
|
SELECT ru.research_id FROM %s ru WHERE ru.user_id = :userId AND ru.aktiv = :activeState |
44
|
|
|
) AND b.id IN ( |
45
|
|
|
SELECT fb.buildings_id FROM %s fb WHERE fb.type IN ( |
46
|
|
|
SELECT fd.type_id FROM %s fd WHERE fd.%s = :hostId |
47
|
|
|
) |
48
|
|
|
)) |
49
|
|
|
%s |
50
|
|
|
ORDER BY b.name', |
51
|
|
|
Building::class, |
52
|
|
|
Researched::class, |
53
|
|
|
PlanetFieldTypeBuilding::class, |
54
|
|
|
PlanetField::class, |
55
|
|
|
$host->getPlanetFieldHostColumnIdentifier(), |
56
|
|
|
$commodityFilter |
57
|
|
|
) |
58
|
|
|
) |
59
|
|
|
->setMaxResults(ColonyEnum::BUILDMENU_SCROLLOFFSET) |
60
|
|
|
->setFirstResult($offset) |
61
|
|
|
->setParameters([ |
62
|
|
|
'activeState' => 0, |
63
|
|
|
'viewState' => 1, |
64
|
|
|
'buildMenu' => $buildMenu, |
65
|
|
|
'userId' => $userId, |
66
|
|
|
'hostId' => $host->getId() |
67
|
|
|
]) |
68
|
|
|
->getResult(); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
public function getByResearch(ResearchInterface $research): array |
72
|
|
|
{ |
73
|
|
|
return $this->findBy([ |
74
|
|
|
'research_id' => $research->getId() |
75
|
|
|
]); |
76
|
|
|
} |
77
|
|
|
} |
78
|
|
|
|