src/Entity/Mantenimiento/DiagramaTarea.php line 19

Open in your IDE?
  1. <?php
  2. namespace App\Entity\Mantenimiento;
  3. use App\Repository\Mantenimiento\DiagramaTareaRepository;
  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  App\Entity\RRHH\Empleado;
  9. use  App\Entity\User;
  10. use Symfony\Component\Validator\Constraints as Assert;
  11. use Doctrine\Common\Collections\Criteria;
  12. /**
  13.  * @ORM\Entity(repositoryClass=DiagramaTareaRepository::class)
  14.  * @ORM\HasLifecycleCallbacks()
  15.  */
  16. class DiagramaTarea
  17. {
  18.     /**
  19.      * @ORM\Id
  20.      * @ORM\GeneratedValue
  21.      * @ORM\Column(type="integer")
  22.      */
  23.     private $id;
  24.     /**
  25.      * @ORM\Column(type="date", nullable=true)
  26.      */
  27.     private $fecha;
  28.     /**
  29.      * @ORM\Column(name="fecha_diagrama", type="datetime")
  30.      */
  31.     private $fechaDiagramacion
  32.     /**
  33.      * @ORM\Column(type="boolean")
  34.      */
  35.     private $procesado false;
  36.     /**
  37.      * @ORM\OneToMany(targetEntity=PedidoReparacionDiagramado::class, mappedBy="diagrama", cascade={"persist", "remove"})
  38.      */
  39.     private $tareas;
  40.     /**
  41.      * @ORM\ManyToMany(targetEntity=Empleado::class)
  42.      * @ORM\JoinTable(name="resp_por_diag_tarea",
  43.      *      joinColumns={@ORM\JoinColumn(name="id_diagrama", referencedColumnName="id")},
  44.      *      inverseJoinColumns={@ORM\JoinColumn(name="id_empleado", referencedColumnName="id")}
  45.      *      )
  46.      */
  47.     private $responsables;
  48.  
  49.     /**
  50.      * @ORM\ManyToOne(targetEntity=Departamento::class)
  51.      * @ORM\JoinColumn(name="id_depto", referencedColumnName="id", nullable=true)
  52.      * @Assert\NotNull(message="El campo es requerido")
  53.      */
  54.     private $departamento;
  55.     /**
  56.      * @ORM\ManyToOne(targetEntity=User::class)
  57.      * @ORM\JoinColumn(name="id_user_alta", referencedColumnName="id", nullable=true)
  58.      */
  59.     private $responsableDiagramacion;
  60.     public function __construct()
  61.     {
  62.         $this->responsables = new ArrayCollection();
  63.         $this->tareas = new ArrayCollection();
  64.     }
  65.     public function getListaEquipos()
  66.     {
  67.         $equipos = array();
  68.         foreach ($this->tareas as $tarea)
  69.         {
  70.             $eq $tarea->getEquipo();
  71.             if ($eq)
  72.             {
  73.                 $equipos[$eq->getId()] = $eq;
  74.             }
  75.         }
  76.         return implode(' // '$equipos);
  77.     }
  78.     public function getEmpleados()
  79.     {
  80.         $emples "";
  81.         foreach ($this->responsables as $resp)
  82.         {
  83.             if ($emples)
  84.             {
  85.                 $emples.= ' - ';
  86.             }
  87.             $emples.= $resp;
  88.         }
  89.         return $emples;
  90.     }
  91.     /**
  92.      * @ORM\PrePersist
  93.      */
  94.     public function setCreatedAtValue()
  95.     {
  96.         $this->fechaDiagramacion = new \DateTimeImmutable();
  97.     }
  98.     public function getId(): ?int
  99.     {
  100.         return $this->id;
  101.     }
  102.     public function getFecha(): ?\DateTimeInterface
  103.     {
  104.         return $this->fecha;
  105.     }
  106.     public function setFecha(?\DateTimeInterface $fecha): self
  107.     {
  108.         $this->fecha $fecha;
  109.         return $this;
  110.     }
  111.     public function getFechaDiagramacion(): ?\DateTimeInterface
  112.     {
  113.         return $this->fechaDiagramacion;
  114.     }
  115.     public function setFechaDiagramacion(\DateTimeInterface $fechaDiagramacion): self
  116.     {
  117.         $this->fechaDiagramacion $fechaDiagramacion;
  118.         return $this;
  119.     }
  120.     /**
  121.      * @return Collection<int, Empleado>
  122.      */
  123.     public function getResponsables(): Collection
  124.     {
  125.         return $this->responsables;
  126.     }
  127.     public function addResponsable(Empleado $responsable): self
  128.     {
  129.         if (!$this->responsables->contains($responsable)) {
  130.             $this->responsables[] = $responsable;
  131.         }
  132.         return $this;
  133.     }
  134.     public function removeResponsable(Empleado $responsable): self
  135.     {
  136.         $this->responsables->removeElement($responsable);
  137.         return $this;
  138.     }
  139.     public function getResponsableDiagramacion(): ?User
  140.     {
  141.         return $this->responsableDiagramacion;
  142.     }
  143.     public function setResponsableDiagramacion(?User $responsableDiagramacion): self
  144.     {
  145.         $this->responsableDiagramacion $responsableDiagramacion;
  146.         return $this;
  147.     }
  148.     public function isProcesado(): ?bool
  149.     {
  150.         return $this->procesado;
  151.     }
  152.     public function setProcesado(bool $procesado): self
  153.     {
  154.         $this->procesado $procesado;
  155.         return $this;
  156.     }
  157.     /**
  158.      * @return Collection<int, PedidoReparacionDiagramado>
  159.      */
  160.     public function getTareas(): Collection
  161.     {
  162. // Usamos filter() en lugar de matching()
  163.         return $this->tareas->filter(function(PedidoReparacionDiagramado $prd) {
  164.             $pedido $prd->getPedido();
  165.             
  166.             // Retornamos true si el pedido existe y no está eliminado
  167.             return $pedido !== null && $pedido->isEliminada() === false;
  168.         });
  169.         // return $this->tareas; // Ya no es necesario, usamos filter()
  170.     }
  171.     public function addTarea(PedidoReparacionDiagramado $tarea): self
  172.     {
  173.         if (!$this->tareas->contains($tarea)) {
  174.             $this->tareas[] = $tarea;
  175.             $tarea->setDiagrama($this);
  176.         }
  177.         return $this;
  178.     }
  179.     public function removeTarea(PedidoReparacionDiagramado $tarea): self
  180.     {
  181.         if ($this->tareas->removeElement($tarea)) {
  182.             // set the owning side to null (unless already changed)
  183.             if ($tarea->getDiagrama() === $this) {
  184.                 $tarea->setDiagrama(null);
  185.             }
  186.         }
  187.         return $this;
  188.     }
  189.     public function getDepartamento(): ?Departamento
  190.     {
  191.         return $this->departamento;
  192.     }
  193.     public function setDepartamento(?Departamento $departamento): self
  194.     {
  195.         $this->departamento $departamento;
  196.         return $this;
  197.     }
  198. }