<?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; | |||||
} |
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() | |||||
] | |||||
); | ); | ||||
} | } | ||||
} | } | ||||
] | ] | ||||
); | ); | ||||
} | } | ||||
} | } |
<?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; | |||||
} | |||||
} |
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, | |||||
]; | ]; | ||||
} | } | ||||
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); |
<?php | |||||
namespace Lc\CaracoleBundle\Model\Reminder; | |||||
interface ReminderInterface | |||||
{ | |||||
} |
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; | |||||
} | |||||
} | } |
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; | ||||
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) |
<?php | |||||
namespace Lc\CaracoleBundle\Model\Setting; | |||||
interface SettingInterface | |||||
{ | |||||
} |
<?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; | |||||
} | |||||
} |
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; | |||||
} | } |
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; | |||||
} | } |