<?php
namespace App\Entity\Mantenimiento;
use App\Repository\Mantenimiento\DiagramaTareaRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
use App\Entity\RRHH\Empleado;
use App\Entity\User;
use Symfony\Component\Validator\Constraints as Assert;
/**
* @ORM\Entity(repositoryClass=DiagramaTareaRepository::class)
* @ORM\HasLifecycleCallbacks()
*/
class DiagramaTarea
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="date", nullable=true)
*/
private $fecha;
/**
* @ORM\Column(name="fecha_diagrama", type="datetime")
*/
private $fechaDiagramacion;
/**
* @ORM\Column(type="boolean")
*/
private $procesado = false;
/**
* @ORM\OneToMany(targetEntity=PedidoReparacionDiagramado::class, mappedBy="diagrama", cascade={"persist", "remove"})
*/
private $tareas;
/**
* @ORM\ManyToMany(targetEntity=Empleado::class)
* @ORM\JoinTable(name="resp_por_diag_tarea",
* joinColumns={@ORM\JoinColumn(name="id_diagrama", referencedColumnName="id")},
* inverseJoinColumns={@ORM\JoinColumn(name="id_empleado", referencedColumnName="id")}
* )
*/
private $responsables;
/**
* @ORM\ManyToOne(targetEntity=Departamento::class)
* @ORM\JoinColumn(name="id_depto", referencedColumnName="id", nullable=true)
* @Assert\NotNull(message="El campo es requerido")
*/
private $departamento;
/**
* @ORM\ManyToOne(targetEntity=User::class)
* @ORM\JoinColumn(name="id_user_alta", referencedColumnName="id", nullable=true)
*/
private $responsableDiagramacion;
public function __construct()
{
$this->responsables = new ArrayCollection();
$this->tareas = new ArrayCollection();
}
public function getListaEquipos()
{
$equipos = array();
foreach ($this->tareas as $tarea)
{
$eq = $tarea->getEquipo();
if ($eq)
{
$equipos[$eq->getId()] = $eq;
}
}
return implode(' // ', $equipos);
}
public function getEmpleados()
{
$emples = "";
foreach ($this->responsables as $resp)
{
if ($emples)
{
$emples.= ' - ';
}
$emples.= $resp;
}
return $emples;
}
/**
* @ORM\PrePersist
*/
public function setCreatedAtValue()
{
$this->fechaDiagramacion = new \DateTimeImmutable();
}
public function getId(): ?int
{
return $this->id;
}
public function getFecha(): ?\DateTimeInterface
{
return $this->fecha;
}
public function setFecha(?\DateTimeInterface $fecha): self
{
$this->fecha = $fecha;
return $this;
}
public function getFechaDiagramacion(): ?\DateTimeInterface
{
return $this->fechaDiagramacion;
}
public function setFechaDiagramacion(\DateTimeInterface $fechaDiagramacion): self
{
$this->fechaDiagramacion = $fechaDiagramacion;
return $this;
}
/**
* @return Collection<int, Empleado>
*/
public function getResponsables(): Collection
{
return $this->responsables;
}
public function addResponsable(Empleado $responsable): self
{
if (!$this->responsables->contains($responsable)) {
$this->responsables[] = $responsable;
}
return $this;
}
public function removeResponsable(Empleado $responsable): self
{
$this->responsables->removeElement($responsable);
return $this;
}
public function getResponsableDiagramacion(): ?User
{
return $this->responsableDiagramacion;
}
public function setResponsableDiagramacion(?User $responsableDiagramacion): self
{
$this->responsableDiagramacion = $responsableDiagramacion;
return $this;
}
public function isProcesado(): ?bool
{
return $this->procesado;
}
public function setProcesado(bool $procesado): self
{
$this->procesado = $procesado;
return $this;
}
/**
* @return Collection<int, PedidoReparacionDiagramado>
*/
public function getTareas(): Collection
{
return $this->tareas;
}
public function addTarea(PedidoReparacionDiagramado $tarea): self
{
if (!$this->tareas->contains($tarea)) {
$this->tareas[] = $tarea;
$tarea->setDiagrama($this);
}
return $this;
}
public function removeTarea(PedidoReparacionDiagramado $tarea): self
{
if ($this->tareas->removeElement($tarea)) {
// set the owning side to null (unless already changed)
if ($tarea->getDiagrama() === $this) {
$tarea->setDiagrama(null);
}
}
return $this;
}
public function getDepartamento(): ?Departamento
{
return $this->departamento;
}
public function setDepartamento(?Departamento $departamento): self
{
$this->departamento = $departamento;
return $this;
}
}