Browse Source

Factory

packProduct
Guillaume 3 years ago
parent
commit
2ab9479084
12 changed files with 125 additions and 109 deletions
  1. +10
    -3
      Controller/Reminder/ReminderAdminController.php
  2. +18
    -0
      Controller/Ticket/TicketAdminController.php
  3. +0
    -43
      Factory/FactoryTrait.php
  4. +18
    -0
      Factory/MerchantFactoryTrait.php
  5. +15
    -2
      Factory/Reminder/ReminderFactory.php
  6. +18
    -0
      Factory/SectionFactoryTrait.php
  7. +10
    -3
      Factory/Setting/MerchantSettingFactory.php
  8. +10
    -3
      Factory/Setting/SectionSettingFactory.php
  9. +8
    -26
      Factory/Ticket/TicketFactory.php
  10. +7
    -26
      Factory/User/UserMerchantFactory.php
  11. +2
    -2
      Model/User/UserMerchantModel.php
  12. +9
    -1
      Resources/config/routes.yaml

+ 10
- 3
Controller/Reminder/ReminderAdminController.php View File

@@ -3,10 +3,17 @@
namespace Lc\CaracoleBundle\Controller\Reminder;

use Lc\CaracoleBundle\Controller\AdminControllerTrait;
use Lc\SovBundle\Controller\Reminder\ReminderAdminController as SovReminderController;
use Lc\SovBundle\Controller\Reminder\ReminderAdminController as SovReminderAdminController;

abstract class ReminderAdminController extends SovReminderController
class ReminderAdminController extends SovReminderAdminController
{

use AdminControllerTrait;

public function createEntity(string $crudAction = null, string $crudControllerFqcn = null, int $entityId = null)
{
return $this->reminderFactory
->setMerchant($this->get('merchant_resolver')->getCurrent())
->setSection($this->get('section_resolver')->getCurrent())
->create($crudAction, $crudControllerFqcn, $entityId);
}
}

+ 18
- 0
Controller/Ticket/TicketAdminController.php View File

@@ -0,0 +1,18 @@
<?php

namespace Lc\CaracoleBundle\Controller\Ticket;

use Lc\CaracoleBundle\Controller\AdminControllerTrait;
use Lc\SovBundle\Controller\Ticket\TicketAdminController as SovTicketAdminController;

class TicketAdminController extends SovTicketAdminController
{
use AdminControllerTrait;

public function createEntityFromFactory()
{
return $this->ticketFactory
->setMerchant($this->get('merchant_resolver')->getCurrent())
->create();
}
}

+ 0
- 43
Factory/FactoryTrait.php View File

@@ -1,43 +0,0 @@
<?php

namespace Lc\CaracoleBundle\Factory;

use Doctrine\ORM\EntityManagerInterface;
use Lc\CaracoleBundle\Doctrine\Extension\FilterMerchantInterface;
use Lc\CaracoleBundle\Doctrine\Extension\FilterSectionInterface;
use Lc\CaracoleBundle\Resolver\MerchantResolver;
use Lc\CaracoleBundle\Resolver\SectionResolver;
use Lc\SovBundle\Factory\AbstractFactory as SovAbstractFactory;

trait FactoryTrait
{
protected $merchantResolver;
protected $sectionResolver;

public function __construct(
EntityManagerInterface $em,
MerchantResolver $merchantResolver,
SectionResolver $sectionResolver
) {
$this->em = $em;
$this->merchantResolver = $merchantResolver;
$this->sectionResolver = $sectionResolver;
}

public function create($params = array())
{
$entityClass = $this->em->getEntityName($this->getEntityClass());
$entity = new $entityClass;

if ($entity instanceof FilterMerchantInterface && !isset($params['merchant'])) {
$params['merchant'] = $this->merchantResolver->getCurrent();
}

if ($entity instanceof FilterSectionInterface && !isset($params['section'])) {
$params['section'] = $this->sectionResolver->getCurrent();
}

return parent::create($params);
}

}

