<?php | |||||
/** | |||||
* Copyright distrib (2018) | |||||
* | |||||
* contact@opendistrib.net | |||||
* | |||||
* Ce logiciel est un programme informatique servant à aider les producteurs | |||||
* à distribuer leur production en circuits courts. | |||||
* | |||||
* Ce logiciel est régi par la licence CeCILL soumise au droit français et | |||||
* respectant les principes de diffusion des logiciels libres. Vous pouvez | |||||
* utiliser, modifier et/ou redistribuer ce programme sous les conditions | |||||
* de la licence CeCILL telle que diffusée par le CEA, le CNRS et l'INRIA | |||||
* sur le site "http://www.cecill.info". | |||||
* | |||||
* En contrepartie de l'accessibilité au code source et des droits de copie, | |||||
* de modification et de redistribution accordés par cette licence, il n'est | |||||
* offert aux utilisateurs qu'une garantie limitée. Pour les mêmes raisons, | |||||
* seule une responsabilité restreinte pèse sur l'auteur du programme, le | |||||
* titulaire des droits patrimoniaux et les concédants successifs. | |||||
* | |||||
* A cet égard l'attention de l'utilisateur est attirée sur les risques | |||||
* associés au chargement, à l'utilisation, à la modification et/ou au | |||||
* développement et à la reproduction du logiciel par l'utilisateur étant | |||||
* donné sa spécificité de logiciel libre, qui peut le rendre complexe à | |||||
* manipuler et qui le réserve donc à des développeurs et des professionnels | |||||
* avertis possédant des connaissances informatiques approfondies. Les | |||||
* utilisateurs sont donc invités à charger et tester l'adéquation du | |||||
* logiciel à leurs besoins dans des conditions permettant d'assurer la | |||||
* sécurité de leurs systèmes et ou de leurs données et, plus généralement, | |||||
* à l'utiliser et l'exploiter dans les mêmes conditions de sécurité. | |||||
* | |||||
* Le fait que vous puissiez accéder à cet en-tête signifie que vous avez | |||||
* pris connaissance de la licence CeCILL, et que vous en avez accepté les | |||||
* termes. | |||||
*/ | |||||
namespace backend\controllers; | |||||
use backend\forms\AdminSettingsForm; | |||||
use common\helpers\Ajax; | |||||
use yii\filters\AccessControl; | |||||
use yii\helpers\Html; | |||||
use yii\web\NotFoundHttpException; | |||||
/** | |||||
* UserController implements the CRUD actions for User model. | |||||
*/ | |||||
class SettingAdminController extends BackendController | |||||
{ | |||||
public function behaviors() | |||||
{ | |||||
return [ | |||||
'access' => [ | |||||
'class' => AccessControl::class, | |||||
'rules' => [ | |||||
[ | |||||
'allow' => true, | |||||
'roles' => ['@'], | |||||
'matchCallback' => function ($rule, $action) { | |||||
return $this->getUserModule() | |||||
->getAuthorizationChecker() | |||||
->isGrantedAsAdministrator($this->getUserCurrent()); | |||||
} | |||||
] | |||||
], | |||||
], | |||||
]; | |||||
} | |||||
public function actionIndex() | |||||
{ | |||||
$settingModule = $this->getSettingModule(); | |||||
$model = new AdminSettingsForm(); | |||||
if($model->load(\Yii::$app->request->post()) && $model->validate()) { | |||||
foreach($settingModule->getAdminSettingDefinition()->getSettingDetailsFlat() as $settingDetail) { | |||||
$settingModule->getAdminSettingBag()->set($settingDetail->getName(), $model->{$settingDetail->getName()}); | |||||
} | |||||
} | |||||
return $this->render('index', [ | |||||
'model' => $model | |||||
]); | |||||
} | |||||
} |
<?php | |||||
namespace backend\forms; | |||||
use common\logic\Setting\SettingModule; | |||||
use yii\base\Model; | |||||
class AdminSettingsForm extends Model | |||||
{ | |||||
public function __get($name) | |||||
{ | |||||
return SettingModule::getInstance()->getAdminSettingBag()->get($name); | |||||
} | |||||
public function __set($name, $value) | |||||
{ | |||||
$this->$name = $value; | |||||
} | |||||
public function rules() | |||||
{ | |||||
$rulesArray = []; | |||||
$typesArray = [ | |||||
'string' => ['string', 'text'], | |||||
'date' => ['date'], | |||||
'boolean' => ['boolean'], | |||||
'integer' => ['integer'], | |||||
'double' => ['double', 'float'], | |||||
]; | |||||
foreach($typesArray as $rule => $typesSettingArray) { | |||||
$rulesArray[] = [$this->getSettingNamesByTypeArray($typesSettingArray), $rule]; | |||||
} | |||||
return $rulesArray; | |||||
} | |||||
public function attributeLabels() | |||||
{ | |||||
$attributeLabelsArray = []; | |||||
foreach(SettingModule::getInstance()->getAdminSettingDefinition()->getSettingDetailsFlat() as $settingDetail) { | |||||
$attributeLabelsArray[$settingDetail->getName()] = $settingDetail->getLabel(); | |||||
} | |||||
return $attributeLabelsArray; | |||||
} | |||||
public function getSettingNamesByTypeArray(array $typesSettingArray): array | |||||
{ | |||||
$settingNamesTypeArray = []; | |||||
foreach(SettingModule::getInstance()->getAdminSettingDefinition()->getSettingDetailsFlat() as $settingDetail) { | |||||
if(in_array($settingDetail->getType(), $typesSettingArray)) { | |||||
$settingNamesTypeArray[] = $settingDetail->getName(); | |||||
} | |||||
} | |||||
return $settingNamesTypeArray; | |||||
} | |||||
} | |||||
?> |
['label' => 'Commandes clients', 'icon' => 'calendar', 'url' => ['/stats-admin/customer-orders'], 'visible' => $isUserCurrentGrantedAsAdministrator], | ['label' => 'Commandes clients', 'icon' => 'calendar', 'url' => ['/stats-admin/customer-orders'], 'visible' => $isUserCurrentGrantedAsAdministrator], | ||||
], | ], | ||||
], | ], | ||||
['label' => 'Paramètres', 'icon' => 'cog', 'url' => ['/setting-admin/index'], 'visible' => $isUserCurrentGrantedAsAdministrator && $featureChecker->isEnabled(Feature::ALIAS_SETTINGS)], | |||||
['label' => 'Fonctionnalités', 'icon' => 'flag', 'url' => ['/feature-admin/index'], 'visible' => $isUserCurrentGrantedAsAdministrator], | ['label' => 'Fonctionnalités', 'icon' => 'flag', 'url' => ['/feature-admin/index'], 'visible' => $isUserCurrentGrantedAsAdministrator], | ||||
['label' => 'Tranches de prix', 'icon' => 'eur', 'url' => ['/producer-price-range-admin/index'], 'visible' => $isUserCurrentGrantedAsAdministrator], | ['label' => 'Tranches de prix', 'icon' => 'eur', 'url' => ['/producer-price-range-admin/index'], 'visible' => $isUserCurrentGrantedAsAdministrator], | ||||
['label' => 'Taxes', 'icon' => 'eur', 'url' => ['/tax-rate-admin/index'], 'visible' => $isUserCurrentGrantedAsAdministrator], | ['label' => 'Taxes', 'icon' => 'eur', 'url' => ['/tax-rate-admin/index'], 'visible' => $isUserCurrentGrantedAsAdministrator], |
<?php | |||||
/** | |||||
* Copyright distrib (2018) | |||||
* | |||||
* contact@opendistrib.net | |||||
* | |||||
* Ce logiciel est un programme informatique servant à aider les producteurs | |||||
* à distribuer leur production en circuits courts. | |||||
* | |||||
* Ce logiciel est régi par la licence CeCILL soumise au droit français et | |||||
* respectant les principes de diffusion des logiciels libres. Vous pouvez | |||||
* utiliser, modifier et/ou redistribuer ce programme sous les conditions | |||||
* de la licence CeCILL telle que diffusée par le CEA, le CNRS et l'INRIA | |||||
* sur le site "http://www.cecill.info". | |||||
* | |||||
* En contrepartie de l'accessibilité au code source et des droits de copie, | |||||
* de modification et de redistribution accordés par cette licence, il n'est | |||||
* offert aux utilisateurs qu'une garantie limitée. Pour les mêmes raisons, | |||||
* seule une responsabilité restreinte pèse sur l'auteur du programme, le | |||||
* titulaire des droits patrimoniaux et les concédants successifs. | |||||
* | |||||
* A cet égard l'attention de l'utilisateur est attirée sur les risques | |||||
* associés au chargement, à l'utilisation, à la modification et/ou au | |||||
* développement et à la reproduction du logiciel par l'utilisateur étant | |||||
* donné sa spécificité de logiciel libre, qui peut le rendre complexe à | |||||
* manipuler et qui le réserve donc à des développeurs et des professionnels | |||||
* avertis possédant des connaissances informatiques approfondies. Les | |||||
* utilisateurs sont donc invités à charger et tester l'adéquation du | |||||
* logiciel à leurs besoins dans des conditions permettant d'assurer la | |||||
* sécurité de leurs systèmes et ou de leurs données et, plus généralement, | |||||
* à l'utiliser et l'exploiter dans les mêmes conditions de sécurité. | |||||
* | |||||
* Le fait que vous puissiez accéder à cet en-tête signifie que vous avez | |||||
* pris connaissance de la licence CeCILL, et que vous en avez accepté les | |||||
* termes. | |||||
*/ | |||||
use common\logic\Setting\SettingModule; | |||||
use yii\bootstrap\ActiveForm; | |||||
use yii\helpers\Html; | |||||
$settingModule = SettingModule::getInstance(); | |||||
$adminSettingDefinition = $settingModule->getAdminSettingDefinition(); | |||||
$this->setTitle('Paramètres'); | |||||
$this->addBreadcrumb($this->getTitle()); | |||||
?> | |||||
<div class="setting-admin-index"> | |||||
<?php $form = ActiveForm::begin(); ?> | |||||
<?php foreach($adminSettingDefinition->getSettingDetails() as $sectionName => $sectionsArray): ?> | |||||
<h2><?php echo $adminSettingDefinition->getSectionLabelBySectionName($sectionName); ?></h2> | |||||
<?php foreach($sectionsArray as $subSectionName => $subSectionsArray): ?> | |||||
<h2><?php echo $adminSettingDefinition->getSectionLabelBySectionName($subSectionName); ?></h2> | |||||
<?php foreach($subSectionsArray as $settingDetail): ?> | |||||
<?php echo field($form, $model, $settingDetail); ?> | |||||
<?php endforeach; ?> | |||||
<?php endforeach; ?> | |||||
<?php endforeach; ?> | |||||
<div class="form-group"> | |||||
<?= Html::submitButton('Sauvegarder', ['class' => 'btn btn-primary']) ?> | |||||
</div> | |||||
<?php ActiveForm::end(); ?> | |||||
</div> | |||||
<?php | |||||
function field($form, $model, $settingDetail) { | |||||
if($settingDetail->getType() == 'boolean') { | |||||
return $form->field($model, $settingDetail->getName())->checkbox(); | |||||
} else { | |||||
return $form->field($model, $settingDetail->getName())->textInput(); | |||||
} | |||||
} | |||||
?> |
$defaultOptions = $this->getDefaultOptionsSearch(); | $defaultOptions = $this->getDefaultOptionsSearch(); | ||||
if(isset($defaultOptions['attribute_id_producer']) | if(isset($defaultOptions['attribute_id_producer']) | ||||
&& $defaultOptions['attribute_id_producer'] | && $defaultOptions['attribute_id_producer'] | ||||
&& $this->getProducerContext(false)) { | |||||
&& $this->getProducerContext()) { | |||||
$this->query->andWhere([$defaultOptions['attribute_id_producer'] => $this->getProducerContextId()]); | $this->query->andWhere([$defaultOptions['attribute_id_producer'] => $this->getProducerContextId()]); | ||||
} | } | ||||
} | } |
const ALIAS_PRODUCT_PRICE_IMPORT = 'product_price_import'; | const ALIAS_PRODUCT_PRICE_IMPORT = 'product_price_import'; | ||||
const ALIAS_ONLINE_PAYMENT = 'online_payment'; | const ALIAS_ONLINE_PAYMENT = 'online_payment'; | ||||
const ALIAS_EXPORT_SHOPPING_CART_LABELS_ADVANCED = 'export_shopping_cart_labels_advanced'; | const ALIAS_EXPORT_SHOPPING_CART_LABELS_ADVANCED = 'export_shopping_cart_labels_advanced'; | ||||
const ALIAS_SETTINGS = 'settings'; | |||||
/** | /** | ||||
* @inheritdoc | * @inheritdoc |
Feature::ALIAS_PRODUCT_PRICE_IMPORT => 'Produits : import prix', | Feature::ALIAS_PRODUCT_PRICE_IMPORT => 'Produits : import prix', | ||||
Feature::ALIAS_ONLINE_PAYMENT => 'Paiement en ligne', | Feature::ALIAS_ONLINE_PAYMENT => 'Paiement en ligne', | ||||
Feature::ALIAS_EXPORT_SHOPPING_CART_LABELS_ADVANCED => "Génération d'étiquettes avec un format spécifique", | Feature::ALIAS_EXPORT_SHOPPING_CART_LABELS_ADVANCED => "Génération d'étiquettes avec un format spécifique", | ||||
Feature::ALIAS_SETTINGS => 'Système de paramètres' | |||||
]; | ]; | ||||
} | } | ||||
} | } |
{ | { | ||||
return $this->getProducerContext()->id; | return $this->getProducerContext()->id; | ||||
} | } | ||||
public function isOutOfProducerContext(): bool | |||||
{ | |||||
return !$this->producerContext; | |||||
} | |||||
} | } |
<?php | |||||
namespace common\logic\Setting; | |||||
use common\logic\AbstractManager; | |||||
use common\logic\Setting\SettingBuilder; | |||||
use common\logic\Setting\SettingRepository; | |||||
class AdminSettingBag extends AbstractManager | |||||
{ | |||||
protected SettingRepository $settingRepository; | |||||
protected SettingBuilder $settingBuilder; | |||||
public function loadDependencies(): void | |||||
{ | |||||
$this->settingRepository = $this->loadService(SettingRepository::class); | |||||
$this->settingBuilder = $this->loadService(SettingBuilder::class); | |||||
} | |||||
public function get(string $name) | |||||
{ | |||||
$setting = $this->settingRepository->findOneAdminSettingByName($name); | |||||
if($setting) { | |||||
return $setting->getValue(); | |||||
} | |||||
return null; | |||||
} | |||||
public function set(string $name, $value) | |||||
{ | |||||
$setting = $this->settingRepository->findOneAdminSettingByName($name); | |||||
if($setting) { | |||||
$this->settingBuilder->updateValue($setting, $value); | |||||
} | |||||
} | |||||
} |
]; | ]; | ||||
} | } | ||||
/* | |||||
* Relations | |||||
*/ | |||||
public function getValue() | |||||
{ | |||||
$settingDetail = $this->getSettingDetail(); | |||||
$type = $settingDetail->getType(); | |||||
return $this->$type; | |||||
} | |||||
public function getSettingDetail() | public function getSettingDetail() | ||||
{ | { |
<?php | |||||
namespace common\logic\Setting; | |||||
use common\logic\AbstractChecker; | |||||
class SettingBag extends AbstractChecker | |||||
{ | |||||
// $settingModule->getSettingBag()->get('administratorEmail'); | |||||
// $settingModule->getProducerSettingBag()->get('isTest'); | |||||
// $producerModule->getSettingBag()->get('isTest'); | |||||
public function get(string $name) | |||||
{ | |||||
} | |||||
public function set(string $name, $value) | |||||
{ | |||||
} | |||||
} |
namespace common\logic\Setting; | namespace common\logic\Setting; | ||||
use common\logic\AbstractBuilder; | use common\logic\AbstractBuilder; | ||||
use common\logic\Producer\Producer\Model\Producer; | |||||
use yii\base\ErrorException; | use yii\base\ErrorException; | ||||
class SettingBuilder extends AbstractBuilder | class SettingBuilder extends AbstractBuilder | ||||
} | } | ||||
public function instanciateSetting( | public function instanciateSetting( | ||||
string $name | |||||
string $name, | |||||
Producer $producer = null | |||||
): Setting | ): Setting | ||||
{ | { | ||||
$setting = new Setting(); | $setting = new Setting(); | ||||
$setting->name = $name; | $setting->name = $name; | ||||
$setting->populateProducer($this->getProducerContext(false)); | |||||
$setting->populateProducer($producer); | |||||
$this->initDefaultValue($setting); | $this->initDefaultValue($setting); | ||||
return $setting; | return $setting; | ||||
} | } | ||||
public function createSetting( | public function createSetting( | ||||
string $name | |||||
string $name, | |||||
Producer $producer = null | |||||
): Setting | ): Setting | ||||
{ | { | ||||
$setting = $this->settingRepository->findOneSettingByName($name); | |||||
if($producer) { | |||||
$setting = $this->settingRepository->findOneProducerSettingByName($name); | |||||
} | |||||
else { | |||||
$setting = $this->settingRepository->findOneAdminSettingByName($name); | |||||
} | |||||
if(!$setting) { | if(!$setting) { | ||||
$setting = $this->instanciateSetting($name); | $setting = $this->instanciateSetting($name); | ||||
$this->create($setting); | $this->create($setting); | ||||
$setting->$type = $value; | $setting->$type = $value; | ||||
} | } | ||||
else { | else { | ||||
throw new ErrorException("Le type de donnée n'est pas reconnu."); | |||||
throw new ErrorException("Le type de donnée du SettingDetail n'est pas reconnu."); | |||||
} | } | ||||
} | } | ||||
} | } | ||||
} | } | ||||
public function updateValueByName(string $name, $value): void | |||||
public function updateValue(Setting $setting, $value): void | |||||
{ | { | ||||
$setting = $this->createSetting($name); | |||||
$this->initValue($setting, $value); | $this->initValue($setting, $value); | ||||
$this->update($setting); | $this->update($setting); | ||||
} | } | ||||
public function updateDefaultValueByName(string $name) | |||||
public function updateDefaultValueByName(Setting $setting) | |||||
{ | { | ||||
$setting = $this->createSetting($name); | |||||
$this->initDefaultValue($setting); | $this->initDefaultValue($setting); | ||||
$this->update($setting); | $this->update($setting); | ||||
} | } |
const TYPE_DOUBLE = 'double'; | const TYPE_DOUBLE = 'double'; | ||||
public string $name; | public string $name; | ||||
public string $label; | |||||
public string $type; | public string $type; | ||||
public string $section; | public string $section; | ||||
public $defaultValue = null; | public $defaultValue = null; | ||||
return $this->name; | return $this->name; | ||||
} | } | ||||
public function setLabel(string $label): self | |||||
{ | |||||
$this->label = $label; | |||||
return $this; | |||||
} | |||||
public function getLabel(): string | |||||
{ | |||||
return $this->label; | |||||
} | |||||
public function setSection(string $section): self | public function setSection(string $section): self | ||||
{ | { | ||||
$this->section = $section; | $this->section = $section; |
use common\logic\Setting\SettingDetails\Admin\General\AdministratorPhoneNumberAdminSetting; | use common\logic\Setting\SettingDetails\Admin\General\AdministratorPhoneNumberAdminSetting; | ||||
use common\logic\Setting\SettingDetails\Admin\General\IsTestAdminSetting; | use common\logic\Setting\SettingDetails\Admin\General\IsTestAdminSetting; | ||||
use common\logic\Setting\SettingDetails\Admin\General\SupportEmailAdminSetting; | use common\logic\Setting\SettingDetails\Admin\General\SupportEmailAdminSetting; | ||||
use common\logic\Setting\SettingDetails\Admin\General2\AnOtherTestAdminSetting; | |||||
class AdminSettingDefinition extends SettingDefinition | class AdminSettingDefinition extends SettingDefinition | ||||
{ | { | ||||
const SECTION_GENERAL = 'general'; | const SECTION_GENERAL = 'general'; | ||||
const SUBSECTION_GENERAL = 'general.main'; | const SUBSECTION_GENERAL = 'general.main'; | ||||
const SECTION_GENERAL2 = 'general2'; | |||||
const SUBSECTION_GENERAL2 = 'general2.main'; | |||||
public function getSettingDetails(): array | public function getSettingDetails(): array | ||||
{ | { | ||||
return [ | return [ | ||||
new AdministratorPhoneNumberAdminSetting, | new AdministratorPhoneNumberAdminSetting, | ||||
new IsTestAdminSetting, | new IsTestAdminSetting, | ||||
] | ] | ||||
], | |||||
self::SECTION_GENERAL2 => [ | |||||
self::SUBSECTION_GENERAL2 => [ | |||||
new AnOtherTestAdminSetting, | |||||
], | |||||
] | ] | ||||
]; | ]; | ||||
} | } | ||||
return [ | return [ | ||||
self::SECTION_GENERAL => 'General', | self::SECTION_GENERAL => 'General', | ||||
self::SUBSECTION_GENERAL => 'General', | self::SUBSECTION_GENERAL => 'General', | ||||
self::SECTION_GENERAL2 => 'General deux', | |||||
self::SUBSECTION_GENERAL2 => 'General deux', | |||||
]; | ]; | ||||
} | } | ||||
public function getSettingDetailsFlat(): array | |||||
{ | |||||
$settingDetailsFlatArray = []; | |||||
foreach($this->getSettingDetails() as $sectionsArray) { | |||||
foreach($sectionsArray as $subsectionsArray) { | |||||
foreach($subsectionsArray as $settingDetail) { | |||||
$settingDetailsFlatArray[] = $settingDetail; | |||||
} | |||||
} | |||||
} | |||||
return $settingDetailsFlatArray; | |||||
} | |||||
public function getSectionLabelBySectionName(string $sectionName): string | |||||
{ | |||||
return $this->getSectionLabels()[$sectionName]; | |||||
} | |||||
} | } |
{ | { | ||||
$this | $this | ||||
->setName('administratorEmail') | ->setName('administratorEmail') | ||||
->setLabel('Administrator Email') | |||||
->setTypeString(); | ->setTypeString(); | ||||
} | } | ||||
} | } |
{ | { | ||||
$this | $this | ||||
->setName('administratorPhoneNumber') | ->setName('administratorPhoneNumber') | ||||
->setLabel('Administrator Phone Number') | |||||
->setTypeString(); | ->setTypeString(); | ||||
} | } | ||||
} | } |
{ | { | ||||
$this | $this | ||||
->setName('isTest') | ->setName('isTest') | ||||
->setLabel('Is Test') | |||||
->setTypeBoolean() | ->setTypeBoolean() | ||||
->setDefaultValue(true); | ->setDefaultValue(true); | ||||
} | } |
{ | { | ||||
$this | $this | ||||
->setName('supportEmail') | ->setName('supportEmail') | ||||
->setLabel('Support Email') | |||||
->setTypeString(); | ->setTypeString(); | ||||
} | } | ||||
} | } |
<?php | |||||
namespace common\logic\Setting\SettingDetails\Admin\General2; | |||||
use common\logic\Setting\SettingDetails\AbstractSettingDetail; | |||||
class AnOtherTestAdminSetting extends AbstractSettingDetail | |||||
{ | |||||
public function __construct() | |||||
{ | |||||
$this | |||||
->setName('anOtherTest') | |||||
->setLabel('Un autre test') | |||||
->setTypeBoolean(); | |||||
} | |||||
} |
public function importFromAdminSettingDefinition(): void | public function importFromAdminSettingDefinition(): void | ||||
{ | { | ||||
\Yii::$app->logic->setProducerContext(null); | \Yii::$app->logic->setProducerContext(null); | ||||
$settingDetails = $this->adminSettingDefinition->getSettingDetails(); | |||||
foreach($settingDetails as $subsectionsArray) { | |||||
foreach($subsectionsArray as $settingDetailsArray) { | |||||
foreach($settingDetailsArray as $settingDetail) { | |||||
$this->settingBuilder->createSetting($settingDetail->getName()); | |||||
} | |||||
} | |||||
foreach ($this->adminSettingDefinition->getSettingDetailsFlat() as $settingDetail) { | |||||
$this->settingBuilder->createSetting($settingDetail->getName()); | |||||
} | } | ||||
} | } | ||||
ProducerSettingDefinition::class, | ProducerSettingDefinition::class, | ||||
SettingRepository::class, | SettingRepository::class, | ||||
SettingBuilder::class, | SettingBuilder::class, | ||||
SettingImporter::class | |||||
SettingImporter::class, | |||||
AdminSettingBag::class | |||||
]; | ]; | ||||
} | } | ||||
return SettingDefinition::getInstance(); | return SettingDefinition::getInstance(); | ||||
} | } | ||||
public function getAdminSettingDefinition(): AdminSettingDefinition | |||||
{ | |||||
return AdminSettingDefinition::getInstance(); | |||||
} | |||||
public function getProducerSettingDefinition(): ProducerSettingDefinition | |||||
{ | |||||
return ProducerSettingDefinition::getInstance(); | |||||
} | |||||
public function getRepository(): SettingRepository | public function getRepository(): SettingRepository | ||||
{ | { | ||||
return SettingRepository::getInstance(); | return SettingRepository::getInstance(); | ||||
{ | { | ||||
return SettingImporter::getInstance(); | return SettingImporter::getInstance(); | ||||
} | } | ||||
public function getAdminSettingBag(): AdminSettingBag | |||||
{ | |||||
return AdminSettingBag::getInstance(); | |||||
} | |||||
} | } |
} | } | ||||
public function findOneSettingByName(string $name) | public function findOneSettingByName(string $name) | ||||
{ | |||||
if($this->isOutOfProducerContext()) { | |||||
return $this->findOneAdminSettingByName($name); | |||||
} | |||||
else { | |||||
return $this->findOneProducerSettingByName($name); | |||||
} | |||||
} | |||||
public function findOneAdminSettingByName(string $name) | |||||
{ | |||||
return $this->createQuery() | |||||
->filterProducerIsNull() | |||||
->filterByName($name) | |||||
->findOne(); | |||||
} | |||||
public function findOneProducerSettingByName(string $name) | |||||
{ | { | ||||
return $this->createDefaultQuery() | return $this->createDefaultQuery() | ||||
->filterByName($name) | ->filterByName($name) |
$this->loadDefinition(SettingDefinition::class); | $this->loadDefinition(SettingDefinition::class); | ||||
} | } | ||||
public function filterProducerIsNull(): self | |||||
{ | |||||
$this->andWhere(['id_producer' => null]); | |||||
return $this; | |||||
} | |||||
public function filterByName(string $name): self | public function filterByName(string $name): self | ||||
{ | { | ||||
$this->andWhere(['name' => $name]); | $this->andWhere(['name' => $name]); |