1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Stu\Module\Maintenance; |
4
|
|
|
|
5
|
|
|
use Stu\Component\Map\MapEnum; |
6
|
|
|
use Stu\Module\Award\Lib\CreateUserAwardInterface; |
7
|
|
|
use Stu\Orm\Entity\UserLayerInterface; |
8
|
|
|
use Stu\Orm\Repository\MapRepositoryInterface; |
9
|
|
|
use Stu\Orm\Repository\UserLayerRepositoryInterface; |
10
|
|
|
use Stu\Orm\Repository\UserMapRepositoryInterface; |
11
|
|
|
|
12
|
|
|
final class MapCycle implements MaintenanceHandlerInterface |
13
|
|
|
{ |
14
|
|
|
private MapRepositoryInterface $mapRepository; |
15
|
|
|
|
16
|
|
|
private UserLayerRepositoryInterface $userLayerRepository; |
17
|
|
|
|
18
|
|
|
private UserMapRepositoryInterface $userMapRepository; |
19
|
|
|
|
20
|
|
|
private CreateUserAwardInterface $createUserAward; |
21
|
|
|
|
22
|
4 |
|
public function __construct( |
23
|
|
|
MapRepositoryInterface $mapRepository, |
24
|
|
|
UserLayerRepositoryInterface $userLayerRepository, |
25
|
|
|
UserMapRepositoryInterface $userMapRepository, |
26
|
|
|
CreateUserAwardInterface $createUserAward |
27
|
|
|
) { |
28
|
4 |
|
$this->mapRepository = $mapRepository; |
29
|
4 |
|
$this->userLayerRepository = $userLayerRepository; |
30
|
4 |
|
$this->userMapRepository = $userMapRepository; |
31
|
4 |
|
$this->createUserAward = $createUserAward; |
32
|
|
|
} |
33
|
|
|
|
34
|
4 |
|
public function handle(): void |
35
|
|
|
{ |
36
|
4 |
|
$userLayers = $this->userLayerRepository->getByMappingType(MapEnum::MAPTYPE_INSERT); |
37
|
4 |
|
foreach ($userLayers as $userLayer) { |
38
|
3 |
|
$user = $userLayer->getUser(); |
39
|
3 |
|
$layer = $userLayer->getLayer(); |
40
|
3 |
|
$fieldcount = $this->mapRepository->getAmountByLayer($layer); |
41
|
|
|
|
42
|
|
|
// if user has mapped everything in this layer |
43
|
3 |
|
if ($this->userMapRepository->getAmountByUser($user, $layer) >= $fieldcount) { |
44
|
2 |
|
$this->cycle($userLayer); |
45
|
|
|
} |
46
|
|
|
} |
47
|
|
|
} |
48
|
|
|
|
49
|
2 |
|
private function cycle(UserLayerInterface $userLayer): void |
50
|
|
|
{ |
51
|
2 |
|
$userLayer->setMappingType(MapEnum::MAPTYPE_LAYER_EXPLORED); |
52
|
2 |
|
$this->userLayerRepository->save($userLayer); |
53
|
|
|
|
54
|
2 |
|
$this->userMapRepository->truncateByUserAndLayer($userLayer); |
55
|
|
|
|
56
|
2 |
|
$award = $userLayer->getLayer()->getAward(); |
57
|
2 |
|
if ($award != null) { |
58
|
1 |
|
$this->createUserAward->createAwardForUser($userLayer->getUser(), $award); |
59
|
|
|
} |
60
|
|
|
} |
61
|
|
|
} |
62
|
|
|
|