@@ -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(); |
@@ -5,5 +5,5 @@ namespace common\logic; | |||
interface ContainerInterface | |||
{ | |||
public function getServices(): array; | |||
public function getDefinition(): DefinitionInterface; | |||
//public function getDefinition(): DefinitionInterface; | |||
} |
@@ -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 | |||
); | |||
} | |||
} |
@@ -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 | |||
]; | |||
} | |||
} |
@@ -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; | |||
} | |||
} |
@@ -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 | |||
]); | |||
} |