public function getModules() | public function getModules() | ||||
{ | { | ||||
return [ | return [ | ||||
$this->getSettingModule(), | |||||
$this->getFeatureModule(), | $this->getFeatureModule(), | ||||
$this->getFeatureProducerModule(), | |||||
$this->getUnitModule(), | $this->getUnitModule(), | ||||
$this->getTaxRateModule(), | $this->getTaxRateModule(), | ||||
$this->getUserUserGroupModule(), | $this->getUserUserGroupModule(), | ||||
return $this->producerContext; | return $this->producerContext; | ||||
} | } | ||||
public function setProducerContext(Producer $producer) | |||||
public function setProducerContext(Producer $producer = null) | |||||
{ | { | ||||
$this->producerContext = $producer; | $this->producerContext = $producer; | ||||
use common\logic\Document\Invoice\Module\InvoiceModule; | use common\logic\Document\Invoice\Module\InvoiceModule; | ||||
use common\logic\Document\Quotation\Module\QuotationModule; | use common\logic\Document\Quotation\Module\QuotationModule; | ||||
use common\logic\Feature\Feature\FeatureModule; | use common\logic\Feature\Feature\FeatureModule; | ||||
use common\logic\Feature\FeatureProducer\FeatureProducerModule; | |||||
use common\logic\Opinion\Module\OpinionModule; | use common\logic\Opinion\Module\OpinionModule; | ||||
use common\logic\Order\Order\Module\OrderModule; | use common\logic\Order\Order\Module\OrderModule; | ||||
use common\logic\Order\ProductOrder\Module\ProductOrderModule; | use common\logic\Order\ProductOrder\Module\ProductOrderModule; | ||||
use common\logic\Product\ProductCategory\Module\ProductCategoryModule; | use common\logic\Product\ProductCategory\Module\ProductCategoryModule; | ||||
use common\logic\Product\ProductPointSale\Module\ProductPointSaleModule; | use common\logic\Product\ProductPointSale\Module\ProductPointSaleModule; | ||||
use common\logic\Product\ProductPrice\Module\ProductPriceModule; | use common\logic\Product\ProductPrice\Module\ProductPriceModule; | ||||
use common\logic\Setting\SettingModule; | |||||
use common\logic\Subscription\ProductSubscription\Module\ProductSubscriptionModule; | use common\logic\Subscription\ProductSubscription\Module\ProductSubscriptionModule; | ||||
use common\logic\Subscription\Subscription\Module\SubscriptionModule; | use common\logic\Subscription\Subscription\Module\SubscriptionModule; | ||||
use common\logic\Ticket\Ticket\Module\TicketModule; | use common\logic\Ticket\Ticket\Module\TicketModule; | ||||
{ | { | ||||
return FeatureModule::getInstance(); | return FeatureModule::getInstance(); | ||||
} | } | ||||
public function getFeatureProducerModule(): FeatureProducerModule | |||||
{ | |||||
return FeatureProducerModule::getInstance(); | |||||
} | |||||
public function getSettingModule(): SettingModule | |||||
{ | |||||
return SettingModule::getInstance(); | |||||
} | |||||
} | } |
namespace common\logic; | namespace common\logic; | ||||
use yii\db\ActiveRecord; | |||||
abstract class AbstractChecker extends AbstractService implements CheckerInterface | abstract class AbstractChecker extends AbstractService implements CheckerInterface | ||||
{ | { | ||||
public function defaultFilterProducerContext(): void | public function defaultFilterProducerContext(): void | ||||
{ | { | ||||
$defaultOptions = $this->getDefaultOptionsSearch(); | $defaultOptions = $this->getDefaultOptionsSearch(); | ||||
if(isset($defaultOptions['attribute_id_producer']) && $defaultOptions['attribute_id_producer']) { | |||||
if(isset($defaultOptions['attribute_id_producer']) | |||||
&& $defaultOptions['attribute_id_producer'] | |||||
&& $this->getProducerContext(false)) { | |||||
$this->query->andWhere([$defaultOptions['attribute_id_producer'] => $this->getProducerContextId()]); | $this->query->andWhere([$defaultOptions['attribute_id_producer'] => $this->getProducerContextId()]); | ||||
} | } | ||||
} | } |
<?php | |||||
namespace common\logic; | |||||
abstract class AbstractResolver extends AbstractService implements ResolverInterface | |||||
{ | |||||
} |
<?php | |||||
namespace common\logic\Feature\FeatureProducer; | |||||
use common\logic\AbstractModule; | |||||
class FeatureProducerModule extends AbstractModule | |||||
{ | |||||
public function getServices(): array | |||||
{ | |||||
return [ | |||||
FeatureProducerDefinition::class, | |||||
FeatureProducerRepository::class, | |||||
FeatureProducerBuilder::class, | |||||
]; | |||||
} | |||||
public function getDefinition(): FeatureProducerDefinition | |||||
{ | |||||
return FeatureProducerDefinition::getInstance(); | |||||
} | |||||
public function getRepository(): FeatureProducerRepository | |||||
{ | |||||
return FeatureProducerRepository::getInstance(); | |||||
} | |||||
public function getBuilder(): FeatureProducerBuilder | |||||
{ | |||||
return FeatureProducerBuilder::getInstance(); | |||||
} | |||||
} |
public function loadDependencies(): void | public function loadDependencies(): void | ||||
{ | { | ||||
$this->producerSolver = $this->loadService(ProducerSolver::class); | $this->producerSolver = $this->loadService(ProducerSolver::class); | ||||
$this->tillerActivated = $this->producerSolver->getConfig('tiller'); | |||||
$this->tillerClient = $this->getClient(); | |||||
if($this->producerSolver->getProducerContext(false)) { | |||||
$this->tillerActivated = $this->producerSolver->getConfig('tiller'); | |||||
$this->tillerClient = $this->getClient(); | |||||
} | |||||
$this->orderSolver = $this->loadService(OrderSolver::class); | $this->orderSolver = $this->loadService(OrderSolver::class); | ||||
$this->orderBuilder = $this->loadService(OrderBuilder::class); | $this->orderBuilder = $this->loadService(OrderBuilder::class); | ||||
$this->productOrderSolver = $this->loadService(ProductOrderSolver::class); | $this->productOrderSolver = $this->loadService(ProductOrderSolver::class); |
trait ProducerContextTrait | trait ProducerContextTrait | ||||
{ | { | ||||
protected ?Producer $producerContext = null; | |||||
protected ?Producer $producerContext; | |||||
public function setProducerContext(Producer $producer): self | |||||
public function setProducerContext(Producer $producer = null): self | |||||
{ | { | ||||
$this->producerContext = $producer; | $this->producerContext = $producer; | ||||
return $this; | return $this; | ||||
} | } | ||||
public function getProducerContext(): Producer | |||||
public function getProducerContext(bool $throwExceptionIfNull = true): ?Producer | |||||
{ | { | ||||
if(is_null($this->producerContext)) { | |||||
if($throwExceptionIfNull && is_null($this->producerContext)) { | |||||
throw new ErrorException("Le contexte producteur n'est pas défini."); | throw new ErrorException("Le contexte producteur n'est pas défini."); | ||||
} | } | ||||
<?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 common\logic\Setting; | |||||
use common\components\ActiveRecordCommon; | |||||
use common\logic\Producer\Producer\Model\Producer; | |||||
class Setting extends ActiveRecordCommon | |||||
{ | |||||
/** | |||||
* @inheritdoc | |||||
*/ | |||||
public static function tableName() | |||||
{ | |||||
return 'setting'; | |||||
} | |||||
/** | |||||
* @inheritdoc | |||||
*/ | |||||
public function rules() | |||||
{ | |||||
return [ | |||||
[['name'], 'required'], | |||||
[['id_producer'], 'integer'], | |||||
[['id_producer'], 'exist', 'skipOnError' => true, 'targetClass' => Producer::class, 'targetAttribute' => ['id_producer' => 'id']], | |||||
[['name', 'string', 'text'], 'string'], | |||||
[['name','string'], 'string', 'max' => 255], | |||||
[['date'], 'date', 'format' => 'php:Y-m-d'], | |||||
[['integer'], 'integer'], | |||||
[['float', 'double'], 'number'], | |||||
[['boolean'], 'boolean'], | |||||
[['name'], 'unique'], | |||||
]; | |||||
} | |||||
/** | |||||
* @inheritdoc | |||||
*/ | |||||
public function attributeLabels() | |||||
{ | |||||
return [ | |||||
'id' => 'ID', | |||||
'id_producer' => 'Producteur', | |||||
'name' => 'Nom', | |||||
]; | |||||
} | |||||
/* | |||||
* Relations | |||||
*/ | |||||
public function getSettingDetail() | |||||
{ | |||||
return SettingDefinition::getInstance()->getSettingDetailByName($this->name); | |||||
} | |||||
public function getProducer() | |||||
{ | |||||
return $this->hasOne(Producer::class, ['id' => 'id_producer']); | |||||
} | |||||
public function populateProducer(Producer $producer = null): void | |||||
{ | |||||
if($producer) { | |||||
$this->populateFieldObject('id_producer', 'producer', $producer); | |||||
} | |||||
} | |||||
} |
<?php | |||||
namespace common\logic\Setting; | |||||
use common\logic\AbstractChecker; | |||||
class SettingBag extends AbstractChecker | |||||
{ | |||||
// $settingModule->getSettingBag()->getSetting(AdminSettingDefinition::SETTING_ADMINISTRATOR_EMAIL); | |||||
// $settingModule->getSettingBag()->get('administratorEmail'); | |||||
// $settingModule->getProducerSettingBag()->get('isTest'); | |||||
public function getSetting(string $name) | |||||
{ | |||||
} | |||||
public function setSetting(string $name, $values) | |||||
{ | |||||
} | |||||
} |
<?php | |||||
namespace common\logic\Setting; | |||||
use common\logic\AbstractBuilder; | |||||
use yii\base\ErrorException; | |||||
class SettingBuilder extends AbstractBuilder | |||||
{ | |||||
protected SettingDefinition $settingDefinition; | |||||
protected SettingRepository $settingRepository; | |||||
public function loadDependencies(): void | |||||
{ | |||||
$this->settingDefinition = $this->loadService(SettingDefinition::class); | |||||
$this->settingRepository = $this->loadService(SettingRepository::class); | |||||
} | |||||
public function instanciateSetting( | |||||
string $name | |||||
): Setting | |||||
{ | |||||
$setting = new Setting(); | |||||
$setting->name = $name; | |||||
$setting->populateProducer($this->getProducerContext(false)); | |||||
$this->initDefaultValue($setting); | |||||
return $setting; | |||||
} | |||||
public function createSetting( | |||||
string $name | |||||
): Setting | |||||
{ | |||||
$setting = $this->settingRepository->findOneSettingByName($name); | |||||
if(!$setting) { | |||||
$setting = $this->instanciateSetting($name); | |||||
$this->create($setting); | |||||
} | |||||
return $setting; | |||||
} | |||||
public function initValue(Setting $setting, $value) | |||||
{ | |||||
$settingDetail = $this->settingDefinition->getSettingDetailByName($setting->name); | |||||
$type = $settingDetail->getType(); | |||||
if(in_array($type, ['string', 'text', 'date', 'integer', 'float', 'double', 'boolean'])) { | |||||
$setting->$type = $value; | |||||
} | |||||
else { | |||||
throw new ErrorException("Le type de donnée n'est pas reconnu."); | |||||
} | |||||
} | |||||
public function initDefaultValue(Setting $setting) | |||||
{ | |||||
$settingDetail = $this->settingDefinition->getSettingDetailByName($setting->name); | |||||
if($settingDetail->getDefaultValue()) { | |||||
$this->initValue($setting, $settingDetail->getDefaultValue()); | |||||
} | |||||
} | |||||
public function updateValueByName(string $name, $value): void | |||||
{ | |||||
$setting = $this->createSetting($name); | |||||
$this->initValue($setting, $value); | |||||
$this->update($setting); | |||||
} | |||||
public function updateDefaultValueByName(string $name) | |||||
{ | |||||
$setting = $this->createSetting($name); | |||||
$this->initDefaultValue($setting); | |||||
$this->update($setting); | |||||
} | |||||
} |
<?php | |||||
namespace common\logic\Setting; | |||||
use common\logic\AbstractDefinition; | |||||
use common\logic\Setting\SettingDetails\Admin\AdminSettingDefinition; | |||||
use common\logic\Setting\SettingDetails\Producer\ProducerSettingDefinition; | |||||
class SettingDefinition extends AbstractDefinition | |||||
{ | |||||
public function getEntityFqcn(): string | |||||
{ | |||||
return Setting::class; | |||||
} | |||||
public function getSettingDetailByName(string $name) | |||||
{ | |||||
$adminSettingDefinition = AdminSettingDefinition::getInstance(); | |||||
$producerSettingDefinition = ProducerSettingDefinition::getInstance(); | |||||
$settingDetail = $this->findSettingDetailInArray($name, $adminSettingDefinition->getSettingDetails()); | |||||
if(!$settingDetail) { | |||||
$this->findSettingDetailInArray($name, $producerSettingDefinition->getSettingDetails()); | |||||
} | |||||
if(!$settingDetail) { | |||||
throw new \Exception('SettingDetail non trouvé'); | |||||
} | |||||
return $settingDetail; | |||||
} | |||||
public function findSettingDetailInArray(string $name, array $settingDetailsArray) | |||||
{ | |||||
foreach($settingDetailsArray as $section => $subsectionsArray) { | |||||
foreach($subsectionsArray as $subsection => $settingDetailsArray) { | |||||
foreach($settingDetailsArray as $settingDetail) { | |||||
if($name == $settingDetail->getName()) { | |||||
return $settingDetail; | |||||
} | |||||
} | |||||
} | |||||
} | |||||
return null; | |||||
} | |||||
} |
<?php | |||||
namespace common\logic\Setting\SettingDetails; | |||||
class AbstractSettingDetail | |||||
{ | |||||
const TYPE_STRING = 'string'; | |||||
const TYPE_TEXT = 'text'; | |||||
const TYPE_BOOLEAN = 'boolean'; | |||||
const TYPE_DATE = 'date'; | |||||
const TYPE_INTEGER = 'integer'; | |||||
const TYPE_FLOAT = 'float'; | |||||
const TYPE_DOUBLE = 'double'; | |||||
public string $name; | |||||
public string $type; | |||||
public string $section; | |||||
public $defaultValue = null; | |||||
public ?string $subSection = null; | |||||
public ?string $helpMessage = null; | |||||
public function setName(string $name): self | |||||
{ | |||||
$this->name = $name; | |||||
return $this; | |||||
} | |||||
public function getName(): string | |||||
{ | |||||
return $this->name; | |||||
} | |||||
public function setSection(string $section): self | |||||
{ | |||||
$this->section = $section; | |||||
return $this; | |||||
} | |||||
public function getSection(): string | |||||
{ | |||||
return $this->section; | |||||
} | |||||
public function setSubSection(string $subSection): self | |||||
{ | |||||
$this->subSection = $subSection; | |||||
return $this; | |||||
} | |||||
public function getSubSection(): ?string | |||||
{ | |||||
return $this->subSection; | |||||
} | |||||
public function setHelpMessage(string $helpMessage): self | |||||
{ | |||||
$this->helpMessage = $helpMessage; | |||||
return $this; | |||||
} | |||||
public function getHelpMessage(): ?string | |||||
{ | |||||
return $this->helpMessage; | |||||
} | |||||
public function setDefaultValue($defaultValue): self | |||||
{ | |||||
$this->defaultValue = $defaultValue; | |||||
return $this; | |||||
} | |||||
public function getDefaultValue() | |||||
{ | |||||
return $this->defaultValue; | |||||
} | |||||
public function setTypeString(): self | |||||
{ | |||||
$this->type = self::TYPE_STRING; | |||||
return $this; | |||||
} | |||||
public function setTypeText(): self | |||||
{ | |||||
$this->type = self::TYPE_TEXT; | |||||
return $this; | |||||
} | |||||
public function setTypeBoolean(): self | |||||
{ | |||||
$this->type = self::TYPE_BOOLEAN; | |||||
return $this; | |||||
} | |||||
public function setTypeDate(): self | |||||
{ | |||||
$this->type = self::TYPE_DATE; | |||||
return $this; | |||||
} | |||||
public function setTypeInteger(): self | |||||
{ | |||||
$this->type = self::TYPE_INTEGER; | |||||
return $this; | |||||
} | |||||
public function setTypeFloat(): self | |||||
{ | |||||
$this->type = self::TYPE_FLOAT; | |||||
return $this; | |||||
} | |||||
public function setTypeDouble(): self | |||||
{ | |||||
$this->type = self::TYPE_DOUBLE; | |||||
return $this; | |||||
} | |||||
public function getType(): string | |||||
{ | |||||
return $this->type; | |||||
} | |||||
} |
<?php | |||||
namespace common\logic\Setting\SettingDetails\Admin; | |||||
use common\logic\Setting\SettingDefinition; | |||||
use common\logic\Setting\SettingDetails\Admin\General\AdministratorEmailAdminSetting; | |||||
use common\logic\Setting\SettingDetails\Admin\General\AdministratorPhoneNumberAdminSetting; | |||||
use common\logic\Setting\SettingDetails\Admin\General\IsTestAdminSetting; | |||||
use common\logic\Setting\SettingDetails\Admin\General\SupportEmailAdminSetting; | |||||
class AdminSettingDefinition extends SettingDefinition | |||||
{ | |||||
const SECTION_GENERAL = 'general'; | |||||
const SUBSECTION_GENERAL = 'general.main'; | |||||
public function getSettingDetails(): array | |||||
{ | |||||
return [ | |||||
self::SECTION_GENERAL => [ | |||||
self::SUBSECTION_GENERAL => [ | |||||
new AdministratorEmailAdminSetting, | |||||
new SupportEmailAdminSetting, | |||||
new AdministratorPhoneNumberAdminSetting, | |||||
new IsTestAdminSetting, | |||||
] | |||||
] | |||||
]; | |||||
} | |||||
public function getSectionLabels(): array | |||||
{ | |||||
return [ | |||||
self::SECTION_GENERAL => 'General', | |||||
self::SUBSECTION_GENERAL => 'General', | |||||
]; | |||||
} | |||||
} |
<?php | |||||
namespace common\logic\Setting\SettingDetails\Admin\General; | |||||
use common\logic\Setting\SettingDetails\AbstractSettingDetail; | |||||
class AdministratorEmailAdminSetting extends AbstractSettingDetail | |||||
{ | |||||
public function __construct() | |||||
{ | |||||
$this | |||||
->setName('administratorEmail') | |||||
->setTypeString(); | |||||
} | |||||
} |
<?php | |||||
namespace common\logic\Setting\SettingDetails\Admin\General; | |||||
use common\logic\Setting\SettingDetails\AbstractSettingDetail; | |||||
class AdministratorPhoneNumberAdminSetting extends AbstractSettingDetail | |||||
{ | |||||
public function __construct() | |||||
{ | |||||
$this | |||||
->setName('administratorPhoneNumber') | |||||
->setTypeString(); | |||||
} | |||||
} |
<?php | |||||
namespace common\logic\Setting\SettingDetails\Admin\General; | |||||
use common\logic\Setting\SettingDetails\AbstractSettingDetail; | |||||
class IsTestAdminSetting extends AbstractSettingDetail | |||||
{ | |||||
public function __construct() | |||||
{ | |||||
$this | |||||
->setName('isTest') | |||||
->setTypeBoolean() | |||||
->setDefaultValue(true); | |||||
} | |||||
} |
<?php | |||||
namespace common\logic\Setting\SettingDetails\Admin\General; | |||||
use common\logic\Setting\SettingDetails\AbstractSettingDetail; | |||||
class SupportEmailAdminSetting extends AbstractSettingDetail | |||||
{ | |||||
public function __construct() | |||||
{ | |||||
$this | |||||
->setName('supportEmail') | |||||
->setTypeString(); | |||||
} | |||||
} |
<?php | |||||
namespace common\logic\Setting\SettingDetails\Producer; | |||||
use common\logic\Setting\SettingDefinition; | |||||
class ProducerSettingDefinition extends SettingDefinition | |||||
{ | |||||
const SECTION_GENERAL = 'general'; | |||||
const SUBSECTION_GENERAL = 'general.main'; | |||||
public function getSettings(): array | |||||
{ | |||||
return [ | |||||
self::SECTION_GENERAL => [ | |||||
self::SUBSECTION_GENERAL => [ | |||||
// ... | |||||
] | |||||
] | |||||
]; | |||||
} | |||||
public function getSectionLabels(): array | |||||
{ | |||||
return [ | |||||
self::SECTION_GENERAL => 'General', | |||||
self::SUBSECTION_GENERAL => 'General', | |||||
]; | |||||
} | |||||
} |
<?php | |||||
namespace common\logic\Setting; | |||||
use common\logic\AbstractManager; | |||||
use common\logic\Setting\SettingDetails\Admin\AdminSettingDefinition; | |||||
class SettingImporter extends AbstractManager | |||||
{ | |||||
protected AdminSettingDefinition $adminSettingDefinition; | |||||
protected SettingBuilder $settingBuilder; | |||||
public function loadDependencies(): void | |||||
{ | |||||
$this->adminSettingDefinition = $this->loadService(AdminSettingDefinition::class); | |||||
$this->settingBuilder = $this->loadService(SettingBuilder::class); | |||||
} | |||||
public function importFromDefinitions() | |||||
{ | |||||
$this->importFromAdminSettingDefinition(); | |||||
$this->importFromProducerSettingDefinition(); | |||||
} | |||||
public function importFromAdminSettingDefinition(): void | |||||
{ | |||||
\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()); | |||||
} | |||||
} | |||||
} | |||||
} | |||||
public function importFromProducerSettingDefinition(): void | |||||
{ | |||||
// /!\ bien définir le contexte producteur | |||||
} | |||||
} |
<?php | |||||
namespace common\logic\Setting; | |||||
use common\logic\AbstractModule; | |||||
use common\logic\Setting\SettingDetails\Admin\AdminSettingDefinition; | |||||
use common\logic\Setting\SettingDetails\Producer\ProducerSettingDefinition; | |||||
class SettingModule extends AbstractModule | |||||
{ | |||||
public function getServices(): array | |||||
{ | |||||
return [ | |||||
SettingDefinition::class, | |||||
AdminSettingDefinition::class, | |||||
ProducerSettingDefinition::class, | |||||
SettingRepository::class, | |||||
SettingBuilder::class, | |||||
SettingImporter::class | |||||
]; | |||||
} | |||||
public function getDefinition(): SettingDefinition | |||||
{ | |||||
return SettingDefinition::getInstance(); | |||||
} | |||||
public function getRepository(): SettingRepository | |||||
{ | |||||
return SettingRepository::getInstance(); | |||||
} | |||||
public function getImporter(): SettingImporter | |||||
{ | |||||
return SettingImporter::getInstance(); | |||||
} | |||||
} |
<?php | |||||
namespace common\logic\Setting; | |||||
use common\logic\AbstractRepository; | |||||
class SettingRepository extends AbstractRepository | |||||
{ | |||||
protected SettingRepositoryQuery $query; | |||||
public function loadDependencies(): void | |||||
{ | |||||
$this->loadQuery(SettingRepositoryQuery::class); | |||||
} | |||||
public function getDefaultOptionsSearch(): array | |||||
{ | |||||
return [ | |||||
self::WITH => ['producer'], | |||||
self::JOIN_WITH => [], | |||||
self::ORDER_BY => '', | |||||
self::ATTRIBUTE_ID_PRODUCER => 'setting.id_producer' | |||||
]; | |||||
} | |||||
public function findOneSettingByName(string $name) | |||||
{ | |||||
return $this->createDefaultQuery() | |||||
->filterByName($name) | |||||
->findOne(); | |||||
} | |||||
} |
<?php | |||||
namespace common\logic\Setting; | |||||
use common\logic\AbstractRepositoryQuery; | |||||
class SettingRepositoryQuery extends AbstractRepositoryQuery | |||||
{ | |||||
protected SettingDefinition $definition; | |||||
public function loadDependencies(): void | |||||
{ | |||||
$this->loadDefinition(SettingDefinition::class); | |||||
} | |||||
public function filterByName(string $name): self | |||||
{ | |||||
$this->andWhere(['name' => $name]); | |||||
return $this; | |||||
} | |||||
} |
<?php | |||||
namespace console\commands; | |||||
use common\logic\Setting\SettingModule; | |||||
use yii\console\Controller; | |||||
class SettingController extends Controller | |||||
{ | |||||
// ./yii setting/import | |||||
public function actionImport() | |||||
{ | |||||
$settingModule = SettingModule::getInstance(); | |||||
$settingModule->getImporter()->importFromDefinitions(); | |||||
} | |||||
} | |||||
?> |
<?php | |||||
use yii\db\Migration; | |||||
use yii\db\Schema; | |||||
/** | |||||
* Class m231114_085352_create_table_setting | |||||
*/ | |||||
class m231114_085352_create_table_setting extends Migration | |||||
{ | |||||
/** | |||||
* {@inheritdoc} | |||||
*/ | |||||
public function safeUp() | |||||
{ | |||||
$this->createTable('setting', [ | |||||
'id' => 'pk', | |||||
'name' => Schema::TYPE_STRING.' NOT NULL', | |||||
'id_producer' => Schema::TYPE_INTEGER, | |||||
'string' => Schema::TYPE_STRING, | |||||
'text' => Schema::TYPE_TEXT, | |||||
'date' => Schema::TYPE_DATE, | |||||
'integer' => Schema::TYPE_INTEGER, | |||||
'float' => Schema::TYPE_FLOAT, | |||||
'double' => Schema::TYPE_DOUBLE, | |||||
'boolean' => Schema::TYPE_BOOLEAN, | |||||
]); | |||||
} | |||||
/** | |||||
* {@inheritdoc} | |||||
*/ | |||||
public function safeDown() | |||||
{ | |||||
$this->dropTable('setting'); | |||||
} | |||||
} |