Commit dad902ba by Damien Moulard

add relation between prestataire and product families & (WIP) display in prestataire info form

parent ce6fa36d
...@@ -15,6 +15,7 @@ parameters: ...@@ -15,6 +15,7 @@ parameters:
tav_env: '%env(TAV_ENV)%' tav_env: '%env(TAV_ENV)%'
presta_self_init_and_eval: '%env(PRESTA_SELF_INIT_AND_EVAL)%' presta_self_init_and_eval: '%env(PRESTA_SELF_INIT_AND_EVAL)%'
automatisation_reconversion: '%env(AUTOMATISATION_RECONVERSION)%' automatisation_reconversion: '%env(AUTOMATISATION_RECONVERSION)%'
presta_extra_data: '%env(PRESTA_EXTRA_DATA)%'
# PARAMETRES DES IMPORTS POSSIBLE POUR L'APPLICATION DE GESTION DE MONNAIE LOCALE COMPLEMENTAIRE # PARAMETRES DES IMPORTS POSSIBLE POUR L'APPLICATION DE GESTION DE MONNAIE LOCALE COMPLEMENTAIRE
app.import.separator: ';' app.import.separator: ';'
......
...@@ -9,6 +9,7 @@ use App\Entity\EntityTrait\HasEcompteEntity; ...@@ -9,6 +9,7 @@ use App\Entity\EntityTrait\HasEcompteEntity;
use App\Flux\AccountableInterface; use App\Flux\AccountableInterface;
use App\Flux\AccountableObject; use App\Flux\AccountableObject;
use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM; use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo; use Gedmo\Mapping\Annotation as Gedmo;
use Gedmo\Timestampable\Traits\TimestampableEntity; use Gedmo\Timestampable\Traits\TimestampableEntity;
...@@ -351,6 +352,11 @@ class Prestataire extends AccountableObject implements AccountableInterface ...@@ -351,6 +352,11 @@ class Prestataire extends AccountableObject implements AccountableInterface
*/ */
private $lastTransactionsExportDatetime; private $lastTransactionsExportDatetime;
/**
* @ORM\OneToMany(targetEntity=PrestataireProductFamily::class, mappedBy="prestataire", orphanRemoval=true)
*/
private $prestataireProductFamilies;
public function __construct() public function __construct()
{ {
$this->users = new ArrayCollection(); $this->users = new ArrayCollection();
...@@ -361,6 +367,7 @@ class Prestataire extends AccountableObject implements AccountableInterface ...@@ -361,6 +367,7 @@ class Prestataire extends AccountableObject implements AccountableInterface
$this->rubriques = new ArrayCollection(); $this->rubriques = new ArrayCollection();
$this->contacts = new ArrayCollection(); $this->contacts = new ArrayCollection();
$this->accounts = new ArrayCollection(); $this->accounts = new ArrayCollection();
$this->prestataireProductFamilies = new ArrayCollection();
} }
public function getId() public function getId()
...@@ -1185,4 +1192,34 @@ class Prestataire extends AccountableObject implements AccountableInterface ...@@ -1185,4 +1192,34 @@ class Prestataire extends AccountableObject implements AccountableInterface
return $this; return $this;
} }
/**
* @return Collection<int, PrestataireProductFamily>
*/
public function getPrestataireProductFamilies(): Collection
{
return $this->prestataireProductFamilies;
}
public function addPrestataireProductFamily(PrestataireProductFamily $prestataireProductFamily): self
{
if (!$this->prestataireProductFamilies->contains($prestataireProductFamily)) {
$this->prestataireProductFamilies[] = $prestataireProductFamily;
$prestataireProductFamily->setPrestataire($this);
}
return $this;
}
public function removePrestataireProductFamily(PrestataireProductFamily $prestataireProductFamily): self
{
if ($this->prestataireProductFamilies->removeElement($prestataireProductFamily)) {
// set the owning side to null (unless already changed)
if ($prestataireProductFamily->getPrestataire() === $this) {
$prestataireProductFamily->setPrestataire(null);
}
}
return $this;
}
} }
<?php
namespace App\Entity;
use App\Repository\PrestataireProductFamilyRepository;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
/**
* @ORM\Entity(repositoryClass=PrestataireProductFamilyRepository::class)
* @ORM\Table(name="prestataire_product_family", uniqueConstraints={@ORM\UniqueConstraint(name="prestataireproductfamily", columns={"prestataire_id", "product_family_id"})}) )
* @UniqueEntity(
* fields={"prestataire", "productFamily"},
* errorPath="prestataire",
* message="Une relation existe déjà entre ce prestataire et cette famille de produits."
* )
*/
class PrestataireProductFamily
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\ManyToOne(targetEntity=Prestataire::class, inversedBy="prestataireProductFamilies")
* @ORM\JoinColumn(nullable=false)
*/
private $prestataire;
/**
* @ORM\ManyToOne(targetEntity=ProductFamily::class)
* @ORM\JoinColumn(nullable=false)
*/
private $productFamily;
/**
* Products list as a string. Not related to any kind of product entity.
*
* @ORM\Column(type="text")
*/
private $products;
public function getId(): ?int
{
return $this->id;
}
public function getPrestataire(): ?Prestataire
{
return $this->prestataire;
}
public function setPrestataire(?Prestataire $prestataire): self
{
$this->prestataire = $prestataire;
return $this;
}
public function getProductFamily(): ?ProductFamily
{
return $this->productFamily;
}
public function setProductFamily(?ProductFamily $productFamily): self
{
$this->productFamily = $productFamily;
return $this;
}
public function getProducts(): ?string
{
return $this->products;
}
public function setProducts(string $products): self
{
$this->products = $products;
return $this;
}
}
...@@ -4,6 +4,8 @@ namespace App\Form\Type; ...@@ -4,6 +4,8 @@ namespace App\Form\Type;
use App\Application\Sonata\MediaBundle\Entity\Media; use App\Application\Sonata\MediaBundle\Entity\Media;
use App\Entity\Prestataire; use App\Entity\Prestataire;
use App\Entity\PrestataireProductFamily;
use App\Form\Type\PrestataireProductFamilyFormType;
use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\DependencyInjection\ContainerInterface;
use FOS\CKEditorBundle\Form\Type\CKEditorType; use FOS\CKEditorBundle\Form\Type\CKEditorType;
...@@ -99,8 +101,17 @@ class PrestataireInfosFormType extends AbstractType ...@@ -99,8 +101,17 @@ class PrestataireInfosFormType extends AbstractType
]); ]);
} }
// $this->container->getParameter('tav_env') if ($this->container->getParameter('tav_env') && $this->container->getParameter('presta_extra_data')) {
$builder
->add('prestataireProductFamilies', CollectionType::class, [
'entry_type' => PrestataireProductFamilyFormType::class,
'required' => true,
'allow_add' => true,
'by_reference' => false,
'label' => "Produits vendus par famille : ",
]);
}
$builder $builder
->add('description', CKEditorType::class, [ ->add('description', CKEditorType::class, [
'label' => 'Description :', 'label' => 'Description :',
......
<?php
namespace App\Form\Type;
use App\Entity\PrestataireProductFamily;
use App\Entity\ProductFamily;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
class PrestataireProductFamilyFormType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('productFamily', EntityType::class, array(
'class' => ProductFamily::class,
'choice_label' => 'name',
'label' => 'Famille de produits',
'required' => true,
))
->add('products', TextType::class, [
'label' => 'Produits :',
'required' => true,
])
;
}
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults([
'data_class' => PrestataireProductFamily::class,
]);
}
public function getBlockPrefix()
{
return 'formPrestataireProductFamily';
}
}
<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20240220101222 extends AbstractMigration
{
public function getDescription() : string
{
return '';
}
public function up(Schema $schema) : void
{
// this up() migration is auto-generated, please modify it to your needs
$this->addSql('CREATE TABLE prestataire_product_family (id INT AUTO_INCREMENT NOT NULL, prestataire_id CHAR(36) NOT NULL COMMENT \'(DC2Type:uuid)\', product_family_id CHAR(36) NOT NULL COMMENT \'(DC2Type:uuid)\', products LONGTEXT NOT NULL, INDEX IDX_9B0F7A58BE3DB2B7 (prestataire_id), INDEX IDX_9B0F7A58ADFEE0E7 (product_family_id), UNIQUE INDEX prestataireproductfamily (prestataire_id, product_family_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE `utf8_general_ci` ENGINE = InnoDB');
$this->addSql('ALTER TABLE prestataire_product_family ADD CONSTRAINT FK_9B0F7A58BE3DB2B7 FOREIGN KEY (prestataire_id) REFERENCES prestataire (id)');
$this->addSql('ALTER TABLE prestataire_product_family ADD CONSTRAINT FK_9B0F7A58ADFEE0E7 FOREIGN KEY (product_family_id) REFERENCES product_family (id)');
$this->addSql('ALTER TABLE prestataire CHANGE iban iban LONGTEXT DEFAULT NULL COMMENT \'(DC2Type:personal_data)\'');
}
public function down(Schema $schema) : void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('DROP TABLE prestataire_product_family');
$this->addSql('ALTER TABLE prestataire CHANGE iban iban LONGTEXT CHARACTER SET utf8mb3 DEFAULT NULL COLLATE `utf8mb3_general_ci` COMMENT \'(DC2Type:personal_data)\'');
}
}
<?php
namespace App\Repository;
use App\Entity\PrestataireProductFamily;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\ORM\OptimisticLockException;
use Doctrine\ORM\ORMException;
use Doctrine\Persistence\ManagerRegistry;
/**
* @extends ServiceEntityRepository<PrestataireProductFamily>
*
* @method PrestataireProductFamily|null find($id, $lockMode = null, $lockVersion = null)
* @method PrestataireProductFamily|null findOneBy(array $criteria, array $orderBy = null)
* @method PrestataireProductFamily[] findAll()
* @method PrestataireProductFamily[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
*/
class PrestataireProductFamilyRepository extends ServiceEntityRepository
{
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, PrestataireProductFamily::class);
}
/**
* @throws ORMException
* @throws OptimisticLockException
*/
public function add(PrestataireProductFamily $entity, bool $flush = true): void
{
$this->_em->persist($entity);
if ($flush) {
$this->_em->flush();
}
}
/**
* @throws ORMException
* @throws OptimisticLockException
*/
public function remove(PrestataireProductFamily $entity, bool $flush = true): void
{
$this->_em->remove($entity);
if ($flush) {
$this->_em->flush();
}
}
// /**
// * @return PrestataireProductFamily[] Returns an array of PrestataireProductFamily objects
// */
/*
public function findByExampleField($value)
{
return $this->createQueryBuilder('p')
->andWhere('p.exampleField = :val')
->setParameter('val', $value)
->orderBy('p.id', 'ASC')
->setMaxResults(10)
->getQuery()
->getResult()
;
}
*/
/*
public function findOneBySomeField($value): ?PrestataireProductFamily
{
return $this->createQueryBuilder('p')
->andWhere('p.exampleField = :val')
->setParameter('val', $value)
->getQuery()
->getOneOrNullResult()
;
}
*/
}
...@@ -27,6 +27,24 @@ ...@@ -27,6 +27,24 @@
{% if form.reconversionFrequency is defined %} {% if form.reconversionFrequency is defined %}
{{ form_row(form.reconversionFrequency) }} {{ form_row(form.reconversionFrequency) }}
{% endif %} {% endif %}
{% if form.prestataireProductFamilies is defined %}
<hr/>
<h3>{{ form_label(form.prestataireProductFamilies) }}</h3>
{{ form_errors(form.prestataireProductFamilies) }}
<div id="presta-products-families-list">
{% for prestataireProductFamilyForm in form.prestataireProductFamilies %}
<div class="presta-products-family">
{{ form_row(prestataireProductFamilyForm.productFamily) }}
{{ form_row(prestataireProductFamilyForm.products) }}
</div>
{% endfor %}
</div>
<button type="button" id="add-products-family" class="btn-primary btn">
<i class="fa fa-plus"></i>
</button>
{% endif %}
<hr/> <hr/>
{{ form_row(form.media) }} {{ form_row(form.media) }}
{{ form_row(form.description) }} {{ form_row(form.description) }}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment