$feature = $this->findModel($id); | $feature = $this->findModel($id); | ||||
if($status) { | if($status) { | ||||
$featureManager->enable($feature); | |||||
$featureManager->enableFeature($feature); | |||||
$messageResponse = 'La fonctionnalité "'.Html::encode($feature->name).'" a bien été activée'; | $messageResponse = 'La fonctionnalité "'.Html::encode($feature->name).'" a bien été activée'; | ||||
} | } | ||||
else { | else { | ||||
$featureManager->disable($feature); | |||||
$featureManager->disableFeature($feature); | |||||
$messageResponse = 'La fonctionnalité "'.Html::encode($feature->name).'" a bien été désactivée'; | $messageResponse = 'La fonctionnalité "'.Html::encode($feature->name).'" a bien été désactivée'; | ||||
} | } | ||||
$feature = $this->findModel($id); | $feature = $this->findModel($id); | ||||
if(is_null($status)) { | if(is_null($status)) { | ||||
$featureManager->defaultForProducer($feature); | |||||
$featureManager->defaultFeatureForProducer($feature); | |||||
} | } | ||||
elseif($status == 0) { | elseif($status == 0) { | ||||
$featureManager->disableForProducer($feature); | |||||
$featureManager->disableFeatureForProducer($feature); | |||||
} | } | ||||
elseif($status == 1) { | elseif($status == 1) { | ||||
$featureManager->enableForProducer($feature); | |||||
$featureManager->enableFeatureForProducer($feature); | |||||
} | } | ||||
return $this->redirectReferer(); | return $this->redirectReferer(); |
$userModule = UserModule::getInstance(); | $userModule = UserModule::getInstance(); | ||||
$userProducerModule = $this->getUserProducerModule(); | $userProducerModule = $this->getUserProducerModule(); | ||||
$ticketModule = $this->getTicketModule(); | $ticketModule = $this->getTicketModule(); | ||||
$featureManager = $this->getFeatureModule()->getManager(); | |||||
$featureChecker = $this->getFeatureModule()->getChecker(); | |||||
$producer = GlobalParam::getCurrentProducer(); | $producer = GlobalParam::getCurrentProducer(); | ||||
$userCurrent = GlobalParam::getCurrentUser(); | $userCurrent = GlobalParam::getCurrentUser(); | ||||
'items' => [ | 'items' => [ | ||||
['label' => 'Liste', 'icon' => 'th-list', 'url' => ['/product/index'], 'visible' => $isUserCurrentGrantedAsProducer], | ['label' => 'Liste', 'icon' => 'th-list', 'url' => ['/product/index'], 'visible' => $isUserCurrentGrantedAsProducer], | ||||
['label' => 'Catégories', 'icon' => 'book', 'url' => ['/product-category/index'], 'visible' => $isUserCurrentGrantedAsProducer], | ['label' => 'Catégories', 'icon' => 'book', 'url' => ['/product-category/index'], 'visible' => $isUserCurrentGrantedAsProducer], | ||||
['label' => 'Import prix', 'icon' => 'upload', 'url' => ['/product/price-import'], 'visible' => $isUserCurrentGrantedAsProducer && $featureManager->isEnabled(Feature::ALIAS_PRODUCT_PRICE_IMPORT)], | |||||
['label' => 'Import prix', 'icon' => 'upload', 'url' => ['/product/price-import'], 'visible' => $isUserCurrentGrantedAsProducer && $featureChecker->isEnabled(Feature::ALIAS_PRODUCT_PRICE_IMPORT)], | |||||
] | ] | ||||
], | ], | ||||
['label' => 'Points de vente', 'icon' => 'map-marker', 'url' => ['/point-sale/index'], 'visible' => $isUserCurrentGrantedAsProducer, 'active' => Yii::$app->controller->id == 'point-sale'], | ['label' => 'Points de vente', 'icon' => 'map-marker', 'url' => ['/point-sale/index'], 'visible' => $isUserCurrentGrantedAsProducer, 'active' => Yii::$app->controller->id == 'point-sale'], |
$userModule = UserModule::getInstance(); | $userModule = UserModule::getInstance(); | ||||
$userGroupModule = UserGroupModule::getInstance(); | $userGroupModule = UserGroupModule::getInstance(); | ||||
$distributionExportManager = DistributionModule::getInstance()->getExportManager(); | $distributionExportManager = DistributionModule::getInstance()->getExportManager(); | ||||
$featureManager = FeatureModule::getInstance()->getManager(); | |||||
$featureChecker = FeatureModule::getInstance()->getChecker(); | |||||
$userCurrent = GlobalParam::getCurrentUser(); | $userCurrent = GlobalParam::getCurrentUser(); | ||||
->dropDownList(Dropdown::noYesChoices()); ?> | ->dropDownList(Dropdown::noYesChoices()); ?> | ||||
<?= $form->field($model, 'option_csv_export_by_piece') | <?= $form->field($model, 'option_csv_export_by_piece') | ||||
->dropDownList(Dropdown::noYesChoices()); ?> | ->dropDownList(Dropdown::noYesChoices()); ?> | ||||
<?php if($featureManager->isEnabled(Feature::ALIAS_EXPORT_SHOPPING_CART_LABELS_ADVANCED)): ?> | |||||
<?php if($featureChecker->isEnabled(Feature::ALIAS_EXPORT_SHOPPING_CART_LABELS_ADVANCED)): ?> | |||||
<?= $form->field($model, 'export_shopping_cart_labels_format') | <?= $form->field($model, 'export_shopping_cart_labels_format') | ||||
->dropDownList($distributionExportManager->getGenerator(ExportManager::SHOPPING_CART_LABELS_PDF)->populateDropdownSpecificFormats()); ?> | ->dropDownList($distributionExportManager->getGenerator(ExportManager::SHOPPING_CART_LABELS_PDF)->populateDropdownSpecificFormats()); ?> | ||||
<?php else: ?> | <?php else: ?> | ||||
<?= $form->field($model, 'option_check_by_default_prevent_user_credit') | <?= $form->field($model, 'option_check_by_default_prevent_user_credit') | ||||
->dropDownList(Dropdown::noYesChoices()); ?> | ->dropDownList(Dropdown::noYesChoices()); ?> | ||||
<?php if($featureManager->isEnabled(Feature::ALIAS_ONLINE_PAYMENT)): ?> | |||||
<?php if($featureChecker->isEnabled(Feature::ALIAS_ONLINE_PAYMENT)): ?> | |||||
<h4>Paiement en ligne</h4> | <h4>Paiement en ligne</h4> | ||||
<?php if($userModule->getAuthorizationChecker()->isGrantedAsAdministrator($userCurrent)): ?> | <?php if($userModule->getAuthorizationChecker()->isGrantedAsAdministrator($userCurrent)): ?> | ||||
<?= $form->field($model, 'online_payment') | <?= $form->field($model, 'online_payment') |
<?php | |||||
namespace common\logic; | |||||
use yii\db\ActiveRecord; | |||||
abstract class AbstractChecker extends AbstractService implements CheckerInterface | |||||
{ | |||||
} |
SolverInterface::class, | SolverInterface::class, | ||||
RepositoryQueryInterface::class, | RepositoryQueryInterface::class, | ||||
RepositoryInterface::class, | RepositoryInterface::class, | ||||
CheckerInterface::class, | |||||
NotifierInterface::class, | NotifierInterface::class, | ||||
BuilderInterface::class, | BuilderInterface::class, | ||||
ResolverInterface::class, | ResolverInterface::class, |
<?php | |||||
namespace common\logic; | |||||
interface CheckerInterface | |||||
{ | |||||
} |
use common\logic\AbstractGenerator; | use common\logic\AbstractGenerator; | ||||
use common\logic\Distribution\Distribution\Model\Distribution; | use common\logic\Distribution\Distribution\Model\Distribution; | ||||
use common\logic\Feature\Feature\Model\Feature; | use common\logic\Feature\Feature\Model\Feature; | ||||
use common\logic\Feature\Feature\Service\FeatureChecker; | |||||
use common\logic\Feature\Feature\Service\FeatureManager; | use common\logic\Feature\Feature\Service\FeatureManager; | ||||
use common\logic\Order\Order\Model\Order; | use common\logic\Order\Order\Model\Order; | ||||
use common\logic\Order\Order\Repository\OrderRepository; | use common\logic\Order\Order\Repository\OrderRepository; | ||||
protected ProducerSolver $producerSolver; | protected ProducerSolver $producerSolver; | ||||
protected OrderRepository $orderRepository; | protected OrderRepository $orderRepository; | ||||
protected OrderSolver $orderSolver; | protected OrderSolver $orderSolver; | ||||
protected FeatureChecker $featureChecker; | |||||
public function loadDependencies(): void | public function loadDependencies(): void | ||||
{ | { | ||||
$this->producerSolver = $this->loadService(ProducerSolver::class); | $this->producerSolver = $this->loadService(ProducerSolver::class); | ||||
$this->orderRepository = $this->loadService(OrderRepository::class); | $this->orderRepository = $this->loadService(OrderRepository::class); | ||||
$this->orderSolver = $this->loadService(OrderSolver::class); | $this->orderSolver = $this->loadService(OrderSolver::class); | ||||
$this->featureChecker = $this->loadService(FeatureChecker::class); | |||||
} | } | ||||
public function getSpecificFormatDetailsArray(): array | public function getSpecificFormatDetailsArray(): array | ||||
public function generate(Distribution $distribution, bool $save = false) | public function generate(Distribution $distribution, bool $save = false) | ||||
{ | { | ||||
// @TODO : obligé de charger FeatureManager comme ça car on est dans un service Generator (problème de hiérarchie de services) | |||||
$featureManager = FeatureManager::getInstance(); | |||||
$isSpecificFormat = false; | $isSpecificFormat = false; | ||||
$exportShoppingCartLabelsFormat = $this->producerSolver->getConfig('export_shopping_cart_labels_format'); | $exportShoppingCartLabelsFormat = $this->producerSolver->getConfig('export_shopping_cart_labels_format'); | ||||
if($featureManager->isEnabled(Feature::ALIAS_EXPORT_SHOPPING_CART_LABELS_ADVANCED)) { | |||||
if($this->featureChecker->isEnabled(Feature::ALIAS_EXPORT_SHOPPING_CART_LABELS_ADVANCED)) { | |||||
if($exportShoppingCartLabelsFormat) { | if($exportShoppingCartLabelsFormat) { | ||||
$isSpecificFormat = true; | $isSpecificFormat = true; | ||||
[$specificFormatWidth, $specificFormatHeight] = $this->getSpecificFormatDetails($exportShoppingCartLabelsFormat); | [$specificFormatWidth, $specificFormatHeight] = $this->getSpecificFormatDetails($exportShoppingCartLabelsFormat); |
use common\logic\AbstractModule; | use common\logic\AbstractModule; | ||||
use common\logic\Feature\Feature\Repository\FeatureRepository; | use common\logic\Feature\Feature\Repository\FeatureRepository; | ||||
use common\logic\Feature\Feature\Service\FeatureBuilder; | use common\logic\Feature\Feature\Service\FeatureBuilder; | ||||
use common\logic\Feature\Feature\Service\FeatureChecker; | |||||
use common\logic\Feature\Feature\Service\FeatureDefinition; | use common\logic\Feature\Feature\Service\FeatureDefinition; | ||||
use common\logic\Feature\Feature\Service\FeatureImporter; | use common\logic\Feature\Feature\Service\FeatureImporter; | ||||
use common\logic\Feature\Feature\Service\FeatureManager; | use common\logic\Feature\Feature\Service\FeatureManager; | ||||
return [ | return [ | ||||
FeatureDefinition::class, | FeatureDefinition::class, | ||||
FeatureRepository::class, | FeatureRepository::class, | ||||
FeatureChecker::class, | |||||
FeatureBuilder::class, | FeatureBuilder::class, | ||||
FeatureImporter::class, | FeatureImporter::class, | ||||
FeatureManager::class | FeatureManager::class | ||||
return FeatureRepository::getInstance(); | return FeatureRepository::getInstance(); | ||||
} | } | ||||
public function getChecker(): FeatureChecker | |||||
{ | |||||
return FeatureChecker::getInstance(); | |||||
} | |||||
public function getBuilder(): FeatureBuilder | public function getBuilder(): FeatureBuilder | ||||
{ | { | ||||
return FeatureBuilder::getInstance(); | return FeatureBuilder::getInstance(); |
<?php | |||||
namespace common\logic\Feature\Feature\Service; | |||||
use common\logic\AbstractChecker; | |||||
use common\logic\Feature\Feature\Repository\FeatureRepository; | |||||
use common\logic\Feature\FeatureProducer\Repository\FeatureProducerRepository; | |||||
use yii\base\ErrorException; | |||||
class FeatureChecker extends AbstractChecker | |||||
{ | |||||
protected FeatureRepository $featureRepository; | |||||
protected FeatureProducerRepository $featureProducerRepository; | |||||
public function loadDependencies(): void | |||||
{ | |||||
$this->featureRepository = $this->loadService(FeatureRepository::class); | |||||
$this->featureProducerRepository = $this->loadService(FeatureProducerRepository::class); | |||||
} | |||||
public function isEnabled(string $aliasFeature): bool | |||||
{ | |||||
$feature = $this->featureRepository->findOneFeatureByAlias($aliasFeature); | |||||
if(!$feature) { | |||||
throw new ErrorException("Fonctionnalité avec l'alias '".$aliasFeature."' non trouvée"); | |||||
} | |||||
if(!$feature->status) { | |||||
return false; | |||||
} | |||||
$featureProducer = $this->featureProducerRepository->findOneFeatureProducer($feature); | |||||
if(!$featureProducer || is_null($featureProducer->status)) { | |||||
if($feature->is_paid_feature || $feature->only_for_selected_producers) { | |||||
return false; | |||||
} | |||||
return $feature->status; | |||||
} | |||||
else { | |||||
return $featureProducer->status; | |||||
} | |||||
} | |||||
public function isDisabled(string $aliasFeature): bool | |||||
{ | |||||
return !$this->isEnabled($aliasFeature); | |||||
} | |||||
} |
use common\logic\AbstractManager; | use common\logic\AbstractManager; | ||||
use common\logic\Feature\Feature\Model\Feature; | use common\logic\Feature\Feature\Model\Feature; | ||||
use common\logic\Feature\Feature\Repository\FeatureRepository; | |||||
use common\logic\Feature\FeatureProducer\Repository\FeatureProducerRepository; | |||||
use common\logic\Feature\FeatureProducer\Service\FeatureProducerBuilder; | use common\logic\Feature\FeatureProducer\Service\FeatureProducerBuilder; | ||||
use yii\base\ErrorException; | |||||
class FeatureManager extends AbstractManager | class FeatureManager extends AbstractManager | ||||
{ | { | ||||
protected FeatureRepository $featureRepository; | |||||
protected FeatureProducerRepository $featureProducerRepository; | |||||
protected FeatureBuilder $featureBuilder; | protected FeatureBuilder $featureBuilder; | ||||
protected FeatureProducerBuilder $featureProducerBuilder; | protected FeatureProducerBuilder $featureProducerBuilder; | ||||
public function loadDependencies(): void | public function loadDependencies(): void | ||||
{ | { | ||||
$this->featureRepository = $this->loadService(FeatureRepository::class); | |||||
$this->featureProducerRepository = $this->loadService(FeatureProducerRepository::class); | |||||
$this->featureBuilder = $this->loadService(FeatureBuilder::class); | $this->featureBuilder = $this->loadService(FeatureBuilder::class); | ||||
$this->featureProducerBuilder = $this->loadService(FeatureProducerBuilder::class); | $this->featureProducerBuilder = $this->loadService(FeatureProducerBuilder::class); | ||||
} | } | ||||
public function isEnabled(string $aliasFeature): bool | |||||
{ | |||||
$feature = $this->featureRepository->findOneFeatureByAlias($aliasFeature); | |||||
if(!$feature) { | |||||
throw new ErrorException("Fonctionnalité avec l'alias '".$aliasFeature."' non trouvée"); | |||||
} | |||||
if(!$feature->status) { | |||||
return false; | |||||
} | |||||
$featureProducer = $this->featureProducerRepository->findOneFeatureProducer($feature); | |||||
if(!$featureProducer || is_null($featureProducer->status)) { | |||||
if($feature->is_paid_feature || $feature->only_for_selected_producers) { | |||||
return false; | |||||
} | |||||
return $feature->status; | |||||
} | |||||
else { | |||||
return $featureProducer->status; | |||||
} | |||||
} | |||||
public function isDisabled(string $aliasFeature): bool | |||||
{ | |||||
return !$this->isEnabled($aliasFeature); | |||||
} | |||||
public function enable(Feature $feature): void | |||||
public function enableFeature(Feature $feature): void | |||||
{ | { | ||||
$this->featureBuilder->updateStatus($feature, true); | $this->featureBuilder->updateStatus($feature, true); | ||||
} | } | ||||
public function disable(Feature $feature): void | |||||
public function disableFeature(Feature $feature): void | |||||
{ | { | ||||
$this->featureBuilder->updateStatus($feature, false); | $this->featureBuilder->updateStatus($feature, false); | ||||
} | } | ||||
public function enableForProducer(Feature $feature) | |||||
public function enableFeatureForProducer(Feature $feature) | |||||
{ | { | ||||
$this->featureProducerBuilder->updateStatusByFeature($feature, true); | $this->featureProducerBuilder->updateStatusByFeature($feature, true); | ||||
} | } | ||||
public function disableForProducer(Feature $feature) | |||||
public function disableFeatureForProducer(Feature $feature) | |||||
{ | { | ||||
$this->featureProducerBuilder->updateStatusByFeature($feature, false); | $this->featureProducerBuilder->updateStatusByFeature($feature, false); | ||||
} | } | ||||
public function defaultForProducer(Feature $feature) | |||||
public function defaultFeatureForProducer(Feature $feature) | |||||
{ | { | ||||
$this->featureProducerBuilder->updateStatusByFeature($feature, null); | $this->featureProducerBuilder->updateStatusByFeature($feature, null); | ||||
} | } |
{ | { | ||||
return FeatureProducer::class; | return FeatureProducer::class; | ||||
} | } | ||||
public function getDefinition(): FeatureProducerDefinition | |||||
{ | |||||
return FeatureProducerDefinition::getInstance(); | |||||
} | |||||
public function getRepository(): FeatureProducerRepository | |||||
{ | |||||
return FeatureProducerRepository::getInstance(); | |||||
} | |||||
} | } |
public function actionAdd() | public function actionAdd() | ||||
{ | { | ||||
$featureManager = $this->getFeatureModule()->getManager(); | |||||
$featureChecker = $this->getFeatureModule()->getChecker(); | |||||
$producer = $this->getProducerCurrent(); | $producer = $this->getProducerCurrent(); | ||||
if (\Yii::$app->user->isGuest) { | if (\Yii::$app->user->isGuest) { | ||||
return $this->redirect($this->getUrlManagerFrontend()->createAbsoluteUrl(['site/producer', 'id' => $producer->id])); | return $this->redirect($this->getUrlManagerFrontend()->createAbsoluteUrl(['site/producer', 'id' => $producer->id])); | ||||
} | } | ||||
if ($featureManager->isEnabled(Feature::ALIAS_ONLINE_PAYMENT) | |||||
if ($featureChecker->isEnabled(Feature::ALIAS_ONLINE_PAYMENT) | |||||
&& ($producer->online_payment || $producer->option_stripe_mode_test)) { | && ($producer->online_payment || $producer->option_stripe_mode_test)) { | ||||
$creditForm = new CreditForm; | $creditForm = new CreditForm; | ||||
$paymentManager = $this->getPaymentModule(); | $paymentManager = $this->getPaymentModule(); | ||||
$producerModule = $this->getProducerModule(); | $producerModule = $this->getProducerModule(); | ||||
$userModule = $this->getUserModule(); | $userModule = $this->getUserModule(); | ||||
$featureManager = $this->getFeatureModule()->getManager(); | |||||
$featureChecker = $this->getFeatureModule()->getChecker(); | |||||
if ($featureManager->isEnabled(Feature::ALIAS_ONLINE_PAYMENT)) { | |||||
if ($featureChecker->isEnabled(Feature::ALIAS_ONLINE_PAYMENT)) { | |||||
$producer = $this->getProducerCurrent(); | $producer = $this->getProducerCurrent(); | ||||
$contactProducer = $producerModule->getMainContact($producer); | $contactProducer = $producerModule->getMainContact($producer); | ||||
public function actionContact() | public function actionContact() | ||||
{ | { | ||||
$featureModule = $this->getFeatureModule(); | $featureModule = $this->getFeatureModule(); | ||||
if($featureModule->getManager()->isDisabled(Feature::ALIAS_CONTACT)) { | |||||
if($featureModule->getChecker()->isDisabled(Feature::ALIAS_CONTACT)) { | |||||
return $this->redirect(['site/index']); | return $this->redirect(['site/index']); | ||||
} | } | ||||
use yii\grid\GridView; | use yii\grid\GridView; | ||||
$paymentManager = PaymentModule::getInstance(); | $paymentManager = PaymentModule::getInstance(); | ||||
$featureManager = FeatureModule::getInstance(); | |||||
$featureChecker = FeatureModule::getInstance()->getChecker(); | |||||
$producer = $this->context->getProducerCurrent(); | $producer = $this->context->getProducerCurrent(); | ||||
$this->setTitle('Crédit : <span id="credit-user">' . number_format($creditUser, 2) . ' €</span>'); | $this->setTitle('Crédit : <span id="credit-user">' . number_format($creditUser, 2) . ' €</span>'); | ||||
$this->setPageTitle('Crédit'); | $this->setPageTitle('Crédit'); | ||||
if ($featureManager->isEnabled(Feature::ALIAS_ONLINE_PAYMENT) && $this->context->getProducerCurrent()->online_payment) { | |||||
if ($featureChecker->isEnabled(Feature::ALIAS_ONLINE_PAYMENT) && $this->context->getProducerCurrent()->online_payment) { | |||||
$this->addButton( | $this->addButton( | ||||
[ | [ | ||||
'label' => '<span class="glyphicon glyphicon-credit-card"></span> Créditer mon compte', | 'label' => '<span class="glyphicon glyphicon-credit-card"></span> Créditer mon compte', |
'label' => '<span class="glyphicon glyphicon-envelope"></span> Contact', | 'label' => '<span class="glyphicon glyphicon-envelope"></span> Contact', | ||||
'url' => $this->getUrlManagerProducer()->createUrl(['site/contact']), | 'url' => $this->getUrlManagerProducer()->createUrl(['site/contact']), | ||||
'active' => $this->getControllerAction() == 'site/contact', | 'active' => $this->getControllerAction() == 'site/contact', | ||||
'visible' => $featureModule->getManager()->isEnabled(Feature::ALIAS_CONTACT) | |||||
'visible' => $featureModule->getChecker()->isEnabled(Feature::ALIAS_CONTACT) | |||||
], | ], | ||||
], | ], | ||||
]); | ]); |