Sfoglia il codice sorgente

[Technique] Logic : possibilité d'avoir un dossier non lié à une ressource en base #1211

feature/souke
Guillaume Bourgeois 1 anno fa
parent
commit
ba7dd54ea8
6 ha cambiato i file con 74 aggiunte e 16 eliminazioni
  1. +6
    -0
      common/components/BusinessLogicTrait.php
  2. +1
    -1
      common/logic/ContainerInterface.php
  3. +30
    -0
      common/logic/Opinion/Service/OpinionUtils.php
  4. +16
    -0
      common/logic/Opinion/Wrapper/OpinionContainer.php
  5. +17
    -0
      common/logic/Opinion/Wrapper/OpinionManager.php
  6. +4
    -15
      frontend/controllers/SiteController.php

+ 6
- 0
common/components/BusinessLogicTrait.php Vedi File

@@ -18,6 +18,7 @@ use common\logic\Document\Invoice\Wrapper\InvoiceContainer;
use common\logic\Document\Invoice\Wrapper\InvoiceManager;
use common\logic\Document\Quotation\Wrapper\QuotationContainer;
use common\logic\Document\Quotation\Wrapper\QuotationManager;
use common\logic\Opinion\Wrapper\OpinionManager;
use common\logic\Order\Order\Wrapper\OrderContainer;
use common\logic\Order\Order\Wrapper\OrderManager;
use common\logic\Order\ProductOrder\Wrapper\ProductOrderContainer;
@@ -61,6 +62,11 @@ use common\logic\User\UserUserGroup\Wrapper\UserUserGroupManager;

trait BusinessLogicTrait
{
public function getOpinionManager(): OpinionManager
{
return OpinionManager::getInstance();
}

public function getUserProducerManager(): UserProducerManager
{
return UserProducerManager::getInstance();

+ 1
- 1
common/logic/ContainerInterface.php Vedi File

@@ -5,5 +5,5 @@ namespace common\logic;
interface ContainerInterface
{
public function getServices(): array;
public function getDefinition(): DefinitionInterface;
//public function getDefinition(): DefinitionInterface;
}

+ 30
- 0
common/logic/Opinion/Service/OpinionUtils.php Vedi File

@@ -0,0 +1,30 @@
<?php

namespace common\logic\Opinion\Service;

use common\logic\AbstractUtils;
use common\logic\User\User\Model\User;
use common\logic\User\User\Service\UserSolver;

class OpinionUtils extends AbstractUtils
{
protected UserSolver $userSolver;

public function loadDependencies(): void
{
$this->userSolver = $this->loadService(UserSolver::class);
}

public function sendOpinionEmailAdmin($opinionFormModel, User $userCurrent = null)
{
\Yii::$app->mailerService->sendAdmin(
'Nouvel avis',
'newOpinionAdmin',
[
'username' => $userCurrent ? $this->userSolver->getUsername($userCurrent) : $opinionFormModel->name,
'message' => $opinionFormModel->message,
],
$userCurrent ? $userCurrent->email : $opinionFormModel->email
);
}
}

+ 16
- 0
common/logic/Opinion/Wrapper/OpinionContainer.php Vedi File

@@ -0,0 +1,16 @@
<?php

namespace common\logic\Opinion\Wrapper;

use common\logic\AbstractContainer;
use common\logic\Opinion\Service\OpinionUtils;

class OpinionContainer extends AbstractContainer
{
public function getServices(): array
{
return [
OpinionUtils::class
];
}
}

+ 17
- 0
common/logic/Opinion/Wrapper/OpinionManager.php Vedi File

@@ -0,0 +1,17 @@
<?php

namespace common\logic\Opinion\Wrapper;

use common\logic\AbstractManager;
use common\logic\Opinion\Service\OpinionUtils;

/**
* @mixin OpinionUtils
*/
class OpinionManager extends AbstractManager
{
public function getContainerFqcn(): string
{
return OpinionContainer::class;
}
}

+ 4
- 15
frontend/controllers/SiteController.php Vedi File

@@ -501,26 +501,15 @@ class SiteController extends FrontendController

public function actionOpinion()
{
$userManager = $this->getUserManager();
$userCurrent = $this->getUserCurrent();
$model = new OpinionForm();
$opinionFormModel = new OpinionForm();
$opinionSent = false;
if ($model->load(Yii::$app->request->post()) && $model->validate()) {
// @TODO : placer l'envoi de l'email dans un service dédié
\Yii::$app->mailerService->sendAdmin(
'Nouvel avis',
'newOpinionAdmin',
[
'username' => $userCurrent ? $userManager->getUsername($userCurrent) : $model->name,
'message' => $model->message,
],
$userCurrent ? $userCurrent->email : $model->email
);
if ($opinionFormModel->load(Yii::$app->request->post()) && $opinionFormModel->validate()) {
$this->getOpinionManager()->sendOpinionEmailAdmin($opinionFormModel, $this->getUserCurrent());
$opinionSent = true;
}

return $this->render('opinion', [
'model' => $model,
'model' => $opinionFormModel,
'opinionSent' => $opinionSent
]);
}

Loading…
Annulla
Salva