|
|
@@ -0,0 +1,52 @@ |
|
|
|
<?php |
|
|
|
|
|
|
|
namespace Lc\ShopBundle\Controller\Admin; |
|
|
|
|
|
|
|
use EasyCorp\Bundle\EasyAdminBundle\Controller\EasyAdminController; |
|
|
|
use Symfony\Component\Security\Core\Security; |
|
|
|
|
|
|
|
class AdminController extends EasyAdminController |
|
|
|
{ |
|
|
|
|
|
|
|
protected $security ; |
|
|
|
|
|
|
|
public function __construct(Security $security) |
|
|
|
{ |
|
|
|
$this->security = $security ; |
|
|
|
} |
|
|
|
|
|
|
|
public function updateEntity($entity) |
|
|
|
{ |
|
|
|
$this->setUpdated($entity) ; |
|
|
|
parent::updateEntity($entity); |
|
|
|
} |
|
|
|
|
|
|
|
public function persistEntity($entity) |
|
|
|
{ |
|
|
|
if (method_exists($entity, 'setCreatedAt')) { |
|
|
|
$entity->setCreatedAt(new \DateTime()); |
|
|
|
} |
|
|
|
|
|
|
|
if (method_exists($entity, 'setCreatedAt')) { |
|
|
|
$entity->setCreatedBy($this->security->getUser()); |
|
|
|
} |
|
|
|
|
|
|
|
$this->setUpdated($entity) ; |
|
|
|
$entity->setPosition(0) ; |
|
|
|
|
|
|
|
parent::persistEntity($entity); |
|
|
|
} |
|
|
|
|
|
|
|
public function setUpdated($entity) |
|
|
|
{ |
|
|
|
if (method_exists($entity, 'setUpdatedAt')) { |
|
|
|
$entity->setUpdatedAt(new \DateTime()); |
|
|
|
} |
|
|
|
|
|
|
|
if (method_exists($entity, 'setUpdatedAt')) { |
|
|
|
$entity->setUpdatedBy($this->security->getUser()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|