namespace Lc\SovBundle\Builder\User; | namespace Lc\SovBundle\Builder\User; | ||||
use Doctrine\ORM\EntityManagerInterface; | use Doctrine\ORM\EntityManagerInterface; | ||||
use Lc\SovBundle\Doctrine\EntityInterface; | |||||
use Lc\SovBundle\Doctrine\Extension\BlameableInterface; | |||||
use Lc\SovBundle\Model\Newsletter\NewsletterInterface; | use Lc\SovBundle\Model\Newsletter\NewsletterInterface; | ||||
use Lc\SovBundle\Model\User\UserInterface; | use Lc\SovBundle\Model\User\UserInterface; | ||||
use Lc\SovBundle\Repository\User\UserStore; | |||||
use Lc\SovBundle\Solver\User\UserSolver; | use Lc\SovBundle\Solver\User\UserSolver; | ||||
class UserBuilder | class UserBuilder | ||||
{ | { | ||||
protected EntityManagerInterface $entityManager; | protected EntityManagerInterface $entityManager; | ||||
protected UserStore $userStore; | |||||
protected UserSolver $userSolver; | protected UserSolver $userSolver; | ||||
public function __construct(EntityManagerInterface $entityManager, UserSolver $userSolver) | |||||
public function __construct(EntityManagerInterface $entityManager, UserStore $userStore, UserSolver $userSolver) | |||||
{ | { | ||||
$this->entityManager = $entityManager; | $this->entityManager = $entityManager; | ||||
$this->userStore = $userStore; | |||||
$this->userSolver = $userSolver; | $this->userSolver = $userSolver; | ||||
} | } | ||||
} else { | } else { | ||||
$user->removeNewsletter($newsletter); | $user->removeNewsletter($newsletter); | ||||
} | } | ||||
$this->entityManager->persist($user); | $this->entityManager->persist($user); | ||||
$this->entityManager->flush(); | $this->entityManager->flush(); | ||||
} | } | ||||
public function initBlameableSystem(EntityInterface $entity) | |||||
{ | |||||
$userSystem = $this->userStore->getOneByDevAlias('system'); | |||||
$this->initBlameable($entity, $userSystem); | |||||
return $entity; | |||||
} | |||||
public function initBlameableUpdatedSystem(EntityInterface $entity) | |||||
{ | |||||
$userSystem = $this->userStore->getOneByDevAlias('system'); | |||||
$this->initBlameableUpdated($entity, $userSystem); | |||||
return $entity; | |||||
} | |||||
public function initBlameable(EntityInterface $entity, UserInterface $user) | |||||
{ | |||||
if ($entity instanceof BlameableInterface) { | |||||
$entity->setCreatedBy($user); | |||||
} | |||||
$this->initBlameableUpdated($entity, $user); | |||||
} | |||||
public function initBlameableUpdated(EntityInterface $entity, UserInterface $user) | |||||
{ | |||||
if ($entity instanceof BlameableInterface) { | |||||
$entity->setUpdatedBy($user); | |||||
} | |||||
} | |||||
} | } |
<?php | |||||
namespace Lc\SovBundle\Doctrine\Extension; | |||||
use Doctrine\ORM\Mapping as ORM; | |||||
use Gedmo\Mapping\Annotation as Gedmo; | |||||
use Lc\SovBundle\Model\User\UserInterface; | |||||
trait BlameableNullableTrait | |||||
{ | |||||
/** | |||||
* @Gedmo\Blameable(on="create") | |||||
* @ORM\ManyToOne(targetEntity="Lc\SovBundle\Model\User\UserInterface") | |||||
* @ORM\JoinColumn(nullable=true) | |||||
*/ | |||||
protected $createdBy; | |||||
/** | |||||
* @Gedmo\Blameable(on="update") | |||||
* @ORM\ManyToOne(targetEntity="Lc\SovBundle\Model\User\UserInterface") | |||||
* @ORM\JoinColumn(nullable=true) | |||||
*/ | |||||
protected $updatedBy; | |||||
} |
trait BlameableTrait | trait BlameableTrait | ||||
{ | { | ||||
/** | |||||
* @Gedmo\Blameable(on="create") | |||||
* @ORM\ManyToOne(targetEntity="Lc\SovBundle\Model\User\UserInterface") | |||||
* @ORM\JoinColumn(nullable=false) | |||||
*/ | |||||
protected $createdBy; | |||||
/** | |||||
* @Gedmo\Blameable(on="update") | |||||
* @ORM\ManyToOne(targetEntity="Lc\SovBundle\Model\User\UserInterface") | |||||
* @ORM\JoinColumn(nullable=false) | |||||
*/ | |||||
protected $updatedBy; | |||||
public function getCreatedBy(): ?UserInterface | |||||
{ | |||||
return $this->createdBy; | |||||
} | |||||
public function setCreatedBy(?UserInterface $createdBy): self | |||||
{ | |||||
$this->createdBy = $createdBy; | |||||
return $this; | |||||
} | |||||
public function getUpdatedBy(): ?UserInterface | |||||
{ | |||||
return $this->updatedBy; | |||||
} | |||||
public function setUpdatedBy(?UserInterface $updatedBy): self | |||||
{ | |||||
$this->updatedBy = $updatedBy; | |||||
return $this; | |||||
} | |||||
} | |||||
/** | |||||
* @Gedmo\Blameable(on="create") | |||||
* @ORM\ManyToOne(targetEntity="Lc\SovBundle\Model\User\UserInterface") | |||||
* @ORM\JoinColumn(nullable=true) | |||||
*/ | |||||
protected $createdBy; | |||||
/** | |||||
* @Gedmo\Blameable(on="update") | |||||
* @ORM\ManyToOne(targetEntity="Lc\SovBundle\Model\User\UserInterface") | |||||
* @ORM\JoinColumn(nullable=true) | |||||
*/ | |||||
protected $updatedBy; | |||||
public function getCreatedBy(): ?UserInterface | |||||
{ | |||||
return $this->createdBy; | |||||
} | |||||
public function setCreatedBy(?UserInterface $createdBy): self | |||||
{ | |||||
$this->createdBy = $createdBy; | |||||
return $this; | |||||
} | |||||
public function getUpdatedBy(): ?UserInterface | |||||
{ | |||||
return $this->updatedBy; | |||||
} | |||||
public function setUpdatedBy(?UserInterface $updatedBy): self | |||||
{ | |||||
$this->updatedBy = $updatedBy; | |||||
return $this; | |||||
} | |||||
} |
private function setSortableProperty(EntityInterface $entity, AbstractRepositoryInterface $entityRepository) | private function setSortableProperty(EntityInterface $entity, AbstractRepositoryInterface $entityRepository) | ||||
{ | { | ||||
$countParam = array(); | |||||
if ($entity instanceof StatusInterface) { | if ($entity instanceof StatusInterface) { | ||||
$countParam['status'] = 1; | $countParam['status'] = 1; | ||||
} | } | ||||
if ($entity instanceof TreeInterface) { | if ($entity instanceof TreeInterface) { | ||||
if($entity->getParent()){ | |||||
if ($entity->getParent()) { | |||||
$countParam['parent'] = $entity->getParent()->getId(); | $countParam['parent'] = $entity->getParent()->getId(); | ||||
}else{ | |||||
} else { | |||||
$countParam['parent'] = null; | $countParam['parent'] = null; | ||||
} | } | ||||
} | } | ||||
} | } | ||||
} | |||||
} |
use Doctrine\ORM\Mapping as ORM; | use Doctrine\ORM\Mapping as ORM; | ||||
use Gedmo\Mapping\Annotation as Gedmo; | use Gedmo\Mapping\Annotation as Gedmo; | ||||
use Lc\SovBundle\Doctrine\Extension\OpenGraphInterface; | |||||
use Lc\SovBundle\Doctrine\Extension\OpenGraphTrait; | |||||
use Lc\SovBundle\Doctrine\Pattern\AbstractFullEntity; | use Lc\SovBundle\Doctrine\Pattern\AbstractFullEntity; | ||||
use Lc\SovBundle\Model\File\FileInterface; | use Lc\SovBundle\Model\File\FileInterface; | ||||
use Lc\SovBundle\Model\Newsletter\NewsletterInterface; | use Lc\SovBundle\Model\Newsletter\NewsletterInterface; | ||||
/** | /** | ||||
* @ORM\MappedSuperclass() | * @ORM\MappedSuperclass() | ||||
*/ | */ | ||||
abstract class NewsModel extends AbstractFullEntity implements NewsInterface | |||||
abstract class NewsModel extends AbstractFullEntity implements NewsInterface, OpenGraphInterface | |||||
{ | { | ||||
use OpenGraphTrait; | |||||
/** | /** | ||||
* @ORM\Column(type="datetime") | * @ORM\Column(type="datetime") | ||||
* @Gedmo\Timestampable(on="create") | * @Gedmo\Timestampable(on="create") |
abstract class TicketMessageModel extends AbstractLightEntity implements TicketMessageInterface, EntityInterface, StatusInterface | abstract class TicketMessageModel extends AbstractLightEntity implements TicketMessageInterface, EntityInterface, StatusInterface | ||||
{ | { | ||||
use StatusTrait; | use StatusTrait; | ||||
use BlameableNullableTrait; | |||||
/** | /** | ||||
* @ORM\Column(type="text") | * @ORM\Column(type="text") |
*/ | */ | ||||
abstract class TicketModel extends AbstractLightEntity implements TicketInterface, EntityInterface | abstract class TicketModel extends AbstractLightEntity implements TicketInterface, EntityInterface | ||||
{ | { | ||||
use BlameableNullableTrait; | |||||
const TYPE_TECHNICAL_PROBLEM = 'technical-problem'; | const TYPE_TECHNICAL_PROBLEM = 'technical-problem'; |
use Doctrine\Common\Collections\ArrayCollection; | use Doctrine\Common\Collections\ArrayCollection; | ||||
use Doctrine\Common\Collections\Collection; | use Doctrine\Common\Collections\Collection; | ||||
use Lc\SovBundle\Doctrine\EntityInterface; | use Lc\SovBundle\Doctrine\EntityInterface; | ||||
use Lc\SovBundle\Doctrine\Pattern\AbstractFullEntity; | |||||
use Lc\SovBundle\Doctrine\Pattern\AbstractLightEntity; | use Lc\SovBundle\Doctrine\Pattern\AbstractLightEntity; | ||||
/** | /** | ||||
* @ORM\MappedSuperclass() | * @ORM\MappedSuperclass() | ||||
*/ | */ | ||||
abstract class GroupUserModel extends AbstractLightEntity implements GroupUserInterface, EntityInterface | |||||
abstract class GroupUserModel extends AbstractFullEntity implements GroupUserInterface, EntityInterface | |||||
{ | { | ||||
/** | |||||
* @ORM\Column(type="string", length=255) | |||||
*/ | |||||
protected $title; | |||||
/** | /** | ||||
* @ORM\ManyToMany(targetEntity="Lc\SovBundle\Model\User\UserInterface", mappedBy="groupUsers") | * @ORM\ManyToMany(targetEntity="Lc\SovBundle\Model\User\UserInterface", mappedBy="groupUsers") | ||||
*/ | */ |
use Lc\SovBundle\Doctrine\EntityInterface; | use Lc\SovBundle\Doctrine\EntityInterface; | ||||
use Lc\SovBundle\Doctrine\Extension\DevAliasInterface; | use Lc\SovBundle\Doctrine\Extension\DevAliasInterface; | ||||
use Lc\SovBundle\Doctrine\Extension\DevAliasTrait; | use Lc\SovBundle\Doctrine\Extension\DevAliasTrait; | ||||
use Lc\SovBundle\Doctrine\Extension\TimestampableTrait; | |||||
use Lc\SovBundle\Model\Newsletter\NewsletterInterface; | use Lc\SovBundle\Model\Newsletter\NewsletterInterface; | ||||
use Lc\SovBundle\Model\Ticket\TicketInterface; | use Lc\SovBundle\Model\Ticket\TicketInterface; | ||||
use Symfony\Component\Security\Core\User\UserInterface; | use Symfony\Component\Security\Core\User\UserInterface; | ||||
abstract class UserModel implements EntityInterface, UserInterface, DevAliasInterface | abstract class UserModel implements EntityInterface, UserInterface, DevAliasInterface | ||||
{ | { | ||||
use DevAliasTrait; | use DevAliasTrait; | ||||
use TimestampableTrait; | |||||
/** | /** | ||||
* @ORM\Column(type="string", length=180, unique=true) | * @ORM\Column(type="string", length=180, unique=true) | ||||
*/ | */ |
$query->filterByEmail($email); | $query->filterByEmail($email); | ||||
return $query->findOne(); | return $query->findOne(); | ||||
} | } | ||||
} | } |