src/Entity/User.php line 25

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use DateTime;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\ORM\Mapping as ORM;
  6. use FOS\UserBundle\Model\User as BaseUser;
  7. use JMS\Serializer\Annotation\ExclusionPolicy;
  8. use JMS\Serializer\Annotation\Expose;
  9. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  10. use Symfony\Component\Validator\Constraints as Assert;
  11. /**
  12.  * Class User
  13.  *
  14.  * @ORM\Entity(repositoryClass="App\Repository\UserRepository")
  15.  * @ORM\Table(name="malys_user")
  16.  * @ORM\HasLifecycleCallbacks()
  17.  * @package App\Entity
  18.  * @ExclusionPolicy("all")
  19.  * @UniqueEntity("email", message="Cet email est déjà pris")
  20.  */
  21. class User extends BaseUser {
  22.     /**
  23.      * @var integer
  24.      *
  25.      * @ORM\Column(name="id", type="integer")
  26.      * @ORM\Id
  27.      * @ORM\GeneratedValue(strategy="AUTO")
  28.      * @Expose
  29.      */
  30.     protected $id;
  31.     /**
  32.      * @var string
  33.      *
  34.      * @ORM\Column(name="first_name", type="string", length=255, nullable=true)
  35.      * @Expose
  36.      */
  37.     protected $firstName;
  38.     /**
  39.      * @var string
  40.      *
  41.      * @ORM\Column(name="last_name", type="string", length=255, nullable=true)
  42.      * @Expose
  43.      */
  44.     protected $lastName;
  45.     /**
  46.      * @var UserJob $userJob
  47.      *
  48.      * @ORM\ManyToOne(targetEntity="App\Entity\UserJob")
  49.      * @ORM\JoinColumn(name="user_job_id", referencedColumnName="id")
  50.      */
  51.     protected $userJob;
  52.     /**
  53.      * @var string
  54.      *
  55.      * @ORM\Column(name="mobile", type="string", length=255, nullable=true)
  56.      * @Expose
  57.      */
  58.     protected $mobile;
  59.     /**
  60.      * @var string
  61.      *
  62.      * @ORM\Column(name="phone", type="string", length=255, nullable=true)
  63.      * @Expose
  64.      */
  65.     protected $phone;
  66.     /**
  67.      * @var ArrayCollection
  68.      *
  69.      * @ORM\ManyToMany(targetEntity="App\Entity\Customer", cascade={"persist"}, inversedBy="teamMembers")
  70.      */
  71.     protected $shops;
  72.     /**
  73.      * @ORM\ManyToMany (targetEntity="App\Entity\CustomerGroup", mappedBy="admins", cascade={"refresh"})
  74.      * @Assert\Count (max=1)
  75.      */
  76.     protected $managedGroups;
  77.     /**
  78.      * @var ArrayCollection
  79.      *
  80.      * @ORM\OneToMany(targetEntity="App\Entity\Cart", mappedBy="user")
  81.      */
  82.     protected $carts;
  83.     /**
  84.   * @var DateTime
  85.   *
  86.   * @ORM\Column(name="createdAt", type="datetime", nullable=false)
  87.   * @Expose
  88.   */
  89.  protected $createdAt;
  90.     /**
  91.   * @var DateTime
  92.   *
  93.   * @ORM\Column(name="updatedAt", type="datetime", nullable=true)
  94.   * @Expose
  95.   */
  96.  protected $updatedAt;
  97.     /**
  98.   * @var DateTime
  99.   *
  100.   * @ORM\Column(name="cgs", type="datetime", nullable=true)
  101.   */
  102.  protected $cgs;
  103.     /**
  104.      * One User has many MessageMatches
  105.      * @ORM\OneToMany(targetEntity="App\Entity\MessageMatch", mappedBy="user", cascade={"persist"})
  106.      */
  107.     protected $messageMatches;
  108.     /**
  109.      * @var boolean
  110.      *
  111.      * @ORM\Column(name="sendOrderEmails", type="boolean", options={"default" : true})
  112.      * @Expose
  113.      */
  114.     protected $sendOrderEmails true;
  115.     /**
  116.      * @var boolean
  117.      *
  118.      * @ORM\Column(name="showOrderPrices", type="boolean", options={"default" : false})
  119.      * @Expose
  120.      */
  121.     protected $showOrderPrices false;
  122.     /**
  123.      * @var ArrayCollection
  124.      * One CustomerGroup has Many GuestProducts.
  125.      * @ORM\OneToMany(targetEntity="App\Entity\Product\GuestProduct", mappedBy="author")
  126.      */
  127.     protected $guestProducts;
  128.     /**
  129.      * @return bool
  130.      */
  131.     public function isSendOrderEmails(): bool
  132.     {
  133.         return $this->sendOrderEmails;
  134.     }
  135.     /**
  136.      * @param bool $sendOrderEmails
  137.      */
  138.     public function setSendOrderEmails(bool $sendOrderEmails): void
  139.     {
  140.         $this->sendOrderEmails $sendOrderEmails;
  141.     }
  142.     /**
  143.      * @return bool
  144.      */
  145.     public function isShowOrderPrices(): bool
  146.     {
  147.         return $this->showOrderPrices;
  148.     }
  149.     /**
  150.      * @param bool $showOrderPrices
  151.      */
  152.     public function setShowOrderPrices(bool $showOrderPrices): void
  153.     {
  154.         $this->showOrderPrices $showOrderPrices;
  155.     }
  156.     /**
  157.      * @return mixed
  158.      */
  159.     public function getMessageMatches() {
  160.         return $this->messageMatches;
  161.     }
  162.     /**
  163.      * @param mixed $messageMatches
  164.      */
  165.     public function setMessageMatches$messageMatches ) {
  166.         $this->messageMatches $messageMatches;
  167.     }
  168.     public function getFullIdentifier() {
  169.         return $this->getFirstName() . ' ' $this->getLastName() . ' (' $this->getEmail() . ')';
  170.     }
  171.     /**
  172.      * User constructor.
  173.      */
  174.     public function __construct() {
  175.         parent::__construct();
  176.         $this->shops          = new ArrayCollection();
  177.         $this->carts          = new ArrayCollection();
  178.         $this->messageMatches = new ArrayCollection();
  179.         $this->managedGroups  = new ArrayCollection();
  180.         $this->guestProducts  = new ArrayCollection();
  181.     }
  182.     /**
  183.      * @return int
  184.      */
  185.     public function getId() {
  186.         return $this->id;
  187.     }
  188.     /**
  189.      * @param int $id
  190.      */
  191.     public function setId$id ) {
  192.         $this->id $id;
  193.     }
  194.     /**
  195.      * @return string
  196.      */
  197.     public function getFirstName() {
  198.         return $this->firstName;
  199.     }
  200.     /**
  201.      * @param string $firstName
  202.      */
  203.     public function setFirstName$firstName ) {
  204.         $this->firstName $firstName;
  205.     }
  206.     /**
  207.      * @return string
  208.      */
  209.     public function getLastName() {
  210.         return $this->lastName;
  211.     }
  212.     /**
  213.      * @param string $lastName
  214.      */
  215.     public function setLastName$lastName ) {
  216.         $this->lastName $lastName;
  217.     }
  218.     /**
  219.      * @return string
  220.      */
  221.     public function getMobile() {
  222.         return $this->mobile;
  223.     }
  224.     /**
  225.      * @param string $mobile
  226.      */
  227.     public function setMobile$mobile ) {
  228.         $this->mobile $mobile;
  229.     }
  230.     /**
  231.      * @return string
  232.      */
  233.     public function getPhone() {
  234.         return $this->phone;
  235.     }
  236.     /**
  237.      * @param string $phone
  238.      */
  239.     public function setPhone$phone ) {
  240.         $this->phone $phone;
  241.     }
  242.     /**
  243.      * @return mixed
  244.      */
  245.     public function getUserJob() {
  246.         return $this->userJob;
  247.     }
  248.     /**
  249.      * @param $userJob
  250.      */
  251.     public function setUserJob$userJob ) {
  252.         $this->userJob $userJob;
  253.     }
  254.     /**
  255.      * @return ArrayCollection
  256.      */
  257.     public function getCustomers() {
  258.         return $this->customers;
  259.     }
  260.     /**
  261.      * @param ArrayCollection $customers
  262.      */
  263.     public function setCustomers$customers ) {
  264.         $this->customers $customers;
  265.     }
  266.     /**
  267.      * @param Customer $customer
  268.      */
  269.     public function addCustomer$customer ) {
  270.         $this->customers->add$customer );
  271.         $customer->addMerchant$this );
  272.     }
  273.     /**
  274.      * @param Customer $customer
  275.      */
  276.     public function removeCustomer$customer ) {
  277.         if ( $this->customers->contains$customer ) ) {
  278.             $this->customers->removeElement$customer );
  279.             $customer->removeMerchant$this );
  280.         }
  281.     }
  282.     /**
  283.      * @return Customer
  284.      */
  285.     public function getCustomer() {
  286.         return $this->customer;
  287.     }
  288.     /**
  289.      * @param Customer $customer
  290.      */
  291.     public function setCustomer$customer ) {
  292.         $this->customer $customer;
  293.     }
  294.     /**
  295.      * Sets the email.
  296.      *
  297.      * @param string $email
  298.      *
  299.      * @return BaseUser
  300.      */
  301.     public function setEmail$email ) {
  302.         $this->setUsername$email );
  303.         return parent::setEmail$email );
  304.     }
  305.     /**
  306.      * Set the canonical email.
  307.      *
  308.      * @param string $emailCanonical
  309.      *
  310.      * @return BaseUser
  311.      */
  312.     public function setEmailCanonical$emailCanonical ) {
  313.         $this->setUsernameCanonical$emailCanonical );
  314.         return parent::setEmailCanonical$emailCanonical );
  315.     }
  316.     /**
  317.      * @return mixed
  318.      */
  319.     public function getCarts() {
  320.         return $this->carts;
  321.     }
  322.     /**
  323.      * @param mixed $carts
  324.      */
  325.     public function setCarts$carts ) {
  326.         $this->carts $carts;
  327.     }
  328.     public function addCart$cart ) {
  329.         $this->cart->add$cart );
  330.         return $this;
  331.     }
  332.     public function removeCart$cart ) {
  333.         $this->carts->removeElement$cart );
  334.         return $this;
  335.     }
  336.     /**
  337.   * @return DateTime
  338.   */
  339.  public function getCreatedAt() {
  340.         return $this->createdAt;
  341.     }
  342.     /**
  343.      * Set createdAt
  344.      *
  345.      * @return User
  346.      * @ORM\PrePersist
  347.      */
  348.     public function setCreatedAt() {
  349.         $this->createdAt = new DateTime();
  350.         $this->updatedAt = new DateTime();
  351.         return $this;
  352.     }
  353.     /**
  354.   * @return DateTime
  355.   */
  356.  public function getUpdatedAt() {
  357.         return $this->updatedAt;
  358.     }
  359.     /**
  360.      * Set updatedAt
  361.      *
  362.      * @return User
  363.      * @ORM\PreUpdate
  364.      */
  365.     public function setUpdatedAt() {
  366.         $this->updatedAt = new DateTime();
  367.         return $this;
  368.     }
  369.     /**
  370.      * @return string
  371.      */
  372.     public function getLabel() {
  373.         return ! empty( $this->lastName ) ? $this->lastName $this->username;
  374.     }
  375.     /**
  376.      * @return string
  377.      */
  378.     public function getFirstnameLabel() {
  379.         return ! empty( $this->firstName ) ? $this->firstName $this->username;
  380.     }
  381.     /**
  382.   * @return DateTime
  383.   */
  384.  public function getCgs() {
  385.         return $this->cgs;
  386.     }
  387.     /**
  388.   * @param DateTime $cgs
  389.   */
  390.  public function setCgs$cgs ) {
  391.         $this->cgs $cgs;
  392.     }
  393.     /**
  394.      * @return mixed
  395.      */
  396.     public function getShops() {
  397.         return $this->shops;
  398.     }
  399.     /**
  400.      * @param mixed $shops
  401.      */
  402.     public function setShops$shops ) {
  403.         $this->shops $shops;
  404.     }
  405.     /**
  406.      * @param mixed $shops
  407.      * @return $this
  408.      */
  409.     public function addShops$shops ): User
  410.     {
  411.         foreach( $shops as $shop ) {
  412.             $this->addShop$shop );
  413.         }
  414.         return $this;
  415.     }
  416.     public function addShopCustomer $shop ) {
  417.         if ( $this->shops->contains$shop ) ) {
  418.             return;
  419.         }
  420.         $this->shops->add$shop );
  421.         $shop->addTeamMember$this );
  422.         return $this;
  423.     }
  424.     public function removeShopCustomer $shop ) {
  425.         if (!$this->shops->contains($shop)) {
  426.             return;
  427.         }
  428.         $this->shops->removeElement$shop );
  429.         $shop->removeTeamMember($this);
  430.         return $this;
  431.     }
  432.     /**
  433.      * @return mixed
  434.      */
  435.     public function getManagedGroups() {
  436.         return $this->managedGroups;
  437.     }
  438.     /**
  439.      * @param mixed $managedGroups
  440.      */
  441.     public function setManagedGroups$managedGroups ): void {
  442.         $this->managedGroups $managedGroups;
  443.     }
  444. }