src/Entity/Invitation.php line 20

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Validator\Constraints as AppAssert;
  4. use App\Classes\Hasher;
  5. use DateTime;
  6. use Doctrine\Common\Collections\ArrayCollection;
  7. use Doctrine\ORM\Mapping as ORM;
  8. use Symfony\Component\Validator\Constraints as Assert;
  9. /**
  10.  * Label
  11.  *
  12.  * @ORM\Table(name="malys_invitation")
  13.  * @ORM\Entity(repositoryClass="App\Repository\InvitationRepository")
  14.  * @ORM\HasLifecycleCallbacks()
  15.  * @AppAssert\Invitation()
  16.  */
  17. class Invitation
  18. {
  19.     public const TYPE_JOIN_SHOPS 'joinShops';
  20.     public const TYPE_BECOME_ADMIN 'becomeGroupAdmin';
  21.     public const TYPES = [
  22.         self::TYPE_JOIN_SHOPS,
  23.         self::TYPE_BECOME_ADMIN
  24.     ];
  25.     public const STATUS_PENDING 'pending';
  26.     public const STATUS_ACCEPTED 'accepted';
  27.     public const STATUS_REFUSED 'refused';
  28.     public const DEFAULT_STATUS self::STATUS_PENDING;
  29.     public const STATUS = [
  30.         self::STATUS_PENDING,
  31.         self::STATUS_ACCEPTED,
  32.         self::STATUS_REFUSED
  33.     ];
  34.     /**
  35.      * @var int
  36.      *
  37.      * @ORM\Column(name="id", type="integer")
  38.      * @ORM\Id
  39.      * @ORM\GeneratedValue(strategy="AUTO")
  40.      */
  41.     private $id;
  42.     /**
  43.      * @ORM\ManyToOne(targetEntity="App\Entity\User")
  44.      * @ORM\JoinColumn(name="invited_user_id", referencedColumnName="id")
  45.      */
  46.     public $invitedUser;
  47.     /**
  48.      * @ORM\Column(name="invited_email", type="string", nullable=true)
  49.      * @Assert\Email
  50.      */
  51.     public $invitedEmail;
  52.     /**
  53.      * @var ArrayCollection
  54.      *
  55.      * @ORM\ManyToMany(targetEntity="App\Entity\Customer")
  56.      */
  57.     protected $shops;
  58.     /**
  59.      * @ORM\ManyToOne(targetEntity="App\Entity\CustomerGroup")
  60.      * @ORM\JoinColumn(name="customer_group_id", referencedColumnName="id")
  61.      * @Assert\NotBlank
  62.      */
  63.     public $customerGroup;
  64.     /**
  65.      * @ORM\Column(name="hashed_id", type="string", nullable=false)
  66.      */
  67.     protected $hashedId;
  68.     /**
  69.      * @var DateTime
  70.      *
  71.      * @ORM\Column(name="createdAt", type="datetime", nullable=false)
  72.      */
  73.     protected $createdAt;
  74.     /**
  75.      * @var DateTime
  76.      *
  77.      * @ORM\Column(name="updatedAt", type="datetime", nullable=true)
  78.      */
  79.     protected $updatedAt;
  80.     /**
  81.      * @ORM\Column(name="type", type="string", nullable=false)
  82.      * @Assert\Choice (callback="getAvailableTypes")
  83.      */
  84.     protected $type;
  85.     /**
  86.      * @ORM\Column(name="status", type="string", nullable=false)
  87.      * @Assert\Choice (callback="getAvailableStatus")
  88.      */
  89.     protected $status 'pending';
  90.     public function __construct()
  91.     {
  92.         $this->shops = new ArrayCollection();
  93.     }
  94.     /**
  95.      * Get id.
  96.      *
  97.      * @return int
  98.      */
  99.     public function getId()
  100.     {
  101.         return $this->id;
  102.     }
  103.     /**
  104.      * @return DateTime
  105.      */
  106.     public function getCreatedAt()
  107.     {
  108.         return $this->createdAt;
  109.     }
  110.     /**
  111.      * Set createdAt
  112.      * @ORM\PrePersist
  113.      */
  114.     public function setCreatedAt()
  115.     {
  116.         $this->createdAt = new DateTime();
  117.         $this->updatedAt = new DateTime();
  118.         return $this;
  119.     }
  120.     /**
  121.      * @return DateTime
  122.      */
  123.     public function getUpdatedAt()
  124.     {
  125.         return $this->updatedAt;
  126.     }
  127.     /**
  128.      * Set updatedAt
  129.      * @ORM\PreUpdate
  130.      */
  131.     public function setUpdatedAt()
  132.     {
  133.         $this->updatedAt = new DateTime();
  134.         return $this;
  135.     }
  136.     public function getPictureFile()
  137.     {
  138.         return $this->pictureFile;
  139.     }
  140.     /**
  141.      * @return mixed
  142.      */
  143.     public function getInvitedUser(): ?User
  144.     {
  145.         return $this->invitedUser;
  146.     }
  147.     /**
  148.      * @param mixed $invitedUser
  149.      */
  150.     public function setInvitedUser(?User $invitedUser): void
  151.     {
  152.         $this->invitedUser $invitedUser;
  153.     }
  154.     /**
  155.      * @return mixed
  156.      */
  157.     public function getInvitedEmail()
  158.     {
  159.         return $this->invitedEmail;
  160.     }
  161.     /**
  162.      * @param mixed $invitedEmail
  163.      */
  164.     public function setInvitedEmail(?string $invitedEmail): void
  165.     {
  166.         $this->invitedEmail $invitedEmail;
  167.     }
  168.     /**
  169.      * @return ArrayCollection
  170.      */
  171.     public function getShops()
  172.     {
  173.         return $this->shops;
  174.     }
  175.     /**
  176.      * @param ArrayCollection $shops
  177.      */
  178.     public function setShops(ArrayCollection $shops): void
  179.     {
  180.         $this->shops $shops;
  181.     }
  182.     public function addShop(Customer $shop)
  183.     {
  184.         if (!$this->shops->contains($shop)) {
  185.             $this->shops->add($shop);
  186.         }
  187.     }
  188.     /**
  189.      * @return mixed
  190.      */
  191.     public function getHashedId()
  192.     {
  193.         return $this->hashedId;
  194.     }
  195.     /**
  196.      * @param mixed $hashedId
  197.      */
  198.     public function setHashedId($hashedId): void
  199.     {
  200.         $this->hashedId $hashedId;
  201.     }
  202.     /**
  203.      * @return string
  204.      */
  205.     public function getStatus(): string
  206.     {
  207.         return $this->status;
  208.     }
  209.     /**
  210.      * @param string $status
  211.      */
  212.     public function setStatus(string $status): void
  213.     {
  214.         $this->status $status;
  215.     }
  216.     public function getAvailableStatus(): array
  217.     {
  218.         return self::STATUS;
  219.     }
  220.     public function getAvailableTypes(): array
  221.     {
  222.         return self::TYPES;
  223.     }
  224.     /**
  225.      * @return mixed
  226.      */
  227.     public function getCustomerGroup()
  228.     {
  229.         return $this->customerGroup;
  230.     }
  231.     /**
  232.      * @param mixed $customerGroup
  233.      */
  234.     public function setCustomerGroup(CustomerGroup $customerGroup): void
  235.     {
  236.         $this->customerGroup $customerGroup;
  237.     }
  238.     /**
  239.      * @return mixed
  240.      */
  241.     public function getType()
  242.     {
  243.         return $this->type;
  244.     }
  245.     /**
  246.      * @param mixed $type
  247.      */
  248.     public function setType($type): void
  249.     {
  250.         $this->type $type;
  251.     }
  252.     /**
  253.      * @ORM\PrePersist
  254.      */
  255.     public function installHashedId()
  256.     {
  257.         if (is_null($this->hashedId)) {
  258.             $this->hashedId Hasher::generateHash(self::class);
  259.         }
  260.     }
  261. }