<?php
namespace App\Entity;
use App\Repository\VariablesGroupRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity(repositoryClass: VariablesGroupRepository::class)]
class VariablesGroup
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
private ?int $id = null;
#[ORM\Column(length: 255)]
private ?string $label = null;
#[ORM\Column(type: Types::DATETIME_MUTABLE)]
private ?\DateTimeInterface $date_creation = null;
#[ORM\Column(type: Types::INTEGER, options: ['default' => 1])]
private int $etat = 1;
#[ORM\Column(type: Types::BOOLEAN, nullable: true)]
private ?bool $contact = null;
#[ORM\Column(type: Types::BOOLEAN, nullable: true)]
private ?bool $objet = null;
#[ORM\OneToMany(mappedBy: 'variable_group', targetEntity: Variable::class, cascade: ['remove', 'persist'])]
private Collection $variables;
#[ORM\OneToMany(mappedBy: 'attributGroupe', targetEntity: AttributGroupeLiaison::class, cascade: ['remove', 'persist'])]
#[ORM\OrderBy(['colonne' => 'ASC', 'ordre' => 'ASC'])]
private Collection $attributGroupeLiaisons;
#[ORM\Column(nullable: true)]
private ?bool $societe = null;
#[ORM\Column(nullable: true)]
private ?bool $utilisateur = null;
#[ORM\ManyToOne(inversedBy: 'variablesGroups')]
private ?Document $document = null;
#[ORM\Column(type: Types::TEXT, nullable: true)]
private ?string $icone = null;
#[ORM\Column(type: Types::BOOLEAN, options: ['default' => false])]
private bool $actif_fiche = false;
#[ORM\Column(type: Types::BOOLEAN, options: ['default' => false])]
private bool $actif_liste = false;
public function __construct()
{
$this->variables = new ArrayCollection();
$this->attributGroupeLiaisons = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getLabel(): ?string
{
return $this->label;
}
public function setLabel(string $label): static
{
$this->label = $label;
return $this;
}
public function getColonne(): int
{
if ($this->societe || $this->utilisateur || $this->document) {
return 1;
}
if (!$this->attributGroupeLiaisons->isEmpty()) {
$firstLiaison = $this->attributGroupeLiaisons->first();
return $firstLiaison->getColonne() ?? 1;
}
return 1;
}
public function getDateCreation(): ?\DateTimeInterface
{
return $this->date_creation;
}
public function setDateCreation(\DateTimeInterface $date_creation): static
{
$this->date_creation = $date_creation;
return $this;
}
public function getVariables(): Collection
{
return $this->variables;
}
public function addVariable(Variable $variable): static
{
if (!$this->variables->contains($variable)) {
$this->variables->add($variable);
$variable->setVariableGroup($this);
}
return $this;
}
public function removeVariable(Variable $variable): static
{
if ($this->variables->removeElement($variable)) {
if ($variable->getVariableGroup() === $this) {
$variable->setVariableGroup(null);
}
}
return $this;
}
public function getAttributGroupeLiaisons(): Collection
{
return $this->attributGroupeLiaisons;
}
public function addAttributGroupeLiaison(AttributGroupeLiaison $attributGroupeLiaison): static
{
if (!$this->attributGroupeLiaisons->contains($attributGroupeLiaison)) {
$this->attributGroupeLiaisons->add($attributGroupeLiaison);
$attributGroupeLiaison->setAttributGroupe($this);
}
return $this;
}
public function removeAttributGroupeLiaison(AttributGroupeLiaison $attributGroupeLiaison): static
{
if ($this->attributGroupeLiaisons->removeElement($attributGroupeLiaison)) {
if ($attributGroupeLiaison->getAttributGroupe() === $this) {
$attributGroupeLiaison->setAttributGroupe(null);
}
}
return $this;
}
public function getContactTypes(): Collection
{
$contactTypes = new ArrayCollection();
foreach ($this->attributGroupeLiaisons as $liaison) {
if ($liaison->getContactType() !== null) {
$contactTypes->add($liaison->getContactType());
}
}
return $contactTypes;
}
public function getObjetTypes(): Collection
{
$objetTypes = new ArrayCollection();
foreach ($this->attributGroupeLiaisons as $liaison) {
if ($liaison->getObjetType() !== null) {
$objetTypes->add($liaison->getObjetType());
}
}
return $objetTypes;
}
public function getContactGroup(): Collection
{
return $this->getContactTypes();
}
public function getObjetGroup(): Collection
{
return $this->getObjetTypes();
}
public function isSociete(): ?bool
{
return $this->societe;
}
public function setSociete(?bool $societe): static
{
$this->societe = $societe;
return $this;
}
public function isUtilisateur(): ?bool
{
return $this->utilisateur;
}
public function setUtilisateur(?bool $utilisateur): static
{
$this->utilisateur = $utilisateur;
return $this;
}
public function getDocument(): ?Document
{
return $this->document;
}
public function setDocument(?Document $document): static
{
$this->document = $document;
return $this;
}
public function getEtat(): int
{
return $this->etat;
}
public function setEtat(int $etat): static
{
$this->etat = $etat;
return $this;
}
public function isContact(): ?bool
{
return $this->contact;
}
public function setContact(?bool $contact): static
{
$this->contact = $contact;
return $this;
}
public function isObjet(): ?bool
{
return $this->objet;
}
public function setObjet(?bool $objet): static
{
$this->objet = $objet;
return $this;
}
public function getIcone(): ?string
{
return $this->icone;
}
public function setIcone(?string $icone): static
{
$this->icone = $icone ? trim($icone) : null;
return $this;
}
public function isActifFiche(): bool
{
return $this->actif_fiche;
}
public function setActifFiche(bool $actif_fiche): static
{
$this->actif_fiche = $actif_fiche;
return $this;
}
public function isActifListe(): bool
{
return $this->actif_liste;
}
public function setActifListe(bool $actif_liste): static
{
$this->actif_liste = $actif_liste;
return $this;
}
}