瀏覽代碼

[Administration] Refactoring SiteController

feature/souke
Guillaume Bourgeois 1 年之前
父節點
當前提交
47e8794ee5
共有 3 個文件被更改,包括 21 次插入14 次删除
  1. +13
    -12
      backend/controllers/SiteController.php
  2. +2
    -2
      backend/views/layouts/header.php
  3. +6
    -0
      common/logic/User/User/Service/UserBuilder.php

+ 13
- 12
backend/controllers/SiteController.php 查看文件

@@ -38,13 +38,6 @@

namespace backend\controllers;

use common\helpers\Alwaysdata;
use common\helpers\GlobalParam;
use common\logic\Distribution\Distribution\Model\Distribution;
use common\logic\Order\Order\Model\Order;
use common\logic\PointSale\PointSale\Model\PointSale;
use common\logic\Product\Product\Model\Product;
use common\logic\Product\Product\Wrapper\ProductContainer;
use common\logic\User\User\Model\User;
use Yii;
use yii\filters\AccessControl;
@@ -70,7 +63,7 @@ class SiteController extends BackendController
'allow' => true,
],
[
'actions' => ['logout', 'index'],
'actions' => ['logout'],
'allow' => true,
'roles' => ['@'],
'matchCallback' => function ($rule, $action) {
@@ -78,7 +71,7 @@ class SiteController extends BackendController
}
],
[
'actions' => ['change-producer'],
'actions' => ['switch-producer'],
'allow' => true,
'roles' => ['@'],
'matchCallback' => function ($rule, $action) {
@@ -140,10 +133,18 @@ class SiteController extends BackendController
* Change le producteur courant de l'utilisateur connecté.
* Permet de passer d'un producteur à un autre en tant qu'administrateur.
*/
public function actionChangeProducer(int $id)
public function actionSwitchProducer(int $id)
{
Yii::$app->user->identity->id_producer = $id;
Yii::$app->user->identity->save();
$user = $this->getUserCurrent();
$producer = $this->getProducerContainer()->getRepository()->findOneProducerById($id);

if($producer) {
$this->getUserContainer()->getBuilder()->switchProducer($user, $producer);
}
else {
$this->addFlash('error', 'Producteur introuvable.');
}

$this->redirect(['dashboard/index']);
}
}

+ 2
- 2
backend/views/layouts/header.php 查看文件

@@ -109,7 +109,7 @@ $producer = GlobalParam::getCurrentProducer();
<?php foreach ($producersArray as $producer): ?>
<?php if ($producer->active == 1): ?>
<li class="producer">
<a href="<?= Yii::$app->urlManagerBackend->createUrl(['site/change-producer', 'id' => $producer->id]); ?>"><?= Html::encode($producer->name) ?></a>
<a href="<?= Yii::$app->urlManagerBackend->createUrl(['site/switch-producer', 'id' => $producer->id]); ?>"><?= Html::encode($producer->name) ?></a>
</li>
<?php endif; ?>
<?php endforeach; ?>
@@ -118,7 +118,7 @@ $producer = GlobalParam::getCurrentProducer();
<?php foreach ($producersArray as $producer): ?>
<?php if ($producer->active != 1): ?>
<li class="producer">
<a href="<?= Yii::$app->urlManagerBackend->createUrl(['site/change-producer', 'id' => $producer->id]); ?>">
<a href="<?= Yii::$app->urlManagerBackend->createUrl(['site/switch-producer', 'id' => $producer->id]); ?>">
<label class="label label-danger">Hors-ligne</label>
<?= Html::encode($producer->name) ?>
</a>

+ 6
- 0
common/logic/User/User/Service/UserBuilder.php 查看文件

@@ -97,4 +97,10 @@ class UserBuilder extends AbstractBuilder

return false;
}

public function switchProducer(User $user, Producer $producer)
{
$user->id_producer = $producer->id;
$this->update($user);
}
}

Loading…
取消
儲存