58 lines
2.1KB

  1. <?php
  2. namespace Lc\ShopBundle\Controller\Backend;
  3. use App\Form\Backend\Common\AddressType;
  4. use FOS\UserBundle\Doctrine\UserManager;
  5. use FOS\UserBundle\Model\UserManagerInterface ;
  6. use Lc\ShopBundle\Context\AddressInterface;
  7. use Lc\ShopBundle\Model\Address;
  8. class UserController extends AdminController
  9. {
  10. public function createNewEntity()
  11. {
  12. return $this->userManager->createUser();
  13. }
  14. public function persistEntity($user)
  15. {
  16. $this->userManager->updateUser($user, false);
  17. parent::persistEntity($user);
  18. }
  19. public function updateEntity($user)
  20. {
  21. $this->userManager->updateUser($user, false);
  22. parent::updateEntity($user);
  23. }
  24. public function removeEntity($user)
  25. {
  26. // désactivation UserMerchant
  27. if($user->getUserMerchants()) {
  28. $merchant = $this->merchantUtils->getMerchantCurrent() ;
  29. foreach($user->getUserMerchants() as $userMerchant) {
  30. if($userMerchant->getMerchant() == $merchant) {
  31. $userMerchant->setActive(false) ;
  32. $this->em->persist($userMerchant);
  33. $this->em->flush() ;
  34. $this->addFlash('success', 'Utilisateur supprimé du hub');
  35. }
  36. }
  37. }
  38. }
  39. protected function createUserListQueryBuilder($entityClass, $sortDirection, $sortField = null, $dqlFilter = null)
  40. {
  41. $queryBuilder = parent::createListQueryBuilder($entityClass, $sortDirection, $sortField, $dqlFilter) ;
  42. $queryBuilder->innerJoin('entity.userMerchants', 'um') ;
  43. $queryBuilder->andWhere('um.merchant = :merchant AND um.active = 1') ;
  44. $queryBuilder->setParameter('merchant', $this->merchantUtils->getMerchantCurrent()) ;
  45. return $queryBuilder ;
  46. }
  47. }