class SiteSettingDefinition extends AbstractSettingDefinition implements SiteSettingDefinitionInterface | class SiteSettingDefinition extends AbstractSettingDefinition implements SiteSettingDefinitionInterface | ||||
{ | { | ||||
const CATEGORY_GENERAL = 'general'; | |||||
const SETTING_MAINTENANCE = 'maintenance'; | |||||
const SETTING_MAINTENANCE_IP_AUTHORIZED = 'maintenanceIpAuthorized'; | |||||
public function __construct() | 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() | public function getCategories() | ||||
{ | { | ||||
return [] ; | |||||
return [ | |||||
self::CATEGORY_GENERAL | |||||
]; | |||||
} | } | ||||
} | } |
{ | { | ||||
$site = $this->getSiteDefault(); | $site = $this->getSiteDefault(); | ||||
if (!$site) { | if (!$site) { | ||||
$site = $this->siteFactory->create( | |||||
[ | |||||
'devAlias' => 'default' | |||||
] | |||||
); | |||||
$site = $this->siteFactory->create('default'); | |||||
$this->em->persist($site); | $this->em->persist($site); | ||||
$this->em->flush($site); | $this->em->flush($site); | ||||
} | } | ||||
$settings = $this->siteSettingDefinition->getSettings(); | $settings = $this->siteSettingDefinition->getSettings(); | ||||
$factory = $this->siteSettingFactory; | $factory = $this->siteSettingFactory; | ||||
$entitySetting = $site->getSetting($settingName); | $entitySetting = $site->getSetting($settingName); | ||||
if (!$entitySetting) { | 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); | $this->em->persist($entitySetting); | ||||
} else { | } else { |
use App\Entity\Setting\SiteSetting; | use App\Entity\Setting\SiteSetting; | ||||
use Lc\SovBundle\Factory\AbstractFactory; | use Lc\SovBundle\Factory\AbstractFactory; | ||||
use Lc\SovBundle\Model\File\FileInterface; | |||||
use Lc\SovBundle\Model\Setting\SiteSettingInterface; | use Lc\SovBundle\Model\Setting\SiteSettingInterface; | ||||
use Lc\SovBundle\Model\Site\SiteInterface; | |||||
class SiteSettingFactory extends AbstractFactory implements SiteSettingFactoryInterface | 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 = new SiteSetting(); | ||||
$siteSetting->setSite($site); | |||||
$siteSetting->setName($name); | |||||
$siteSetting->setText($text); | |||||
$siteSetting->setDate($date); | |||||
$siteSetting->setFile($file); | |||||
return $siteSetting; | return $siteSetting; | ||||
} | } | ||||
} | } |
class SiteFactory extends AbstractFactory implements SiteFactoryInterface | class SiteFactory extends AbstractFactory implements SiteFactoryInterface | ||||
{ | { | ||||
public function create(): SiteInterface | |||||
public function create(string $devAlias = null): SiteInterface | |||||
{ | { | ||||
$site = new Site(); | $site = new Site(); | ||||
$site->setDevAlias($devAlias); | |||||
return $site; | return $site; | ||||
} | } | ||||
} | } |