Pārlūkot izejas kodu

Refactoring services

develop
Guillaume pirms 3 gadiem
vecāks
revīzija
e0951c4250
16 mainītis faili ar 369 papildinājumiem un 180 dzēšanām
  1. +7
    -22
      Controller/Setting/SettingAdminController.php
  2. +51
    -0
      Doctrine/Extension/BlameableNullableTrait.php
  3. +6
    -4
      Model/Setting/EntitySettingTrait.php
  4. +8
    -0
      Model/Setting/SettingInterface.php
  5. +1
    -12
      Model/Setting/SettingModel.php
  6. +0
    -17
      Model/Site/PageModel.php
  7. +2
    -14
      Model/Ticket/TicketMessageModel.php
  8. +4
    -83
      Model/Ticket/TicketModel.php
  9. +87
    -24
      Model/User/UserModel.php
  10. +14
    -0
      Repository/AbstractRepositoryQuery.php
  11. +18
    -0
      Repository/AbstractStore.php
  12. +9
    -1
      Repository/User/UserRepositoryQuery.php
  13. +12
    -3
      Repository/User/UserStore.php
  14. +21
    -0
      Solver/Setting/SettingSolver.php
  15. +76
    -0
      Solver/Ticket/TicketSolver.php
  16. +53
    -0
      Solver/User/UserSolver.php

+ 7
- 22
Controller/Setting/SettingAdminController.php Parādīt failu

@@ -16,45 +16,30 @@ use Symfony\Component\Routing\Annotation\Route;

