src/Entity/Customer.php line 55

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use ApiPlatform\Core\Annotation\ApiResource;
  4. use App\Entity\Traits\AddressTrait;
  5. use App\Entity\Traits\GroupsCollectionTrait;
  6. use App\Entity\Traits\TimestampableTrait;
  7. use App\Serializer\Annotation\ApiKeyAlias;
  8. use Doctrine\Common\Collections\ArrayCollection;
  9. use Doctrine\Common\Collections\Collection;
  10. use App\Controller\Api\EditProfile;
  11. use Doctrine\ORM\Mapping as ORM;
  12. use Faker\Core\Uuid;
  13. use Gedmo\Mapping\Annotation as Gedmo;
  14. use Symfony\Component\Validator\Constraints as Assert;
  15. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  16. use Symfony\Component\Security\Core\Validator\Constraints as SecurityAssert;
  17. use Symfony\Component\Serializer\Annotation\Groups as SerializerGroups;
  18. /**
  19.  * Customer.
  20.  *
  21.  * @ApiResource(
  22.  *     collectionOperations={},
  23.  *     itemOperations={
  24.  *        "get",
  25.  *        "update_profile"= {
  26.  *              "method"="PUT",
  27.  *              "validation_groups"={"profile"},
  28.  *              "controller"="EditProfile::class"
  29.  *          },
  30.  *        "update_iban"= {
  31.  *              "method"="PUT",
  32.  *              "validation_groups"={"edit_iban"},
  33.  *              "controller"="EditIban::class"
  34.  *          },
  35.  *        "change_pwd"= {"method"="PUT", "path"="customers/{id}/change-pwd", "validation_groups"={"changePwd"}}
  36.  *     },
  37.  *     attributes={
  38.  *     "normalization_context"={"groups"={"get"}},
  39.  *     "access_control"="is_granted('ROLE_USER')"
  40.  * })
  41.  *
  42.  * @ORM\Table(name="customer")
  43.  * @ORM\InheritanceType("SINGLE_TABLE")
  44.  * @ORM\DiscriminatorColumn(name="discr", type="string")
  45.  * @ORM\DiscriminatorMap({"partner" = "Customer", "groups" = "Groupement"})
  46.  *
  47.  * @UniqueEntity("email")
  48.  * @UniqueEntity("companyId")
  49.  *
  50.  * @ORM\Entity(repositoryClass="App\Repository\CustomerRepository")
  51.  */
  52. class Customer extends AbstractUser
  53. {
  54.     const UPLOAD_CSV_PATH 'resources/uploads/operation/';
  55.     use TimestampableTraitGroupsCollectionTraitAddressTrait;
  56.     /**
  57.      * @var bool
  58.      *
  59.      * @ORM\Column(name="opt_in", type="boolean")
  60.      */
  61.     protected $optIn false;
  62.     /**
  63.      * @var string
  64.      *
  65.      * @ORM\Column(name="company_id", type="string", length=25, nullable=true)
  66.      *
  67.      * @SerializerGroups({
  68.      *     "get",
  69.      *     "get_participation_coll",
  70.      * })
  71.      *
  72.      * @ApiKeyAlias("id")
  73.      */
  74.     protected $companyId;
  75.     /**
  76.      * @var Sector
  77.      *
  78.      * @ORM\ManyToOne(targetEntity="App\Entity\Sector")
  79.      */
  80.     private $sector;
  81.     /**
  82.      * @var Collection
  83.      *
  84.      * @ORM\ManyToMany(targetEntity="Groupement", inversedBy="customers")
  85.      */
  86.     private $groupements;
  87.     /**
  88.      * @var Collection
  89.      *
  90.      * @ORM\OneToMany(targetEntity="App\Entity\Signature", mappedBy="customer", cascade={"persist", "remove"}, orphanRemoval=true)
  91.      */
  92.     private $signatures;
  93.     /**
  94.      * @var string
  95.      *
  96.      * @Assert\NotBlank(groups={"changePwd"})
  97.      */
  98.     protected $plainPassword;
  99.     /**
  100.      * @var string
  101.      *
  102.      * @SecurityAssert\UserPassword(
  103.      *     message = "Votre mot de passe est incorrect",
  104.      *     groups={"profile", "changePwd", "edit_iban"}
  105.      * )
  106.      */
  107.     protected $currentPwd;
  108.     /**
  109.      * @var Collection
  110.      *
  111.      * @ORM\OneToMany(targetEntity="App\Entity\CustomerOperation", mappedBy="customer", cascade={"persist"})
  112.      */
  113.     protected $customerOperations;
  114.     /**
  115.      * @var \App\Entity\CustomerBrand
  116.      *
  117.      * @ORM\ManyToOne(targetEntity="CustomerBrand", inversedBy="customers")
  118.      *
  119.      */
  120.     private $brand;
  121.     /**
  122.      * @ORM\Column(type="string", length=50, unique=true, nullable=true)
  123.      * @Assert\NotBlank()
  124.      */
  125.     private $sogecId null;
  126.     /**
  127.      * @return string
  128.      */
  129.     public function getCurrentPwd(): ?string
  130.     {
  131.         return $this->currentPwd;
  132.     }
  133.     /**
  134.      * @param string $currentPwd
  135.      */
  136.     public function setCurrentPwd(string $currentPwd)
  137.     {
  138.         $this->currentPwd $currentPwd;
  139.     }
  140.     /**
  141.      * Customer constructor.
  142.      *
  143.      * @param string|null $username
  144.      * @param array|null  $roles
  145.      * @param string|null $email
  146.      */
  147.     public function __construct($username null, array $roles null$email null)
  148.     {
  149.         $this->companyId $username;
  150.         $this->roles $roles;
  151.         $this->email $email;
  152.         $this->signatures = new ArrayCollection();
  153.         $this->customerOperations = new ArrayCollection();
  154.         $this->groupements = new ArrayCollection();
  155.     }
  156.     /**
  157.      * Get username.
  158.      *
  159.      * @return string
  160.      */
  161.     public function getUsername()
  162.     {
  163.         return $this->companyId;
  164.     }
  165.     /**
  166.      * @return bool
  167.      */
  168.     public function isOptIn()
  169.     {
  170.         return $this->optIn;
  171.     }
  172.     /**
  173.      * Set optIn.
  174.      *
  175.      * @param bool $optIn
  176.      *
  177.      * @return Customer
  178.      */
  179.     public function setOptIn(bool $optIn)
  180.     {
  181.         $this->optIn $optIn;
  182.         return $this;
  183.     }
  184.     /**
  185.      * @return string
  186.      */
  187.     public function getCompanyId()
  188.     {
  189.         return $this->companyId;
  190.     }
  191.     /**
  192.      * @param string $companyId
  193.      *
  194.      * @return Customer
  195.      */
  196.     public function setCompanyId($companyId)
  197.     {
  198.         $this->companyId $companyId;
  199.         return $this;
  200.     }
  201.     /**
  202.      * Set sector.
  203.      *
  204.      * @param Sector $sector
  205.      *
  206.      * @return Customer
  207.      */
  208.     public function setSector(Sector $sector null)
  209.     {
  210.         $this->sector $sector;
  211.         return $this;
  212.     }
  213.     /**
  214.      * Get sector.
  215.      *
  216.      * @return Sector
  217.      */
  218.     public function getSector()
  219.     {
  220.         return $this->sector;
  221.     }
  222.     /**
  223.      * Add operation.
  224.      *
  225.      * @param \App\Entity\Signature $signature
  226.      *
  227.      * @return Customer
  228.      */
  229.     public function addSignature(\App\Entity\Signature $signature)
  230.     {
  231.         if ($this->signatures->contains($signature)) {
  232.             return;
  233.         }
  234.         $this->signatures->add($signature);
  235.         $signature->setCustomer($this);
  236.         return $this;
  237.     }
  238.     /**
  239.      * Remove operation.
  240.      *
  241.      * @param \App\Entity\Signature $signature
  242.      */
  243.     public function removeSignature(\App\Entity\Signature $signature)
  244.     {
  245.         if (!$this->signatures->contains($signature)) {
  246.             return;
  247.         }
  248.         $this->signatures->removeElement($signature);
  249.     }
  250.     /**
  251.      * Get operations.
  252.      *
  253.      * @return Collection
  254.      */
  255.     public function getSignatures()
  256.     {
  257.         return $this->signatures;
  258.     }
  259.     /**
  260.      * {@inheritdoc}
  261.      */
  262.     public static function createFromPayload($username, array $payload)
  263.     {
  264.         return new self(
  265.             $username,
  266.             $payload['roles'],
  267.             $payload['email']
  268.         );
  269.     }
  270.     /**
  271.      * Add customer.
  272.      *
  273.      * @param \App\Entity\CustomerOperation $customerOperation
  274.      *
  275.      * @return Customer
  276.      */
  277.     public function addCustomerOperation(\App\Entity\CustomerOperation $customerOperation)
  278.     {
  279.         if ($this->customerOperations->contains($customerOperation)) {
  280.             return;
  281.         }
  282.         $this->customerOperations->add($customerOperation);
  283.         return $this;
  284.     }
  285.     /**
  286.      * Remove operation.
  287.      *
  288.      * @param \App\Entity\CustomerOperation $customerOperation
  289.      */
  290.     public function removeCustomerOperation(\App\Entity\CustomerOperation $customerOperation)
  291.     {
  292.         if (!$this->customerOperations->contains($customerOperation)) {
  293.             return;
  294.         }
  295.         $this->customerOperations->removeElement($customerOperation);
  296.     }
  297.     /**
  298.      * Get operations.
  299.      *
  300.      * @return Collection
  301.      */
  302.     public function getCustomerOperations()
  303.     {
  304.         return $this->customerOperations;
  305.     }
  306.     /**
  307.      * @return CustomerBrand
  308.      */
  309.     public function getBrand(): ?CustomerBrand
  310.     {
  311.         return $this->brand;
  312.     }
  313.     /**
  314.      * @param CustomerBrand $brand
  315.      *
  316.      * @return self
  317.      */
  318.     public function setBrand(CustomerBrand $brand): self
  319.     {
  320.         $this->brand $brand;
  321.         return $this;
  322.     }
  323.     /**
  324.      * @return null
  325.      */
  326.     public function getSogecId()
  327.     {
  328.         return $this->sogecId;
  329.     }
  330.     /**
  331.      * @param null $sogecId
  332.      * @return Customer
  333.      */
  334.     public function setSogecId($sogecId)
  335.     {
  336.         $this->sogecId $sogecId;
  337.         return $this;
  338.     }
  339. }