Browse Source

Merge branch 'develop' of https://forge.laclic.fr/Laclic/CaracoleBundle into develop

feature/ticket^2
Guillaume 3 years ago
parent
commit
90539b6f90
13 changed files with 201 additions and 333 deletions
  1. +12
    -0
      Controller/Reminder/ReminderAdminController.php
  2. +8
    -9
      Controller/Setting/SettingAdminController.php
  3. +129
    -0
      Definition/AbstractSettingDefinition.php
  4. +7
    -8
      Definition/MerchantSettingDefinition.php
  5. +25
    -24
      EventSubscriber/SettingEventSubscriber.php
  6. +0
    -7
      Model/Reminder/ReminderInterface.php
  7. +4
    -167
      Model/Reminder/ReminderModel.php
  8. +5
    -5
      Model/Setting/MerchantSettingModel.php
  9. +2
    -3
      Model/Setting/SectionSettingModel.php
  10. +0
    -8
      Model/Setting/SettingInterface.php
  11. +0
    -87
      Model/Setting/SettingTrait.php
  12. +5
    -8
      Repository/Reminder/ReminderRepository.php
  13. +4
    -7
      Repository/Setting/SectionSettingRepository.php

+ 12
- 0
Controller/Reminder/ReminderAdminController.php View File

<?php

namespace Lc\CaracoleBundle\Controller\Reminder;

use Lc\CaracoleBundle\Controller\AdminControllerTrait;
use Lc\SovBundle\Controller\Reminder\ReminderController as SovReminderController;

abstract class ReminderAdminController extends SovReminderController
{

use AdminControllerTrait;
}

+ 8
- 9
Controller/Setting/SettingAdminController.php View File



namespace Lc\CaracoleBundle\Controller\Setting; namespace Lc\CaracoleBundle\Controller\Setting;


use Lc\SovBundle\Controller\Setting\SettingAdminController as SovSettingController;
use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityManagerInterface;
use Lc\CaracoleBundle\Definition\MerchantSettingDefinitionInterface; use Lc\CaracoleBundle\Definition\MerchantSettingDefinitionInterface;
use Lc\CaracoleBundle\Form\Setting\MerchantSettingsFormType; use Lc\CaracoleBundle\Form\Setting\MerchantSettingsFormType;
use Lc\SovBundle\Form\Setting\SiteSettingsFormType; use Lc\SovBundle\Form\Setting\SiteSettingsFormType;
use Lc\SovBundle\Repository\Site\SiteRepository; use Lc\SovBundle\Repository\Site\SiteRepository;
use Lc\SovBundle\Translation\TranslatorAdmin; use Lc\SovBundle\Translation\TranslatorAdmin;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;


class SettingAdminController extends AbstractController
class SettingAdminController extends SovSettingController
{ {
protected $em; protected $em;
protected $translatorAdmin; protected $translatorAdmin;
} }


return $this->render( return $this->render(
'@LcCaracole/admin/setting/' . $type . '.html.twig',
[
'resolver' => $resolver,
'setting_definition' => $settingDefinition,
'form' => $form->createView()
]
'@LcCaracole/admin/setting/' . $type . '.html.twig',
[
'resolver' => $resolver,
'setting_definition' => $settingDefinition,
'form' => $form->createView()
]
); );
} }
} }
] ]
); );
} }

} }

+ 129
- 0
Definition/AbstractSettingDefinition.php View File

<?php


namespace Lc\CaracoleBundle\Definition;


