<?php declare(strict_types=1);
/*
- * this file is part of the rapsys packbundle package.
+ * This file is part of the Rapsys AirBundle package.
*
- * (c) raphaël gertz <symfony@rapsys.eu>
+ * (c) Raphaël Gertz <symfony@rapsys.eu>
*
- * for the full copyright and license information, please view the license
+ * For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Rapsys\AirBundle\Entity;
+use Doctrine\Common\Collections\Collection;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Event\PreUpdateEventArgs;
*/
class Dance {
/**
- * @var integer
+ * Primary key
*/
- private $id;
+ private ?int $id = null;
/**
- * @var string
+ * Create datetime
*/
- protected $name;
+ private \DateTime $created;
/**
- * @var string
+ * Update datetime
*/
- protected $type;
+ private \DateTime $updated;
/**
- * @var \DateTime
+ * Applications collection
*/
- private $created;
+ private Collection $applications;
/**
- * @var \DateTime
+ * Users collection
*/
- private $updated;
-
- /**
- * @var ArrayCollection
- */
- private $applications;
-
- /**
- * @var ArrayCollection
- */
- private $users;
+ private Collection $users;
/**
* Constructor
* @param string $name The dance name
* @param string $type The dance type
*/
- public function __construct(string $name, string $type) {
+ public function __construct(private string $name, private string $type) {
//Set defaults
- $this->name = $name;
- $this->type = $type;
$this->created = new \DateTime('now');
$this->updated = new \DateTime('now');
*
* @return integer
*/
- public function getId(): int {
+ public function getId(): ?int {
return $this->id;
}
*/
public function addUser(User $user): Dance {
//Add from owning side
- $user->addSubscriber($this);
+ $user->addDance($this);
$this->users[] = $user;
* @return bool
*/
public function removeUser(User $user): bool {
+ if (!$this->dances->contains($user)) {
+ return true;
+ }
+
//Remove from owning side
- $user->removeSubscriber($this);
+ $user->removeDance($this);
return $this->users->removeElement($user);
}
*/
public function preUpdate(PreUpdateEventArgs $eventArgs) {
//Check that we have a dance instance
- if (($dance = $eventArgs->getEntity()) instanceof Dance) {
+ if (($dance = $eventArgs->getObject()) instanceof Dance) {
//Set updated value
$dance->setUpdated(new \DateTime('now'));
}