|
- <?php
-
- namespace Lc\CaracoleBundle\Controller\User;
-
-
- use EasyCorp\Bundle\EasyAdminBundle\Collection\EntityCollection;
- use EasyCorp\Bundle\EasyAdminBundle\Config\Crud;
- use Lc\CaracoleBundle\Controller\ControllerTrait;
- use Lc\SovBundle\Container\User\UserContainer;
- use Lc\SovBundle\Controller\User\UserAdminController as SovUserAdminController;
- use Lc\SovBundle\Definition\ActionDefinition;
- use Lc\SovBundle\Repository\RepositoryQueryInterface;
-
- abstract class UserAdminController extends SovUserAdminController
- {
- use ControllerTrait;
-
- public function getRepositoryQuery(): RepositoryQueryInterface
- {
- return $this->getUserContainer()->getRepositoryQuery();
- }
-
- public function createEntity(string $entityFqcn)
- {
- return $this->getUserContainer()->getFactory()->create();
- }
-
- public function overrideEntitiesActions(?EntityCollection $entities): void
- {
- foreach ($entities as $entity) {
- foreach ($entity->getActions() as $action){
- if($action->getName() == ActionDefinition::SWITCH_USER){
- $sectionDefault = $this->getSectionContainer()->getStore()->setMerchant($this->getMerchantCurrent())->getOneDefault();
- $url = $this->generateUrl($this->getParameter('lc_sov.homepage_route'), array('_switch_user' => $entity->getInstance()->getEmail(), 'section'=> $sectionDefault));
- $action->setLinkUrl($url);
- }
- }
-
- }
- }
-
- public function configureFields(string $pageName): iterable
- {
- $fields = $this->get(UserContainer::class)
- ->getFieldDefinition()
- ->setMerchant($this->getMerchantCurrent())
- ->getAllFields();
-
- if ($pageName == Crud::PAGE_INDEX) {
- return [
- $fields['id'],
- $fields['gender'],
- $fields['lastname'],
- $fields['firstname'],
- $fields['email'],
- $fields['phone'],
- $fields['birthdate'],
- $fields['groupUsers'],
- $fields['isSaleAlwaysOpen'],
- $fields['newsletters']
- ];
- } elseif ($pageName == Crud::PAGE_EDIT || $pageName == Crud::PAGE_NEW) {
- $fieldToReturn = [
- $fields['id'],
- $fields['gender'],
- $fields['lastname'],
- $fields['firstname'],
- $fields['email'],
- $fields['phone'],
- $fields['birthdate'],
- $fields['groupUsers'],
- $fields['isSaleAlwaysOpen'],
- $fields['newsletters'],
- $fields['ticketTypesNotification']
- ];
-
- if ($this->isGranted('ROLE_SUPER_ADMIN')) {
- $fieldToReturn[] = $fields['roles'];
- }
- return $fieldToReturn;
- } elseif ($pageName == Crud::PAGE_DETAIL) {
- return [$fields['id']];
- }
- }
-
-
- }
|