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.

91 lines
3.3KB

  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. $this->orderShoprepo->getRankSumCommand($entity);
  19. $this->dispatch(EasyAdminEvents::PRE_SHOW);
  20. $fields = $this->entity['show']['fields'];
  21. $deleteForm = $this->createDeleteForm($this->entity['name'], $id);
  22. $this->dispatch(EasyAdminEvents::POST_SHOW, [
  23. 'deleteForm' => $deleteForm,
  24. 'fields' => $fields,
  25. 'entity' => $entity,
  26. ]);
  27. $parameters = [
  28. 'entity' => $entity,
  29. 'fields' => $fields,
  30. 'delete_form' => $deleteForm->createView(),
  31. ];
  32. return $this->executeDynamicMethod('render<EntityName>Template', ['show', $this->entity['templates']['show'], $parameters]);
  33. }
  34. public function createNewEntity()
  35. {
  36. return $this->userManager->createUser();
  37. }
  38. public function persistEntity($user)
  39. {
  40. $this->userManager->updateUser($user, false);
  41. parent::persistEntity($user);
  42. }
  43. public function updateEntity($user)
  44. {
  45. $this->userManager->updateUser($user, false);
  46. parent::updateEntity($user);
  47. }
  48. public function removeEntity($user)
  49. {
  50. // désactivation UserMerchant
  51. if($user->getUserMerchants()) {
  52. $merchant = $this->merchantUtils->getMerchantCurrent() ;
  53. foreach($user->getUserMerchants() as $userMerchant) {
  54. if($userMerchant->getMerchant() == $merchant) {
  55. $userMerchant->setActive(false) ;
  56. $this->em->persist($userMerchant);
  57. $this->em->flush() ;
  58. $this->addFlash('success', 'Utilisateur supprimé du hub');
  59. }
  60. }
  61. }
  62. }
  63. protected function createUserListQueryBuilder($entityClass, $sortDirection, $sortField = null, $dqlFilter = null)
  64. {
  65. $queryBuilder = parent::createListQueryBuilder($entityClass, $sortDirection, $sortField, $dqlFilter) ;
  66. $queryBuilder->innerJoin('entity.userMerchants', 'um') ;
  67. $queryBuilder->andWhere('um.merchant = :merchant AND um.active = 1') ;
  68. $queryBuilder->setParameter('merchant', $this->merchantUtils->getMerchantCurrent()) ;
  69. return $queryBuilder ;
  70. }
  71. }