+ 18
- 0
Factory/MerchantFactoryTrait.php View File

@@ -0,0 +1,18 @@
<?php

namespace Lc\CaracoleBundle\Factory;

use Lc\CaracoleBundle\Model\Merchant\MerchantInterface;

trait MerchantFactoryTrait
{
public ?MerchantInterface $merchant = null;

public function setMerchant(MerchantInterface $merchant)
{
$this->merchant = $merchant;

return $this;
}

}

+ 15
- 2
Factory/Reminder/ReminderFactory.php View File

@@ -2,11 +2,24 @@

namespace Lc\CaracoleBundle\Factory\Reminder;

use Lc\CaracoleBundle\Factory\FactoryTrait;
use Lc\CaracoleBundle\Factory\MerchantFactoryTrait;
use Lc\CaracoleBundle\Factory\SectionFactoryTrait;
use Lc\SovBundle\Factory\Reminder\ReminderFactory as SovReminderFactory;
use Lc\SovBundle\Model\Reminder\ReminderInterface;

class ReminderFactory extends SovReminderFactory
{
use FactoryTrait;
use MerchantFactoryTrait;
use SectionFactoryTrait;

public function create(string $crudAction = null, string $crudControllerFqcn = null, int $entityId = null): ReminderInterface
{
$reminder = parent::create($crudAction, $crudControllerFqcn, $entityId);

$reminder->setMerchant($this->merchant) ;
$reminder->setSection($this->section) ;

return $reminder;
}

}

+ 18
- 0
Factory/SectionFactoryTrait.php View File

@@ -0,0 +1,18 @@
<?php

namespace Lc\CaracoleBundle\Factory;

use Lc\CaracoleBundle\Model\Section\SectionInterface;

trait SectionFactoryTrait
{
public ?SectionInterface $section = null;

public function setSection(SectionInterface $section)
{
$this->section = $section;

return $this;
}

}

+ 10
- 3
Factory/Setting/MerchantSettingFactory.php View File

@@ -2,13 +2,20 @@

namespace Lc\CaracoleBundle\Factory\Setting;

use Lc\CaracoleBundle\Model\Setting\MerchantSettingInterface;
use App\Entity\Setting\MerchantSetting;
use Lc\CaracoleBundle\Factory\MerchantFactoryTrait;
use Lc\SovBundle\Factory\AbstractFactory;

class MerchantSettingFactory extends AbstractFactory
{
public function getEntityClass()
use MerchantFactoryTrait;

public function create()
{
return MerchantSettingInterface::class;
$merchantSetting = new MerchantSetting();

$merchantSetting->setMerchant($this->merchant);

return $merchantSetting;
}
}

+ 10
- 3
Factory/Setting/SectionSettingFactory.php View File

@@ -2,13 +2,20 @@

namespace Lc\CaracoleBundle\Factory\Setting;

use Lc\CaracoleBundle\Model\Setting\SectionSettingInterface;
use App\Entity\Setting\SectionSetting;
use Lc\CaracoleBundle\Factory\MerchantFactoryTrait;
use Lc\SovBundle\Factory\AbstractFactory;

class SectionSettingFactory extends AbstractFactory
{
public function getEntityClass()
use MerchantFactoryTrait;

public function create()
{
return SectionSettingInterface::class;
$sectionSetting = new SectionSetting();

$sectionSetting->setMerchant($this->merchant);

return $sectionSetting;
}
}

+ 8
- 26
Factory/Ticket/TicketFactory.php View File

@@ -2,38 +2,20 @@

namespace Lc\CaracoleBundle\Factory\Ticket;

use Doctrine\ORM\EntityManagerInterface;
use Lc\CaracoleBundle\Factory\FactoryTrait;
use Lc\CaracoleBundle\Resolver\MerchantResolver;
use Lc\CaracoleBundle\Resolver\SectionResolver;
use Lc\CaracoleBundle\Factory\MerchantFactoryTrait;
use Lc\CaracoleBundle\Factory\SectionFactoryTrait;
use Lc\SovBundle\Factory\Ticket\TicketFactory as SovTicketFactory;
use Lc\SovBundle\Factory\Ticket\TicketMessageFactory;