class SettingAdminController extends AbstractController
{
protected EntityManagerInterface $entityManager;
protected TranslatorAdmin $translatorAdmin;
protected SiteSettingContainer $siteSettingContainer;
protected SiteContainer $siteContainer;

public function __construct(
EntityManagerInterface $entityManager,
TranslatorAdmin $translatorAdmin,
SiteSettingContainer $siteSettingContainer,
SiteContainer $siteContainer
) {
$this->entityManager = $entityManager;
$this->translatorAdmin = $translatorAdmin;
$this->siteSettingContainer = $siteSettingContainer;
$this->siteContainer = $siteContainer;
}

/**
* @Route("/admin/setting/site", name="sov_admin_setting_site")
*/
public function manageGlobal(Request $request)
public function manageGlobal(Request $request, EntityManagerInterface $entityManager)
{
$site = $this->siteContainer->getRepositoryQuery()->getRepository()->findOneByDevAlias('default') ;

$site = $this->get(SiteContainer::class)->getStore()->getOneByDevAlias('default') ;
$form = $this->createForm(SiteSettingsFormType::class, $site);

$form->handleRequest($request);

if ($form->isSubmitted() && $form->isValid()) {

$this->entityManager->update($site);
$this->entityManager->flush();
$entityManager->update($site);
$entityManager->flush();

$this->addFlash('success', $this->translatorAdmin->transFlashMessage('settings_saved'));
$this->addFlash('success', $this->get(TranslatorAdmin::class)->transFlashMessage('settings_saved'));
}

return $this->render(
'@LcSov/admin/setting/edit_site.html.twig' ,
[
'setting_definition' => $this->siteSettingContainer->getDefinition(),
'setting_definition' => $this->get(SiteSettingContainer::class)->getDefinition(),
'form' => $form->createView()
]
);

+ 51
- 0
Doctrine/Extension/BlameableNullableTrait.php Parādīt failu

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


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

}

+ 6
- 4
Model/Setting/EntitySettingTrait.php Parādīt failu

@@ -2,9 +2,11 @@

namespace Lc\SovBundle\Model\Setting;

//TODO à déplacer dans un solver

trait EntitySettingTrait
{
public function getSetting($name)
public function getSetting($name): ?SettingModel
{
if ($this->getSettings()) {
foreach ($this->getSettings() as $setting) {
@@ -14,10 +16,10 @@ trait EntitySettingTrait
}
}

return false;
return null;
}

public function getSettingValue($name)
public function getSettingValue($name): ?string
{
if ($this->getSettings()) {
foreach ($this->getSettings() as $setting) {
@@ -27,7 +29,7 @@ trait EntitySettingTrait
}
}

return false;
return null;
}

}

+ 8
- 0
Model/Setting/SettingInterface.php Parādīt failu

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

namespace Lc\SovBundle\Model\Setting;

interface SettingInterface
{

}

+ 1
- 12
Model/Setting/SettingModel.php Parādīt failu

@@ -8,7 +8,7 @@ use Lc\SovBundle\Model\File\FileInterface;
/**
* @ORM\MappedSuperclass()
*/
abstract class SettingModel
abstract class SettingModel implements SettingInterface
{
/**
* @ORM\Column(type="string", length=63)
@@ -30,17 +30,6 @@ abstract class SettingModel
*/
protected $file;

public function getValue()
{
if ($this->getText()) {
return $this->getText();
} elseif ($this->getDate()) {
return $this->getDate();
} elseif ($this->getFile()) {
return $this->getFile();
}
}

public function getName(): ?string
{
return $this->name;

+ 0
- 17
Model/Site/PageModel.php Parādīt failu

@@ -10,26 +10,9 @@ use Lc\SovBundle\Doctrine\Pattern\AbstractFullEntity;
*/
abstract class PageModel extends AbstractFullEntity implements PageInterface
{
/**
* @ORM\Column(type="text", nullable=true)
*/
protected $content;

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

public function getContent(): ?string
{
return $this->content;
}

public function setContent(?string $content): self
{
$this->content = $content;

return $this;
}

}

+ 2
- 14
Model/Ticket/TicketMessageModel.php Parādīt failu

@@ -5,6 +5,7 @@ namespace Lc\SovBundle\Model\Ticket;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
use Lc\SovBundle\Doctrine\EntityInterface;
use Lc\SovBundle\Doctrine\Extension\BlameableNullableTrait;
use Lc\SovBundle\Doctrine\Extension\StatusInterface;
use Lc\SovBundle\Doctrine\Extension\StatusTrait;
use Lc\SovBundle\Doctrine\Pattern\AbstractLightEntity;
@@ -15,20 +16,7 @@ use Lc\SovBundle\Doctrine\Pattern\AbstractLightEntity;
abstract class TicketMessageModel extends AbstractLightEntity implements TicketMessageInterface, EntityInterface, StatusInterface
{
use StatusTrait;

/**
* @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;
use BlameableNullableTrait;

/**
* @ORM\Column(type="text")

+ 4
- 83
Model/Ticket/TicketModel.php Parādīt failu

@@ -7,6 +7,7 @@ use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
use Lc\SovBundle\Doctrine\EntityInterface;
use Lc\SovBundle\Doctrine\Extension\BlameableNullableTrait;
use Lc\SovBundle\Doctrine\Pattern\AbstractLightEntity;
use Lc\SovBundle\Model\User\UserInterface;

@@ -15,6 +16,9 @@ use Lc\SovBundle\Model\User\UserInterface;
*/
abstract class TicketModel extends AbstractLightEntity implements TicketInterface, EntityInterface
{
use BlameableNullableTrait;


const TYPE_TECHNICAL_PROBLEM = 'technical-problem';
const TYPE_GENERAL_QUESTION = 'general-question';

@@ -22,49 +26,6 @@ abstract class TicketModel extends AbstractLightEntity implements TicketInterfac
const TICKET_STATUS_BEING_PROCESSED = 'being-processed';
const TICKET_STATUS_CLOSED = 'closed';


public function getTypeChoices(): array
{
return [
TicketModel::TYPE_GENERAL_QUESTION,
TicketModel::TYPE_TECHNICAL_PROBLEM,
];
}

public function getStatusChoices(): array
{
return [
TicketModel::TICKET_STATUS_OPEN,
TicketModel::TICKET_STATUS_BEING_PROCESSED,
TicketModel::TICKET_STATUS_CLOSED,
];
}


public function getTypeLabel(): string
{
return 'entity.Ticket.fields.typeChoices.'.$this->getType();
}

public function getStatusLabel(): string
{
return 'entity.Ticket.statuChoices.'.$this->getStatus();
}

/**
* @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;

/**
* @ORM\Column(type="string", length=32)
*/
@@ -121,46 +82,6 @@ abstract class TicketModel extends AbstractLightEntity implements TicketInterfac
$this->ticketMessages = new ArrayCollection();
}

public function getUsername()
{
if ($this->getUser()) {
return $this->getUser()->getName();
} else {
return strtoupper($this->getVisitorLastname()).' '.$this->getVisitorFirstname();
}
}

public function getUserInfosTicket()
{
$user = $this->getUser();
if ($user) {
return '#'.$user->getId().' '.$user->getName().' '.$user->getEmail();
} else {
return strtoupper($this->getVisitorLastname()).' '.$this->getVisitorFirstname().' '.$this->getVisitorEmail(
);
}
}

public function getEmail()
{
if ($this->getUser()) {
return $this->getUser()->getEmail();
} else {
return $this->getVisitorEmail();
}
}

public function getVisitorInfos()
{
return strtoupper($this->getVisitorLastname()).' '.$this->getVisitorFirstname().' ('.$this->getVisitorEmail(
).')';
}

public function getLastMessage()
{
return $this->getTicketMessages()->last();
}

public function getType(): ?string
{
return $this->type;

Model/User/User.php → Model/User/UserModel.php Parādīt failu

@@ -2,16 +2,18 @@

namespace Lc\SovBundle\Model\User;

use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Lc\SovBundle\Doctrine\EntityInterface;
use Lc\SovBundle\Model\Newsletter\NewsletterInterface;
use Lc\SovBundle\Model\Ticket\TicketInterface;
use Symfony\Component\Security\Core\User\UserInterface;

/**
* @ORM\MappedSuperclass()
*/
abstract class User implements EntityInterface, UserInterface
abstract class UserModel implements EntityInterface, UserInterface
{
/**
* @ORM\Column(type="string", length=180, unique=true)
@@ -39,6 +41,15 @@ abstract class User implements EntityInterface, UserInterface
*/
protected $firstname;

/**
* @ORM\Column(type="string", length=20, nullable=true)
*/
protected $phone;
/**
* @ORM\Column(type="boolean", nullable=true)
*/
protected $gender;

/**
* @ORM\Column(type="boolean")
*/
@@ -49,37 +60,29 @@ abstract class User implements EntityInterface, UserInterface
*/
protected $groupUsers;

// isUserInGroupVip
public function isInGroupUserVip()
{
return $this->isInGroupByDevAlias('vip') ;
}
/**
* @ORM\OneToMany(targetEntity="Lc\SovBundle\Model\Ticket\TicketInterface", mappedBy="user")
*/
protected $tickets;

// isUserInGroup
public function isInGroupUser(GroupUserInterface $groupUser)
{
return $this->isInGroupByDevAlias($groupUser->getDevAlias());
}
/**
* @ORM\Column(type="array", nullable=true)
*/
protected $ticketTypesNotification = [];

// isUserInGroupByDevAlias
public function isInGroupByDevAlias(string $groupUserDevAlias)
public function __construct()
{
$groupUsers = $this->getGroupUsers();

foreach($groupUsers as $groupUser) {
if($groupUser->getDevAlias() == $groupUserDevAlias) {
return true;
}
}

return false;
$this->tickets = new ArrayCollection();
}

public function isSubscribedToNewsletter(NewsletterInterface $newsletter)
public function __toString()
{
return $this->getNewsletters()->contains($newsletter);
return '#' . $this->getId() . ' ' . strtoupper($this->getLastname()) . ' ' . $this->getFirstname(
) . ' (' . $this->getEmail() . ')';
}



public function getEmail(): ?string
{
return $this->email;
@@ -102,6 +105,20 @@ abstract class User implements EntityInterface, UserInterface
return (string)$this->email;
}



public function getGender(): ?bool
{
return $this->gender;
}

public function setGender(?bool $gender): self
{
$this->gender = $gender;

return $this;
}

/**
* @see UserInterface
*/
@@ -241,4 +258,50 @@ abstract class User implements EntityInterface, UserInterface
return $this;
}



/**
* @return Collection|TicketInterface[]
*/
public function getTickets(): Collection
{
return $this->tickets;
}

public function addTicket(TicketInterface $ticket): self
{
if (!$this->tickets->contains($ticket)) {
$this->tickets[] = $ticket;
$ticket->setUser($this);
}

return $this;
}

public function removeTicket(TicketInterface $ticket): self
{
if ($this->tickets->contains($ticket)) {
$this->tickets->removeElement($ticket);
// set the owning side to null (unless already changed)
if ($ticket->getUser() === $this) {
$ticket->setUser(null);
}
}

return $this;
}

public function getTicketTypesNotification(): ?array
{
return $this->ticketTypesNotification;
}

public function setTicketTypesNotification(?array $ticketTypesNotification): self
{
$this->ticketTypesNotification = $ticketTypesNotification;

return $this;
}


}

+ 14
- 0
Repository/AbstractRepositoryQuery.php Parādīt failu

@@ -108,5 +108,19 @@ abstract class AbstractRepositoryQuery
return $this->addOrderBy('.' . $field, $sort);
}
}

public function filterById(int $id)
{
return $this
->andWhere('.id = :id')
->setParameter('id', $id);
}

public function filterByDevAlias(string $devAlias): self
{
return $this
->andWhere('.devAlias = :devAlias')
->setParameter('devAlias', $devAlias);
}
}


+ 18
- 0
Repository/AbstractStore.php Parādīt failu

@@ -8,4 +8,22 @@ abstract class AbstractStore
{
return $this->query;
}

public function getOneById(int $id)
{
$query = $this->query->create();

$query->filterById($id);

return $query->findOne();
}

public function getOneByDevAlias(string $devAlias)
{
$query = $this->query->create();

$query->filterByDevAlias($devAlias);

return $query->findOne();
}
}