abstract class AbstractSettingDefinition
{
protected $settings = [];

public function addSettingText(array $params): self
{
$params['type'] = 'text';
$params['field'] = 'text';
return $this->addSetting($params);
}

public function addSettingTextarea(array $params): self
{
$params['type'] = 'textarea';
$params['field'] = 'text';
return $this->addSetting($params);
}

public function addSettingTextareaAdvanced(array $params): self
{
$params['type'] = 'textarea_advanced';
$params['field'] = 'text';
return $this->addSetting($params);
}

public function addSettingDate(array $params): self
{
$params['type'] = 'date';
$params['field'] = 'date';
return $this->addSetting($params);
}

public function addSettingTime(array $params): self
{
$params['type'] = 'time';
$params['field'] = 'date';
return $this->addSetting($params);
}

public function addSettingFile(array $params): self
{
$params['type'] = 'file';
$params['field'] = 'file';
return $this->addSetting($params);
}

public function addSettingImage(array $params): self
{
$params['type'] = 'image';
$params['field'] = 'file';
return $this->addSetting($params);
}

public function addSettingSelect(array $params): self
{
$params['type'] = 'select';
$params['field'] = 'text';
return $this->addSetting($params);
}

public function addSettingRadio(array $params): self
{
$params['type'] = 'radio';
$params['field'] = 'text';
return $this->addSetting($params);
}

public function addSetting($params)
{
$name = $params['name'];
$category = $params['category'];

if (!isset($this->settings[$category])) {
$this->settings[$category] = [];
}

$this->settings[$category][$name] = $params;

return $this;
}

public function getSettings(): array
{
return $this->settings;
}

public function getSettingsByCategory($category)
{
$settings = $this->getSettings();

if (isset($settings[$category])) {
return $settings[$category];
}

return [];
}

public function getSettingByName($name): ?array
{
$settings = $this->getSettings();

foreach ($settings as $category => $settingsCategory) {
foreach ($settingsCategory as $nameSetting => $setting) {
if ($nameSetting == $name) {
return $setting;
}
}
}

return null;
}

public function getSettingType($name): ?string
{
$setting = $this->getSettingByName($name);

if ($setting) {
return $setting['type'];
}

return null;
}
}

+ 7
- 8
Definition/MerchantSettingDefinition.php View File

