You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

72 line
2.1KB

  1. <?php
  2. namespace Lc\ShopBundle\Controller\Admin;
  3. use EasyCorp\Bundle\EasyAdminBundle\Controller\EasyAdminController;
  4. use Symfony\Component\Security\Core\Security;
  5. class AdminController extends EasyAdminController
  6. {
  7. protected $security ;
  8. public function __construct(Security $security)
  9. {
  10. $this->security = $security ;
  11. }
  12. public function updateEntity($entity)
  13. {
  14. $this->setUpdated($entity) ;
  15. parent::updateEntity($entity);
  16. }
  17. public function persistEntity($entity)
  18. {
  19. if (method_exists($entity, 'setCreatedAt')) {
  20. $entity->setCreatedAt(new \DateTime());
  21. }
  22. if (method_exists($entity, 'setCreatedAt')) {
  23. $entity->setCreatedBy($this->security->getUser());
  24. }
  25. if (method_exists($entity, 'getAddress')
  26. && method_exists($entity->getAddress(), 'setCreatedBy')) {
  27. $entity->getAddress()->setCreatedBy($this->security->getUser());
  28. }
  29. $this->setUpdated($entity) ;
  30. if (method_exists($entity, 'setPosition')) {
  31. $entity->setPosition(0) ;
  32. }
  33. if (method_exists($entity, 'setStatus')) {
  34. $entity->setStatus(1) ;
  35. }
  36. parent::persistEntity($entity);
  37. }
  38. public function setUpdated($entity)
  39. {
  40. if (method_exists($entity, 'setUpdatedAt')) {
  41. $entity->setUpdatedAt(new \DateTime());
  42. }
  43. if (method_exists($entity, 'setUpdatedAt')) {
  44. $entity->setUpdatedBy($this->security->getUser());
  45. }
  46. if (method_exists($entity, 'getAddress')
  47. && method_exists($entity->getAddress(), 'setUpdatedBy')) {
  48. $entity->getAddress()->setUpdatedBy($this->security->getUser());
  49. }
  50. }
  51. }