+ 9
- 1
Repository/User/UserRepositoryQuery.php Parādīt failu

@@ -34,4 +34,12 @@ class UserRepositoryQuery extends AbstractRepositoryQuery implements UserReposit
->andWhere('.ticketTypesNotification LIKE :ticketType')
->setParameter('ticketType', '%"' . $ticketType . '"%');
}
}

public function filterByEmail(string $email): self
{
return $this
->andWhere('.email LIKE :email')
->setParameter('email', $email);
}

}

+ 12
- 3
Repository/User/UserStore.php Parādīt failu

@@ -22,7 +22,7 @@ class UserStore extends AbstractStore implements UserStoreInterface
}

$query
->filterByNewsletter($newsletter);
->filterByNewsletter($newsletter);

return $query->find();
}
@@ -32,7 +32,7 @@ class UserStore extends AbstractStore implements UserStoreInterface
{
$query = $this->query->create();
$query
->filterByRole($role);
->filterByRole($role);

return $query->find();
}
@@ -42,8 +42,17 @@ class UserStore extends AbstractStore implements UserStoreInterface
{
$query = $this->query->create();
$query
->filterByTicketTypeNotification($ticketType);
->filterByTicketTypeNotification($ticketType);

return $query->find();
}

public function getOneByEmail(string $email)
{
$query = $this->query->create();
$query
->filterByEmail($email);

return $query->findOne();
}
}

