Sfoglia il codice sorgente

Liaison UserPointSale (ambassades privées)

feature/export_comptable
Guillaume 4 anni fa
parent
commit
87b459ccf4
7 ha cambiato i file con 226 aggiunte e 3 eliminazioni
  1. +8
    -0
      ShopBundle/Context/PointSaleUtilsInterface.php
  2. +8
    -0
      ShopBundle/Context/UserPointSaleInterface.php
  3. +43
    -3
      ShopBundle/Model/PointSale.php
  4. +38
    -0
      ShopBundle/Model/User.php
  5. +64
    -0
      ShopBundle/Model/UserPointSale.php
  6. +22
    -0
      ShopBundle/Repository/UserPointSaleRepository.php
  7. +43
    -0
      ShopBundle/Services/PointSaleUtils.php

+ 8
- 0
ShopBundle/Context/PointSaleUtilsInterface.php Vedi File

@@ -0,0 +1,8 @@
<?php

namespace Lc\ShopBundle\Context;

interface PointSaleUtilsInterface
{

}

+ 8
- 0
ShopBundle/Context/UserPointSaleInterface.php Vedi File

@@ -0,0 +1,8 @@
<?php

namespace Lc\ShopBundle\Context;

interface UserPointSaleInterface
{

}

+ 43
- 3
ShopBundle/Model/PointSale.php Vedi File

@@ -2,6 +2,8 @@

namespace Lc\ShopBundle\Model;

use App\Entity\User;
use App\Entity\UserPointSale;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
@@ -36,15 +38,17 @@ abstract class PointSale extends AbstractDocumentEntity implements FilterMultipl
*/
protected $address;

/**
* @ORM\OneToMany(targetEntity="Lc\ShopBundle\Context\UserPointSaleInterface", mappedBy="pointSale", orphanRemoval=true)
*/
protected $userPointSales;

public function labelAdminChoice(){
return $this->getTitle();
}

public function __construct()
{
$this->merchants = new ArrayCollection();
$this->pointSaleDayInfos = new ArrayCollection();
$this->userPointSales = new ArrayCollection();
}

public function __toString()
@@ -52,6 +56,11 @@ abstract class PointSale extends AbstractDocumentEntity implements FilterMultipl
return $this->getTitle() ;
}

public function labelAdminChoice()
{
return $this->getTitle();
}

/**
* @return Collection|Merchant[]
*/
@@ -132,4 +141,35 @@ abstract class PointSale extends AbstractDocumentEntity implements FilterMultipl

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;
}
}

+ 38
- 0
ShopBundle/Model/User.php Vedi File

@@ -3,6 +3,7 @@
namespace Lc\ShopBundle\Model;

use App\Entity\Newsletter;
use App\Entity\UserPointSale;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
@@ -80,6 +81,11 @@ abstract class User extends UserModelFOS
*/
protected $favoriteProductFamilies;

/**
* @ORM\OneToMany(targetEntity="Lc\ShopBundle\Context\UserPointSaleInterface", mappedBy="user", orphanRemoval=true)
*/
protected $userPointSales;


public function __construct()
{
@@ -91,6 +97,7 @@ abstract class User extends UserModelFOS
$this->groupUsers = new ArrayCollection();
$this->newsletters = new ArrayCollection();
$this->favoriteProductFamilies = new ArrayCollection();
$this->userPointSales = new ArrayCollection();
}

public function setEmail($email)
@@ -374,4 +381,35 @@ abstract class User extends UserModelFOS

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;
}
}

+ 64
- 0
ShopBundle/Model/UserPointSale.php Vedi File

@@ -0,0 +1,64 @@
<?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;
}
}

+ 22
- 0
ShopBundle/Repository/UserPointSaleRepository.php Vedi File

@@ -0,0 +1,22 @@
<?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;
}

}

+ 43
- 0
ShopBundle/Services/PointSaleUtils.php Vedi File

@@ -0,0 +1,43 @@
<?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() ;
}
}

}

Loading…
Annulla
Salva