@@ -37,7 +37,9 @@ | |||
*/ | |||
use common\components\BusinessLogic; | |||
use common\logic\Distribution\Distribution\Model\Distribution; | |||
use common\logic\Ticket\Ticket\Model\Ticket; | |||
use common\logic\User\CreditHistory\Model\CreditHistory; | |||
$serverName = isset($_SERVER['SERVER_NAME']) ?? ''; | |||
@@ -127,9 +129,15 @@ return [ | |||
'class' => \justcoded\yii2\eventlistener\components\EventListener::class, | |||
'listeners' => [], | |||
'observers' => [ | |||
CreditHistory::class => [ | |||
common\logic\User\UserProducer\Event\CreditHistoryObserver::class | |||
], | |||
Distribution::class => [ | |||
common\logic\Subscription\Subscription\Event\DistributionObserver::class | |||
], | |||
Ticket::class => [ | |||
common\logic\User\User\Event\TicketObserver::class, | |||
] | |||
], | |||
], | |||
], | |||
], |
@@ -43,11 +43,11 @@ use common\logic\Distribution\PointSaleDistribution\Model\PointSaleDistribution; | |||
use common\logic\Distribution\ProductDistribution\Model\ProductDistribution; | |||
use common\logic\Order\Order\Model\Order; | |||
use common\logic\Producer\Producer\Model\Producer; | |||
use common\logic\Subscription\Subscription\Event\SubscriptionEventSubscriber; | |||
use common\logic\Subscription\Subscription\Event\DistributionObserver; | |||
class Distribution extends ActiveRecordCommon | |||
{ | |||
const EVENT_ACTIVE = 'distribution.active'; | |||
const EVENT_ACTIVE = 'distribution.event.active'; | |||
/** | |||
* @inheritdoc | |||
@@ -81,15 +81,6 @@ class Distribution extends ActiveRecordCommon | |||
]; | |||
} | |||
public function init() | |||
{ | |||
parent::init(); | |||
$this->on(Distribution::EVENT_ACTIVE, function($event) { | |||
SubscriptionEventSubscriber::onActiveDistribution($event->distribution); | |||
}); | |||
} | |||
/* | |||
* Relations | |||
*/ |
@@ -0,0 +1,26 @@ | |||
<?php | |||
namespace common\logic\Subscription\Subscription\Event; | |||
use common\logic\Distribution\Distribution\Event\DistributionActiveEvent; | |||
use common\logic\Distribution\Distribution\Model\Distribution; | |||
use common\logic\Order\Order\Wrapper\OrderManager; | |||
use justcoded\yii2\eventlistener\observers\Observer; | |||
class DistributionObserver extends Observer | |||
{ | |||
public function events() | |||
{ | |||
return [ | |||
Distribution::EVENT_ACTIVE => 'onDistributionActive' | |||
]; | |||
} | |||
public static function onDistributionActive(DistributionActiveEvent $event): void | |||
{ | |||
$distribution = $event->distribution; | |||
$orderManager = OrderManager::getInstance(); | |||
$orderManager->createAllOrdersFromSubscriptions($distribution->date); | |||
} | |||
} |
@@ -1,15 +0,0 @@ | |||
<?php | |||
namespace common\logic\Subscription\Subscription\Event; | |||
use common\logic\Distribution\Distribution\Model\Distribution; | |||
use common\logic\Order\Order\Wrapper\OrderManager; | |||
class SubscriptionEventSubscriber | |||
{ | |||
public static function onActiveDistribution(Distribution $distribution): void | |||
{ | |||
$orderManager = OrderManager::getInstance(); | |||
$orderManager->createAllOrdersFromSubscriptions($distribution->date); | |||
} | |||
} |
@@ -42,7 +42,7 @@ use common\components\ActiveRecordCommon; | |||
use common\events\EntityManagerEvent; | |||
use common\logic\Distribution\Distribution\Model\Distribution; | |||
use common\logic\Producer\Producer\Model\Producer; | |||
use common\logic\Subscription\Subscription\Event\SubscriptionEventSubscriber; | |||
use common\logic\Subscription\Subscription\Event\DistributionObserver; | |||
use common\logic\Ticket\TicketMessage\Model\TicketMessage; | |||
use common\logic\Ticket\TicketUser\Model\TicketUser; | |||
use common\logic\User\User\Model\User; |
@@ -1,12 +0,0 @@ | |||
<?php | |||
namespace common\logic\User\CreditHistory\Event; | |||
use common\logic\Distribution\Distribution\Model\Distribution; | |||
use common\logic\User\CreditHistory\Model\CreditHistory; | |||
use yii\base\Event; | |||
class CreditHistoryCreateEvent extends Event | |||
{ | |||
public CreditHistory $creditHistory; | |||
} |
@@ -47,8 +47,6 @@ use yii\db\ActiveQuery; | |||
class CreditHistory extends ActiveRecordCommon | |||
{ | |||
const EVENT_CREATE = 'creditHistory.create'; | |||
const TYPE_INITIAL_CREDIT = 'initial-credit'; | |||
const TYPE_CREDIT = 'credit'; | |||
const TYPE_PAYMENT = 'payment'; | |||
@@ -97,15 +95,6 @@ class CreditHistory extends ActiveRecordCommon | |||
]; | |||
} | |||
public function init() | |||
{ | |||
$this->on(CreditHistory::EVENT_CREATE, function($event) { | |||
UserProducerEventSubscriber::onCreateCreditHistory($event); | |||
}); | |||
parent::init(); | |||
} | |||
/* | |||
* Relations | |||
*/ |
@@ -6,7 +6,6 @@ use common\logic\AbstractBuilder; | |||
use common\logic\Order\Order\Model\Order; | |||
use common\logic\Order\Order\Service\OrderSolver; | |||
use common\logic\Producer\Producer\Model\Producer; | |||
use common\logic\User\CreditHistory\Event\CreditHistoryCreateEvent; | |||
use common\logic\User\CreditHistory\Model\CreditHistory; | |||
use common\logic\User\User\Model\User; | |||
use yii\base\Event; | |||
@@ -68,11 +67,7 @@ class CreditHistoryBuilder extends AbstractBuilder | |||
$creditHistory = $this->instanciateCreditHistory($type, $amount, $producer, $user, $userAction, $meanPayment, $order); | |||
$creditHistory->setComment($creditHistory->getComment() . $this->orderSolver->getCreditHistoryComment($creditHistory)); | |||
$this->saveCreate($creditHistory); | |||
$creditHistoryCreateEvent = new CreditHistoryCreateEvent(); | |||
$creditHistoryCreateEvent->creditHistory = $creditHistory; | |||
$creditHistory->trigger(CreditHistory::EVENT_CREATE, $creditHistoryCreateEvent); | |||
$this->create($creditHistory); | |||
return $creditHistory; | |||
} |
@@ -39,7 +39,6 @@ class UserUtils extends AbstractService implements UtilsInterface | |||
/** | |||
* Envoie un email de bienvenue à l'utilisateur lors de son inscription | |||
* via le backend du site. | |||
* | |||
*/ | |||
public function sendMailWelcome(User $user, string $password): void | |||
{ |
@@ -0,0 +1,18 @@ | |||
<?php | |||
namespace common\logic\User\UserProducer\Event; | |||
use common\logic\User\UserProducer\Wrapper\UserProducerManager; | |||
use justcoded\yii2\eventlistener\observers\ActiveRecordObserver; | |||
use yii\db\AfterSaveEvent; | |||
class CreditHistoryObserver extends ActiveRecordObserver | |||
{ | |||
public function inserted(AfterSaveEvent $event) | |||
{ | |||
$creditHistory = $event->sender; | |||
$userProducerManager = UserProducerManager::getInstance(); | |||
$userProducerManager->updateCredit($creditHistory); | |||
} | |||
} |
@@ -1,14 +0,0 @@ | |||
<?php | |||
namespace common\logic\User\UserProducer\Event; | |||
use common\logic\User\UserProducer\Wrapper\UserProducerManager; | |||
class UserProducerEventSubscriber | |||
{ | |||
public static function onCreateCreditHistory($event) | |||
{ | |||
$userProducerManager = UserProducerManager::getInstance(); | |||
$userProducerManager->updateCredit($event->creditHistory); | |||
} | |||
} |