+ 21
- 0
Solver/Setting/SettingSolver.php Parādīt failu

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

namespace Lc\SovBundle\Solver\Setting;

use Lc\SovBundle\Model\Setting\SettingInterface;
use Lc\SovBundle\Model\Ticket\TicketInterface;
use Lc\SovBundle\Model\Ticket\TicketModel;

class SettingSolver
{
public function getValue(SettingInterface $setting)
{
if ($this->getText()) {
return $this->getText();
} elseif ($this->getDate()) {
return $this->getDate();
} elseif ($this->getFile()) {
return $this->getFile();
}
}
}

+ 76
- 0
Solver/Ticket/TicketSolver.php Parādīt failu

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

namespace Lc\SovBundle\Solver\Ticket;

use Lc\SovBundle\Model\Ticket\TicketInterface;
use Lc\SovBundle\Model\Ticket\TicketModel;

class TicketSolver
{
public function getTypeChoices(): array
{
return [
TicketModel::TYPE_GENERAL_QUESTION,
TicketModel::TYPE_TECHNICAL_PROBLEM,
];
}

public function getStatusChoices(): array
{
return [
TicketModel::TICKET_STATUS_OPEN,
TicketModel::TICKET_STATUS_BEING_PROCESSED,
TicketModel::TICKET_STATUS_CLOSED,
];
}

public function getTypeLabel(TicketInterface $ticket): string
{
return 'entity.Ticket.fields.typeChoices.'.$ticket->getType();
}

public function getStatusLabel(TicketInterface $ticket): string
{
return 'entity.Ticket.statuChoices.'.$ticket->getStatus();
}

public function getUsername(TicketInterface $ticket)
{
if ($ticket->getUser()) {
return $ticket->getUser()->getName();
} else {
return strtoupper($ticket->getVisitorLastname()).' '.$ticket->getVisitorFirstname();
}
}

public function getUserInfosTicket(TicketInterface $ticket)
{
$user = $ticket->getUser();
if ($user) {
return '#'.$user->getId().' '.$user->getName().' '.$user->getEmail();
} else {
return strtoupper($ticket->getVisitorLastname()).' '.$ticket->getVisitorFirstname().' '.$ticket->getVisitorEmail(
);
}
}

public function getEmail(TicketInterface $ticket)
{
if ($ticket->getUser()) {
return $ticket->getUser()->getEmail();
} else {
return $ticket->getVisitorEmail();
}
}

public function getVisitorInfos(TicketInterface $ticket)
{
return strtoupper($ticket->getVisitorLastname()).' '.$ticket->getVisitorFirstname().' ('.$ticket->getVisitorEmail(
).')';
}

public function getLastMessage(TicketInterface $ticket)
{
return $ticket->getTicketMessages()->last();
}
}

