1 | <?php |
||
25 | class UserOrder |
||
26 | { |
||
27 | use TimestampableTrait, BlameableEntity, DeletedByTrait; |
||
28 | |||
29 | const STATUS_OPENED = 'opened'; |
||
30 | const STATUS_CLOSED = 'closed'; |
||
31 | const STATUS_PENDING = 'pending'; |
||
32 | const STATUS_PAID = 'paid'; |
||
33 | const STATUS_REJECTED = 'rejected'; |
||
34 | |||
35 | /** |
||
36 | * @var string |
||
37 | * @ORM\Id |
||
38 | * @ORM\Column(type="string") |
||
39 | */ |
||
40 | private $id; |
||
41 | |||
42 | /** |
||
43 | * @var ArrayCollection|Ticket[] |
||
44 | * |
||
45 | * @ORM\OneToMany( |
||
46 | * targetEntity="AppBundle\Entity\Ticket", |
||
47 | * mappedBy="userOrder", |
||
48 | * cascade={"persist", "remove"}, |
||
49 | * orphanRemoval=true |
||
50 | * |
||
51 | * ) |
||
52 | */ |
||
53 | protected $tickets; |
||
54 | |||
55 | /** |
||
56 | * @var string |
||
57 | * @Assert\Choice(callback="getStatuses") |
||
58 | * @ORM\Column(name="status", type="string", length=15) |
||
59 | * @Serializer\Type("string") |
||
60 | * @Expose() |
||
61 | */ |
||
62 | protected $status; |
||
63 | |||
64 | /** |
||
65 | * @var User |
||
66 | * |
||
67 | * @ORM\ManyToOne(targetEntity="AppBundle\Entity\User", inversedBy="orders") |
||
68 | * |
||
69 | * @Type("AppBundle\Entity\User") |
||
70 | */ |
||
71 | private $user; |
||
72 | /** |
||
73 | * UserOrder constructor. |
||
74 | */ |
||
75 | 4 | public function __construct() |
|
76 | { |
||
77 | 4 | $this->id = Uuid::uuid4()->toString(); |
|
78 | 4 | $this->status = self::STATUS_OPENED; |
|
79 | 4 | $this->tickets = new ArrayCollection(); |
|
80 | 4 | } |
|
81 | |||
82 | /** |
||
83 | * @return string |
||
84 | */ |
||
85 | 4 | public function getId(): string |
|
86 | { |
||
87 | 4 | return $this->id; |
|
88 | } |
||
89 | /** |
||
90 | * Get user. |
||
91 | * |
||
92 | * @return \AppBundle\Entity\User |
||
93 | */ |
||
94 | 2 | public function getUser() |
|
95 | { |
||
96 | 2 | return $this->user; |
|
97 | } |
||
98 | |||
99 | 4 | public function setUser(\AppBundle\Entity\User $user = null) |
|
100 | { |
||
101 | 4 | $this->user = $user; |
|
102 | |||
103 | 4 | return $this; |
|
104 | } |
||
105 | /** |
||
106 | * @return Ticket[]|ArrayCollection |
||
107 | */ |
||
108 | public function getTickets() |
||
112 | |||
113 | /** |
||
114 | * @param Ticket[]|ArrayCollection $tickets |
||
115 | * |
||
116 | * @return $this |
||
117 | */ |
||
118 | public function setTickets($tickets) |
||
119 | { |
||
120 | $this->tickets = $tickets; |
||
121 | |||
122 | return $this; |
||
123 | } |
||
124 | |||
125 | /** |
||
126 | * @return string |
||
127 | */ |
||
128 | public function getStatus(): string |
||
132 | |||
133 | /** |
||
134 | * @param String $status |
||
135 | * |
||
136 | * @return $this |
||
137 | */ |
||
138 | 4 | public function setStatus($status) |
|
144 | |||
145 | /** |
||
146 | * Add Ticket |
||
147 | * |
||
148 | * @param Ticket $ticket |
||
149 | * |
||
150 | * @return $this |
||
151 | */ |
||
152 | public function addTicket(Ticket $ticket) |
||
161 | |||
162 | /** |
||
163 | * @param Ticket $ticket |
||
164 | * |
||
165 | * @return $this |
||
166 | */ |
||
167 | public function removeTicket(Ticket $ticket) |
||
176 | |||
177 | /** |
||
178 | * @return bool |
||
179 | */ |
||
180 | private function isStatusPaid(): bool |
||
184 | |||
185 | /** |
||
186 | * @return array |
||
187 | */ |
||
188 | public static function getStatuses(): array |
||
198 | |||
199 | 4 | public function __toString() |
|
203 | } |
||
204 |