class TicketFactory extends SovTicketFactory
{
// use FactoryTrait;
use MerchantFactoryTrait;

protected $merchantResolver;
protected $sectionResolver;
protected $ticketMessageFactory;

public function __construct(
EntityManagerInterface $em,
MerchantResolver $merchantResolver,
SectionResolver $sectionResolver,
TicketMessageFactory $ticketMessageFactory
) {
parent::__construct($em, $ticketMessageFactory);
$this->merchantResolver = $merchantResolver;
$this->sectionResolver = $sectionResolver;
}

public function create($params = array())
public function create()
{
if (!isset($params['merchant'])) {
$params['merchant'] = $this->merchantResolver->getCurrent();
}
$ticket = parent::create();

$ticket->setMerchant($this->merchant);

return parent::create($params);
return $ticket;
}
}

+ 7
- 26
Factory/User/UserMerchantFactory.php View File

@@ -2,40 +2,21 @@

namespace Lc\CaracoleBundle\Factory\User;

use Doctrine\ORM\EntityManagerInterface;
use App\Entity\User\UserMerchant;
use Lc\CaracoleBundle\Factory\MerchantFactoryTrait;
use Lc\CaracoleBundle\Model\User\UserMerchantInterface;
use Lc\CaracoleBundle\Resolver\MerchantResolver;
use Lc\SovBundle\Factory\AbstractFactory;

class UserMerchantFactory extends AbstractFactory
{
protected $merchantResolver;
use MerchantFactoryTrait;

public function __construct(EntityManagerInterface $em, MerchantResolver $merchantResolver)
public function create(): UserMerchantInterface
{
parent::__construct($em);
$this->merchantResolver = $merchantResolver;
}

public function getEntityClass()
{
return UserMerchantInterface::class;
}

public function create($params = array())
{
if(!isset($params['merchant'])){
$params['merchant'] = $this->merchantResolver->getCurrent();
}

if(!isset($params['creditActive'])){
$params['creditActive'] =false;
}
$userMerchant = new UserMerchant();

if(!isset($params['active'])){
$params['active'] = true;
}
$userMerchant->setMerchant($this->merchant);

return parent::create($params); // TODO: Change the autogenerated stub
return $userMerchant;
}
}

+ 2
- 2
Model/User/UserMerchantModel.php View File

@@ -42,7 +42,7 @@ abstract class UserMerchantModel implements FilterMerchantInterface, EntityInter
/**
* @ORM\Column(type="boolean")
*/
protected $creditActive;
protected $creditActive = false;

/**
* @ORM\OneToMany(targetEntity="Lc\CaracoleBundle\Model\Credit\CreditHistoryInterface", mappedBy="userMerchant", orphanRemoval=true)
@@ -52,7 +52,7 @@ abstract class UserMerchantModel implements FilterMerchantInterface, EntityInter
/**
* @ORM\Column(type="boolean")
*/
protected $active;
protected $active = true;

/**
* @ORM\Column(type="json")

+ 9
- 1
Resources/config/routes.yaml View File

@@ -20,4 +20,12 @@ carac_admin_setting_section:

carac_admin_setting_global:
path: /admin/setting/global2
controller: Lc\CaracoleBundle\Controller\Setting\SettingAdminController::manageGlobal
controller: Lc\CaracoleBundle\Controller\Setting\SettingAdminController::manageGlobal

carac_admin_reminder_render_modal:
path: /admin/caracole/reminder/modal
controller: Lc\CaracoleBundle\Controller\Reminder\ReminderAdminController::renderModal

carac_admin_reminder_new:
path: /admin/caracole/reminder/new
controller: Lc\CaracoleBundle\Controller\Reminder\ReminderAdminController::new

Loading…
Cancel
Save