+ 53
- 0
Solver/User/UserSolver.php Parādīt failu

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

namespace Lc\SovBundle\Solver\User;

use Lc\SovBundle\Model\Newsletter\NewsletterInterface;
use Lc\SovBundle\Model\User\GroupUserInterface;
use Lc\SovBundle\Model\User\UserInterface;

class UserSolver
{
// @TODO : à écrire si besoin (voir __toString de UserModel)
public function getSummary(UserInterface $user)
{

}

public function getName(UserInterface $user): ?string
{
return (string) ucfirst(strtolower($user->getFirstname())) . ' ' . strtoupper($user->getLastname());
}


// isUserInGroupVip
public function isInGroupUserVip(UserInterface $user)
{
return $this->isInGroupByDevAlias($user, 'vip') ;
}

// isUserInGroup
public function isInGroupUser(UserInterface $user, GroupUserInterface $groupUser)
{
return $this->isInGroupByDevAlias($user, $groupUser->getDevAlias());
}

// isUserInGroupByDevAlias
public function isInGroupByDevAlias(UserInterface $user, string $groupUserDevAlias)
{
$groupUsers = $user->getGroupUsers();

foreach($groupUsers as $groupUser) {
if($groupUser->getDevAlias() == $groupUserDevAlias) {
return true;
}
}

return false;
}

public function isSubscribedToNewsletter(UserInterface $user, NewsletterInterface $newsletter)
{
return $user->getNewsletters()->contains($newsletter);
}
}

Notiek ielāde…
Atcelt
Saglabāt