浏览代码

SiteSetting : maintenance

develop
Guillaume 3 年前
父节点
当前提交
b90660fd85
共有 4 个文件被更改,包括 56 次插入16 次删除
  1. +25
    -1
      Definition/SiteSettingDefinition.php
  2. +19
    -13
      EventSubscriber/SiteSettingEventSubscriber.php
  3. +9
    -1
      Factory/Setting/SiteSettingFactory.php
  4. +3
    -1
      Factory/Site/SiteFactory.php

+ 25
- 1
Definition/SiteSettingDefinition.php 查看文件

@@ -5,13 +5,37 @@ namespace Lc\SovBundle\Definition;

class SiteSettingDefinition extends AbstractSettingDefinition implements SiteSettingDefinitionInterface
{
const CATEGORY_GENERAL = 'general';

const SETTING_MAINTENANCE = 'maintenance';
const SETTING_MAINTENANCE_IP_AUTHORIZED = 'maintenanceIpAuthorized';

public function __construct()
{
$this->addSettingSelect(
[
'category' => self::CATEGORY_GENERAL,
'name' => self::SETTING_MAINTENANCE,
'choices' => [
'Non' => 0,
'Oui' => 1,
]
]
);

$this->addSettingText(
[
'category' => self::CATEGORY_GENERAL,
'name' => self::SETTING_MAINTENANCE_IP_AUTHORIZED,
]
);
}

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

}

+ 19
- 13
EventSubscriber/SiteSettingEventSubscriber.php 查看文件

@@ -47,16 +47,11 @@ class SiteSettingEventSubscriber implements EventSubscriberInterface
{
$site = $this->getSiteDefault();
if (!$site) {
$site = $this->siteFactory->create(
[
'devAlias' => 'default'
]
);
$site = $this->siteFactory->create('default');
$this->em->persist($site);
$this->em->flush($site);
}


$settings = $this->siteSettingDefinition->getSettings();
$factory = $this->siteSettingFactory;

@@ -65,13 +60,24 @@ class SiteSettingEventSubscriber implements EventSubscriberInterface
$entitySetting = $site->getSetting($settingName);

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

$text = null;
$date = null;
$file = null;

$fieldValue = isset($setting['default']) ? $setting['default'] : null;

if($setting['field'] == 'text') {
$text = $fieldValue;
}
if($setting['field'] == 'date') {
$date = $fieldValue;
}
if($setting['field'] == 'file') {
$file = $fieldValue;
}

$entitySetting = $factory->create($site, $setting['name'], $text, $date, $file);

$this->em->persist($entitySetting);
} else {

+ 9
- 1
Factory/Setting/SiteSettingFactory.php 查看文件

@@ -4,14 +4,22 @@ namespace Lc\SovBundle\Factory\Setting;

use App\Entity\Setting\SiteSetting;
use Lc\SovBundle\Factory\AbstractFactory;
use Lc\SovBundle\Model\File\FileInterface;
use Lc\SovBundle\Model\Setting\SiteSettingInterface;
use Lc\SovBundle\Model\Site\SiteInterface;

class SiteSettingFactory extends AbstractFactory implements SiteSettingFactoryInterface
{
public function create(): SiteSettingInterface
public function create(SiteInterface $site, string $name, string $text = null, \DateTime $date = null, FileInterface $file = null): SiteSettingInterface
{
$siteSetting = new SiteSetting();

$siteSetting->setSite($site);
$siteSetting->setName($name);
$siteSetting->setText($text);
$siteSetting->setDate($date);
$siteSetting->setFile($file);

return $siteSetting;
}
}

+ 3
- 1
Factory/Site/SiteFactory.php 查看文件

@@ -8,10 +8,12 @@ use Lc\SovBundle\Model\Site\SiteInterface;

class SiteFactory extends AbstractFactory implements SiteFactoryInterface
{
public function create(): SiteInterface
public function create(string $devAlias = null): SiteInterface
{
$site = new Site();

$site->setDevAlias($devAlias);

return $site;
}
}

正在加载...
取消
保存