|
- <?php
-
- namespace Lc\CaracoleBundle\Controller\User;
-
- use App\Controller\Credit\CreditHistoryAdminController;
- use Doctrine\ORM\EntityManagerInterface;
- use EasyCorp\Bundle\EasyAdminBundle\Collection\EntityCollection;
- use EasyCorp\Bundle\EasyAdminBundle\Collection\FieldCollection;
- use EasyCorp\Bundle\EasyAdminBundle\Collection\FilterCollection;
- use EasyCorp\Bundle\EasyAdminBundle\Config\Action;
- use EasyCorp\Bundle\EasyAdminBundle\Config\Actions;
- use EasyCorp\Bundle\EasyAdminBundle\Config\Crud;
- use EasyCorp\Bundle\EasyAdminBundle\Config\Filters;
- use EasyCorp\Bundle\EasyAdminBundle\Context\AdminContext;
- use EasyCorp\Bundle\EasyAdminBundle\Dto\EntityDto;
- use EasyCorp\Bundle\EasyAdminBundle\Dto\SearchDto;
- use EasyCorp\Bundle\EasyAdminBundle\Filter\BooleanFilter;
- use EasyCorp\Bundle\EasyAdminBundle\Provider\AdminContextProvider;
- use EasyCorp\Bundle\EasyAdminBundle\Router\AdminUrlGenerator;
- use Lc\CaracoleBundle\Container\User\UserMerchantContainer;
- use Lc\CaracoleBundle\Controller\AbstractAdminController;
- use Lc\CaracoleBundle\Definition\ActionDefinition;
- use Lc\CaracoleBundle\Form\User\UserMerchantActiveCreditFormType;
- use Lc\CaracoleBundle\Model\Credit\CreditHistoryInterface;
- use Lc\CaracoleBundle\Resolver\MerchantResolver;
- use Lc\SovBundle\Repository\RepositoryQueryInterface;
- use Lc\SovBundle\Translation\TranslatorAdmin;
- use Symfony\Component\HttpFoundation\Response;
-
- abstract class UserMerchantAdminController extends AbstractAdminController
- {
-
-
- public function getRepositoryQuery(): RepositoryQueryInterface
- {
- return $this->getUserMerchantContainer()->getRepositoryQuery();
- }
-
- public function createEntity(string $entityFqcn)
- {
- return $this->getUserMerchantContainer()->getFactory()->createBase($this->getMerchantCurrent());
- }
-
- public function createIndexRepositoryQuery(
- SearchDto $searchDto,
- EntityDto $entityDto,
- FieldCollection $fields,
- FilterCollection $filters
- ): RepositoryQueryInterface {
- $repositoryQuery = parent::createIndexRepositoryQuery($searchDto, $entityDto, $fields, $filters);
- $repositoryQuery->filterIsCreditActive();
- return $repositoryQuery;
- }
-
- public function overrideEntitiesActions(?EntityCollection $entities, string $pageName): void
- {
- $context = $this->get(AdminContextProvider::class)->getContext();
- $adminUrlGenerator = $this->get(AdminUrlGenerator::class);
-
- $creditControllerFqcn = $context->getCrudControllers()->findCrudFqcnByEntityFqcn(
- $this->get(EntityManagerInterface::class)->getEntityName(CreditHistoryInterface::class)
- );
-
- if ($entities) {
- foreach ($entities as $entity) {
- foreach ($entity->getActions() as $action) {
- if ($action->getName() == 'credit_history') {
- $url = $adminUrlGenerator
- ->setController($creditControllerFqcn)
- ->set('userMerchantId', $entity->getInstance()->getId())
- ->generateUrl();
- $action->setLinkUrl($url);
- }
- }
- }
- }
- }
-
- public function configureActions(Actions $actions): Actions
- {
- $actions = parent::configureActions($actions);
-
- $creditAction = Action::new('credit_history', false, 'fa fa-cash-register')
- ->linkToCrudAction('credit_history')
- ->setHtmlAttributes(
- array(
- 'data-toggle' => 'tooltip',
- 'title' => $this->get(TranslatorAdmin::class)->transAction('credit'),
- )
- )
- ->setCssClass('btn btn-sm btn-success');
- $actions->add(Crud::PAGE_INDEX, $creditAction);
- $actions->disable(
- ActionDefinition::EDIT,
- ActionDefinition::DUPLICATE,
- ActionDefinition::DELETE,
- ActionDefinition::DUPLICATE_TO_OTHER_MERCHANT
- );
-
- return $actions;
- }
-
- public function configureFields(string $pageName): iterable
- {
- return $this->getUserMerchantContainer()->getFieldDefinition()->getFields($pageName);
- }
-
- public function configureFilters(Filters $filters): Filters
- {
- return $filters
- ->add(BooleanFilter::new('active'));
- }
-
- public function new(AdminContext $context): Response
- {
- $entityManager = $this->get(EntityManagerInterface::class);
- $merchantResolver = $this->get(MerchantResolver::class);
-
- $userMerchant = $this->get(UserMerchantContainer::class)
- ->getFactory()
- ->create($merchantResolver->getCurrent());
-
- $form = $this->createForm(
- UserMerchantActiveCreditFormType::class,
- $userMerchant,
- array(
- 'merchant' => $this->getMerchantCurrent()
- )
- );
-
- $form->handleRequest($context->getRequest());
-
- if ($form->isSubmitted() && $form->isValid()) {
-
- $user = $form->get('user')->getData();
- $userMerchant = $merchantResolver->getUserMerchant($user);
- $userMerchant->setCreditActive(true);
- $entityManager->update($userMerchant);
- $entityManager->flush();
-
- $this->addFlashTranslator('success', 'creditActive');
-
- return $this->redirect($this->generateEaUrl(CreditHistoryAdminController::class, ActionDefinition::INDEX, null, array(
- 'userMerchantId'=> $userMerchant->getId()
- )));
- }
-
- return $this->render(
- '@LcCaracole/admin/user/new_usermerchant.html.twig',
- [
- 'form' => $form->createView(),
- ]
- );
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- }
|