use yii\filters\VerbFilter; | use yii\filters\VerbFilter; | ||||
use yii\filters\AccessControl; | use yii\filters\AccessControl; | ||||
use common\helpers\Upload; | use common\helpers\Upload; | ||||
use yii\web\UploadedFile; | |||||
/** | /** | ||||
* UserController implements the CRUD actions for User model. | * UserController implements the CRUD actions for User model. | ||||
*/ | */ | ||||
public function actionUpdate() | public function actionUpdate() | ||||
{ | { | ||||
$producerManager = $this->getProducerManager(); | |||||
$producerContainer = $this->getProducerContainer(); | |||||
$producerBuilder = $producerContainer->getBuilder(); | |||||
$request = Yii::$app->request; | $request = Yii::$app->request; | ||||
$model = $this->findModel(GlobalParam::getCurrentProducerId()); | $model = $this->findModel(GlobalParam::getCurrentProducerId()); | ||||
$logoFilenameOld = $model->logo; | $logoFilenameOld = $model->logo; | ||||
$photoFilenameOld = $model->photo; | $photoFilenameOld = $model->photo; | ||||
if (strlen($model->option_dashboard_date_start)) { | |||||
$model->option_dashboard_date_start = date('d/m/Y', strtotime($model->option_dashboard_date_start)); | |||||
} | |||||
if (strlen($model->option_dashboard_date_end)) { | |||||
$model->option_dashboard_date_end = date('d/m/Y', strtotime($model->option_dashboard_date_end)); | |||||
} | |||||
$producerBuilder->initOptionDashboardDatesDisplay($model); | |||||
if ($model->load(\Yii::$app->request->post()) && $model->save()) { | |||||
if ($model->load(\Yii::$app->request->post())) { | |||||
if (strlen($model->option_dashboard_date_start)) { | |||||
$model->option_dashboard_date_start = date( | |||||
'Y-m-d', | |||||
strtotime(str_replace('/', '-', $model->option_dashboard_date_start) | |||||
)); | |||||
$model->save(); | |||||
} | |||||
if (strlen($model->option_dashboard_date_end)) { | |||||
$model->option_dashboard_date_end = date( | |||||
'Y-m-d', | |||||
strtotime(str_replace('/', '-', $model->option_dashboard_date_end)) | |||||
); | |||||
$model->save(); | |||||
} | |||||
$model->logoFile = UploadedFile::getInstance($model, 'logoFile'); | |||||
$model->photoFile = UploadedFile::getInstance($model, 'photoFile'); | |||||
Upload::uploadFile($model, 'logo', $logoFilenameOld); | |||||
Upload::uploadFile($model, 'photo', $photoFilenameOld); | |||||
if($model->validate()) { | |||||
$deleteLogo = $request->post('delete_logo', 0); | |||||
if ($deleteLogo) { | |||||
$model->logo = ''; | |||||
$producerBuilder->processUploadImage($model, 'logo', $logoFilenameOld, $request->post('delete_logo', 0)); | |||||
$producerBuilder->processUploadImage($model, 'photo', $photoFilenameOld, $request->post('delete_photo', 0)); | |||||
$producerBuilder->initOptionDashboardDatesBeforeSave($model); | |||||
$producerBuilder->savePrivateKeysStripe($model); | |||||
$model->save(); | $model->save(); | ||||
} | |||||
$deletePhoto = $request->post('delete_photo', 0); | |||||
if ($deletePhoto) { | |||||
$model->photo = ''; | |||||
$model->save(); | |||||
$this->setFlash('success', 'Paramètres mis à jour.'); | |||||
return $this->redirect(['update', 'id' => $model->id, 'edit_ok' => true]); | |||||
} | } | ||||
} | |||||
$producerManager->savePrivateKeyApiStripe($model); | |||||
$producerManager->savePrivateKeyEndpointStripe($model); | |||||
$model->option_stripe_private_key = ''; | |||||
$model->option_stripe_endpoint_secret = ''; | |||||
$model->save(); | |||||
$this->setFlash('success', 'Paramètres mis à jour.'); | |||||
return $this->redirect(['update', 'id' => $model->id, 'edit_ok' => true]); | |||||
} else { | |||||
if ($model->load(\Yii::$app->request->post())) { | |||||
$this->setFlash('error', 'Le formulaire comporte des erreurs.'); | |||||
} | |||||
return $this->render('update', [ | |||||
'model' => $model, | |||||
]); | |||||
if ($model->load(\Yii::$app->request->post())) { | |||||
$this->setFlash('error', 'Le formulaire comporte des erreurs.'); | |||||
} | } | ||||
return $this->render('update', [ | |||||
'model' => $model, | |||||
]); | |||||
} | } | ||||
/** | /** |
if ($lastProductOrder) { | if ($lastProductOrder) { | ||||
$model->order = ++$lastProductOrder->order; | $model->order = ++$lastProductOrder->order; | ||||
} | } | ||||
$productManager->create($model); | $productManager->create($model); | ||||
if($model->photoFile) { | if($model->photoFile) { | ||||
$this->setFlash('success', 'Produit <strong>' . Html::encode($model->name) . '</strong> modifié'); | $this->setFlash('success', 'Produit <strong>' . Html::encode($model->name) . '</strong> modifié'); | ||||
return $this->redirect(['index']); | return $this->redirect(['index']); | ||||
} | } | ||||
} | } | ||||
<h4>Apparence</h4> | <h4>Apparence</h4> | ||||
<?= $form->field($model, 'background_color_logo') ?> | <?= $form->field($model, 'background_color_logo') ?> | ||||
<?= $form->field($model, 'logo')->fileInput() ?> | |||||
<?= $form->field($model, 'logoFile')->fileInput() ?> | |||||
<?php | <?php | ||||
if (strlen($model->logo)) { | if (strlen($model->logo)) { | ||||
echo '<img src="' . Yii::$app->urlManagerProducer->getHostInfo() . '/' . Yii::$app->urlManagerProducer->baseUrl . '/uploads/' . $model->logo . '" width="200px" /><br />'; | echo '<img src="' . Yii::$app->urlManagerProducer->getHostInfo() . '/' . Yii::$app->urlManagerProducer->baseUrl . '/uploads/' . $model->logo . '" width="200px" /><br />'; | ||||
echo '<input type="checkbox" name="delete_logo" id="delete_logo" /> <label for="delete_logo">Supprimer le logo</label><br /><br />'; | echo '<input type="checkbox" name="delete_logo" id="delete_logo" /> <label for="delete_logo">Supprimer le logo</label><br /><br />'; | ||||
} | } | ||||
?> | ?> | ||||
<?= $form->field($model, 'photo')->fileInput()->hint('Format idéal : 900 x 150 px') ?> | |||||
<?= $form->field($model, 'photoFile')->fileInput()->hint('Format idéal : 900 x 150 px') ?> | |||||
<?php | <?php | ||||
if (strlen($model->photo)) { | if (strlen($model->photo)) { | ||||
echo '<img src="' . Yii::$app->urlManagerProducer->getHostInfo() . '/' . Yii::$app->urlManagerProducer->baseUrl . '/uploads/' . $model->photo . '" width="400px" /><br />'; | echo '<img src="' . Yii::$app->urlManagerProducer->getHostInfo() . '/' . Yii::$app->urlManagerProducer->baseUrl . '/uploads/' . $model->photo . '" width="400px" /><br />'; |
use common\logic\User\User\Model\User; | use common\logic\User\User\Model\User; | ||||
use common\logic\User\UserProducer\Model\UserProducer; | use common\logic\User\UserProducer\Model\UserProducer; | ||||
use common\components\ActiveRecordCommon; | use common\components\ActiveRecordCommon; | ||||
use yii\web\UploadedFile; | |||||
/** | /** | ||||
* This is the model class for table "producer". | * This is the model class for table "producer". | ||||
self::BILLING_TYPE_FREE_PRICE => 'Prix libre', | self::BILLING_TYPE_FREE_PRICE => 'Prix libre', | ||||
]; | ]; | ||||
var $secret_key_payplug; | |||||
const ONLINE_PAYMENT_MINIMUM_AMOUNT_DEFAULT = 25; | const ONLINE_PAYMENT_MINIMUM_AMOUNT_DEFAULT = 25; | ||||
const ORDER_DEADLINE_DEFAULT = 20; | const ORDER_DEADLINE_DEFAULT = 20; | ||||
const ORDER_DELAY_DEFAULT = 1; | const ORDER_DELAY_DEFAULT = 1; | ||||
var $secret_key_payplug; | |||||
/** | |||||
* @var UploadedFile | |||||
*/ | |||||
public $logoFile; | |||||
/** | |||||
* @var UploadedFile | |||||
*/ | |||||
public $photoFile; | |||||
/** | /** | ||||
* @inheritdoc | * @inheritdoc | ||||
*/ | */ | ||||
return $model->tiller == true; | return $model->tiller == true; | ||||
} | } | ||||
], | ], | ||||
[['logoFile', 'photoFile'], 'file', 'extensions' => 'png, jpg, jpeg', 'mimeTypes' => 'image/png, image/jpeg'], | |||||
[ | [ | ||||
[ | [ | ||||
'order_delay', | 'order_delay', |
use common\helpers\Opendistrib; | use common\helpers\Opendistrib; | ||||
use common\helpers\Password; | use common\helpers\Password; | ||||
use common\helpers\Upload; | |||||
use common\logic\AbstractBuilder; | use common\logic\AbstractBuilder; | ||||
use common\logic\Producer\Producer\Model\Producer; | use common\logic\Producer\Producer\Model\Producer; | ||||
use common\logic\Producer\Producer\Repository\ProducerRepository; | use common\logic\Producer\Producer\Repository\ProducerRepository; | ||||
$producer->option_stripe_endpoint_secret | $producer->option_stripe_endpoint_secret | ||||
); | ); | ||||
} | } | ||||
public function savePrivateKeysStripe(Producer $producer) | |||||
{ | |||||
$this->savePrivateKeyApiStripe($producer); | |||||
$this->savePrivateKeyEndpointStripe($producer); | |||||
$producer->option_stripe_private_key = ''; | |||||
$producer->option_stripe_endpoint_secret = ''; | |||||
$producer->save(); | |||||
} | |||||
public function initOptionDashboardDatesBeforeSave(Producer $producer): void | |||||
{ | |||||
$this->initOptionDashboardDateStartEndBeforeSave($producer, true); | |||||
$this->initOptionDashboardDateStartEndBeforeSave($producer, false); | |||||
} | |||||
private function initOptionDashboardDateStartEndBeforeSave(Producer $producer, bool $dateStart): void | |||||
{ | |||||
$field = 'option_dashboard_date_'.($dateStart ? 'start' : 'end'); | |||||
if ($producer->$field && strlen($producer->$field)) { | |||||
$producer->$field = date( | |||||
'Y-m-d', | |||||
strtotime(str_replace('/', '-', $producer->$field)) | |||||
); | |||||
} | |||||
} | |||||
public function initOptionDashboardDatesDisplay(Producer $producer, bool $dateStart = true): void | |||||
{ | |||||
$this->initOptionDashboardDateStartEndDisplay($producer, true); | |||||
$this->initOptionDashboardDateStartEndDisplay($producer, false); | |||||
} | |||||
private function initOptionDashboardDateStartEndDisplay(Producer $producer, bool $dateStart): void | |||||
{ | |||||
$field = 'option_dashboard_date_'.($dateStart ? 'start' : 'end'); | |||||
if (strlen($producer->$field)) { | |||||
$producer->$field = date('d/m/Y', strtotime($producer->$field)); | |||||
} | |||||
} | |||||
public function processUploadImage(Producer $producer, string $name, string $filenameOld, bool $deleteImage) | |||||
{ | |||||
Upload::uploadFile($producer, $name.'File', $name, $filenameOld); | |||||
if ($deleteImage) { | |||||
$producer->$name = ''; | |||||
$producer->save(); | |||||
} | |||||
} | |||||
} | } |