瀏覽代碼

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

feature/ticket^2
Guillaume 3 年之前
父節點
當前提交
90539b6f90
共有 13 個文件被更改,包括 201 次插入333 次删除
  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 查看文件

@@ -0,0 +1,12 @@
<?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 查看文件

@@ -2,6 +2,7 @@

namespace Lc\CaracoleBundle\Controller\Setting;

use Lc\SovBundle\Controller\Setting\SettingAdminController as SovSettingController;
use Doctrine\ORM\EntityManagerInterface;
use Lc\CaracoleBundle\Definition\MerchantSettingDefinitionInterface;
use Lc\CaracoleBundle\Form\Setting\MerchantSettingsFormType;
@@ -13,10 +14,9 @@ use Lc\SovBundle\Definition\SiteSettingDefinition;
use Lc\SovBundle\Form\Setting\SiteSettingsFormType;
use Lc\SovBundle\Repository\Site\SiteRepository;
use Lc\SovBundle\Translation\TranslatorAdmin;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;

class SettingAdminController extends AbstractController
class SettingAdminController extends SovSettingController
{
protected $em;
protected $translatorAdmin;
@@ -86,12 +86,12 @@ class SettingAdminController extends AbstractController
}

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()
]
);
}
}
@@ -119,5 +119,4 @@ class SettingAdminController extends AbstractController
]
);
}

}

+ 129
- 0
Definition/AbstractSettingDefinition.php 查看文件

@@ -0,0 +1,129 @@
<?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 查看文件

@@ -7,24 +7,23 @@ use Lc\SovBundle\Definition\AbstractSettingDefinition;
class MerchantSettingDefinition extends AbstractSettingDefinition implements MerchantSettingDefinitionInterface
{
const CATEGORY_GENERAL = 'general';

const SETTING_URL = 'url';

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

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


+ 25
- 24
EventSubscriber/SettingEventSubscriber.php 查看文件

@@ -27,14 +27,15 @@ class SettingEventSubscriber implements EventSubscriberInterface
protected $sectionSettingFactory;

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->merchantRepository = $merchantRepository;
$this->sectionRepository = $sectionRepository;
@@ -47,24 +48,24 @@ class SettingEventSubscriber implements EventSubscriberInterface
public static function getSubscribedEvents()
{
return [
KernelEvents::CONTROLLER => ['initSettings']
KernelEvents::CONTROLLER => ['initSettings']
];
}

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

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

}
@@ -85,19 +86,19 @@ class SettingEventSubscriber implements EventSubscriberInterface

if ($createEntitySetting) {
$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);
}
} else {
if ($entitySetting->getValue() === null
&& isset($setting['default'])
&& $setting['default'] !== null) {
&& isset($setting['default'])
&& $setting['default'] !== null) {
$methodSetValue = 'set' . ucfirst($setting['field']);
$entitySetting->$methodSetValue($setting['default']);
$this->em->update($entitySetting);

+ 0
- 7
Model/Reminder/ReminderInterface.php 查看文件

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

namespace Lc\CaracoleBundle\Model\Reminder;

interface ReminderInterface
{
}

+ 4
- 167
Model/Reminder/ReminderModel.php 查看文件

@@ -2,195 +2,32 @@

namespace Lc\CaracoleBundle\Model\Reminder;

use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Lc\CaracoleBundle\Doctrine\Extension\FilterMerchantInterface;
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()
*/
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\JoinColumn(nullable=false)
*/
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;
}

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

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 查看文件

@@ -2,26 +2,26 @@

namespace Lc\CaracoleBundle\Model\Setting;

use Lc\CaracoleBundle\Doctrine\Extension\FilterMerchantInterface;
use Lc\CaracoleBundle\Model\Merchant\MerchantInterface;
use Doctrine\ORM\Mapping as ORM;
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\JoinColumn(nullable=false)
*/
protected $merchant;

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

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


+ 2
- 3
Model/Setting/SectionSettingModel.php 查看文件

@@ -5,11 +5,10 @@ namespace Lc\CaracoleBundle\Model\Setting;
use Lc\CaracoleBundle\Model\Section\SectionInterface;
use Doctrine\ORM\Mapping as ORM;
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\JoinColumn(nullable=false)

+ 0
- 8
Model/Setting/SettingInterface.php 查看文件

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

namespace Lc\CaracoleBundle\Model\Setting;

interface SettingInterface
{

}

+ 0
- 87
Model/Setting/SettingTrait.php 查看文件

@@ -1,87 +0,0 @@
<?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 查看文件

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

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)
@@ -12,10 +12,7 @@ use Lc\CaracoleBundle\Model\Reminder\ReminderInterface;
* @method ReminderInterface[] findAll()
* @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 查看文件

@@ -3,7 +3,8 @@
namespace Lc\CaracoleBundle\Repository\Setting;

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)
@@ -11,11 +12,7 @@ use Lc\CaracoleBundle\Repository\AbstractRepository;
* @method SectionSettingInterface[] findAll()
* @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…
取消
儲存