← Back
Editing: Controle.php
<?php namespace App\Entity; use App\Contract\PersistableUserInterface; use App\Repository\ControleRepository; use App\Solution\Annotation\SolutionAware; use App\Solution\SolutionTrait; use App\Validator as CustomAssert; use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\Collection; use Doctrine\Common\Collections\Criteria; use Doctrine\ORM\Mapping as ORM; use Symfony\Component\Serializer\Annotation\Groups; use Symfony\Component\Validator\Constraints as Assert; /** * @SolutionAware(solutionFieldName="solution_id") */ #[ORM\Table(name: 'controle')] #[ORM\Index(columns: ['agent_id'], name: 'IDX_E39396E36F5263E')] #[ORM\Index(columns: ['adresse_id'], name: 'IDX_E39396E4DE7DC5C')] #[ORM\Index(columns: ['valide'], name: 'valid')] #[ORM\Index(columns: ['date_realisation'], name: 'dateDone')] #[ORM\Index(columns: ['date_realisation', 'valide'], name: 'dateDoneValid')] #[ORM\Entity(repositoryClass: ControleRepository::class)] #[CustomAssert\ControlTimer] class Controle { use SolutionTrait; #[ORM\Column(name: 'id', type: 'integer', nullable: false)] #[ORM\Id] #[ORM\GeneratedValue(strategy: 'IDENTITY')] #[Groups(['show_control'])] private ?int $id = null; #[ORM\Column(name: 'date_realisation', type: 'datetime', nullable: true)] #[Groups(['show_control', 'show_user'])] private ?\DateTimeInterface $dateRealisation = null; #[ORM\Column(name: 'valide', type: 'boolean', nullable: false)] #[Assert\Type(type: 'bool')] #[Groups(['show_control'])] private bool $valide = false; #[ORM\Column(name: 'commentaire_general', type: 'text', length: 0, nullable: true)] #[Groups(['show_control'])] private ?string $commentaireGeneral = null; /** * @deprecated use $alerts instead */ #[ORM\Column(name: 'alerte_prestataire', type: 'boolean', nullable: false)] #[Assert\Type(type: 'bool')] private bool $alertePrestataire = false; /** * @var ?User */ #[ORM\JoinColumn(name: 'agent_id', referencedColumnName: 'id', nullable: true, onDelete: 'SET NULL')] #[ORM\ManyToOne(targetEntity: 'User', inversedBy: 'controles')] private ?PersistableUserInterface $agent = null; #[ORM\JoinColumn(name: 'adresse_id', referencedColumnName: 'id', nullable: true, onDelete: 'CASCADE')] #[ORM\ManyToOne(targetEntity: 'Adresse', inversedBy: 'controles')] private ?Adresse $adresse = null; /** * @var Collection<array-key, Note> */ #[ORM\OneToMany(mappedBy: 'controle', targetEntity: 'Note', cascade: ['persist', 'remove'])] private Collection $notes; /** * @var Collection<array-key, HistoriqueAlerte> */ #[ORM\OneToMany(mappedBy: 'controle', targetEntity: HistoriqueAlerte::class)] private Collection $alertes; #[ORM\OneToOne(mappedBy: 'controle', targetEntity: Service::class, cascade: ['persist', 'remove'])] private ?Service $service = null; #[ORM\Column(name: 'is_contradictory', type: 'boolean', options: ['default' => 0])] #[Groups(['show_control'])] private bool $isContradictory = false; #[ORM\Column(type: 'string', nullable: true)] private ?string $contradictoryPerson = null; #[ORM\Column(type: 'string', length: 255, nullable: true)] private ?string $contradictoryPersonDetail = null; #[ORM\Column(type: 'datetime', nullable: true)] private ?\DateTimeInterface $createdAt; #[ORM\Column(type: 'float', nullable: true)] private ?float $averageNote = null; private ?bool $receiveReport = null; private ?bool $sendToManager = null; /** * Constructor. */ public function __construct() { $this->notes = new ArrayCollection(); $this->alertes = new ArrayCollection(); $this->createdAt = new \DateTime(); } public function getId(): ?int { return $this->id; } public function getDateRealisation(): ?\DateTimeInterface { return $this->dateRealisation; } /** * @return $this */ public function setDateRealisation(?\DateTimeInterface $dateRealisation): self { $this->dateRealisation = $dateRealisation; return $this; } public function getValide(): ?bool { return $this->valide; } /** * @return $this */ public function setValide(bool $valide): self { $this->valide = $valide; return $this; } /** * @deprecated use getAlerts instead */ public function getAlertePrestataire(): ?bool { return $this->alertePrestataire; } /** * @deprecated use addAlert instead */ public function setAlertePrestataire(bool $alertePrestataire): self { $this->alertePrestataire = $alertePrestataire; return $this; } public function getCommentaireGeneral(): ?string { return $this->commentaireGeneral; } public function setCommentaireGeneral(string $commentaireGeneral): self { $this->commentaireGeneral = $commentaireGeneral; return $this; } public function getAgent(): ?User { return $this->agent; } /** * @return $this */ public function setAgent(?User $agent): self { $this->agent = $agent; return $this; } public function getAdresse(): ?Adresse { return $this->adresse; } /** * @return $this */ public function setAdresse(?Adresse $adresse): self { $this->adresse = $adresse; return $this; } /** * @return Collection<array-key, Note>|null */ public function getNotes(): ?Collection { return $this->notes; } public function addNote(Note $note): self { if (!$this->notes->contains($note)) { $this->notes[] = $note; } return $this; } public function removeNote(Note $note): self { if ($this->notes->contains($note)) { $this->notes->removeElement($note); } return $this; } public function hasNote(Item $item): bool { foreach ($this->getNotes() as $note) { if ($note->getItem()->getId() === $item->getId()) { return true; } } return false; } /** * @return Collection<array-key, HistoriqueAlerte> */ public function getAlertes(): Collection { return $this->alertes; } /** * @return $this */ public function addAlerte(HistoriqueAlerte $alerte): self { if (!$this->alertes->contains($alerte)) { $this->alertes[] = $alerte; $alerte->setControle($this); } return $this; } /** * @return float|int */ public function getNoteAverage() { $items = 0; $sum = 0; foreach ($this->getNotes() as $note) { $sum += $note->getNote(); ++$items; } if ($items > 0) { return $sum / $items; } return 0; } public function getService(): ?Service { return $this->service; } public function setService(Service $service): self { // set the owning side of the relation if necessary if ($service->getControle() !== $this) { $service->setControle($this); } $this->service = $service; return $this; } public function getIsContradictory(): ?bool { return $this->isContradictory; } public function setIsContradictory(bool $isContradictory): self { $this->isContradictory = $isContradictory; return $this; } public function getContradictoryPerson(): ?string { return $this->contradictoryPerson; } public function setContradictoryPerson(?string $contradictoryPerson): self { $this->contradictoryPerson = $contradictoryPerson; return $this; } public function getContradictoryPersonDetail(): ?string { return $this->contradictoryPersonDetail; } /** * @return $this */ public function setContradictoryPersonDetail(?string $contradictoryPersonDetail): self { $this->contradictoryPersonDetail = $contradictoryPersonDetail; return $this; } public function getCreatedAt(): ?\DateTimeInterface { return $this->createdAt; } /** * @return $this */ public function setCreatedAt(?\DateTimeInterface $createdAt): self { $this->createdAt = $createdAt; return $this; } public function getAlertNotes(int $maxNote = 3) { $criteria = Criteria::create(); $criteria->andWhere(Criteria::expr()->lte('note', $maxNote)); return $this->notes->matching($criteria); } public function getAverageNote(): ?float { return $this->averageNote; } public function setAverageNote(?float $averageNote): self { $this->averageNote = $averageNote; return $this; } public function isValide(): ?bool { return $this->valide; } public function isAlertePrestataire(): ?bool { return $this->alertePrestataire; } public function isIsContradictory(): ?bool { return $this->isContradictory; } public function removeAlerte(HistoriqueAlerte $alerte): self { if ($this->alertes->removeElement($alerte)) { // set the owning side to null (unless already changed) if ($alerte->getControle() === $this) { $alerte->setControle(null); } } return $this; } public function getReceiveReport(): ?bool { return $this->receiveReport; } public function setReceiveReport(?bool $receiveReport): self { $this->receiveReport = $receiveReport; return $this; } public function getSendToManager(): ?bool { return $this->sendToManager; } public function setSendToManager(?bool $sendToManager): self { $this->sendToManager = $sendToManager; return $this; } }
Save File
Cancel