src/Entity/Progetto.php line 13

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use Doctrine\Common\Collections\ArrayCollection;
  4. use Doctrine\Common\Collections\Collection;
  5. use Doctrine\ORM\Mapping as ORM;
  6. /**
  7.  * @ORM\Entity
  8.  * @ORM\Table(name="progetti")
  9.  */
  10. class Progetto
  11. {
  12.     /**
  13.      * @var int
  14.      *
  15.      * @ORM\Column(type="integer")
  16.      * @ORM\Id
  17.      * @ORM\GeneratedValue
  18.      */
  19.     private $id;
  20.     /**
  21.      * @var string
  22.      *
  23.      * @ORM\Column(type="string", length=150)
  24.      */
  25.     private $name;
  26.     /**
  27.      * @var string|null
  28.      *
  29.      * @ORM\Column(type="text", nullable=true)
  30.      */
  31.     private $description null;
  32.     /**
  33.      * @var Servizio[]|null
  34.      *
  35.      * @ORM\OneToMany(targetEntity=Servizio::class, mappedBy="progetto")
  36.      */
  37.     private $services;
  38.     /**
  39.      * @var Cliente|null
  40.      *
  41.      * @ORM\ManyToOne(targetEntity=Cliente::class, inversedBy="projects")
  42.      */
  43.     private $client;
  44.     /**
  45.      * @var Collection
  46.      *
  47.      * @ORM\OneToMany(targetEntity=Progetto::class, mappedBy="parent")
  48.      */
  49.     private $subprojects;
  50.     /**
  51.      * @var Progetto|null
  52.      *
  53.      * @ORM\ManyToOne(targetEntity=Progetto::class, inversedBy="subprojects")
  54.      */
  55.     private $parent null;
  56.     public function __construct()
  57.     {
  58.         $this->services = new ArrayCollection();
  59.         $this->subprojects = new ArrayCollection();
  60.     }
  61.     public function __toString(): string
  62.     {
  63.         return $this->getFullName();
  64.     }
  65.     /**
  66.      * @return int
  67.      */
  68.     public function getId(): int
  69.     {
  70.         return $this->id;
  71.     }
  72.     /**
  73.      * @param int $id
  74.      * @return Progetto
  75.      */
  76.     public function setId(int $id): Progetto
  77.     {
  78.         $this->id $id;
  79.         return $this;
  80.     }
  81.     /**
  82.      * @return string
  83.      */
  84.     public function getName(): string
  85.     {
  86.         return $this->name;
  87.     }
  88.     /**
  89.      * @param string $name
  90.      * @return Progetto
  91.      */
  92.     public function setName(string $name): Progetto
  93.     {
  94.         $this->name $name;
  95.         return $this;
  96.     }
  97.     /**
  98.      * @return string
  99.      */
  100.     public function getDescription(): ?string
  101.     {
  102.         return $this->description;
  103.     }
  104.     /**
  105.      * @param string $description
  106.      * @return Progetto
  107.      */
  108.     public function setDescription(?string $description): Progetto
  109.     {
  110.         $this->description $description;
  111.         return $this;
  112.     }
  113.     /**
  114.      * @return Servizio[]|null
  115.      */
  116.     public function getServices(): ?array
  117.     {
  118.         return $this->services;
  119.     }
  120.     /**
  121.      * @param Servizio[]|null $services
  122.      * @return Progetto
  123.      */
  124.     public function setServices(?array $services): Progetto
  125.     {
  126.         $this->services $services;
  127.         return $this;
  128.     }
  129.     /**
  130.      * @return Cliente|null
  131.      */
  132.     public function getClient(): ?Cliente
  133.     {
  134.         return $this->client;
  135.     }
  136.     /**
  137.      * @param Cliente $client
  138.      * @return Progetto
  139.      */
  140.     public function setClient(?Cliente $client): Progetto
  141.     {
  142.         $this->client $client;
  143.         return $this;
  144.     }
  145.     public function getParent(): ?Progetto
  146.     {
  147.         return $this->parent;
  148.     }
  149.     public function setParent(?Progetto $parent): Progetto
  150.     {
  151.         $this->parent $parent;
  152.         return $this;
  153.     }
  154.     public function getSubprojects(): Collection
  155.     {
  156.         return $this->subprojects;
  157.     }
  158.     public function setSubprojects(Collection $subprojects): Progetto
  159.     {
  160.         $this->subprojects $subprojects;
  161.         return $this;
  162.     }
  163.     public function getFullName()
  164.     {
  165.         $name $this->getName();
  166.         $start $this;
  167.         while($parent $start->getParent()) {
  168.             $name $parent->getName().' - '.$name;
  169.             $start $parent;
  170.         }
  171.         return $name;
  172.     }
  173. }