class MerchantSettingDefinition extends AbstractSettingDefinition implements MerchantSettingDefinitionInterface class MerchantSettingDefinition extends AbstractSettingDefinition implements MerchantSettingDefinitionInterface
{ {
const CATEGORY_GENERAL = 'general'; const CATEGORY_GENERAL = 'general';

const SETTING_URL = 'url'; const SETTING_URL = 'url';


public function __construct() public function __construct()
{ {
$this $this
->addSettingText(
[
'name' => self::SETTING_URL,
'category' => self::CATEGORY_GENERAL,
]
) ;
->addSettingText(
[
'name' => self::SETTING_URL,
'category' => self::CATEGORY_GENERAL,
]
);
} }


public function getCategories() public function getCategories()
{ {
return [ return [
self::CATEGORY_GENERAL,
self::CATEGORY_GENERAL,
]; ];
} }



+ 25
- 24
EventSubscriber/SettingEventSubscriber.php View File

protected $sectionSettingFactory; protected $sectionSettingFactory;


public function __construct( public function __construct(
EntityManagerInterface $em,
MerchantSettingDefinitionInterface $merchantSettingDefinition,
SectionSettingDefinitionInterface $sectionSettingDefinition,
MerchantRepository $merchantRepository,
SectionRepository $sectionRepository,
MerchantSettingFactory $merchantSettingFactory,
SectionSettingFactory $sectionSettingFactory
) {
EntityManagerInterface $em,
MerchantSettingDefinitionInterface $merchantSettingDefinition,
SectionSettingDefinitionInterface $sectionSettingDefinition,
MerchantRepository $merchantRepository,
SectionRepository $sectionRepository,
MerchantSettingFactory $merchantSettingFactory,
SectionSettingFactory $sectionSettingFactory
)
{
$this->em = $em; $this->em = $em;
$this->merchantRepository = $merchantRepository; $this->merchantRepository = $merchantRepository;
$this->sectionRepository = $sectionRepository; $this->sectionRepository = $sectionRepository;
public static function getSubscribedEvents() public static function getSubscribedEvents()
{ {
return [ return [
KernelEvents::CONTROLLER => ['initSettings']
KernelEvents::CONTROLLER => ['initSettings']
]; ];
} }


public function initSettings() public function initSettings()
{ {
$this->initSettingsGeneric( $this->initSettingsGeneric(
'merchant',
$this->merchantSettingDefinition->getSettings(),
$this->merchantRepository->findAll(),
$this->merchantSettingFactory
'merchant',
$this->merchantSettingDefinition->getSettings(),
$this->merchantRepository->findAll(),
$this->merchantSettingFactory
); );


$this->initSettingsGeneric( $this->initSettingsGeneric(
'section',
$this->sectionSettingDefinition->getSettings(),
$this->sectionRepository->findAll(),
$this->sectionSettingFactory
'section',
$this->sectionSettingDefinition->getSettings(),
$this->sectionRepository->findAll(),
$this->sectionSettingFactory
); );


} }


if ($createEntitySetting) { if ($createEntitySetting) {
$entitySetting = $factory->create( $entitySetting = $factory->create(
[
$type => $entity,
'name' => $setting['name'],
$setting['field'] => isset($setting['default']) ? $setting['default'] : null,
]
[
$type => $entity,
'name' => $setting['name'],
$setting['field'] => isset($setting['default']) ? $setting['default'] : null,
]
); );


$this->em->persist($entitySetting); $this->em->persist($entitySetting);
} }
} else { } else {
if ($entitySetting->getValue() === null if ($entitySetting->getValue() === null
&& isset($setting['default'])
&& $setting['default'] !== null) {
&& isset($setting['default'])
&& $setting['default'] !== null) {
$methodSetValue = 'set' . ucfirst($setting['field']); $methodSetValue = 'set' . ucfirst($setting['field']);
$entitySetting->$methodSetValue($setting['default']); $entitySetting->$methodSetValue($setting['default']);
$this->em->update($entitySetting); $this->em->update($entitySetting);

+ 0
- 7
Model/Reminder/ReminderInterface.php View File

<?php

namespace Lc\CaracoleBundle\Model\Reminder;

interface ReminderInterface
{
}

+ 4
- 167
Model/Reminder/ReminderModel.php View File



namespace Lc\CaracoleBundle\Model\Reminder; namespace Lc\CaracoleBundle\Model\Reminder;


use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM; use Doctrine\ORM\Mapping as ORM;
use Lc\CaracoleBundle\Doctrine\Extension\FilterMerchantInterface; use Lc\CaracoleBundle\Doctrine\Extension\FilterMerchantInterface;
use Lc\CaracoleBundle\Model\Merchant\MerchantInterface; use Lc\CaracoleBundle\Model\Merchant\MerchantInterface;
use Lc\SovBundle\Doctrine\Pattern\AbstractLightEntity;
use Lc\SovBundle\Model\User\UserInterface;
use Lc\SovBundle\Model\Reminder\ReminderModel as SovReminderModel;


/** /**
* @ORM\MappedSuperclass() * @ORM\MappedSuperclass()
*/ */
abstract class ReminderModel extends AbstractLightEntity implements FilterMerchantInterface
abstract class ReminderModel extends SovReminderModel implements FilterMerchantInterface
{ {
public $relatedPage;

/** /**
* @ORM\ManyToOne(targetEntity="Lc\CaracoleBundle\Model\Merchant\MerchantInterface") * @ORM\ManyToOne(targetEntity="Lc\CaracoleBundle\Model\Merchant\MerchantInterface")
* @ORM\JoinColumn(nullable=false) * @ORM\JoinColumn(nullable=false)
*/ */
protected $merchant; protected $merchant;


/**
* @ORM\Column(type="string", length=255)
*/
protected $title;

/**
* @ORM\Column(type="text", nullable=true)
*/
protected $description;

/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
protected $entityName;

/**
* @ORM\Column(type="integer", nullable=true)
*/
protected $entityId;

/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
protected $entityAction;

/**
* @ORM\ManyToMany(targetEntity="Lc\SovBundle\Model\User\UserInterface")
*/
protected $users;

/**
* @ORM\Column(type="date", nullable=true)
*/
protected $dateReminder;


/**
* @ORM\Column(type="boolean", nullable=false)
*/
protected $done;



public function __construct()
{
$this->users = new ArrayCollection();
$this->done = false;
}

public function getMerchant(): ?MerchantInterface
public function getMerchant(): MerchantInterface
{ {
return $this->merchant; return $this->merchant;
} }


public function setMerchant(?MerchantInterface $merchant): self
public function setMerchant(MerchantInterface $merchant): self
{ {
$this->merchant = $merchant; $this->merchant = $merchant;


return $this; return $this;
} }

public function getTitle(): ?string
{
return $this->title;
}

public function setTitle(string $title): self
{
$this->title = $title;

return $this;
}

public function getDescription(): ?string
{
return $this->description;
}

public function setDescription(?string $description): self
{
$this->description = $description;

return $this;
}

public function getEntityName(): ?string
{
return $this->entityName;
}

public function setEntityName(?string $entityName): self
{
$this->entityName = $entityName;

return $this;
}

public function getEntityAction(): ?string
{
return $this->entityAction;
}

public function setEntityAction(?string $entityAction): self
{
$this->entityAction = $entityAction;

return $this;
}

public function getEntityId(): ?int
{
return $this->entityId;
}

public function setEntityId(?int $entityId): self
{
$this->entityId = $entityId;

return $this;
}

/**
* @return Collection|UserInterface[]
*/
public function getUsers(): Collection
{
return $this->users;
}

public function addUser(UserInterface $user): self
{
if (!$this->users->contains($user)) {
$this->users[] = $user;
}

return $this;
}

public function removeUser(UserInterface $user): self
{
if ($this->users->contains($user)) {
$this->users->removeElement($user);
}

return $this;
}

public function getDateReminder(): ?\DateTimeInterface
{
return $this->dateReminder;
}

public function setDateReminder(?\DateTimeInterface $dateReminder): self
{
$this->dateReminder = $dateReminder;

return $this;
}

public function getDone(): ?bool
{
return $this->done;
}

public function setDone(?bool $done): self
{
$this->done = $done;

return $this;
}

} }

+ 5
- 5
Model/Setting/MerchantSettingModel.php View File



namespace Lc\CaracoleBundle\Model\Setting; namespace Lc\CaracoleBundle\Model\Setting;


use Lc\CaracoleBundle\Doctrine\Extension\FilterMerchantInterface;
use Lc\CaracoleBundle\Model\Merchant\MerchantInterface; use Lc\CaracoleBundle\Model\Merchant\MerchantInterface;
use Doctrine\ORM\Mapping as ORM; use Doctrine\ORM\Mapping as ORM;
use Lc\SovBundle\Doctrine\EntityInterface; use Lc\SovBundle\Doctrine\EntityInterface;
use Lc\SovBundle\Model\Setting\SettingModel as SovSettingModel;


abstract class MerchantSettingModel implements SettingInterface, EntityInterface
abstract class MerchantSettingModel extends SovSettingModel implements EntityInterface, FilterMerchantInterface
{ {
use SettingTrait;

/** /**
* @ORM\ManyToOne(targetEntity="Lc\CaracoleBundle\Model\Merchant\MerchantInterface", inversedBy="settings") * @ORM\ManyToOne(targetEntity="Lc\CaracoleBundle\Model\Merchant\MerchantInterface", inversedBy="settings")
* @ORM\JoinColumn(nullable=false) * @ORM\JoinColumn(nullable=false)
*/ */
protected $merchant; protected $merchant;


public function getMerchant(): ?MerchantInterface
public function getMerchant(): MerchantInterface
{ {
return $this->merchant; return $this->merchant;
} }


public function setMerchant(?MerchantInterface $merchant): self
public function setMerchant(MerchantInterface $merchant): self
{ {
$this->merchant = $merchant; $this->merchant = $merchant;



+ 2
- 3
Model/Setting/SectionSettingModel.php View File

use Lc\CaracoleBundle\Model\Section\SectionInterface; use Lc\CaracoleBundle\Model\Section\SectionInterface;
use Doctrine\ORM\Mapping as ORM; use Doctrine\ORM\Mapping as ORM;
use Lc\SovBundle\Doctrine\EntityInterface; use Lc\SovBundle\Doctrine\EntityInterface;
use Lc\SovBundle\Model\Setting\SettingModel as SovSettingModel;


abstract class SectionSettingModel implements SettingInterface, EntityInterface
abstract class SectionSettingModel extends SovSettingModel implements EntityInterface
{ {
use SettingTrait;

/** /**
* @ORM\ManyToOne(targetEntity="Lc\CaracoleBundle\Model\Section\SectionInterface", inversedBy="settings") * @ORM\ManyToOne(targetEntity="Lc\CaracoleBundle\Model\Section\SectionInterface", inversedBy="settings")
* @ORM\JoinColumn(nullable=false) * @ORM\JoinColumn(nullable=false)

+ 0
- 8
Model/Setting/SettingInterface.php View File

<?php

namespace Lc\CaracoleBundle\Model\Setting;

interface SettingInterface
{

}

+ 0
- 87
Model/Setting/SettingTrait.php View File

<?php

namespace Lc\CaracoleBundle\Model\Setting;

use Lc\SovBundle\Model\File\FileInterface;

trait SettingTrait
{
/**
* @ORM\Column(type="string", length=63)
*/
protected $name;

/**
* @ORM\Column(type="text", nullable=true)
*/
protected $text;

/**
* @ORM\Column(type="datetime", nullable=true)
*/
protected $date;

/**
* @ORM\ManyToOne(targetEntity=FileInterface::class, cascade={"persist", "remove"})
*/
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;
}

public function setName(string $name): self
{
$this->name = $name;

return $this;
}

public function getText(): ?string
{
return $this->text;
}

public function setText($text): self
{
$this->text = $text;

return $this;
}

public function getDate(): ?\DateTimeInterface
{
return $this->date;
}

public function setDate(?\DateTimeInterface $date): self
{
$this->date = $date;

return $this;
}

public function getFile(): ?FileInterface
{
return $this->file;
}

public function setFile(?FileInterface $file): self
{
$this->file = $file;

return $this;
}
}

+ 5
- 8
Repository/Reminder/ReminderRepository.php View File



namespace Lc\CaracoleBundle\Repository\Reminder; namespace Lc\CaracoleBundle\Repository\Reminder;


use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
use Lc\CaracoleBundle\Model\Reminder\ReminderInterface;
use Lc\CaracoleBundle\Repository\RepositoryTrait;
use Lc\SovBundle\Model\Reminder\ReminderInterface;
use Lc\SovBundle\Repository\Reminder\ReminderRepository as SovReminderRepository;


/** /**
* @method ReminderInterface|null find($id, $lockMode = null, $lockVersion = null) * @method ReminderInterface|null find($id, $lockMode = null, $lockVersion = null)
* @method ReminderInterface[] findAll() * @method ReminderInterface[] findAll()
* @method ReminderInterface[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null) * @method ReminderInterface[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
*/ */
class ReminderRepository extends ServiceEntityRepository
class ReminderRepository extends SovReminderRepository
{ {
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, ReminderInterface::class);
}
use RepositoryTrait;
} }

+ 4
- 7
Repository/Setting/SectionSettingRepository.php View File

namespace Lc\CaracoleBundle\Repository\Setting; namespace Lc\CaracoleBundle\Repository\Setting;


use Lc\CaracoleBundle\Model\Setting\SectionSettingInterface; use Lc\CaracoleBundle\Model\Setting\SectionSettingInterface;
use Lc\CaracoleBundle\Repository\AbstractRepository;
use Lc\CaracoleBundle\Repository\RepositoryTrait;
use Lc\SovBundle\Repository\Setting\SettingRepository as SovSettingRepository;


/** /**
* @method SectionSettingInterface|null find($id, $lockMode = null, $lockVersion = null) * @method SectionSettingInterface|null find($id, $lockMode = null, $lockVersion = null)
* @method SectionSettingInterface[] findAll() * @method SectionSettingInterface[] findAll()
* @method SectionSettingInterface[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null) * @method SectionSettingInterface[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
*/ */
class SectionSettingRepository extends AbstractRepository
class SectionSettingRepository extends SovSettingRepository
{ {
public function getInterfaceClass()
{
return SectionSettingInterface::class;
}

use RepositoryTrait;
} }

Loading…
Cancel
Save