src/Entity/Model.php line 19

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\ModelRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\DBAL\Types\Types;
  7. use Doctrine\ORM\Mapping as ORM;
  8. use Gedmo\Mapping\Annotation as Gedmo;
  9. use Gedmo\Timestampable\Traits\TimestampableEntity;
  10. use DateTime;
  11. //Repository de la classe Model
  12. #[ORM\Entity(repositoryClassModelRepository::class)]
  13. class Model
  14. {
  15.     use TimestampableEntity;
  16.     //Déclarations des variables
  17.     #[ORM\Id]
  18.     #[ORM\Column(name'id_model',type'integer'nullablefalse)]
  19.     //Spécifie que la valeur générée est un ID auto-incrémenté
  20.     #[ORM\GeneratedValue(strategy:'IDENTITY')]
  21.     private ?int $id;
  22.     #[ORM\Column(type:'integer',nullable:true)]
  23.     private ?int $annee null;
  24.     #[ORM\Column(length:255,nullable:true)]
  25.     private ?string $nbExemplaireEdite null;
  26.     #[ORM\Column(length:255,nullable:true)]
  27.     private ?string $fournisseur null;
  28.     #[ORM\Column(length255nullablefalse)]
  29.     private ?string $titre null;
  30.     #[ORM\Column(length2000nullablefalse)]
  31.     private ?string $description null;
  32.     #[ORM\Column(type'integer',nullablefalse)]
  33.     private ?int $nb null;
  34.     #[ORM\Column(typeTypes::DATETIME_MUTABLEnullablefalse)]
  35.     #[Gedmo\Timestampable(on 'create'field'dateCreation')]
  36.     private ?DateTime $dateCreation;
  37.     #[ORM\Column(typeTypes::DATETIME_MUTABLEnullablefalse)]
  38.     #[Gedmo\Timestampable(on 'update'field'dateModification')]
  39.     private ?DateTime $dateModification;
  40.     #[ORM\Column(nullable:true)]
  41.     private ?string $diametre null;
  42.     #[ORM\Column(nullable:true)]
  43.     private ?string $reference null;
  44.     //Association
  45.     #[ORM\OneToMany(mappedBy:'model'targetEntityPhoto::class, orphanRemovaltrue)]
  46.     private Collection $photos;
  47.     //Associations bidirectionnelle
  48.     #[ORM\ManyToMany(targetEntityCategorie::class, inversedBy'models'fetch"EAGER")]
  49.     #[ORM\JoinTable(name:'model_categorie')]
  50.     #[ORM\JoinColumn(name'id_model'referencedColumnName'id_model')]
  51.     #[ORM\InverseJoinColumn(name'id_categorie'referencedColumnName'id_categorie')]
  52.     private ?Collection $categories;
  53.     #[ORM\ManyToMany(targetEntitySousCategorie::class, inversedBy'models'fetch"EAGER")]
  54.     #[ORM\JoinTable(name:'model_ss_categorie')]
  55.     #[ORM\JoinColumn(name'id_model'referencedColumnName'id_model')]
  56.     #[ORM\InverseJoinColumn(name'id_sous_categorie'referencedColumnName'id_sous_categorie')]
  57.     private ?Collection $sousCategories;
  58.     #[ORM\ManyToMany(targetEntityTag::class, inversedBy'models'fetch"EAGER"orphanRemovaltrue)]
  59.     #[ORM\JoinTable(name:'model_tag')]
  60.     #[ORM\JoinColumn(name'id_model'referencedColumnName'id_model')]
  61.     #[ORM\InverseJoinColumn(name'id_tag'referencedColumnName'id_tag')]
  62.     private ?Collection $tags;
  63.     #[ORM\ManyToMany(targetEntityPage::class, inversedBy'models'fetch"EAGER")]
  64.     #[ORM\JoinTable(name:'model_page')]
  65.     #[ORM\JoinColumn(name'id_model'referencedColumnName'id_model')]
  66.     #[ORM\InverseJoinColumn(name'id_page'referencedColumnName'id_page')]
  67.     private ?Collection $pages;
  68.     #[ORM\ManyToOne(targetEntityMatiere::class, inversedBy'models')]
  69.     #[ORM\JoinColumn(referencedColumnName'id_matiere'nullablefalse)]
  70.     private ?Matiere $matiere null;
  71.     #[ORM\ManyToOne(targetEntityForme::class, inversedBy'models')]
  72.     #[ORM\JoinColumn(referencedColumnName'id_forme'nullablefalse)]
  73.     private ?Forme $forme null;
  74.     #[ORM\ManyToOne(targetEntityLocalisation::class, inversedBy'models')]
  75.     #[ORM\JoinColumn(referencedColumnName'id_localisation'nullablefalse)]
  76.     private ?Localisation $localisation null;
  77.     #[ORM\ManyToOne(targetEntityTypeCollection::class, inversedBy'models')]
  78.     #[ORM\JoinColumn(referencedColumnName'id_type_collection'nullablefalse)]
  79.     private ?TypeCollection $typeCollection null;
  80.     //Constructeur
  81.     public function __construct()
  82.     {
  83.         $this->photos = new ArrayCollection();
  84.         $this->categories = new ArrayCollection();
  85.         $this->sousCategories = new ArrayCollection();
  86.         $this->tags = new ArrayCollection();
  87.         $this->pages = new ArrayCollection();
  88.     }
  89.     //On génère uniquement un getter pour l'id auto implémenté
  90.     /**
  91.      * @return int|null
  92.      */
  93.     public function getId(): ?int
  94.     {
  95.         return $this->id;
  96.     }
  97.     /**
  98.      * @return Localisation|null
  99.      */
  100.     public function getLocalisation(): ?Localisation
  101.     {
  102.         return $this->localisation;
  103.     }
  104.     /**
  105.      * @param Localisation|null $localisation
  106.      */
  107.     public function setLocalisation(?Localisation $localisation): void
  108.     {
  109.         $this->localisation $localisation;
  110.     }
  111.     /**
  112.      * @return Forme|null
  113.      */
  114.     public function getForme(): ?Forme
  115.     {
  116.         return $this->forme;
  117.     }
  118.     /**
  119.      * @param Forme|null $forme
  120.      */
  121.     public function setForme(?Forme $forme): void
  122.     {
  123.         $this->forme $forme;
  124.     }
  125.     /**
  126.      * @return int|null
  127.      */
  128.     public function getAnnee(): ?int
  129.     {
  130.         return $this->annee;
  131.     }
  132.     /**
  133.      * @param int|null $annee
  134.      */
  135.     public function setAnnee(?int $annee): void
  136.     {
  137.         $this->annee $annee;
  138.     }
  139.     /**
  140.      * @return string|null
  141.      */
  142.     public function getNbExemplaireEdite(): ?string
  143.     {
  144.         return $this->nbExemplaireEdite;
  145.     }
  146.     /**
  147.      * @param string|null $nbExemplaireEdite
  148.      */
  149.     public function setNbExemplaireEdite(?string $nbExemplaireEdite): void
  150.     {
  151.         $this->nbExemplaireEdite $nbExemplaireEdite;
  152.     }
  153.     /**
  154.      * @return string|null
  155.      */
  156.     public function getFournisseur(): ?string
  157.     {
  158.         return $this->fournisseur;
  159.     }
  160.     /**
  161.      * @return string|null
  162.      */
  163.     public function getLocalisationVille(): ?string
  164.     {
  165.         return ($this->localisation)?$this->localisation->getVille():null;
  166.     }
  167.     /**
  168.      * @return string|null
  169.      */
  170.     public function getLocalisationPays(): ?string
  171.     {
  172.         return ($this->localisation)?$this->localisation->getPays():null;
  173.     }
  174.     /**
  175.      * @return string|null
  176.      */
  177.     public function getLocalisationRegion(): ?string
  178.     {
  179.         return ($this->localisation)?$this->localisation->getRegion():null;
  180.     }
  181.     /**
  182.      * @return string|null
  183.      */
  184.     public function getLocalisationDepartement(): ?string
  185.     {
  186.         return ($this->localisation)?$this->localisation->getDepartement():null;
  187.     }
  188.     /**
  189.      * @param string|null $fournisseur
  190.      */
  191.     public function setFournisseur(?string $fournisseur): void
  192.     {
  193.         $this->fournisseur $fournisseur;
  194.     }
  195.     /**
  196.      * @return string|null
  197.      */
  198.     public function getTitre(): ?string
  199.     {
  200.         return $this->titre;
  201.     }
  202.     /**
  203.      * @param string|null $titre
  204.      */
  205.     public function setTitre(?string $titre): void
  206.     {
  207.         $this->titre $titre;
  208.     }
  209.     /**
  210.      * @return string|null
  211.      */
  212.     public function getDescription(): ?string
  213.     {
  214.         return $this->description;
  215.     }
  216.     /**
  217.      * @param string|null $description
  218.      */
  219.     public function setDescription(?string $description): void
  220.     {
  221.         $this->description $description;
  222.     }
  223.     /**
  224.      * @return int|null
  225.      */
  226.     public function getNb(): ?int
  227.     {
  228.         return $this->nb;
  229.     }
  230.     /**
  231.      * @param int|null $nb
  232.      */
  233.     public function setNb(?int $nb): void
  234.     {
  235.         $this->nb $nb;
  236.     }
  237.     /**
  238.      * @return DateTime|null
  239.      */
  240.     public function getDateCreation(): ?DateTime
  241.     {
  242.         return $this->dateCreation;
  243.     }
  244.     /**
  245.      * @param DateTime|null $dateCreation
  246.      */
  247.     public function setDateCreation(?DateTime $dateCreation): void
  248.     {
  249.         $this->dateCreation $dateCreation;
  250.     }
  251.     /**
  252.      * @return DateTime|null
  253.      */
  254.     public function getDateModification(): ?DateTime
  255.     {
  256.         return $this->dateModification;
  257.     }
  258.     /**
  259.      * @param DateTime|null $dateModification
  260.      */
  261.     public function setDateModification(?DateTime $dateModification): void
  262.     {
  263.         $this->dateModification $dateModification;
  264.     }
  265.     /**
  266.      * @return string|null
  267.      */
  268.     public function getDiametre(): ?string
  269.     {
  270.         return $this->diametre;
  271.     }
  272.     /**
  273.      * @param string|null $diametre
  274.      */
  275.     public function setDiametre(?string $diametre): void
  276.     {
  277.         $this->diametre $diametre;
  278.     }
  279.     /**
  280.      * @return string|null
  281.      */
  282.     public function getReference(): ?string
  283.     {
  284.         return $this->reference;
  285.     }
  286.     /**
  287.      * @param string|null $reference
  288.      */
  289.     public function setReference(?string $reference): void
  290.     {
  291.         $this->reference $reference;
  292.     }
  293.     /**
  294.      * @return Matiere|null
  295.      */
  296.     public function getMatiere(): ?Matiere
  297.     {
  298.         return $this->matiere;
  299.     }
  300.     /**
  301.      * @param Matiere|null $matiere
  302.      */
  303.     public function setMatiere(?Matiere $matiere): void
  304.     {
  305.         $this->matiere $matiere;
  306.     }
  307.     //Getter et Setter associations
  308.     /**
  309.      * @return Collection<int, Tag>
  310.      */
  311.     public function getTags(): Collection
  312.     {
  313.         return $this->tags;
  314.     }
  315.     public function addTag(?Tag $tag): self
  316.     {
  317.         if (!$this->tags->contains($tag)) {
  318.             $this->tags->add($tag);
  319.             $tag->addModel($this);
  320.         }
  321.         return $this;
  322.     }
  323.     public function removeTag(?Tag $tag): self
  324.     {
  325.         if ($this->tags->removeElement($tag)) {
  326.             // set the owning side to null (unless already changed)
  327.             if ($tag->getModels() === $this) {
  328.                 $tag->removeModel($this) ;
  329.             }
  330.         }
  331.         return $this;
  332.     }
  333.     /**
  334.      * @return Collection<int, Photo>
  335.      */
  336.     public function getPhotos(): Collection
  337.     {
  338.         return $this->photos;
  339.     }
  340.     public function addPhoto(Photo $photo): self
  341.     {
  342.         if (!$this->photos->contains($photo)) {
  343.             $this->photos->add($photo);
  344.             $photo->addModel($this);
  345.         }
  346.         return $this;
  347.     }
  348.     public function removePhoto(Photo $photo): self
  349.     {
  350.         if ($this->photos->removeElement($photo)) {
  351.             // set the owning side to null (unless already changed)
  352.             if ($photo->getModel() === $this) {
  353.                 $photo->setModel(null);
  354.             }
  355.         }
  356.         return $this;
  357.     }
  358.     /**
  359.      * @return Collection<int, Categorie>
  360.      */
  361.     public function getCategories(): Collection
  362.     {
  363.         return $this->categories;
  364.     }
  365.     public function addCategorie(?Categorie $categorie): self
  366.     {
  367.         if (!is_null($categorie) && !$this->categories->contains($categorie)) {
  368.             $this->categories->add($categorie);
  369.             $categorie->addModel($this);
  370.         }
  371.         return $this;
  372.     }
  373.     public function removeCategorie(?Categorie $categorie): self
  374.     {
  375.         if ($this->categories->removeElement($categorie)) {
  376.             // set the owning side to null (unless already changed)
  377.             if ($categorie->getModels() === $this) {
  378.                 $categorie->removeModel(null);
  379.             }
  380.         }
  381.         return $this;
  382.     }
  383.     public function setCategories(?Collection $categories): void
  384.     {
  385.         // Remove associations with current categories
  386.         foreach ($this->categories as $existingCategory) {
  387.             if (!$categories || !$categories->contains($existingCategory)) {
  388.                 $this->removeCategorie($existingCategory);
  389.             }
  390.         }
  391.         // Add associations with new categories
  392.         if ($categories) {
  393.             foreach ($categories as $newCategory) {
  394.                 $this->addCategorie($newCategory);
  395.             }
  396.         }
  397.     }
  398.     /**
  399.      * @return Collection<int, SousCategorie>
  400.      */
  401.     public function getSousCategories(): Collection
  402.     {
  403.         return $this->sousCategories;
  404.     }
  405.     public function addSousCategorie(?SousCategorie $sousCategorie): self
  406.     {
  407.         if (!is_null($sousCategorie) && !$this->sousCategories->contains($sousCategorie)) {
  408.             $this->sousCategories->add($sousCategorie);
  409.             $sousCategorie->addModel($this);
  410.         }
  411.         return $this;
  412.     }
  413.     public function removeSousCategorie(?SousCategorie $sousCategorie): self
  414.     {
  415.         if ($this->sousCategories->removeElement($sousCategorie)) {
  416.             // set the owning side to null (unless already changed)
  417.             if ($sousCategorie->getModels() === $this) {
  418.                 $sousCategorie->removeModel(null);
  419.             }
  420.         }
  421.         return $this;
  422.     }
  423.     public function setSousCategories(Collection $sousCategories): self
  424.     {
  425.         // Dissocier le modèle actuel de toutes les sous-catégories existantes
  426.         foreach ($this->sousCategories as $sousCategorie) {
  427.             if (!$sousCategories->contains($sousCategorie)) {
  428.                 $this->removeSousCategorie($sousCategorie);
  429.             }
  430.         }
  431.         // Associer le modèle aux nouvelles sous-catégories et vice versa
  432.         foreach ($sousCategories as $sousCategorie) {
  433.             $this->addSousCategorie($sousCategorie);
  434.         }
  435.         return $this;
  436.     }
  437.     /**
  438.      * @return Collection<string, Page>
  439.      */
  440.     public function getPages(): Collection
  441.     {
  442.         return $this->pages;
  443.     }
  444.     public function addPage(Page $page): self
  445.     {
  446.         if (!$this->pages->contains($page)) {
  447.             $this->pages->add($page);
  448.             $page->addModel($this);
  449.         }
  450.         return $this;
  451.     }
  452.     public function removePage(Page $page): self
  453.     {
  454.         if ($this->pages->removeElement($page)) {
  455.             // set the owning side to null (unless already changed)
  456.             if ($page->getModels() === $this) {
  457.                 $page->addModel(null);
  458.             }
  459.         }
  460.         return $this;
  461.     }
  462.     /**
  463.      * @return int|null
  464.      */
  465.     public function getPageNumero(): ?int
  466.     {
  467.         $page $this->pages->first();
  468.         if ($page){
  469.             return $page->getNumero();
  470.         }
  471.         return null;
  472.     }
  473.     public function getTypeCollection(): ?TypeCollection
  474.     {
  475.         return $this->typeCollection;
  476.     }
  477.     public function setTypeCollection(?TypeCollection $typeCollection): self
  478.     {
  479.         $this->typeCollection $typeCollection;
  480.         return $this;
  481.     }
  482.     public function getTagsText() {
  483.         return join(', '$this->tags->toArray());
  484.     }
  485.     /*Model emplacement traitement*/
  486.     /**
  487.      * @return Armoire|null
  488.      */
  489.     public function getArmoireNom(): ?Armoire
  490.     {
  491.         $page $this->pages->first(); // Récupère la première page associée au modèle
  492.         if ($page) {
  493.             $classeur $page->getClasseur(); // Récupère le classeur associé à la page
  494.             if ($classeur) {
  495.                 $armoire $classeur->getArmoire(); // Récupère l'armoire associée au classeur
  496.                 return $armoire;
  497.             }
  498.         }
  499.         return null;
  500.     }
  501.          /**
  502.          * @return Etagere|null
  503.          */
  504.     public function getEtagereNom(): ?Etagere
  505.     {
  506.         $page $this->pages->first(); // Récupère la première page associée au modèle
  507.         if ($page) {
  508.             $classeur $page->getClasseur(); // Récupère le classeur associé à la page
  509.             if ($classeur) {
  510.                 $etagere $classeur->getEtagere(); // Récupère l'armoire associée au classeur
  511.                 return $etagere;
  512.             }
  513.         }
  514.         return null;
  515.     }
  516.         /**
  517.          * @return Classeur|null
  518.          */
  519.     public function getClasseurNom(): ?Classeur
  520.     {
  521.         $page $this->pages->first(); // Récupère la première page associée au modèle
  522.         if ($page) {
  523.             $classeur $page->getClasseur(); // Récupère le classeur associé à la page
  524.             return $classeur;
  525.         }
  526.         return null;
  527.     }
  528.     /**
  529.      * @param Classeur $classeur
  530.      */
  531.     public function setClasseur(Classeur $classeur)
  532.     {
  533.         $page $this->getPages()->first();
  534.         if ($page) {
  535.             $page->setClasseur($classeur);
  536.         }
  537.     }
  538. }