Kaynağa Gözat

[Administration] Problème upload images webp #1260

feature/souke
Guillaume Bourgeois 1 yıl önce
ebeveyn
işleme
5bbd5b01b5
5 değiştirilmiş dosya ile 89 ekleme ve 55 silme
  1. +22
    -49
      backend/controllers/ProducerController.php
  2. +0
    -2
      backend/controllers/ProductController.php
  3. +2
    -2
      backend/views/producer/update.php
  4. +13
    -2
      common/logic/Producer/Producer/Model/Producer.php
  5. +52
    -0
      common/logic/Producer/Producer/Service/ProducerBuilder.php

+ 22
- 49
backend/controllers/ProducerController.php Dosyayı Görüntüle

@@ -47,6 +47,7 @@ use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;
use yii\filters\AccessControl;
use common\helpers\Upload;
use yii\web\UploadedFile;

/**
* UserController implements the CRUD actions for User model.
@@ -84,68 +85,40 @@ class ProducerController extends BackendController
*/
public function actionUpdate()
{
$producerManager = $this->getProducerManager();
$producerContainer = $this->getProducerContainer();
$producerBuilder = $producerContainer->getBuilder();
$request = Yii::$app->request;
$model = $this->findModel(GlobalParam::getCurrentProducerId());

$logoFilenameOld = $model->logo;
$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();
}

$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,
]);
}

/**

+ 0
- 2
backend/controllers/ProductController.php Dosyayı Görüntüle

@@ -134,7 +134,6 @@ class ProductController extends BackendController
if ($lastProductOrder) {
$model->order = ++$lastProductOrder->order;
}

$productManager->create($model);

if($model->photoFile) {
@@ -195,7 +194,6 @@ class ProductController extends BackendController

$this->setFlash('success', 'Produit <strong>' . Html::encode($model->name) . '</strong> modifié');
return $this->redirect(['index']);

}
}


+ 2
- 2
backend/views/producer/update.php Dosyayı Görüntüle

@@ -100,14 +100,14 @@ $this->addBreadcrumb($this->getTitle());

<h4>Apparence</h4>
<?= $form->field($model, 'background_color_logo') ?>
<?= $form->field($model, 'logo')->fileInput() ?>
<?= $form->field($model, 'logoFile')->fileInput() ?>
<?php
if (strlen($model->logo)) {
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 />';
}
?>
<?= $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
if (strlen($model->photo)) {
echo '<img src="' . Yii::$app->urlManagerProducer->getHostInfo() . '/' . Yii::$app->urlManagerProducer->baseUrl . '/uploads/' . $model->photo . '" width="400px" /><br />';

+ 13
- 2
common/logic/Producer/Producer/Model/Producer.php Dosyayı Görüntüle

@@ -42,6 +42,7 @@ use common\logic\Config\TaxRate\Model\TaxRate;
use common\logic\User\User\Model\User;
use common\logic\User\UserProducer\Model\UserProducer;
use common\components\ActiveRecordCommon;
use yii\web\UploadedFile;

/**
* This is the model class for table "producer".
@@ -98,13 +99,22 @@ class Producer extends ActiveRecordCommon
self::BILLING_TYPE_FREE_PRICE => 'Prix libre',
];

var $secret_key_payplug;

const ONLINE_PAYMENT_MINIMUM_AMOUNT_DEFAULT = 25;

const ORDER_DEADLINE_DEFAULT = 20;
const ORDER_DELAY_DEFAULT = 1;

var $secret_key_payplug;

/**
* @var UploadedFile
*/
public $logoFile;
/**
* @var UploadedFile
*/
public $photoFile;

/**
* @inheritdoc
*/
@@ -127,6 +137,7 @@ class Producer extends ActiveRecordCommon
return $model->tiller == true;
}
],
[['logoFile', 'photoFile'], 'file', 'extensions' => 'png, jpg, jpeg', 'mimeTypes' => 'image/png, image/jpeg'],
[
[
'order_delay',

+ 52
- 0
common/logic/Producer/Producer/Service/ProducerBuilder.php Dosyayı Görüntüle

@@ -4,6 +4,7 @@ namespace common\logic\Producer\Producer\Service;

use common\helpers\Opendistrib;
use common\helpers\Password;
use common\helpers\Upload;
use common\logic\AbstractBuilder;
use common\logic\Producer\Producer\Model\Producer;
use common\logic\Producer\Producer\Repository\ProducerRepository;
@@ -109,4 +110,55 @@ class ProducerBuilder extends AbstractBuilder
$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();
}
}
}

Yükleniyor…
İptal
Kaydet