-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathContract.php
111 lines (98 loc) · 2.58 KB
/
Contract.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
<?php
/**
* @copyright 2016-present Hostnet B.V.
*/
declare(strict_types=1);
namespace Functional\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Hostnet\Component\EntityMutation\Mutation;
use Hostnet\Component\EntityMutation\MutationAwareInterface;
/**
* @ORM\Entity()
* @ORM\InheritanceType("JOINED")
* @ORM\DiscriminatorColumn("type")
* @ORM\DiscriminatorMap({
* 1 = "HostingContract",
* 2 = "DomainContract",
* 3 = "Contract"
* })
* @Mutation(strategy="current")
*/
class Contract implements MutationAwareInterface
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string")
*/
private $identifier;
/**
* @ORM\Column(type="integer")
*/
private $status;
/**
* The history of this object.
*
* @ORM\OneToMany(targetEntity="ContractMutation", mappedBy="contract")
* @ORM\OrderBy(value={"id"="DESC"})
* @var Collection
*/
private $mutations;
/**
* @param string $identifier
* @param int $status
*/
public function __construct($identifier, $status)
{
$this->identifier = $identifier;
$this->status = $status;
$this->mutations = new ArrayCollection();
}
public function getId(): int
{
return $this->id;
}
public function getIdentifier(): string
{
return $this->identifier;
}
public function getStatus(): int
{
return $this->status;
}
/**
* @param DomainContractMutation $mutation
*/
public function addMutation($mutation): void
{
// $this->mutations is sorted by id descending, so we should add new
// items at the start of the Collection. Doctrine collections don't
// allow this right now, so we add it to the end. This is fixed in
// getMutations.
$this->mutations->add($mutation);
}
/**
* @return ContractMutation[]
*/
public function getMutations(): array
{
$mutations = $this->mutations->toArray();
usort($mutations, function (ContractMutation $ma, ContractMutation $mb) {
if ($ma->getId() === $mb->getId()) {
return 0;
}
return ($ma->getId() > $mb->getId()) ? -1 : 1;
});
return $mutations;
}
public function getPreviousMutation(): DomainContractMutation
{
throw new \BadMethodCallException(__METHOD__ . ' is not implemented.');
}
}