Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

UserController.php 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <?php
  2. namespace Lc\ShopBundle\Controller\Backend;
  3. use App\Entity\OrderShop;
  4. use App\Form\Backend\Common\AddressType;
  5. use EasyCorp\Bundle\EasyAdminBundle\Event\EasyAdminEvents;
  6. use FOS\UserBundle\Doctrine\UserManager;
  7. use FOS\UserBundle\Model\UserManagerInterface ;
  8. use Lc\ShopBundle\Context\AddressInterface;
  9. use Lc\ShopBundle\Model\Address;
  10. class UserController extends AdminController
  11. {
  12. public function showAction()
  13. {
  14. $id = $this->request->query->get('id');
  15. $easyadmin = $this->request->attributes->get('easyadmin');
  16. $entity = $easyadmin['item'];
  17. $this->orderShoprepo = $this->em->getRepository(OrderShop::class);
  18. /* dump($this->orderUtils->getRankTotalOrder($entity));
  19. die();
  20. dump($this->orderUtils->getRankSumOrderByUser($entity));
  21. dump($this->orderUtils->getRankTotalOrderByUser($entity));
  22. dump($this->orderUtils->getTotalSpentByUser($entity));
  23. dump($this->orderUtils->getAverageOrderByUser($entity));
  24. die();*/
  25. $this->dispatch(EasyAdminEvents::PRE_SHOW);
  26. $fields = $this->entity['show']['fields'];
  27. $deleteForm = $this->createDeleteForm($this->entity['name'], $id);
  28. $this->dispatch(EasyAdminEvents::POST_SHOW, [
  29. 'deleteForm' => $deleteForm,
  30. 'fields' => $fields,
  31. 'entity' => $entity,
  32. ]);
  33. $parameters = [
  34. 'entity' => $entity,
  35. 'fields' => $fields,
  36. 'delete_form' => $deleteForm->createView(),
  37. ];
  38. return $this->executeDynamicMethod('render<EntityName>Template', ['show', $this->entity['templates']['show'], $parameters]);
  39. }
  40. public function createNewEntity()
  41. {
  42. return $this->userManager->createUser();
  43. }
  44. public function persistEntity($user)
  45. {
  46. $this->userManager->updateUser($user, false);
  47. parent::persistEntity($user);
  48. }
  49. public function updateEntity($user)
  50. {
  51. $this->userManager->updateUser($user, false);
  52. parent::updateEntity($user);
  53. }
  54. public function removeEntity($user)
  55. {
  56. // désactivation UserMerchant
  57. if($user->getUserMerchants()) {
  58. $merchant = $this->merchantUtils->getMerchantCurrent() ;
  59. foreach($user->getUserMerchants() as $userMerchant) {
  60. if($userMerchant->getMerchant() == $merchant) {
  61. $userMerchant->setActive(false) ;
  62. $this->em->persist($userMerchant);
  63. $this->em->flush() ;
  64. $this->addFlash('success', 'Utilisateur supprimé du hub');
  65. }
  66. }
  67. }
  68. }
  69. protected function createUserListQueryBuilder($entityClass, $sortDirection, $sortField = null, $dqlFilter = null)
  70. {
  71. $queryBuilder = parent::createListQueryBuilder($entityClass, $sortDirection, $sortField, $dqlFilter) ;
  72. $queryBuilder->innerJoin('entity.userMerchants', 'um') ;
  73. $queryBuilder->andWhere('um.merchant = :merchant AND um.active = 1') ;
  74. $queryBuilder->setParameter('merchant', $this->merchantUtils->getMerchantCurrent()) ;
  75. return $queryBuilder ;
  76. }
  77. }