src/Entity/Mantenimiento/Preventivo/PlanMantenimiento.php line 24

Open in your IDE?
  1. <?php
  2. namespace App\Entity\Mantenimiento\Preventivo;
  3. use App\Repository\Mantenimiento\Preventivo\PlanMantenimientoRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use App\Entity\Equipos\Maquinaria as Equipo;
  8. use Symfony\Component\Validator\Constraints as Assert;
  9. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  10. use App\Entity\Mantenimiento\SectorPlanta;
  11. /**
  12.  * @ORM\Entity(repositoryClass=PlanMantenimientoRepository::class)
  13.  * @ORM\Table(name="mant_prev_planes_mant")
  14.  * @UniqueEntity(
  15.  *     fields={"nombre"},
  16.  *     errorPath="nombre",
  17.  *     message="Ya existe una plan con el nombre ingresado"
  18.  * )
  19.  */
  20. class PlanMantenimiento
  21. {
  22.     /**
  23.      * @ORM\Id
  24.      * @ORM\GeneratedValue
  25.      * @ORM\Column(type="integer")
  26.      */
  27.     private $id;
  28.     /**
  29.      * @ORM\Column(type="integer")
  30.      * @Assert\NotNull(message="El campo es requerido")
  31.      */
  32.     private $periodicidad;
  33.     /**
  34.      * @ORM\Column(type="string", length=255)
  35.      * @Assert\NotNull(message="El campo es requerido")
  36.      */
  37.     private $nombre;
  38.     /**
  39.      * @ORM\Column(type="boolean")
  40.      */
  41.     private $activo = true;
  42.     /**
  43.      * @ORM\ManyToOne(targetEntity=SectorPlanta::class)
  44.      * @ORM\JoinColumn(name="id_sector", referencedColumnName="id", nullable=true)
  45.      */
  46.     private $sector;
  47.     /**
  48.      * @ORM\OneToMany(targetEntity=TareaPlan::class, mappedBy="planMantenimiento", cascade={"persist", "remove"})
  49.      */
  50.     private $tareas;
  51.     /**
  52.      * @ORM\OneToMany(targetEntity=PlanMantenimientoDiagramado::class, mappedBy="planMantenimiento", cascade={"persist", "remove"})
  53.      */
  54.     private $planesDiagramados;
  55.     /**
  56.      * @ORM\ManyToMany(targetEntity=Equipo::class)
  57.      * @ORM\JoinTable(name="mant_prev_equipos_planes_mant",
  58.      *      joinColumns={@ORM\JoinColumn(name="id_plan", referencedColumnName="id")},
  59.      *      inverseJoinColumns={@ORM\JoinColumn(name="id_equipo", referencedColumnName="id")}
  60.      *      )
  61.      */
  62.     private $equipos;
  63.     public function getFrecuenciaPlan(): string
  64.     {
  65.         $frecuencia = "";
  66.         if ($this->periodicidad == 1)
  67.         {
  68.             $frecuencia = "Diaria";
  69.         }
  70.         else if ($this->periodicidad == 7)
  71.         {
  72.             $frecuencia = "Semanal";
  73.         }
  74.         else if ($this->periodicidad == 30)
  75.         {
  76.             $frecuencia = "Mensual";
  77.         }
  78.         else if ($this->periodicidad == 365)
  79.         {
  80.             $frecuencia = "Anual";
  81.         }
  82.         else if ($this->periodicidad == 180)
  83.         {
  84.             $frecuencia = "Semestral";
  85.         }
  86.         else if ($this->periodicidad == 90)
  87.         {
  88.             $frecuencia = "Trimestral";
  89.         }
  90.         else if ($this->periodicidad == 15)
  91.         {
  92.             $frecuencia = "Quincenal";
  93.         }
  94.         else if ($this->periodicidad == 60)
  95.         {
  96.             $frecuencia = "Bimestral";
  97.         }
  98.         else
  99.         {
  100.             $frecuencia = "Unica";
  101.         }
  102.         return $frecuencia;
  103.     }
  104.     public function getEquiposAfectados()
  105.     {
  106.         $equipos = null;
  107.         foreach ($this->equipos as $e) 
  108.         {
  109.             if ($equipos)
  110.             {
  111.                 $equipos.= " - $e";
  112.             }
  113.             else
  114.             {
  115.                 $equipos = $e;
  116.             }
  117.         }
  118.         return $equipos;
  119.     }
  120.     public function __construct()
  121.     {
  122.         $this->tareas = new ArrayCollection();
  123.         $this->equipos = new ArrayCollection();
  124.         $this->planesDiagramados = new ArrayCollection();
  125.     }
  126.     public function getId(): ?int
  127.     {
  128.         return $this->id;
  129.     }
  130.     public function getPeriodicidad(): ?int
  131.     {
  132.         return $this->periodicidad;
  133.     }
  134.     public function setPeriodicidad(int $periodicidad): self
  135.     {
  136.         $this->periodicidad = $periodicidad;
  137.         return $this;
  138.     }
  139.     public function getNombre(): ?string
  140.     {
  141.         return $this->nombre;
  142.     }
  143.     public function setNombre(string $nombre): self
  144.     {
  145.         $this->nombre = $nombre;
  146.         return $this;
  147.     }
  148.     /**
  149.      * @return Collection<int, TareaPlan>
  150.      */
  151.     public function getTareas(): Collection
  152.     {
  153.         return $this->tareas;
  154.     }
  155.     public function addTarea(TareaPlan $tarea): self
  156.     {
  157.         if (!$this->tareas->contains($tarea)) {
  158.             $this->tareas[] = $tarea;
  159.             $tarea->setPlanMantenimiento($this);
  160.         }
  161.         return $this;
  162.     }
  163.     public function removeTarea(TareaPlan $tarea): self
  164.     {
  165.         if ($this->tareas->removeElement($tarea)) {
  166.             // set the owning side to null (unless already changed)
  167.             if ($tarea->getPlanMantenimiento() === $this) {
  168.                 $tarea->setPlanMantenimiento(null);
  169.             }
  170.         }
  171.         return $this;
  172.     }
  173.     /**
  174.      * @return Collection<int, Equipo>
  175.      */
  176.     public function getEquipos(): Collection
  177.     {
  178.         return $this->equipos;
  179.     }
  180.     public function addEquipo(Equipo $equipo): self
  181.     {
  182.         if (!$this->equipos->contains($equipo)) {
  183.             $this->equipos[] = $equipo;
  184.         }
  185.         return $this;
  186.     }
  187.     public function removeEquipo(Equipo $equipo): self
  188.     {
  189.         $this->equipos->removeElement($equipo);
  190.         return $this;
  191.     }
  192.     /**
  193.      * @return Collection<int, PlanMantenimientoDiagramado>
  194.      */
  195.     public function getPlanesDiagramados(): Collection
  196.     {
  197.         return $this->planesDiagramados;
  198.     }
  199.     public function addPlanesDiagramado(PlanMantenimientoDiagramado $planesDiagramado): self
  200.     {
  201.         if (!$this->planesDiagramados->contains($planesDiagramado)) {
  202.             $this->planesDiagramados[] = $planesDiagramado;
  203.             $planesDiagramado->setPlanMantenimiento($this);
  204.         }
  205.         return $this;
  206.     }
  207.     public function removePlanesDiagramado(PlanMantenimientoDiagramado $planesDiagramado): self
  208.     {
  209.         if ($this->planesDiagramados->removeElement($planesDiagramado)) {
  210.             // set the owning side to null (unless already changed)
  211.             if ($planesDiagramado->getPlanMantenimiento() === $this) {
  212.                 $planesDiagramado->setPlanMantenimiento(null);
  213.             }
  214.         }
  215.         return $this;
  216.     }
  217.     public function isActivo(): ?bool
  218.     {
  219.         return $this->activo;
  220.     }
  221.     public function setActivo(bool $activo): self
  222.     {
  223.         $this->activo = $activo;
  224.         return $this;
  225.     }
  226.     public function getSector(): ?SectorPlanta
  227.     {
  228.         return $this->sector;
  229.     }
  230.     public function setSector(?SectorPlanta $sector): self
  231.     {
  232.         $this->sector = $sector;
  233.         return $this;
  234.     }
  235. }