1 <?php
declare(strict_types
=1);
4 * This file is part of the Rapsys AirBundle package.
6 * (c) Raphaël Gertz <symfony@rapsys.eu>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Rapsys\AirBundle\Entity
;
14 use Doctrine\Common\Collections\Collection
;
15 use Doctrine\Common\Collections\ArrayCollection
;
16 use Doctrine\ORM\Event\PreUpdateEventArgs
;
25 private ?int $id = null;
30 private \DateTime
$created;
35 private \DateTime
$updated;
38 * Applications collection
40 private Collection
$applications;
45 private Collection
$users;
50 * @param string $name The dance name
51 * @param string $type The dance type
53 public function __construct(private string $name, private string $type) {
55 $this->created
= new \
DateTime('now');
56 $this->updated
= new \
DateTime('now');
59 $this->applications
= new ArrayCollection();
60 $this->users
= new ArrayCollection();
68 public function getId(): ?int {
79 public function setName(string $name): Dance
{
90 public function getName(): string {
101 public function setType(string $type): Dance
{
112 public function getType(): string {
119 * @param \DateTime $created
123 public function setCreated(\DateTime
$created): Dance
{
124 $this->created
= $created;
134 public function getCreated(): \DateTime
{
135 return $this->created
;
141 * @param \DateTime $updated
145 public function setUpdated(\DateTime
$updated): Dance
{
146 $this->updated
= $updated;
156 public function getUpdated(): \DateTime
{
157 return $this->updated
;
163 * @param Application $application
167 public function addApplication(Application
$application): Dance
{
168 $this->applications
[] = $application;
176 * @param Application $application
180 public function removeApplication(Application
$application): bool {
181 return $this->applications
->removeElement($application);
187 * @return ArrayCollection
189 public function getApplications(): ArrayCollection
{
190 return $this->applications
;
200 public function addUser(User
$user): Dance
{
201 //Add from owning side
202 $user->addDance($this);
204 $this->users
[] = $user;
216 public function removeUser(User
$user): bool {
217 if (!$this->dances
->contains($user)) {
221 //Remove from owning side
222 $user->removeDance($this);
224 return $this->users
->removeElement($user);
230 * @return ArrayCollection
232 public function getUsers(): ArrayCollection
{
239 public function preUpdate(PreUpdateEventArgs
$eventArgs) {
240 //Check that we have a dance instance
241 if (($dance = $eventArgs->getObject()) instanceof Dance
) {
243 $dance->setUpdated(new \
DateTime('now'));
248 * Returns a string representation of the slot
252 public function __toString(): string {
253 return $this->name
.' '.lcfirst($this->type
);