use common\logic\Document\Invoice\Wrapper\InvoiceManager; | use common\logic\Document\Invoice\Wrapper\InvoiceManager; | ||||
use common\logic\Document\Quotation\Wrapper\QuotationContainer; | use common\logic\Document\Quotation\Wrapper\QuotationContainer; | ||||
use common\logic\Document\Quotation\Wrapper\QuotationManager; | 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\OrderContainer; | ||||
use common\logic\Order\Order\Wrapper\OrderManager; | use common\logic\Order\Order\Wrapper\OrderManager; | ||||
use common\logic\Order\ProductOrder\Wrapper\ProductOrderContainer; | use common\logic\Order\ProductOrder\Wrapper\ProductOrderContainer; | ||||
trait BusinessLogicTrait | trait BusinessLogicTrait | ||||
{ | { | ||||
public function getOpinionManager(): OpinionManager | |||||
{ | |||||
return OpinionManager::getInstance(); | |||||
} | |||||
public function getUserProducerManager(): UserProducerManager | public function getUserProducerManager(): UserProducerManager | ||||
{ | { | ||||
return UserProducerManager::getInstance(); | return UserProducerManager::getInstance(); |
interface ContainerInterface | interface ContainerInterface | ||||
{ | { | ||||
public function getServices(): array; | public function getServices(): array; | ||||
public function getDefinition(): DefinitionInterface; | |||||
//public function getDefinition(): DefinitionInterface; | |||||
} | } |
<?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 | |||||
); | |||||
} | |||||
} |
<?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 | |||||
]; | |||||
} | |||||
} |
<?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; | |||||
} | |||||
} |
public function actionOpinion() | public function actionOpinion() | ||||
{ | { | ||||
$userManager = $this->getUserManager(); | |||||
$userCurrent = $this->getUserCurrent(); | |||||
$model = new OpinionForm(); | |||||
$opinionFormModel = new OpinionForm(); | |||||
$opinionSent = false; | $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; | $opinionSent = true; | ||||
} | } | ||||
return $this->render('opinion', [ | return $this->render('opinion', [ | ||||
'model' => $model, | |||||
'model' => $opinionFormModel, | |||||
'opinionSent' => $opinionSent | 'opinionSent' => $opinionSent | ||||
]); | ]); | ||||
} | } |