1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Stu\Module\Ship\Lib\Interaction; |
6
|
|
|
|
7
|
|
|
use Stu\Module\Message\Lib\PrivateMessageFolderSpecialEnum; |
8
|
|
|
use Stu\Module\Message\Lib\PrivateMessageSenderInterface; |
9
|
|
|
use Stu\Module\Ship\View\ShowShip\ShowShip; |
10
|
|
|
use Stu\Orm\Entity\ShipInterface; |
11
|
|
|
use Stu\Orm\Repository\ShipRepositoryInterface; |
12
|
|
|
|
13
|
|
|
final class ShipUndocking implements ShipUndockingInterface |
14
|
|
|
{ |
15
|
|
|
private ShipRepositoryInterface $shipRepository; |
16
|
|
|
|
17
|
|
|
private PrivateMessageSenderInterface $privateMessageSender; |
18
|
|
|
|
19
|
6 |
|
public function __construct( |
20
|
|
|
ShipRepositoryInterface $shipRepository, |
21
|
|
|
PrivateMessageSenderInterface $privateMessageSender |
22
|
|
|
) { |
23
|
6 |
|
$this->shipRepository = $shipRepository; |
24
|
6 |
|
$this->privateMessageSender = $privateMessageSender; |
25
|
|
|
} |
26
|
|
|
|
27
|
2 |
|
public function undockAllDocked(ShipInterface $station): bool |
28
|
|
|
{ |
29
|
2 |
|
$dockedShips = $station->getDockedShips(); |
30
|
2 |
|
if ($dockedShips->isEmpty()) { |
31
|
1 |
|
return false; |
32
|
|
|
} |
33
|
|
|
|
34
|
1 |
|
foreach ($dockedShips as $dockedShip) { |
35
|
1 |
|
$dockedShip->setDockedTo(null); |
36
|
1 |
|
$dockedShip->setDockedToId(null); |
37
|
1 |
|
$this->shipRepository->save($dockedShip); |
38
|
|
|
|
39
|
1 |
|
$href = sprintf('ship.php?%s=1&id=%d', ShowShip::VIEW_IDENTIFIER, $dockedShip->getId()); |
40
|
|
|
|
41
|
1 |
|
$this->privateMessageSender->send( |
42
|
1 |
|
$station->getUser()->getId(), |
43
|
1 |
|
$dockedShip->getUser()->getId(), |
44
|
1 |
|
sprintf( |
45
|
1 |
|
'Die %s wurde von der %s abgedockt', |
46
|
1 |
|
$dockedShip->getName(), |
47
|
1 |
|
$station->getName() |
48
|
1 |
|
), |
49
|
1 |
|
PrivateMessageFolderSpecialEnum::PM_SPECIAL_SHIP, |
50
|
1 |
|
$href |
51
|
1 |
|
); |
52
|
|
|
} |
53
|
|
|
|
54
|
1 |
|
$dockedShips->clear(); |
55
|
|
|
|
56
|
1 |
|
return true; |
57
|
|
|
} |
58
|
|
|
} |
59
|
|
|
|