<?php | |||||
namespace Lc\CaracoleBundle\Controller\User; | |||||
use App\Entity\Address; | |||||
use App\Form\Backend\Common\AddressType; | |||||
use EasyCorp\Bundle\EasyAdminBundle\Config\Crud; | |||||
use EasyCorp\Bundle\EasyAdminBundle\Config\Filters; | |||||
use EasyCorp\Bundle\EasyAdminBundle\Context\AdminContext; | |||||
use EasyCorp\Bundle\EasyAdminBundle\Filter\BooleanFilter; | |||||
use Lc\CaracoleBundle\Container\Address\AddressContainer; | |||||
use Lc\CaracoleBundle\Controller\ControllerTrait; | |||||
use Lc\SovBundle\Container\User\UserContainer; | |||||
use Lc\CaracoleBundle\Controller\AbstractAdminController; | |||||
use Lc\SovBundle\Repository\RepositoryQueryInterface; | |||||
use Symfony\Component\HttpFoundation\Response; | |||||
abstract class UserAdminController extends AbstractAdminController | |||||
{ | |||||
use ControllerTrait; | |||||
public function getRepositoryQuery(): RepositoryQueryInterface | |||||
{ | |||||
return $this->getUserContainer()->getRepositoryQuery(); | |||||
} | |||||
public function createEntity(string $entityFqcn) | |||||
{ | |||||
return $this->getUserContainer()->getFactory()->create(); | |||||
} | |||||
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'] | |||||
]; | |||||
if($this->isGranted('ROLE_SUPER_ADMIN')){ | |||||
$fieldToReturn[] = $fields['roles']; | |||||
} | |||||
return $fieldToReturn; | |||||
} | |||||
} | |||||
} |
<?php | |||||
namespace Lc\CaracoleBundle\Definition\Field\User; | |||||
use Lc\CaracoleBundle\Context\MerchantContextTrait; | |||||
use Lc\CaracoleBundle\Field\AssociationField; | |||||
use Lc\CaracoleBundle\Repository\Newsletter\NewsletterStore; | |||||
use Lc\CaracoleBundle\Repository\User\GroupUserStore; | |||||
use Lc\SovBundle\Definition\Field\User\UserFieldDefinition as SovUserFieldDefinition; | |||||
use Lc\SovBundle\Definition\RolesDefinition; | |||||
use Lc\SovBundle\Field\BooleanField; | |||||
use Lc\SovBundle\Translation\TranslatorAdmin; | |||||
use function Clue\StreamFilter\fun; | |||||
class UserFieldDefinition extends SovUserFieldDefinition | |||||
{ | |||||
use MerchantContextTrait; | |||||
protected GroupUserStore $groupUserStore; | |||||
protected NewsletterStore $newsletterStore; | |||||
public function __construct(TranslatorAdmin $translatorAdmin, RolesDefinition $rolesDefinition, GroupUserStore $groupUserStore, NewsletterStore $newsletterStore) | |||||
{ | |||||
parent::__construct($translatorAdmin, $rolesDefinition); | |||||
$this->groupUserStore = $groupUserStore; | |||||
$this->newsletterStore = $newsletterStore; | |||||
} | |||||
public function configureForm(): array | |||||
{ | |||||
return [ | |||||
'gender', | |||||
'lastname', | |||||
'firstname', | |||||
'email', | |||||
'phone', | |||||
'birthdate', | |||||
'groupUsers', | |||||
'isSaleAlwaysOpen', | |||||
'newsletters' | |||||
]; | |||||
} | |||||
public function configureFields(): array | |||||
{ | |||||
$groupUsers = $this->groupUserStore->setMerchant($this->merchant)->getAll(); | |||||
$newsletters = $this->newsletterStore->getAll(); | |||||
return array_merge(parent::configureFields(),[ | |||||
'isSaleAlwaysOpen' => BooleanField::new('isSaleAlwaysOpen'), | |||||
'newsletters' => AssociationField::new('newsletters') | |||||
->setFormTypeOption('choices', $newsletters) | |||||
->setFormTypeOption('choice_label', function ($choice) { | |||||
return $choice->getTitle(). '['.$choice->getSection()->getMerchant().']'; | |||||
}) | |||||
->setSortable(true), | |||||
'groupUsers' => AssociationField::new('groupUsers') | |||||
->setFormTypeOption('choices', $groupUsers) | |||||
->setFormTypeOption('choice_label', function ($choice) { | |||||
return $choice->getTitle(). '['.$choice->getMerchant().']'; | |||||
}) | |||||
->setSortable(true) | |||||
]); | |||||
} | |||||
} |
namespace Lc\CaracoleBundle\Repository\Newsletter; | namespace Lc\CaracoleBundle\Repository\Newsletter; | ||||
use Lc\CaracoleBundle\Model\Merchant\MerchantInterface; | |||||
use Lc\CaracoleBundle\Repository\MerchantRepositoryQueryTrait; | use Lc\CaracoleBundle\Repository\MerchantRepositoryQueryTrait; | ||||
use Lc\CaracoleBundle\Repository\SectionRepositoryQueryTrait; | use Lc\CaracoleBundle\Repository\SectionRepositoryQueryTrait; | ||||
use Lc\SovBundle\Repository\Newsletter\NewsletterRepositoryQuery as SovNewsletterRepositoryQuery; | use Lc\SovBundle\Repository\Newsletter\NewsletterRepositoryQuery as SovNewsletterRepositoryQuery; |
namespace Lc\CaracoleBundle\Repository\Newsletter; | namespace Lc\CaracoleBundle\Repository\Newsletter; | ||||
use Lc\CaracoleBundle\Model\Merchant\MerchantInterface; | |||||
use Lc\CaracoleBundle\Repository\SectionStoreTrait; | use Lc\CaracoleBundle\Repository\SectionStoreTrait; | ||||
use Lc\SovBundle\Repository\Newsletter\NewsletterStore as SovNewsletterStore; | use Lc\SovBundle\Repository\Newsletter\NewsletterStore as SovNewsletterStore; | ||||
use Lc\SovBundle\Repository\RepositoryQueryInterface; | use Lc\SovBundle\Repository\RepositoryQueryInterface; | ||||
{ | { | ||||
return $query; | return $query; | ||||
} | } | ||||
public function getByMerchant(MerchantInterface $merchant, RepositoryQueryInterface $query = null):array | |||||
{ | |||||
$query = $this->createQuery($query); | |||||
$query->filterByMerchantViaSection($merchant); | |||||
return $query->find(); | |||||
} | |||||
} | } |
lastname: Nom | lastname: Nom | ||||
firstname: Prénom | firstname: Prénom | ||||
creditActive: Crédit activer | creditActive: Crédit activer | ||||
User: | |||||
fields: | |||||
isSaleAlwaysOpen: Vente toujours ouverte | |||||
newsletters: Newsletter | |||||
CreditHistory: | CreditHistory: | ||||
label: Historique de compte prépayé | label: Historique de compte prépayé | ||||
label_plurial: Historiques de compte prépayé | label_plurial: Historiques de compte prépayé |
namespace Lc\CaracoleBundle\Solver\Address; | namespace Lc\CaracoleBundle\Solver\Address; | ||||
use Lc\CaracoleBundle\Model\Address\AddressInterface; | use Lc\CaracoleBundle\Model\Address\AddressInterface; | ||||
use Lc\CaracoleBundle\Model\Address\AddressModel; | |||||
class AddressSolver | class AddressSolver | ||||
{ | { | ||||
return $address->getLatitude(); | return $address->getLatitude(); | ||||
} | } | ||||
} | } | ||||
public static function getTypeChoices():array{ | |||||
return[ | |||||
AddressModel::TYPE_INDIVIDUAL, | |||||
AddressModel::TYPE_LEGAL_PERSON, | |||||
]; | |||||
} | |||||
} | |||||
} |