<?php | |||||
namespace Lc\ShopBundle\Context; | |||||
interface PointSaleUtilsInterface | |||||
{ | |||||
} |
<?php | |||||
namespace Lc\ShopBundle\Context; | |||||
interface UserPointSaleInterface | |||||
{ | |||||
} |
namespace Lc\ShopBundle\Model; | namespace Lc\ShopBundle\Model; | ||||
use App\Entity\User; | |||||
use App\Entity\UserPointSale; | |||||
use Doctrine\Common\Collections\ArrayCollection; | use Doctrine\Common\Collections\ArrayCollection; | ||||
use Doctrine\Common\Collections\Collection; | use Doctrine\Common\Collections\Collection; | ||||
use Doctrine\ORM\Mapping as ORM; | use Doctrine\ORM\Mapping as ORM; | ||||
*/ | */ | ||||
protected $address; | protected $address; | ||||
/** | |||||
* @ORM\OneToMany(targetEntity="Lc\ShopBundle\Context\UserPointSaleInterface", mappedBy="pointSale", orphanRemoval=true) | |||||
*/ | |||||
protected $userPointSales; | |||||
public function labelAdminChoice(){ | |||||
return $this->getTitle(); | |||||
} | |||||
public function __construct() | public function __construct() | ||||
{ | { | ||||
$this->merchants = new ArrayCollection(); | $this->merchants = new ArrayCollection(); | ||||
$this->pointSaleDayInfos = new ArrayCollection(); | $this->pointSaleDayInfos = new ArrayCollection(); | ||||
$this->userPointSales = new ArrayCollection(); | |||||
} | } | ||||
public function __toString() | public function __toString() | ||||
return $this->getTitle() ; | return $this->getTitle() ; | ||||
} | } | ||||
public function labelAdminChoice() | |||||
{ | |||||
return $this->getTitle(); | |||||
} | |||||
/** | /** | ||||
* @return Collection|Merchant[] | * @return Collection|Merchant[] | ||||
*/ | */ | ||||
return $this; | return $this; | ||||
} | } | ||||
/** | |||||
* @return Collection|UserPointSale[] | |||||
*/ | |||||
public function getUserPointSales(): Collection | |||||
{ | |||||
return $this->userPointSales; | |||||
} | |||||
public function addUserPointSale(UserPointSale $userPointSale): self | |||||
{ | |||||
if (!$this->userPointSales->contains($userPointSale)) { | |||||
$this->userPointSales[] = $userPointSale; | |||||
$userPointSale->setPointSale($this); | |||||
} | |||||
return $this; | |||||
} | |||||
public function removeUserPointSale(UserPointSale $userPointSale): self | |||||
{ | |||||
if ($this->userPointSales->contains($userPointSale)) { | |||||
$this->userPointSales->removeElement($userPointSale); | |||||
// set the owning side to null (unless already changed) | |||||
if ($userPointSale->getPointSale() === $this) { | |||||
$userPointSale->setPointSale(null); | |||||
} | |||||
} | |||||
return $this; | |||||
} | |||||
} | } |
namespace Lc\ShopBundle\Model; | namespace Lc\ShopBundle\Model; | ||||
use App\Entity\Newsletter; | use App\Entity\Newsletter; | ||||
use App\Entity\UserPointSale; | |||||
use Doctrine\Common\Collections\ArrayCollection; | use Doctrine\Common\Collections\ArrayCollection; | ||||
use Doctrine\Common\Collections\Collection; | use Doctrine\Common\Collections\Collection; | ||||
use Doctrine\ORM\Mapping as ORM; | use Doctrine\ORM\Mapping as ORM; | ||||
*/ | */ | ||||
protected $favoriteProductFamilies; | protected $favoriteProductFamilies; | ||||
/** | |||||
* @ORM\OneToMany(targetEntity="Lc\ShopBundle\Context\UserPointSaleInterface", mappedBy="user", orphanRemoval=true) | |||||
*/ | |||||
protected $userPointSales; | |||||
public function __construct() | public function __construct() | ||||
{ | { | ||||
$this->groupUsers = new ArrayCollection(); | $this->groupUsers = new ArrayCollection(); | ||||
$this->newsletters = new ArrayCollection(); | $this->newsletters = new ArrayCollection(); | ||||
$this->favoriteProductFamilies = new ArrayCollection(); | $this->favoriteProductFamilies = new ArrayCollection(); | ||||
$this->userPointSales = new ArrayCollection(); | |||||
} | } | ||||
public function setEmail($email) | public function setEmail($email) | ||||
return $this; | return $this; | ||||
} | } | ||||
/** | |||||
* @return Collection|UserPointSale[] | |||||
*/ | |||||
public function getUserPointSales(): Collection | |||||
{ | |||||
return $this->userPointSales; | |||||
} | |||||
public function addUserPointSale(UserPointSale $userPointSale): self | |||||
{ | |||||
if (!$this->userPointSales->contains($userPointSale)) { | |||||
$this->userPointSales[] = $userPointSale; | |||||
$userPointSale->setUser($this); | |||||
} | |||||
return $this; | |||||
} | |||||
public function removeUserPointSale(UserPointSale $userPointSale): self | |||||
{ | |||||
if ($this->userPointSales->contains($userPointSale)) { | |||||
$this->userPointSales->removeElement($userPointSale); | |||||
// set the owning side to null (unless already changed) | |||||
if ($userPointSale->getUser() === $this) { | |||||
$userPointSale->setUser(null); | |||||
} | |||||
} | |||||
return $this; | |||||
} | |||||
} | } |
<?php | |||||
namespace Lc\ShopBundle\Model; | |||||
use Doctrine\ORM\Mapping as ORM; | |||||
/** | |||||
* @ORM\MappedSuperclass | |||||
*/ | |||||
abstract class UserPointSale | |||||
{ | |||||
/** | |||||
* @ORM\ManyToOne(targetEntity="Lc\ShopBundle\Context\UserInterface", inversedBy="userPointSales") | |||||
* @ORM\JoinColumn(nullable=false) | |||||
*/ | |||||
protected $user; | |||||
/** | |||||
* @ORM\ManyToOne(targetEntity="Lc\ShopBundle\Context\PointSaleInterface", inversedBy="userPointSales") | |||||
* @ORM\JoinColumn(nullable=false) | |||||
*/ | |||||
protected $pointSale; | |||||
/** | |||||
* @ORM\Column(type="text", nullable=true) | |||||
*/ | |||||
protected $comment; | |||||
public function getUser(): ?User | |||||
{ | |||||
return $this->user; | |||||
} | |||||
public function setUser(?User $user): self | |||||
{ | |||||
$this->user = $user; | |||||
return $this; | |||||
} | |||||
public function getPointSale(): ?PointSale | |||||
{ | |||||
return $this->pointSale; | |||||
} | |||||
public function setPointSale(?PointSale $pointSale): self | |||||
{ | |||||
$this->pointSale = $pointSale; | |||||
return $this; | |||||
} | |||||
public function getComment(): ?string | |||||
{ | |||||
return $this->comment; | |||||
} | |||||
public function setComment(?string $comment): self | |||||
{ | |||||
$this->comment = $comment; | |||||
return $this; | |||||
} | |||||
} |
<?php | |||||
namespace Lc\ShopBundle\Repository; | |||||
use Lc\ShopBundle\Context\DefaultRepositoryInterface; | |||||
use Lc\ShopBundle\Context\PointSaleInterface; | |||||
/** | |||||
* @method UserPointSaleInterface|null find($id, $lockMode = null, $lockVersion = null) | |||||
* @method UserPointSaleInterface|null findOneBy(array $criteria, array $orderBy = null) | |||||
* @method UserPointSaleInterface[] findAll() | |||||
* @method UserPointSaleInterface[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null) | |||||
*/ | |||||
class UserPointSaleRepository extends BaseRepository implements DefaultRepositoryInterface | |||||
{ | |||||
public function getInterfaceClass() | |||||
{ | |||||
return UserPointSaleInterface::class; | |||||
} | |||||
} |
<?php | |||||
namespace Lc\ShopBundle\Services ; | |||||
use Doctrine\ORM\EntityManagerInterface; | |||||
use Lc\ShopBundle\Context\PointSaleInterface; | |||||
use Lc\ShopBundle\Context\UserInterface; | |||||
use Lc\ShopBundle\Context\UserPointSaleInterface; | |||||
class PointSaleUtils | |||||
{ | |||||
protected $em ; | |||||
public function __construct(EntityManagerInterface $em) | |||||
{ | |||||
$this->em = $em ; | |||||
} | |||||
public function isUserLinkedToPointSale(UserInterface $user, PointSaleInterface $pointSale) | |||||
{ | |||||
foreach($user->getUserPointSales() as $userPointSale) { | |||||
if($userPointSale->getPointSale()->getId() == $pointSale->getId()) { | |||||
return true ; | |||||
} | |||||
} | |||||
return false ; | |||||
} | |||||
public function linkUserToPointSale(UserInterface $user, PointSaleInterface $pointSale) | |||||
{ | |||||
if(!$this->isUserLinkedToPointSale($user, $pointSale)) { | |||||
$userPointSaleClass = $this->em->getClassMetadata(UserPointSaleInterface::class)->getName(); | |||||
$userPointSale = new $userPointSaleClass ; | |||||
$userPointSale->setUser($user) ; | |||||
$userPointSale->setPointSale($pointSale) ; | |||||
$this->em->persist($userPointSale); | |||||
$this->em->flush() ; | |||||
} | |||||
} | |||||
} |