<?php
namespace App\Entity;
use DateTime;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
use FOS\UserBundle\Model\User as BaseUser;
use JMS\Serializer\Annotation\ExclusionPolicy;
use JMS\Serializer\Annotation\Expose;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\Validator\Constraints as Assert;
/**
* Class User
*
* @ORM\Entity(repositoryClass="App\Repository\UserRepository")
* @ORM\Table(name="malys_user")
* @ORM\HasLifecycleCallbacks()
* @package App\Entity
* @ExclusionPolicy("all")
* @UniqueEntity("email", message="Cet email est déjà pris")
*/
class User extends BaseUser {
/**
* @var integer
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
* @Expose
*/
protected $id;
/**
* @var string
*
* @ORM\Column(name="first_name", type="string", length=255, nullable=true)
* @Expose
*/
protected $firstName;
/**
* @var string
*
* @ORM\Column(name="last_name", type="string", length=255, nullable=true)
* @Expose
*/
protected $lastName;
/**
* @var UserJob $userJob
*
* @ORM\ManyToOne(targetEntity="App\Entity\UserJob")
* @ORM\JoinColumn(name="user_job_id", referencedColumnName="id")
*/
protected $userJob;
/**
* @var string
*
* @ORM\Column(name="mobile", type="string", length=255, nullable=true)
* @Expose
*/
protected $mobile;
/**
* @var string
*
* @ORM\Column(name="phone", type="string", length=255, nullable=true)
* @Expose
*/
protected $phone;
/**
* @var ArrayCollection
*
* @ORM\ManyToMany(targetEntity="App\Entity\Customer", cascade={"persist"}, inversedBy="teamMembers")
*/
protected $shops;
/**
* @ORM\ManyToMany (targetEntity="App\Entity\CustomerGroup", mappedBy="admins", cascade={"refresh"})
* @Assert\Count (max=1)
*/
protected $managedGroups;
/**
* @var ArrayCollection
*
* @ORM\OneToMany(targetEntity="App\Entity\Cart", mappedBy="user")
*/
protected $carts;
/**
* @var DateTime
*
* @ORM\Column(name="createdAt", type="datetime", nullable=false)
* @Expose
*/
protected $createdAt;
/**
* @var DateTime
*
* @ORM\Column(name="updatedAt", type="datetime", nullable=true)
* @Expose
*/
protected $updatedAt;
/**
* @var DateTime
*
* @ORM\Column(name="cgs", type="datetime", nullable=true)
*/
protected $cgs;
/**
* One User has many MessageMatches
* @ORM\OneToMany(targetEntity="App\Entity\MessageMatch", mappedBy="user", cascade={"persist"})
*/
protected $messageMatches;
/**
* @var boolean
*
* @ORM\Column(name="sendOrderEmails", type="boolean", options={"default" : true})
* @Expose
*/
protected $sendOrderEmails = true;
/**
* @var boolean
*
* @ORM\Column(name="showOrderPrices", type="boolean", options={"default" : false})
* @Expose
*/
protected $showOrderPrices = false;
/**
* @var ArrayCollection
* One CustomerGroup has Many GuestProducts.
* @ORM\OneToMany(targetEntity="App\Entity\Product\GuestProduct", mappedBy="author")
*/
protected $guestProducts;
/**
* @return bool
*/
public function isSendOrderEmails(): bool
{
return $this->sendOrderEmails;
}
/**
* @param bool $sendOrderEmails
*/
public function setSendOrderEmails(bool $sendOrderEmails): void
{
$this->sendOrderEmails = $sendOrderEmails;
}
/**
* @return bool
*/
public function isShowOrderPrices(): bool
{
return $this->showOrderPrices;
}
/**
* @param bool $showOrderPrices
*/
public function setShowOrderPrices(bool $showOrderPrices): void
{
$this->showOrderPrices = $showOrderPrices;
}
/**
* @return mixed
*/
public function getMessageMatches() {
return $this->messageMatches;
}
/**
* @param mixed $messageMatches
*/
public function setMessageMatches( $messageMatches ) {
$this->messageMatches = $messageMatches;
}
public function getFullIdentifier() {
return $this->getFirstName() . ' ' . $this->getLastName() . ' (' . $this->getEmail() . ')';
}
/**
* User constructor.
*/
public function __construct() {
parent::__construct();
$this->shops = new ArrayCollection();
$this->carts = new ArrayCollection();
$this->messageMatches = new ArrayCollection();
$this->managedGroups = new ArrayCollection();
$this->guestProducts = new ArrayCollection();
}
/**
* @return int
*/
public function getId() {
return $this->id;
}
/**
* @param int $id
*/
public function setId( $id ) {
$this->id = $id;
}
/**
* @return string
*/
public function getFirstName() {
return $this->firstName;
}
/**
* @param string $firstName
*/
public function setFirstName( $firstName ) {
$this->firstName = $firstName;
}
/**
* @return string
*/
public function getLastName() {
return $this->lastName;
}
/**
* @param string $lastName
*/
public function setLastName( $lastName ) {
$this->lastName = $lastName;
}
/**
* @return string
*/
public function getMobile() {
return $this->mobile;
}
/**
* @param string $mobile
*/
public function setMobile( $mobile ) {
$this->mobile = $mobile;
}
/**
* @return string
*/
public function getPhone() {
return $this->phone;
}
/**
* @param string $phone
*/
public function setPhone( $phone ) {
$this->phone = $phone;
}
/**
* @return mixed
*/
public function getUserJob() {
return $this->userJob;
}
/**
* @param $userJob
*/
public function setUserJob( $userJob ) {
$this->userJob = $userJob;
}
/**
* @return ArrayCollection
*/
public function getCustomers() {
return $this->customers;
}
/**
* @param ArrayCollection $customers
*/
public function setCustomers( $customers ) {
$this->customers = $customers;
}
/**
* @param Customer $customer
*/
public function addCustomer( $customer ) {
$this->customers->add( $customer );
$customer->addMerchant( $this );
}
/**
* @param Customer $customer
*/
public function removeCustomer( $customer ) {
if ( $this->customers->contains( $customer ) ) {
$this->customers->removeElement( $customer );
$customer->removeMerchant( $this );
}
}
/**
* @return Customer
*/
public function getCustomer() {
return $this->customer;
}
/**
* @param Customer $customer
*/
public function setCustomer( $customer ) {
$this->customer = $customer;
}
/**
* Sets the email.
*
* @param string $email
*
* @return BaseUser
*/
public function setEmail( $email ) {
$this->setUsername( $email );
return parent::setEmail( $email );
}
/**
* Set the canonical email.
*
* @param string $emailCanonical
*
* @return BaseUser
*/
public function setEmailCanonical( $emailCanonical ) {
$this->setUsernameCanonical( $emailCanonical );
return parent::setEmailCanonical( $emailCanonical );
}
/**
* @return mixed
*/
public function getCarts() {
return $this->carts;
}
/**
* @param mixed $carts
*/
public function setCarts( $carts ) {
$this->carts = $carts;
}
public function addCart( $cart ) {
$this->cart->add( $cart );
return $this;
}
public function removeCart( $cart ) {
$this->carts->removeElement( $cart );
return $this;
}
/**
* @return DateTime
*/
public function getCreatedAt() {
return $this->createdAt;
}
/**
* Set createdAt
*
* @return User
* @ORM\PrePersist
*/
public function setCreatedAt() {
$this->createdAt = new DateTime();
$this->updatedAt = new DateTime();
return $this;
}
/**
* @return DateTime
*/
public function getUpdatedAt() {
return $this->updatedAt;
}
/**
* Set updatedAt
*
* @return User
* @ORM\PreUpdate
*/
public function setUpdatedAt() {
$this->updatedAt = new DateTime();
return $this;
}
/**
* @return string
*/
public function getLabel() {
return ! empty( $this->lastName ) ? $this->lastName : $this->username;
}
/**
* @return string
*/
public function getFirstnameLabel() {
return ! empty( $this->firstName ) ? $this->firstName : $this->username;
}
/**
* @return DateTime
*/
public function getCgs() {
return $this->cgs;
}
/**
* @param DateTime $cgs
*/
public function setCgs( $cgs ) {
$this->cgs = $cgs;
}
/**
* @return mixed
*/
public function getShops() {
return $this->shops;
}
/**
* @param mixed $shops
*/
public function setShops( $shops ) {
$this->shops = $shops;
}
/**
* @param mixed $shops
* @return $this
*/
public function addShops( $shops ): User
{
foreach( $shops as $shop ) {
$this->addShop( $shop );
}
return $this;
}
public function addShop( Customer $shop ) {
if ( $this->shops->contains( $shop ) ) {
return;
}
$this->shops->add( $shop );
$shop->addTeamMember( $this );
return $this;
}
public function removeShop( Customer $shop ) {
if (!$this->shops->contains($shop)) {
return;
}
$this->shops->removeElement( $shop );
$shop->removeTeamMember($this);
return $this;
}
/**
* @return mixed
*/
public function getManagedGroups() {
return $this->managedGroups;
}
/**
* @param mixed $managedGroups
*/
public function setManagedGroups( $managedGroups ): void {
$this->managedGroups = $managedGroups;
}
}