|
- <?php
-
- namespace Lc\CaracoleBundle\Controller\Credit;
-
- use Doctrine\ORM\EntityManagerInterface;
- use EasyCorp\Bundle\EasyAdminBundle\Collection\ActionCollection;
- use EasyCorp\Bundle\EasyAdminBundle\Collection\FieldCollection;
- use EasyCorp\Bundle\EasyAdminBundle\Collection\FilterCollection;
- use EasyCorp\Bundle\EasyAdminBundle\Config\Actions;
- use EasyCorp\Bundle\EasyAdminBundle\Config\Crud;
- use EasyCorp\Bundle\EasyAdminBundle\Config\KeyValueStore;
- use EasyCorp\Bundle\EasyAdminBundle\Dto\EntityDto;
- use EasyCorp\Bundle\EasyAdminBundle\Dto\SearchDto;
- use EasyCorp\Bundle\EasyAdminBundle\Field\ChoiceField;
- use EasyCorp\Bundle\EasyAdminBundle\Field\DateField;
- use EasyCorp\Bundle\EasyAdminBundle\Field\IdField;
- use EasyCorp\Bundle\EasyAdminBundle\Field\NumberField;
- use EasyCorp\Bundle\EasyAdminBundle\Field\TextField;
- use EasyCorp\Bundle\EasyAdminBundle\Provider\AdminContextProvider;
- use EasyCorp\Bundle\EasyAdminBundle\Router\AdminUrlGenerator;
- use Lc\CaracoleBundle\Container\Credit\CreditHistoryContainer;
- use Lc\CaracoleBundle\Container\User\UserMerchantContainer;
- use Lc\CaracoleBundle\Controller\AbstractAdminController;
- use Lc\CaracoleBundle\Definition\ActionDefinition;
- use Lc\CaracoleBundle\Model\Credit\CreditHistoryInterface;
- use Lc\CaracoleBundle\Model\User\UserMerchantInterface;
- use Lc\CaracoleBundle\Solver\Credit\CreditHistorySolver;
- use Lc\CaracoleBundle\Solver\Order\OrderPaymentSolver;
- use Lc\SovBundle\Repository\RepositoryQueryInterface;
- use Lc\SovBundle\Translation\TranslatorAdmin;
-
- abstract class CreditHistoryAdminController extends AbstractAdminController
- {
-
- public function getRepositoryQuery(): RepositoryQueryInterface
- {
- return $this->get(CreditHistoryContainer::class)->getRepositoryQuery();
- }
-
- public function overrideGlobalActions(?ActionCollection $actions): void
- {
- parent::overrideGlobalActions($actions);
- if ($actions) {
- $adminUrlGenerator = $this->get(AdminUrlGenerator::class);
-
- $creditControllerFqcn = $this->getControllerFqcnByInterface(CreditHistoryInterface::class);
-
- foreach ($actions as $action) {
- $url = $adminUrlGenerator
- ->setController($creditControllerFqcn)
- ->setAction(ActionDefinition::NEW)
- ->set('userMerchantId', $this->getUserMerchant()->getId())
- ->generateUrl();
- $action->setLinkUrl($url);
- }
- }
- }
-
- public function createEntity(string $entityFqcn)
- {
- return $this->get(CreditHistoryContainer::class)->getFactory()->createBase($this->getUserMerchant());
- }
-
- protected function getUserMerchant(): UserMerchantInterface
- {
- $request = $this->get(AdminContextProvider::class)->getContext()->getRequest();
- return $this->get(UserMerchantContainer::class)->getStore()->getOneById(
- $request->get('userMerchantId')
- );
- }
-
- public function configureActions(Actions $actions): Actions
- {
- $actions = parent::configureActions($actions);
- $actions->disable(ActionDefinition::DELETE, ActionDefinition::EDIT, ActionDefinition::DUPLICATE);
-
- return $actions;
- }
-
- public function persistEntity(EntityManagerInterface $entityManager, $entityInstance): void
- {
- if ($this->get(CreditHistoryContainer::class)->getBuilder()->save($entityInstance)) {
- $this->addFlashTranslator('success', 'saveCreditHistory');
- } else {
- $this->addFlashTranslator('error', 'saveCreditHistory');
- }
- }
-
-
- public function configureCrud(Crud $crud): Crud
- {
- $crud->overrideTemplate('crud/index', '@LcCaracole/admin/credit/index_credithistory.html.twig');
-
- return $crud;
- }
-
- public function configureResponseParameters(KeyValueStore $responseParameters): KeyValueStore
- {
- $responseParameters = parent::configureResponseParameters($responseParameters);
-
- $responseParameters->set('user_merchant', $this->getUserMerchant());
- return $responseParameters;
- }
-
- public function configureFields(string $pageName): iterable
- {
- return $this->getCreditHistoryContainer()->getFieldDefinition()->getFields($pageName);
-
- }
-
- public function createIndexRepositoryQuery(
- SearchDto $searchDto,
- EntityDto $entityDto,
- FieldCollection $fields,
- FilterCollection $filters
- ): RepositoryQueryInterface {
- $repositoryQuery = parent::createIndexRepositoryQuery(
- $searchDto,
- $entityDto,
- $fields,
- $filters
- );
- $repositoryQuery->filterByUserMerchant($this->getUserMerchant());
-
- return $repositoryQuery;
- }
- }
|