@@ -3,16 +3,21 @@ | |||
namespace Lc\SovBundle\Builder\User; | |||
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\User\UserInterface; | |||
use Lc\SovBundle\Repository\User\UserStore; | |||
class UserBuilder | |||
{ | |||
protected EntityManagerInterface $entityManager; | |||
protected UserStore $userStore; | |||
public function __construct(EntityManagerInterface $entityManager) | |||
public function __construct(EntityManagerInterface $entityManager, UserStore $userStore) | |||
{ | |||
$this->entityManager = $entityManager; | |||
$this->userStore = $userStore; | |||
} | |||
public function setNewsletter(UserInterface $user, NewsletterInterface $newsletter, bool $subscribeNewsletter): void | |||
@@ -22,8 +27,38 @@ class UserBuilder | |||
} else { | |||
$user->removeNewsletter($newsletter); | |||
} | |||
$this->entityManager->persist($user); | |||
$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); | |||
} | |||
} | |||
} |
@@ -12,14 +12,14 @@ trait BlameableTrait | |||
/** | |||
* @Gedmo\Blameable(on="create") | |||
* @ORM\ManyToOne(targetEntity="Lc\SovBundle\Model\User\UserInterface") | |||
* @ORM\JoinColumn(nullable=false) | |||
* @ORM\JoinColumn(nullable=true) | |||
*/ | |||
protected $createdBy; | |||
/** | |||
* @Gedmo\Blameable(on="update") | |||
* @ORM\ManyToOne(targetEntity="Lc\SovBundle\Model\User\UserInterface") | |||
* @ORM\JoinColumn(nullable=false) | |||
* @ORM\JoinColumn(nullable=true) | |||
*/ | |||
protected $updatedBy; | |||
@@ -48,4 +48,4 @@ trait BlameableTrait | |||
return $this; | |||
} | |||
} | |||
} |
@@ -41,14 +41,15 @@ class SortablePropertyEventSubscriber implements EventSubscriberInterface | |||
private function setSortableProperty(EntityInterface $entity, AbstractRepositoryInterface $entityRepository) | |||
{ | |||
$countParam = array(); | |||
if ($entity instanceof StatusInterface) { | |||
$countParam['status'] = 1; | |||
} | |||
if ($entity instanceof TreeInterface) { | |||
if($entity->getParent()){ | |||
if ($entity->getParent()) { | |||
$countParam['parent'] = $entity->getParent()->getId(); | |||
}else{ | |||
} else { | |||
$countParam['parent'] = null; | |||
} | |||
} | |||
@@ -59,4 +60,4 @@ class SortablePropertyEventSubscriber implements EventSubscriberInterface | |||
} | |||
} | |||
} |
@@ -4,6 +4,8 @@ namespace Lc\SovBundle\Model\Site; | |||
use Doctrine\ORM\Mapping as ORM; | |||
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\Model\File\FileInterface; | |||
use Lc\SovBundle\Model\Newsletter\NewsletterInterface; | |||
@@ -11,81 +13,83 @@ use Lc\SovBundle\Model\Newsletter\NewsletterInterface; | |||
/** | |||
* @ORM\MappedSuperclass() | |||
*/ | |||
abstract class NewsModel extends AbstractFullEntity implements NewsInterface | |||
abstract class NewsModel extends AbstractFullEntity implements NewsInterface, OpenGraphInterface | |||
{ | |||
/** | |||
* @ORM\Column(type="datetime") | |||
* @Gedmo\Timestampable(on="create") | |||
*/ | |||
protected $date; | |||
use OpenGraphTrait; | |||
/** | |||
* @ORM\Column(type="boolean", nullable=true) | |||
*/ | |||
protected $isSent; | |||
/** | |||
* @ORM\Column(type="datetime") | |||
* @Gedmo\Timestampable(on="create") | |||
*/ | |||
protected $date; | |||
/** | |||
* @ORM\Column(type="boolean", nullable=true) | |||
*/ | |||
protected $isSent; | |||
/** | |||
* @ORM\ManyToOne(targetEntity="Lc\SovBundle\Model\Newsletter\NewsletterInterface", inversedBy="news") | |||
*/ | |||
protected $newsletter; | |||
/** | |||
* @ORM\ManyToOne(targetEntity="Lc\SovBundle\Model\File\FileInterface", cascade={"persist", "remove"}) | |||
*/ | |||
protected $image; | |||
/** | |||
* @ORM\ManyToOne(targetEntity="Lc\SovBundle\Model\Newsletter\NewsletterInterface", inversedBy="news") | |||
*/ | |||
protected $newsletter; | |||
public function __toString() | |||
{ | |||
return $this->getTitle(); | |||
} | |||
/** | |||
* @ORM\ManyToOne(targetEntity="Lc\SovBundle\Model\File\FileInterface", cascade={"persist", "remove"}) | |||
*/ | |||
protected $image; | |||
public function getDate(): ?\DateTimeInterface | |||
{ | |||
return $this->date; | |||
} | |||
public function __toString() | |||
{ | |||
return $this->getTitle(); | |||
} | |||
public function setDate(\DateTimeInterface $date): self | |||
{ | |||
$this->date = $date; | |||
public function getDate(): ?\DateTimeInterface | |||
{ | |||
return $this->date; | |||
} | |||
return $this; | |||
} | |||
public function setDate(\DateTimeInterface $date): self | |||
{ | |||
$this->date = $date; | |||
public function getIsSent(): ?bool | |||
{ | |||
return $this->isSent; | |||
} | |||
return $this; | |||
} | |||
public function setIsSent(?bool $isSent): self | |||
{ | |||
$this->isSent = $isSent; | |||
public function getIsSent(): ?bool | |||
{ | |||
return $this->isSent; | |||
} | |||
return $this; | |||
} | |||
public function setIsSent(?bool $isSent): self | |||
{ | |||
$this->isSent = $isSent; | |||
public function getImage(): ?FileInterface | |||
{ | |||
return $this->image; | |||
} | |||
return $this; | |||
} | |||
public function setImage(?FileInterface $image): self | |||
{ | |||
$this->image = $image; | |||
public function getImage(): ?FileInterface | |||
{ | |||
return $this->image; | |||
} | |||
return $this; | |||
} | |||
public function setImage(?FileInterface $image): self | |||
{ | |||
$this->image = $image; | |||
public function getNewsletter(): ?NewsletterInterface | |||
{ | |||
return $this->newsletter; | |||
} | |||
return $this; | |||
} | |||
public function setNewsletter(?NewsletterInterface $newsletter): self | |||
{ | |||
$this->newsletter = $newsletter; | |||
public function getNewsletter(): ?NewsletterInterface | |||
{ | |||
return $this->newsletter; | |||
} | |||
return $this; | |||
} | |||
public function setNewsletter(?NewsletterInterface $newsletter): self | |||
{ | |||
$this->newsletter = $newsletter; | |||
return $this; | |||
} | |||
} |
@@ -6,12 +6,13 @@ use Doctrine\ORM\Mapping as ORM; | |||
use Doctrine\Common\Collections\ArrayCollection; | |||
use Doctrine\Common\Collections\Collection; | |||
use Lc\SovBundle\Doctrine\EntityInterface; | |||
use Lc\SovBundle\Doctrine\Pattern\AbstractFullEntity; | |||
use Lc\SovBundle\Doctrine\Pattern\AbstractLightEntity; | |||
/** | |||
* @ORM\MappedSuperclass() | |||
*/ | |||
abstract class GroupUserModel extends AbstractLightEntity implements GroupUserInterface, EntityInterface | |||
abstract class GroupUserModel extends AbstractFullEntity implements GroupUserInterface, EntityInterface | |||
{ | |||
/** |
@@ -8,6 +8,7 @@ use Doctrine\ORM\Mapping as ORM; | |||
use Lc\SovBundle\Doctrine\EntityInterface; | |||
use Lc\SovBundle\Doctrine\Extension\DevAliasInterface; | |||
use Lc\SovBundle\Doctrine\Extension\DevAliasTrait; | |||
use Lc\SovBundle\Doctrine\Extension\TimestampableTrait; | |||
use Lc\SovBundle\Model\Newsletter\NewsletterInterface; | |||
use Lc\SovBundle\Model\Ticket\TicketInterface; | |||
use Symfony\Component\Security\Core\User\UserInterface; | |||
@@ -18,6 +19,8 @@ use Symfony\Component\Security\Core\User\UserInterface; | |||
abstract class UserModel implements EntityInterface, UserInterface, DevAliasInterface | |||
{ | |||
use DevAliasTrait; | |||
use TimestampableTrait; | |||
/** | |||
* @ORM\Column(type="string", length=180, unique=true) | |||
*/ |
@@ -61,4 +61,5 @@ class UserStore extends AbstractStore implements UserStoreInterface | |||
$query->filterByEmail($email); | |||
return $query->findOne(); | |||
} | |||
} |