選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

77 行
2.2KB

  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. }