src/Entity/Localidad.php line 25

  1. <?php
  2. namespace App\Entity;
  3. use Doctrine\Common\Collections\ArrayCollection;
  4. use Doctrine\Common\Collections\Collection;
  5. use Symfony\Component\Validator\Constraints as Assert;
  6. use Gedmo\Mapping\Annotation as Gedmo;
  7. use Knp\DoctrineBehaviors\Contract\Entity\TranslatableInterface;
  8. use Knp\DoctrineBehaviors\Model\Translatable\TranslatableTrait;
  9. use Knp\DoctrineBehaviors\Model\Sluggable\SluggableTrait;
  10. use Knp\DoctrineBehaviors\Contract\Entity\SluggableInterface;
  11. use Doctrine\ORM\Mapping as ORM;
  12. /**
  13.  * Localidad
  14.  *
  15.  * @ORM\Table(name="localidad")
  16.  * @ORM\Entity
  17.  */
  18. class Localidad implements TranslatableInterface//, SluggableInterface
  19. {
  20.     use TranslatableTrait;
  21.     //use SluggableTrait;
  22.     
  23.     /**
  24.      * @var integer
  25.      *
  26.      * @ORM\Column(name="id", type="integer")
  27.      * @ORM\Id
  28.      * @ORM\GeneratedValue(strategy="AUTO")
  29.      */
  30.     private $id;
  31.     /**
  32.      * @var string
  33.      *
  34.      * @ORM\Column(name="nombre", type="string", length=63)
  35.      */
  36.     private $nombre;
  37.     /**
  38.     * @ORM\ManyToOne(targetEntity="Provincia", inversedBy="localidades")
  39.     * @ORM\JoinColumn(name="provincia", referencedColumnName="id", nullable=false)
  40.     */
  41.     private $provincia;
  42.     private $nofis;
  43.     /**
  44.      * @var integer
  45.      *
  46.      * @ORM\Column(name="peso", type="integer", nullable=false)
  47.      */
  48.     private $peso=0;
  49.     /**
  50.      *
  51.      * @ORM\OneToMany(targetEntity="Oficina", mappedBy="localidad",  fetch="EXTRA_LAZY")
  52.      * @ORM\OrderBy({"peso" = "DESC"})
  53.      */
  54.     private $oficinas;
  55.     
  56.     /**
  57.      * @var string
  58.      *
  59.      * @ORM\Column(name="slug", type="string", length=255, nullable=true)
  60.      */
  61.     private $slug;
  62.         
  63.     
  64.     public function getSluggableFields(): array
  65.     {
  66.         return ['nombre'];
  67.     }   
  68.     
  69.     public function __call($method$args)
  70.     {
  71.         //return $this->proxyCurrentLocaleTranslation($method, $arguments);
  72.         if (!method_exists(self::getTranslationEntityClass(), $method)) {
  73.             $method 'get'ucfirst($method);
  74.         }
  75.         return $this->proxyCurrentLocaleTranslation($method$args);        
  76.     }
  77.     
  78.     public function __toString() {
  79.         return $this->nombre;
  80.     }
  81.     public function __construct() {
  82.         $this->oficinas = new ArrayCollection();
  83.     }
  84.     /**
  85.      * Get id
  86.      *
  87.      * @return integer
  88.      */
  89.     public function getId()
  90.     {
  91.         return $this->id;
  92.     }
  93.     /**
  94.      * Set nombre
  95.      *
  96.      * @param string $nombre
  97.      * @return Localidad
  98.      */
  99.     public function setNombre($nombre)
  100.     {
  101.         $this->nombre $nombre;
  102.         return $this;
  103.     }
  104.     /**
  105.      * Get nombre
  106.      *
  107.      * @return string
  108.      */
  109.     public function getNombre()
  110.     {
  111.         return $this->nombre;
  112.     }
  113.     /**
  114.      * Set provincia
  115.      *
  116.      * @param string $provincia
  117.      * @return Localidad
  118.      */
  119.     public function setProvincia(Provincia $provincia)
  120.     {
  121.         $this->provincia $provincia;
  122.         return $this;
  123.     }
  124.     /**
  125.      * Get provincia
  126.      *
  127.      * @return string
  128.      */
  129.     public function getProvincia()
  130.     {
  131.         return $this->provincia;
  132.     }
  133.     
  134.     /**
  135.      * Set peso
  136.      *
  137.      * @param integer $peso
  138.      * @return Localidad
  139.      */
  140.     public function setPeso($peso)
  141.     {
  142.         $this->peso=$peso;
  143.         return $this;
  144.     }
  145.     /**
  146.      * Get peso
  147.      *
  148.      * @return integer
  149.      */
  150.     public function getPeso()
  151.     {
  152.         return $this->peso;
  153.     }
  154.     /**
  155.      * Set nofis
  156.      *
  157.      * @param integer $nofis
  158.      * @return Localidad
  159.      */
  160.     public function setNOfis($nofis)
  161.     {
  162.         $this->nofis=$nofis;
  163.         return $this;
  164.     }
  165.     /**
  166.      * Get nofis
  167.      *
  168.      * @return integer
  169.      */
  170.     public function getNofis()
  171.     {
  172.         return $this->oficinas->count();
  173.     }
  174.     /**
  175.      * Set oficinas
  176.      *
  177.      * @param ArrayCollection $oficinas
  178.      * @return ArrayCollection
  179.      */
  180.     public function setOficinas($oficinas)
  181.     {
  182.         $this->oficinas=$oficinas;
  183.         return $this;
  184.     }
  185.     /**
  186.      * Get oficinas
  187.      *
  188.      * @return integer
  189.      */
  190.     public function getOficinas()
  191.     {
  192.         return $this->oficinas;
  193.     }
  194.     public function getSlug(): ?string
  195.     {
  196.         return $this->slug;
  197.     }
  198.     public function setSlug(?string $slug): self
  199.     {
  200.         $this->slug $slug;
  201.         return $this;
  202.     }
  203.     public function addOficina(Oficina $oficina): self
  204.     {
  205.         if (!$this->oficinas->contains($oficina)) {
  206.             $this->oficinas->add($oficina);
  207.             $oficina->setLocalidad($this);
  208.         }
  209.         return $this;
  210.     }
  211.     public function removeOficina(Oficina $oficina): self
  212.     {
  213.         if ($this->oficinas->removeElement($oficina)) {
  214.             // set the owning side to null (unless already changed)
  215.             if ($oficina->getLocalidad() === $this) {
  216.                 $oficina->setLocalidad(null);
  217.             }
  218.         }
  219.         return $this;
  220.     }
  221. }