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.

AdminController.php 2.2KB

4 jaren geleden
4 jaren geleden
4 jaren geleden
4 jaren geleden
4 jaren geleden
4 jaren geleden
4 jaren geleden
4 jaren geleden
4 jaren geleden
4 jaren geleden
4 jaren geleden
4 jaren geleden
4 jaren geleden
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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, 'setMerchant')) {
  20. $entity->setMerchant($this->security->getUser()->getMerchant());
  21. }
  22. if (method_exists($entity, 'setCreatedAt')) {
  23. $entity->setCreatedAt(new \DateTime());
  24. }
  25. if (method_exists($entity, 'setCreatedAt')) {
  26. $entity->setCreatedBy($this->security->getUser());
  27. }
  28. if (method_exists($entity, 'getAddress')
  29. && method_exists($entity->getAddress(), 'setCreatedBy')) {
  30. $entity->getAddress()->setCreatedBy($this->security->getUser());
  31. }
  32. $this->setUpdated($entity);
  33. if (method_exists($entity, 'setPosition')) {
  34. $entity->setPosition(0);
  35. }
  36. if (method_exists($entity, 'setStatus')) {
  37. $entity->setStatus(1);
  38. }
  39. parent::persistEntity($entity);
  40. }
  41. public function setUpdated($entity)
  42. {
  43. if (method_exists($entity, 'setUpdatedAt')) {
  44. $entity->setUpdatedAt(new \DateTime());
  45. }
  46. if (method_exists($entity, 'setUpdatedAt')) {
  47. $entity->setUpdatedBy($this->security->getUser());
  48. }
  49. if (method_exists($entity, 'getAddress')
  50. && method_exists($entity->getAddress(), 'setUpdatedBy')) {
  51. $entity->getAddress()->setUpdatedBy($this->security->getUser());
  52. }
  53. }
  54. }