Deprecated : Constant E_STRICT is deprecated in /home/pastorz/old-espace-client/vendor/symfony/error-handler/ErrorHandler.php on line 58
Deprecated : Constant E_STRICT is deprecated in /home/pastorz/old-espace-client/vendor/symfony/error-handler/ErrorHandler.php on line 76
Symfony Profiler
<?php
namespace App\EventSubscriber ;
use App\Entity\Address ;
use App\Entity\DeliveryNote ;
use App\Service\ConstantsService ;
use Doctrine\ORM\EntityManagerInterface ;
use EasyCorp\Bundle\EasyAdminBundle\Event\BeforeEntityPersistedEvent ;
use EasyCorp\Bundle\EasyAdminBundle\Event\BeforeEntityUpdatedEvent ;
use Symfony\Component\EventDispatcher\EventSubscriberInterface ;
class EasyAdminEventSubscriber implements EventSubscriberInterface
{
private EntityManagerInterface $em ;
/**
* @param EntityManagerInterface $em
*/
public function __construct ( EntityManagerInterface $em )
{
$this -> em = $em ;
}
public static function getSubscribedEvents (): array
{
return [
BeforeEntityPersistedEvent ::class => array(
['setUserBillingAddress' ],
),
BeforeEntityUpdatedEvent ::class => array(
['resetWharehouseStatus' ]
)
];
}
public function setUserBillingAddress ( BeforeEntityPersistedEvent $event ): void
{
$entity = $event -> getEntityInstance ();
if (!($entity instanceof Address )) {
return;
}
if(!$entity -> getId ()) {
$entity -> setFirstname ( $entity -> getUser ()-> getFirstname ());
$entity -> setLastname ( $entity -> getUser ()-> getLastname ());
if(!$entity -> getUser ()-> getBillingAddress ()) {
$entity -> getUser ()-> setBillingAddress ( $entity );
}
if(!$entity -> getUser ()-> getDeliveryAddress ()) {
$entity -> getUser ()-> setDeliveryAddress ( $entity );
}
}
}
public function resetWharehouseStatus ( BeforeEntityUpdatedEvent $event ): void
{
$entity = $event -> getEntityInstance ();
if (!($entity instanceof DeliveryNote )) {
return;
}
$uow = $this -> em -> getUnitOfWork ();
$uow -> computeChangeSets ();
if($entity -> getShipment ()) {
$changes = $uow -> getEntityChangeSet ( $entity -> getShipment ());
if (isset($changes [ 'carrier' ])) {
$entity -> setWarehouseStatus ( ConstantsService :: WAREHOUSE_STATUS_NULL );
$entity -> setPreparationDate ( null );
$entity -> setPreparationMailSent ( false );
}
}
}
}