{ | { | ||||
return Producer::searchOne(); | return Producer::searchOne(); | ||||
} | } | ||||
public function redirectDashboard() | |||||
{ | |||||
return $this->redirect(['dashboard/index']); | |||||
} | |||||
} | } | ||||
?> | ?> |
<?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 common\helpers\Ajax; | |||||
use yii\filters\AccessControl; | |||||
use yii\helpers\Html; | |||||
use yii\web\NotFoundHttpException; | |||||
/** | |||||
* UserController implements the CRUD actions for User model. | |||||
*/ | |||||
class FeatureAdminController 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() | |||||
{ | |||||
$featureModule = $this->getFeatureModule(); | |||||
$dataProviderFeatures = $featureModule->getRepository()->queryAll()->getDataProvider(100); | |||||
return $this->render('index', [ | |||||
'producerCurrent' => $this->getProducerCurrent(), | |||||
'dataProviderFeatures' => $dataProviderFeatures | |||||
]); | |||||
} | |||||
public function actionAjaxToggleStatus($id, $status) | |||||
{ | |||||
$featureManager = $this->getFeatureModule()->getManager(); | |||||
$feature = $this->findModel($id); | |||||
if($status) { | |||||
$featureManager->enable($feature); | |||||
$messageResponse = 'La fonctionnalité "'.Html::encode($feature->name).'" a bien été activée'; | |||||
} | |||||
else { | |||||
$featureManager->disable($feature); | |||||
$messageResponse = 'La fonctionnalité "'.Html::encode($feature->name).'" a bien été désactivée'; | |||||
} | |||||
return Ajax::responseSuccess($messageResponse); | |||||
} | |||||
public function actionToggleStatusFeatureProducer(int $id, bool $status = null) | |||||
{ | |||||
$featureManager = $this->getFeatureModule()->getManager(); | |||||
$feature = $this->findModel($id); | |||||
if(is_null($status)) { | |||||
$featureManager->defaultForProducer($feature); | |||||
} | |||||
elseif($status == 0) { | |||||
$featureManager->disableForProducer($feature); | |||||
} | |||||
elseif($status == 1) { | |||||
$featureManager->enableForProducer($feature); | |||||
} | |||||
return $this->redirectReferer(); | |||||
} | |||||
public function actionUpdate($id) | |||||
{ | |||||
$model = $this->findModel($id); | |||||
if ($model->load(\Yii::$app->request->post()) && $model->save()) { | |||||
$this->setFlash('success', 'Fonctionnalité modifiée.'); | |||||
return $this->redirect(['index']); | |||||
} else { | |||||
return $this->render('update', [ | |||||
'model' => $model, | |||||
]); | |||||
} | |||||
} | |||||
protected function findModel($id) | |||||
{ | |||||
$featureModule = $this->getFeatureModule(); | |||||
if (($feature = $featureModule->getRepository()->findOneFeatureById($id)) !== null) { | |||||
return $feature; | |||||
} else { | |||||
throw new NotFoundHttpException('La fonctionnalité demandée est introuvable.'); | |||||
} | |||||
} | |||||
} |
use common\helpers\CSV; | use common\helpers\CSV; | ||||
use common\helpers\GlobalParam; | use common\helpers\GlobalParam; | ||||
use common\logic\Distribution\ProductDistribution\Model\ProductDistribution; | use common\logic\Distribution\ProductDistribution\Model\ProductDistribution; | ||||
use common\logic\Feature\Feature\Model\Feature; | |||||
use common\logic\PointSale\PointSale\Model\PointSale; | use common\logic\PointSale\PointSale\Model\PointSale; | ||||
use common\logic\Product\Product\Model\Product; | use common\logic\Product\Product\Model\Product; | ||||
use common\logic\Product\Product\Model\ProductSearch; | use common\logic\Product\Product\Model\ProductSearch; | ||||
*/ | */ | ||||
public function actionPriceImport() | public function actionPriceImport() | ||||
{ | { | ||||
if($this->getFeatureModule()->getManager()->isDisabled(Feature::ALIAS_PRODUCT_PRICE_IMPORT)) { | |||||
return $this->redirectDashboard(); | |||||
} | |||||
$productModule = $this->getProductModule(); | $productModule = $this->getProductModule(); | ||||
$productPriceModule = $this->getProductPriceModule(); | $productPriceModule = $this->getProductPriceModule(); | ||||
$userGroupModule = $this->getUserGroupModule(); | $userGroupModule = $this->getUserGroupModule(); | ||||
*/ | */ | ||||
public function actionPriceExport() | public function actionPriceExport() | ||||
{ | { | ||||
if($this->getFeatureModule()->getManager()->isDisabled(Feature::ALIAS_PRODUCT_PRICE_IMPORT)) { | |||||
return $this->redirectDashboard(); | |||||
} | |||||
$productModule = $this->getProductModule(); | $productModule = $this->getProductModule(); | ||||
$productPriceModule = $this->getProductPriceModule(); | $productPriceModule = $this->getProductPriceModule(); | ||||
$userModule = $this->getUserModule(); | $userModule = $this->getUserModule(); |
'matchCallback' => function ($rule, $action) { | 'matchCallback' => function ($rule, $action) { | ||||
return $this->getUserModule() | return $this->getUserModule() | ||||
->getAuthorizationChecker() | ->getAuthorizationChecker() | ||||
->isGrantedAsProducer($this->getUserCurrent()); | |||||
->isGrantedAsAdministrator($this->getUserCurrent()); | |||||
} | } | ||||
] | ] | ||||
], | ], |
<?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\helpers\Price; | |||||
use lo\widgets\Toggle; | |||||
use yii\helpers\Html; | |||||
use yii\grid\GridView; | |||||
$this->setTitle('Fonctionnalités'); | |||||
$this->addBreadcrumb($this->getTitle()); | |||||
?> | |||||
<div class="feature-admin-index"> | |||||
<?= GridView::widget([ | |||||
'dataProvider' => $dataProviderFeatures, | |||||
'columns' => [ | |||||
'name', | |||||
[ | |||||
'attribute' => 'status', | |||||
'headerOptions' => ['class' => 'status column-hide-on-mobile'], | |||||
'filterOptions' => ['class' => 'column-hide-on-mobile'], | |||||
'contentOptions' => ['class' => 'center column-hide-on-mobile'], | |||||
'format' => 'raw', | |||||
'filter' => [0 => 'Désactivée', 1 => 'Activée'], | |||||
'value' => function ($model) { | |||||
return Toggle::widget( | |||||
[ | |||||
'name' => 'active', | |||||
'checked' => $model->status, | |||||
'options' => [ | |||||
'data-id' => $model->id, | |||||
'data-on' => 'Activée', | |||||
'data-off' => 'Désactivée', | |||||
], | |||||
] | |||||
); | |||||
} | |||||
], | |||||
[ | |||||
'attribute' => 'producers', | |||||
'label' => 'Producteurs', | |||||
'headerOptions' => ['class' => 'column-hide-on-mobile'], | |||||
'filterOptions' => ['class' => 'column-hide-on-mobile'], | |||||
'contentOptions' => ['class' => 'column-hide-on-mobile'], | |||||
'format' => 'raw', | |||||
'value' => function ($model) { | |||||
$html = ''; | |||||
foreach($model->featureProducers as $featureProducer) { | |||||
if(!is_null($featureProducer->status)) { | |||||
$html .= feature_status_producer($featureProducer->producer->name, $featureProducer->status); | |||||
} | |||||
} | |||||
return $html; | |||||
} | |||||
], | |||||
[ | |||||
'attribute' => 'only_for_selected_producers', | |||||
'label' => "Producteurs sélectionnés", | |||||
'headerOptions' => ['class' => 'only-for-selected-producers column-hide-on-mobile'], | |||||
'filterOptions' => ['class' => 'column-hide-on-mobile'], | |||||
'contentOptions' => ['class' => 'only-for-selected-producers column-hide-on-mobile'], | |||||
'format' => 'raw', | |||||
'value' => function ($model) { | |||||
return '<span class="label label-'.($model->only_for_selected_producers ? 'success' : 'default').'">' | |||||
.($model->only_for_selected_producers ? 'Oui' : 'Non') .'</span>'; | |||||
} | |||||
], | |||||
[ | |||||
'attribute' => 'is_paid_feature', | |||||
'headerOptions' => ['class' => 'column-hide-on-mobile'], | |||||
'filterOptions' => ['class' => 'column-hide-on-mobile'], | |||||
'contentOptions' => ['class' => 'column-hide-on-mobile'], | |||||
'format' => 'raw', | |||||
'value' => function ($model) { | |||||
return '<span class="label label-'.($model->is_paid_feature ? 'success' : 'default').'">' | |||||
.($model->is_paid_feature ? 'Oui' : 'Non') .'</span>'; | |||||
} | |||||
], | |||||
[ | |||||
'attribute' => 'price', | |||||
'headerOptions' => ['class' => 'column-hide-on-mobile'], | |||||
'filterOptions' => ['class' => 'column-hide-on-mobile'], | |||||
'contentOptions' => ['class' => 'column-hide-on-mobile'], | |||||
'format' => 'raw', | |||||
'value' => function ($model) { | |||||
if($model->is_paid_feature && $model->price) { | |||||
return Price::format($model->price); | |||||
} | |||||
return ''; | |||||
} | |||||
], | |||||
[ | |||||
'class' => 'yii\grid\ActionColumn', | |||||
'template' => '{toggle_status_feature_producer} {update}', | |||||
'headerOptions' => ['class' => 'column-actions'], | |||||
'contentOptions' => ['class' => 'column-actions'], | |||||
'buttons' => [ | |||||
'toggle_status_feature_producer' => function ($url, $model) use ($producerCurrent) { | |||||
return '<div class="dropdown"> | |||||
<button class="btn btn-default dropdown-toggle" type="button" id="dropdownMenu1" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true"> | |||||
'.Html::encode($producerCurrent->name).' | |||||
<span class="caret"></span> | |||||
</button> | |||||
<ul class="dropdown-menu" aria-labelledby="dropdownMenu1"> | |||||
<li><a href="'.Yii::$app->urlManager->createUrl(['feature-admin/toggle-status-feature-producer', 'id' => $model->id]).'">Par défaut</a></li> | |||||
<li><a href="'.Yii::$app->urlManager->createUrl(['feature-admin/toggle-status-feature-producer', 'id' => $model->id, 'status' => 1]).'">Activer</a></li> | |||||
<li><a href="'.Yii::$app->urlManager->createUrl(['feature-admin/toggle-status-feature-producer', 'id' => $model->id, 'status' => 0]).'">Désactiver</a></li> | |||||
</ul> | |||||
</div>'; | |||||
}, | |||||
'update' => function ($url, $model) { | |||||
return Html::a('<span class="glyphicon glyphicon-pencil"></span>', $url, [ | |||||
'title' => 'Modifier', 'class' => 'btn btn-default' | |||||
]); | |||||
}, | |||||
], | |||||
], | |||||
] | |||||
]); | |||||
?> | |||||
</div> | |||||
<?php | |||||
function feature_status_producer($producerName, $status): string { | |||||
return '<span class="label label-'.($status ? 'success' : 'danger').'">'.Html::encode($producerName).'</span> '; | |||||
} | |||||
?> |
<?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 yii\helpers\Html; | |||||
use yii\widgets\ActiveForm; | |||||
$this->setTitle('Modifier une fonctionnalité') ; | |||||
$this->addBreadcrumb(['label' => 'Fonctionnalité', 'url' => ['index']]) ; | |||||
$this->addBreadcrumb('Modifier') ; | |||||
?> | |||||
<div class="feature-admin-update"> | |||||
<?php $form = ActiveForm::begin(); ?> | |||||
<?= $form->field($model, 'status')->radioList([1 => 'Oui', 0 => 'Non']) ?> | |||||
<?= $form->field($model, 'name') ?> | |||||
<?= $form->field($model, 'description')->textarea(['rows' => '4']) ; ?> | |||||
<?= $form->field($model, 'only_for_selected_producers')->radioList([1 => 'Oui', 0 => 'Non']) ?> | |||||
<?= $form->field($model, 'is_paid_feature')->radioList([1 => 'Oui', 0 => 'Non']) ?> | |||||
<?= $form->field($model, 'price') ?> | |||||
<div class="form-group"> | |||||
<?= Html::submitButton('Modifier', ['class' => 'btn btn-success']) ?> | |||||
</div> | |||||
<?php ActiveForm::end(); ?> | |||||
</div> |
*/ | */ | ||||
use common\helpers\GlobalParam; | use common\helpers\GlobalParam; | ||||
use common\logic\Feature\Feature\Model\Feature; | |||||
use common\logic\User\User\Module\UserModule; | use common\logic\User\User\Module\UserModule; | ||||
$producerModule = $this->getProducerModule(); | $producerModule = $this->getProducerModule(); | ||||
$userModule = UserModule::getInstance(); | $userModule = UserModule::getInstance(); | ||||
$userProducerModule = $this->getUserProducerModule(); | $userProducerModule = $this->getUserProducerModule(); | ||||
$ticketModule = $this->getTicketModule(); | $ticketModule = $this->getTicketModule(); | ||||
$featureManager = $this->getFeatureModule()->getManager(); | |||||
$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], | |||||
['label' => 'Import prix', 'icon' => 'upload', 'url' => ['/product/price-import'], 'visible' => $isUserCurrentGrantedAsProducer && $featureManager->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'], | ||||
['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' => '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], | ||||
['label' => 'Communiquer', 'icon' => 'bullhorn', 'url' => ['/communicate-admin/index'], 'visible' => $isUserCurrentGrantedAsAdministrator], | ['label' => 'Communiquer', 'icon' => 'bullhorn', 'url' => ['/communicate-admin/index'], 'visible' => $isUserCurrentGrantedAsAdministrator], |
margin-top: 5px; | margin-top: 5px; | ||||
} | } | ||||
/* line 4, ../sass/feature-admin/_index.scss */ | |||||
.feature-admin-index table th.only-for-selected-producers, | |||||
.feature-admin-index table td.only-for-selected-producers { | |||||
width: 100px; | |||||
} | |||||
/** | /** | ||||
Copyright distrib (2018) | Copyright distrib (2018) | ||||
opendistrib_gridview_pagesize(); | opendistrib_gridview_pagesize(); | ||||
opendistrib_producers_admin(); | opendistrib_producers_admin(); | ||||
opendistrib_user_form(); | opendistrib_user_form(); | ||||
opendistrib_features_index(); | |||||
}); | }); | ||||
var UrlManager = { | var UrlManager = { | ||||
'.btn-order', | '.btn-order', | ||||
'product/order' | 'product/order' | ||||
); | ); | ||||
} | |||||
/*var fixHelper = function(e, ui) { | |||||
ui.children().each(function() { | |||||
$(this).width($(this).width()); | |||||
}); | |||||
return ui; | |||||
}; | |||||
$(".product-index table tbody").sortable({ | |||||
items: "> tr", | |||||
appendTo: "parent", | |||||
cursor: "move", | |||||
placeholder: "ui-state-highlight", | |||||
handle: '.btn-order', | |||||
//helper: "clone" | |||||
helper: fixHelper, | |||||
stop: function(event, ui) { | |||||
var tab_ordre = {} ; | |||||
var ordre = 1 ; | |||||
if($('ul.pagination').size()) { | |||||
var page = parseInt($('ul.pagination li.active a').html()) ; | |||||
var nb_items_by_page = parseInt($('#page-size').html()) ; | |||||
if(page != 1) { | |||||
ordre = (page - 1) * nb_items_by_page ; | |||||
} | |||||
function opendistrib_features_index() { | |||||
$('body.feature-admin-index .toggle input').change(function () { | |||||
var id = $(this).data('id'); | |||||
var checked = $(this).prop('checked'); | |||||
/*$.get(UrlManager.getBaseUrl() + 'feature-admin/ajax-toggle-status', { | |||||
id: id, | |||||
status: checked ? 1 : 0 | |||||
});*/ | |||||
axios.get(UrlManager.getBaseUrlAbsolute() + "feature-admin/ajax-toggle-status", { | |||||
params: { | |||||
id: id, | |||||
status: checked ? 1 : 0 | |||||
} | } | ||||
$(".product-index table tbody tr").each(function() { | |||||
tab_ordre[$(this).attr('data-key')] = ordre ; | |||||
ordre++ ; | |||||
}) ; | |||||
$.post(UrlManager.getBaseUrl()+'product/order',{ | |||||
array: JSON.stringify(tab_ordre) | |||||
}) ; | |||||
} | |||||
}).disableSelection();*/ | |||||
}) | |||||
.then(function (response) { | |||||
appAlerts.alertResponse(response); | |||||
}); | |||||
}) | |||||
} | } | ||||
function opendistrib_datepicker() { | function opendistrib_datepicker() { |
.feature-admin-index { | |||||
table { | |||||
th.only-for-selected-producers, | |||||
td.only-for-selected-producers { | |||||
width: 100px; | |||||
} | |||||
} | |||||
} |
@import "support/_index.scss"; | @import "support/_index.scss"; | ||||
@import "support/_view.scss"; | @import "support/_view.scss"; | ||||
@import "producer-admin/_index.scss"; | @import "producer-admin/_index.scss"; | ||||
@import "feature-admin/_index.scss"; | |||||
@import "_responsive.scss" ; | @import "_responsive.scss" ; |
public function getModules() | public function getModules() | ||||
{ | { | ||||
return [ | return [ | ||||
$this->getFeatureModule(), | |||||
$this->getFeatureProducerModule(), | |||||
$this->getUnitModule(), | $this->getUnitModule(), | ||||
$this->getTaxRateModule(), | $this->getTaxRateModule(), | ||||
$this->getUserUserGroupModule(), | $this->getUserUserGroupModule(), |
use common\logic\Document\Document\Module\DocumentModule; | use common\logic\Document\Document\Module\DocumentModule; | ||||
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\Module\FeatureModule; | |||||
use common\logic\Feature\FeatureProducer\Module\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; | ||||
{ | { | ||||
return TicketUserModule::getInstance(); | return TicketUserModule::getInstance(); | ||||
} | } | ||||
public function getFeatureModule(): FeatureModule | |||||
{ | |||||
return FeatureModule::getInstance(); | |||||
} | |||||
public function getFeatureProducerModule(): FeatureProducerModule | |||||
{ | |||||
return FeatureProducerModule::getInstance(); | |||||
} | |||||
} | } |
{ | { | ||||
return $this->createQuery()->find(); | return $this->createQuery()->find(); | ||||
} | } | ||||
public function queryAll() | |||||
{ | |||||
return $this->createQuery(); | |||||
} | |||||
} | } |
<?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\Feature\Feature\Model; | |||||
use common\components\ActiveRecordCommon; | |||||
use common\logic\Feature\FeatureProducer\Model\FeatureProducer; | |||||
use yii\db\ActiveQuery; | |||||
use yii\db\Schema; | |||||
class Feature extends ActiveRecordCommon | |||||
{ | |||||
const ALIAS_CONTACT = 'contact'; | |||||
const ALIAS_PRODUCT_PRICE_IMPORT = 'product_price_import'; | |||||
/** | |||||
* @inheritdoc | |||||
*/ | |||||
public static function tableName() | |||||
{ | |||||
return 'feature'; | |||||
} | |||||
/** | |||||
* @inheritdoc | |||||
*/ | |||||
public function rules() | |||||
{ | |||||
return [ | |||||
[['alias', 'name'], 'required'], | |||||
[['status', 'is_paid_feature', 'only_for_selected_producers'], 'boolean'], | |||||
[['price'], 'double'], | |||||
[['alias', 'name', 'description'], 'string'], | |||||
]; | |||||
} | |||||
/** | |||||
* @inheritdoc | |||||
*/ | |||||
public function attributeLabels() | |||||
{ | |||||
return [ | |||||
'id' => 'ID', | |||||
'alias' => 'Alias', | |||||
'name' => 'Nom', | |||||
'description' => 'Description', | |||||
'status' => 'Statut', | |||||
'is_paid_feature' => "Fonctionnalité payante", | |||||
'price' => 'Prix', | |||||
'only_for_selected_producers' => 'Uniquement pour les producteurs sélectionnés' | |||||
]; | |||||
} | |||||
public function getFeatureProducers(): ActiveQuery | |||||
{ | |||||
return $this->hasMany(FeatureProducer::class, ['id_feature' => 'id']); | |||||
} | |||||
} |
<?php | |||||
namespace common\logic\Feature\Feature\Module; | |||||
use common\logic\AbstractModule; | |||||
use common\logic\Feature\Feature\Repository\FeatureRepository; | |||||
use common\logic\Feature\Feature\Service\FeatureBuilder; | |||||
use common\logic\Feature\Feature\Service\FeatureDefinition; | |||||
use common\logic\Feature\Feature\Service\FeatureImporter; | |||||
use common\logic\Feature\Feature\Service\FeatureManager; | |||||
class FeatureModule extends AbstractModule | |||||
{ | |||||
public function getServices(): array | |||||
{ | |||||
return [ | |||||
FeatureDefinition::class, | |||||
FeatureRepository::class, | |||||
FeatureBuilder::class, | |||||
FeatureImporter::class, | |||||
FeatureManager::class | |||||
]; | |||||
} | |||||
public function getDefinition(): FeatureDefinition | |||||
{ | |||||
return FeatureDefinition::getInstance(); | |||||
} | |||||
public function getRepository(): FeatureRepository | |||||
{ | |||||
return FeatureRepository::getInstance(); | |||||
} | |||||
public function getBuilder(): FeatureBuilder | |||||
{ | |||||
return FeatureBuilder::getInstance(); | |||||
} | |||||
public function getImporter(): FeatureImporter | |||||
{ | |||||
return FeatureImporter::getInstance(); | |||||
} | |||||
public function getManager(): FeatureManager | |||||
{ | |||||
return FeatureManager::getInstance(); | |||||
} | |||||
} |
<?php | |||||
namespace common\logic\Feature\Feature\Repository; | |||||
use common\logic\AbstractRepository; | |||||
use common\logic\Feature\Feature\Model\Feature; | |||||
class FeatureRepository extends AbstractRepository | |||||
{ | |||||
protected FeatureRepositoryQuery $query; | |||||
public function loadDependencies(): void | |||||
{ | |||||
$this->loadQuery(FeatureRepositoryQuery::class); | |||||
} | |||||
public function getDefaultOptionsSearch(): array | |||||
{ | |||||
return [ | |||||
self::WITH => ['featureProducers'], | |||||
self::JOIN_WITH => [], | |||||
self::ORDER_BY => '', | |||||
self::ATTRIBUTE_ID_PRODUCER => '' | |||||
]; | |||||
} | |||||
public function findOneFeatureById(int $id): ?Feature | |||||
{ | |||||
return $this->createQuery() | |||||
->filterById($id) | |||||
->findOne(); | |||||
} | |||||
public function findOneFeatureByAlias(string $alias): ?Feature | |||||
{ | |||||
return $this->createQuery() | |||||
->filterByAlias($alias) | |||||
->findOne(); | |||||
} | |||||
} |
<?php | |||||
namespace common\logic\Feature\Feature\Repository; | |||||
use common\logic\AbstractRepositoryQuery; | |||||
use common\logic\Feature\Feature\Service\FeatureDefinition; | |||||
class FeatureRepositoryQuery extends AbstractRepositoryQuery | |||||
{ | |||||
protected FeatureDefinition $definition; | |||||
public function loadDependencies(): void | |||||
{ | |||||
$this->loadDefinition(FeatureDefinition::class); | |||||
} | |||||
public function filterByAlias(string $alias): self | |||||
{ | |||||
$this->andWhere(['alias' => $alias]); | |||||
return $this; | |||||
} | |||||
} |
<?php | |||||
namespace common\logic\Feature\Feature\Service; | |||||
use common\logic\AbstractBuilder; | |||||
use common\logic\Feature\Feature\Model\Feature; | |||||
use common\logic\Feature\Feature\Repository\FeatureRepository; | |||||
class FeatureBuilder extends AbstractBuilder | |||||
{ | |||||
protected FeatureRepository $featureRepository; | |||||
public function loadDependencies(): void | |||||
{ | |||||
$this->featureRepository = $this->loadService(FeatureRepository::class); | |||||
} | |||||
public function instanciateFeature( | |||||
string $alias, | |||||
string $name, | |||||
string $description, | |||||
bool $status = true, | |||||
bool $isPaidFeature = false, | |||||
float $price = null | |||||
): Feature | |||||
{ | |||||
$feature = new Feature(); | |||||
$feature->alias = $alias; | |||||
$feature->name = $name; | |||||
$feature->description = $description; | |||||
$feature->status = $status; | |||||
$feature->is_paid_feature = $isPaidFeature; | |||||
$feature->price = $price; | |||||
return $feature; | |||||
} | |||||
public function createFeature( | |||||
string $alias, | |||||
string $name, | |||||
string $description, | |||||
bool $status = true, | |||||
bool $isPaidFeature = false, | |||||
float $price = null | |||||
): Feature | |||||
{ | |||||
$feature = $this->featureRepository->findOneFeatureByAlias($alias); | |||||
if(!$feature) { | |||||
$feature = $this->instanciateFeature($alias, $name, $description, $status, $isPaidFeature, $price); | |||||
$this->create($feature); | |||||
} | |||||
return $feature; | |||||
} | |||||
public function updateStatus(Feature $feature, bool $status) | |||||
{ | |||||
$feature->status = $status; | |||||
$this->update($feature); | |||||
} | |||||
} |
<?php | |||||
namespace common\logic\Feature\Feature\Service; | |||||
use common\logic\AbstractDefinition; | |||||
use common\logic\Feature\Feature\Model\Feature; | |||||
class FeatureDefinition extends AbstractDefinition | |||||
{ | |||||
public function getEntityFqcn(): string | |||||
{ | |||||
return Feature::class; | |||||
} | |||||
public function getFeaturesBase(): array | |||||
{ | |||||
return [ | |||||
Feature::ALIAS_CONTACT => $this->buildFeatureArray('Formulaire de contact', true, false), | |||||
Feature::ALIAS_PRODUCT_PRICE_IMPORT => $this->buildFeatureArray('Produits : import prix', true, false), | |||||
]; | |||||
} | |||||
public function buildFeatureArray(string $name, bool $status, bool $isPaidFeature): array | |||||
{ | |||||
return [ | |||||
'name' => $name, | |||||
'status' => $status, | |||||
'is_paid_feature' => $isPaidFeature | |||||
]; | |||||
} | |||||
} |
<?php | |||||
namespace common\logic\Feature\Feature\Service; | |||||
use common\logic\AbstractManager; | |||||
class FeatureImporter extends AbstractManager | |||||
{ | |||||
protected FeatureDefinition $featureDefinition; | |||||
protected FeatureBuilder $featureBuilder; | |||||
public function loadDependencies(): void | |||||
{ | |||||
$this->featureDefinition = $this->loadService(FeatureDefinition::class); | |||||
$this->featureBuilder = $this->loadService(FeatureBuilder::class); | |||||
} | |||||
public function importFromDefinition() | |||||
{ | |||||
$featuresBaseArray = $this->featureDefinition->getFeaturesBase(); | |||||
foreach($featuresBaseArray as $alias => $featureBase) { | |||||
$this->featureBuilder->createFeature( | |||||
$alias, | |||||
$featureBase['name'], | |||||
'', | |||||
$featureBase['status'], | |||||
$featureBase['is_paid_feature'] | |||||
); | |||||
} | |||||
} | |||||
} |
<?php | |||||
namespace common\logic\Feature\Feature\Service; | |||||
use common\logic\AbstractManager; | |||||
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 yii\base\ErrorException; | |||||
class FeatureManager extends AbstractManager | |||||
{ | |||||
protected FeatureRepository $featureRepository; | |||||
protected FeatureProducerRepository $featureProducerRepository; | |||||
protected FeatureBuilder $featureBuilder; | |||||
protected FeatureProducerBuilder $featureProducerBuilder; | |||||
public function loadDependencies(): void | |||||
{ | |||||
$this->featureRepository = $this->loadService(FeatureRepository::class); | |||||
$this->featureProducerRepository = $this->loadService(FeatureProducerRepository::class); | |||||
$this->featureBuilder = $this->loadService(FeatureBuilder::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 | |||||
{ | |||||
$this->featureBuilder->updateStatus($feature, true); | |||||
} | |||||
public function disable(Feature $feature): void | |||||
{ | |||||
$this->featureBuilder->updateStatus($feature, false); | |||||
} | |||||
public function enableForProducer(Feature $feature) | |||||
{ | |||||
$this->featureProducerBuilder->updateStatusByFeature($feature, true); | |||||
} | |||||
public function disableForProducer(Feature $feature) | |||||
{ | |||||
$this->featureProducerBuilder->updateStatusByFeature($feature, false); | |||||
} | |||||
public function defaultForProducer(Feature $feature) | |||||
{ | |||||
$this->featureProducerBuilder->updateStatusByFeature($feature, null); | |||||
} | |||||
} |
<?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\Feature\FeatureProducer\Model; | |||||
use common\components\ActiveRecordCommon; | |||||
use common\logic\Feature\Feature\Model\Feature; | |||||
use common\logic\Producer\Producer\Model\Producer; | |||||
use yii\db\ActiveQuery; | |||||
class FeatureProducer extends ActiveRecordCommon | |||||
{ | |||||
/** | |||||
* @inheritdoc | |||||
*/ | |||||
public static function tableName() | |||||
{ | |||||
return 'feature_producer'; | |||||
} | |||||
/** | |||||
* @inheritdoc | |||||
*/ | |||||
public function rules() | |||||
{ | |||||
return [ | |||||
[['id_producer', 'id_feature'], 'required'], | |||||
[['status'], 'boolean'], | |||||
]; | |||||
} | |||||
/** | |||||
* @inheritdoc | |||||
*/ | |||||
public function attributeLabels() | |||||
{ | |||||
return [ | |||||
'id' => 'ID', | |||||
]; | |||||
} | |||||
public function getProducer(): ActiveQuery | |||||
{ | |||||
return $this->hasOne(Producer::class, ['id' => 'id_producer']); | |||||
} | |||||
public function populateProducer(Producer $producer): void | |||||
{ | |||||
$this->populateFieldObject('id_producer', 'producer', $producer); | |||||
} | |||||
public function getFeature(): ActiveQuery | |||||
{ | |||||
return $this->hasOne(Feature::class, ['id' => 'id_feature']); | |||||
} | |||||
public function populateFeature(Feature $feature): void | |||||
{ | |||||
$this->populateFieldObject('id_feature', 'feature', $feature); | |||||
} | |||||
} |
<?php | |||||
namespace common\logic\Feature\FeatureProducer\Module; | |||||
use common\logic\AbstractModule; | |||||
use common\logic\Feature\FeatureProducer\Repository\FeatureProducerRepository; | |||||
use common\logic\Feature\FeatureProducer\Service\FeatureProducerBuilder; | |||||
use common\logic\Feature\FeatureProducer\Service\FeatureProducerDefinition; | |||||
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(); | |||||
} | |||||
} |
<?php | |||||
namespace common\logic\Feature\FeatureProducer\Repository; | |||||
use common\logic\AbstractRepository; | |||||
use common\logic\Feature\Feature\Model\Feature; | |||||
use common\logic\Producer\Producer\Model\Producer; | |||||
class FeatureProducerRepository extends AbstractRepository | |||||
{ | |||||
protected FeatureProducerRepositoryQuery $query; | |||||
public function loadDependencies(): void | |||||
{ | |||||
$this->loadQuery(FeatureProducerRepositoryQuery::class); | |||||
} | |||||
public function getDefaultOptionsSearch(): array | |||||
{ | |||||
return [ | |||||
self::WITH => ['feature', 'producer'], | |||||
self::JOIN_WITH => [], | |||||
self::ORDER_BY => '', | |||||
self::ATTRIBUTE_ID_PRODUCER => 'feature_producer.id_producer' | |||||
]; | |||||
} | |||||
public function findOneFeatureProducer(Feature $feature) | |||||
{ | |||||
return $this->createDefaultQuery() | |||||
->filterByFeature($feature) | |||||
->findOne(); | |||||
} | |||||
} |
<?php | |||||
namespace common\logic\Feature\FeatureProducer\Repository; | |||||
use common\logic\AbstractRepositoryQuery; | |||||
use common\logic\Feature\Feature\Model\Feature; | |||||
use common\logic\Feature\FeatureProducer\Service\FeatureProducerDefinition; | |||||
class FeatureProducerRepositoryQuery extends AbstractRepositoryQuery | |||||
{ | |||||
protected FeatureProducerDefinition $definition; | |||||
public function loadDependencies(): void | |||||
{ | |||||
$this->loadDefinition(FeatureProducerDefinition::class); | |||||
} | |||||
public function filterByFeature(Feature $feature): self | |||||
{ | |||||
$this->andWhere(['id_feature' => $feature]); | |||||
return $this; | |||||
} | |||||
} |
<?php | |||||
namespace common\logic\Feature\FeatureProducer\Service; | |||||
use common\logic\AbstractBuilder; | |||||
use common\logic\Feature\Feature\Model\Feature; | |||||
use common\logic\Feature\FeatureProducer\Model\FeatureProducer; | |||||
use common\logic\Feature\FeatureProducer\Repository\FeatureProducerRepository; | |||||
use common\logic\Producer\Producer\Model\Producer; | |||||
class FeatureProducerBuilder extends AbstractBuilder | |||||
{ | |||||
protected FeatureProducerRepository $featureProducerRepository; | |||||
public function loadDependencies(): void | |||||
{ | |||||
$this->featureProducerRepository = $this->loadService(FeatureProducerRepository::class); | |||||
} | |||||
public function instanciateFeatureProducer( | |||||
Feature $feature, | |||||
bool $status = null | |||||
): FeatureProducer | |||||
{ | |||||
$featureProducer = new FeatureProducer(); | |||||
$featureProducer->populateFeature($feature); | |||||
$featureProducer->populateProducer($this->getProducerContext()); | |||||
$featureProducer->status = $status; | |||||
return $featureProducer; | |||||
} | |||||
public function createFeatureProducer( | |||||
Feature $feature, | |||||
bool $status = null | |||||
): FeatureProducer | |||||
{ | |||||
$featureProducer = $this->featureProducerRepository->findOneFeatureProducer($feature); | |||||
if(!$featureProducer) { | |||||
$featureProducer = $this->instanciateFeatureProducer($feature, $status); | |||||
$this->create($featureProducer); | |||||
} | |||||
return $featureProducer; | |||||
} | |||||
public function updateStatus(FeatureProducer $featureProducer, bool $status = null) | |||||
{ | |||||
$featureProducer->status = $status; | |||||
$this->update($featureProducer); | |||||
} | |||||
public function updateStatusByFeature(Feature $feature, bool $status = null) | |||||
{ | |||||
$featureProducer = $this->createFeatureProducer($feature, $status); | |||||
$this->updateStatus($featureProducer, $status); | |||||
} | |||||
} |
<?php | |||||
namespace common\logic\Feature\FeatureProducer\Service; | |||||
use common\logic\AbstractDefinition; | |||||
use common\logic\Feature\FeatureProducer\Model\FeatureProducer; | |||||
use common\logic\Feature\FeatureProducer\Repository\FeatureProducerRepository; | |||||
class FeatureProducerDefinition extends AbstractDefinition | |||||
{ | |||||
public function getEntityFqcn(): string | |||||
{ | |||||
return FeatureProducer::class; | |||||
} | |||||
public function getDefinition(): FeatureProducerDefinition | |||||
{ | |||||
return FeatureProducerDefinition::getInstance(); | |||||
} | |||||
public function getRepository(): FeatureProducerRepository | |||||
{ | |||||
return FeatureProducerRepository::getInstance(); | |||||
} | |||||
} |
public function search($context, $params) | public function search($context, $params) | ||||
{ | { | ||||
$ticketRepository = TicketRepository::getInstance(); | |||||
$ticketRepository = FeatureRepository::getInstance(); | |||||
$optionsSearch = $ticketRepository->getDefaultOptionsSearch(); | $optionsSearch = $ticketRepository->getDefaultOptionsSearch(); | ||||
$query = Ticket::find() | $query = Ticket::find() |
<?php | |||||
namespace console\commands; | |||||
use common\logic\Feature\Feature\Module\FeatureModule; | |||||
use yii\console\Controller; | |||||
class ImportFeaturesController extends Controller | |||||
{ | |||||
public function actionIndex() | |||||
{ | |||||
$featureModule = FeatureModule::getInstance(); | |||||
$featureModule->getImporter()->importFromDefinition(); | |||||
} | |||||
} | |||||
?> |
<?php | |||||
use yii\db\Migration; | |||||
use yii\db\Schema; | |||||
/** | |||||
* Class m231110_084013_create_tables_feature_flag | |||||
*/ | |||||
class m231110_084013_create_tables_feature_flag extends Migration | |||||
{ | |||||
/** | |||||
* {@inheritdoc} | |||||
*/ | |||||
public function safeUp() | |||||
{ | |||||
$this->createTable('feature', [ | |||||
'id' => 'pk', | |||||
'alias' => Schema::TYPE_STRING.' NOT NULL', | |||||
'name' => Schema::TYPE_STRING.' NOT NULL', | |||||
'description' => Schema::TYPE_TEXT, | |||||
'is_paid_feature' => Schema::TYPE_BOOLEAN, | |||||
'price' => Schema::TYPE_FLOAT, | |||||
'only_for_selected_producers' => Schema::TYPE_BOOLEAN, | |||||
'status' => Schema::TYPE_BOOLEAN.' DEFAULT 1', | |||||
]); | |||||
$this->createTable('feature_producer', [ | |||||
'id' => 'pk', | |||||
'id_producer' => Schema::TYPE_INTEGER.' NOT NULL', | |||||
'id_feature' => Schema::TYPE_INTEGER.' NOT NULL', | |||||
'status' => Schema::TYPE_BOOLEAN.' DEFAULT 1', | |||||
]); | |||||
$this->addForeignKey('producer_fk', 'feature_producer', 'id_producer', 'producer', 'id'); | |||||
$this->addForeignKey('feature_fk', 'feature_producer', 'id_feature', 'feature', 'id'); | |||||
} | |||||
/** | |||||
* {@inheritdoc} | |||||
*/ | |||||
public function safeDown() | |||||
{ | |||||
$this->dropTable('feature'); | |||||
$this->dropTable('feature_producer'); | |||||
} | |||||
} |
use common\forms\ContactForm; | use common\forms\ContactForm; | ||||
use common\helpers\GlobalParam; | use common\helpers\GlobalParam; | ||||
use common\logic\Feature\Feature\Model\Feature; | |||||
use common\logic\Product\Product\Model\Product; | use common\logic\Product\Product\Model\Product; | ||||
use yii\data\ActiveDataProvider; | use yii\data\ActiveDataProvider; | ||||
use yii\helpers\Html; | use yii\helpers\Html; | ||||
*/ | */ | ||||
public function actionContact() | public function actionContact() | ||||
{ | { | ||||
$model = new ContactForm(); | |||||
$producer = $this->getProducerCurrent(); | |||||
// @TODO : à gérer avec les feature flag | |||||
if($producer->id == 1) { | |||||
$featureModule = $this->getFeatureModule(); | |||||
if($featureModule->getManager()->isDisabled(Feature::ALIAS_CONTACT)) { | |||||
return $this->redirect(['site/index']); | return $this->redirect(['site/index']); | ||||
} | } | ||||
$model = new ContactForm(); | |||||
$producer = $this->getProducerCurrent(); | |||||
if ($model->load(\Yii::$app->request->post()) && $model->validate()) { | if ($model->load(\Yii::$app->request->post()) && $model->validate()) { | ||||
$isSent = false; | $isSent = false; | ||||
if ($producer->contact_email && strlen($producer->contact_email) > 0 && $model->sendEmail($producer)) { | if ($producer->contact_email && strlen($producer->contact_email) > 0 && $model->sendEmail($producer)) { |
* termes. | * termes. | ||||
*/ | */ | ||||
use common\logic\Feature\Feature\Model\Feature; | |||||
use common\logic\Feature\Feature\Module\FeatureModule; | |||||
use common\logic\Order\Order\Model\Order; | use common\logic\Order\Order\Model\Order; | ||||
use common\logic\Producer\Producer\Module\ProducerModule; | use common\logic\Producer\Producer\Module\ProducerModule; | ||||
use common\logic\User\User\Module\UserModule; | use common\logic\User\User\Module\UserModule; | ||||
$userModule = UserModule::getInstance(); | $userModule = UserModule::getInstance(); | ||||
$userCurrent = GlobalParam::getCurrentUser(); | $userCurrent = GlobalParam::getCurrentUser(); | ||||
$producerModule = ProducerModule::getInstance(); | $producerModule = ProducerModule::getInstance(); | ||||
$featureModule = FeatureModule::getInstance(); | |||||
$producerUser = null; | $producerUser = null; | ||||
if($userModule->getAuthorizationChecker()->isGrantedAsProducer($userCurrent)) { | if($userModule->getAuthorizationChecker()->isGrantedAsProducer($userCurrent)) { | ||||
$producerUser = $producerModule->findOneProducerById($userCurrent->id_producer); | $producerUser = $producerModule->findOneProducerById($userCurrent->id_producer); | ||||
'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', | ||||
// @TODO : à gérer avec les feature flag | |||||
'visible' => $producer->id != 1 | |||||
'visible' => $featureModule->getManager()->isEnabled(Feature::ALIAS_CONTACT) | |||||
], | ], | ||||
], | ], | ||||
]); | ]); |