src/Entity/PointType.php line 74

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use ApiPlatform\Core\Annotation\ApiResource;
  4. use JsonSerializable;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use Doctrine\Common\Collections\Collection;
  7. use Doctrine\ORM\Mapping as ORM;
  8. use Symfony\Component\Serializer\Annotation\Groups;
  9. /**
  10.  * @ApiResource(
  11.  *     collectionOperations={"get", "post"},
  12.  *     itemOperations={
  13.  *          "get"={
  14.  *              "normalization_context"={"groups"={"point_type:read", "point_type:item:get", "point:read", "point:item:get"}},
  15.  *          },
  16.  *          "put",
  17.  *     },
  18.  *     normalizationContext={  "groups"={"point_type:read"},  "swagger_definition_name"="Read"},
  19.  *     denormalizationContext={"groups"={"point_type:write"}, "swagger_definition_name"="Write"},
  20.  *     attributes={
  21.  *          "pagination_items_per_page"=50,
  22.  *          "formats"={"jsonld", "json", "html", "csv"}
  23.  *     }
  24.  * )
  25. * @package App\Entity
  26. *
  27. * @ORM\Entity
  28. * @ORM\Table(name="point_types")
  29. */
  30. class PointType implements JsonSerializable
  31. {
  32.     /**
  33.      * @ORM\Id()
  34.      * @ORM\GeneratedValue()
  35.      * @ORM\Column(type="integer")
  36.      * @Groups({"point_type:read", "point:read", "point:item:get"})
  37.      */
  38.     private $id;
  39.     /**
  40.      * @ORM\Column(type="string", length=128, nullable=true)
  41.      * @Groups({"point_type:read", "point:read", "point_type:write", "point:item:get"})
  42.      */
  43.     private $name;
  44.     /**
  45.      * @ORM\Column(type="boolean", nullable=true)
  46.      * @Groups({"point_type:read", "point_type:write"})
  47.      */
  48.     private $defaultVisibility;
  49.     /**
  50.      * @ORM\Column(type="string", length=128, nullable=true)
  51.      * @Groups({"point_type:read", "point_type:write"})
  52.      */
  53.     private $defaultPointGroup;
  54.     /**
  55.      * @ORM\OneToMany(targetEntity="App\Entity\Point", mappedBy="pointType", fetch="EXTRA_LAZY", cascade={"persist"})
  56.      * @ORM\OrderBy({"name" = "ASC"})
  57.      */
  58.     private $points;
  59.     public function __construct()
  60.     {
  61.         $this->points = new ArrayCollection();
  62.     }
  63.     public function jsonSerialize()
  64.     {
  65.         return array(
  66.             'id'=> $this->id,
  67.             'name' => $this->name,
  68.             'defaultVisibility' => $this->defaultVisibility,
  69.             'defaultPointGroup' => $this->defaultPointGroup,
  70.         );
  71.     }
  72.     /**
  73.      * get id
  74.      *
  75.      * @return integer
  76.      */
  77.     public function getId()
  78.     {
  79.         return $this->id;
  80.     }
  81.     /**
  82.      * get name
  83.      *
  84.      * @return string
  85.      */
  86.     public function getName()
  87.     {
  88.         return $this->name;
  89.     }
  90.     /**
  91.      * set name
  92.      *
  93.      * @param string $name
  94.      *
  95.      * @return PointType
  96.      */
  97.     public function setNamestring $name )
  98.     {
  99.         $this->name $name;
  100.         return $this;
  101.     }
  102.     /**
  103.      * get defaultVisibility
  104.      *
  105.      * @return boolean
  106.      */
  107.     public function getDefaultVisibility()
  108.     {
  109.         return $this->defaultVisibility;
  110.     }
  111.     /**
  112.      * set defaultVisibility
  113.      *
  114.      * @param boolean $defaultVisibility
  115.      *
  116.      * @return PointType
  117.      */
  118.     public function setDefaultVisibility$defaultVisibility )
  119.     {
  120.         $this->defaultVisibility $defaultVisibility;
  121.         return $this;
  122.     }
  123.     /**
  124.      * get defaultPointGroup
  125.      *
  126.      * @return string
  127.      */
  128.     public function getDefaultPointGroup()
  129.     {
  130.         return $this->defaultPointGroup;
  131.     }
  132.     /**
  133.      * set defaultPointGroup
  134.      *
  135.      * @param string $defaultPointGroup
  136.      *
  137.      * @return PointType
  138.      */
  139.     public function setDefaultPointGroup$defaultPointGroup )
  140.     {
  141.         $this->defaultPointGroup $defaultPointGroup;
  142.         return $this;
  143.     }
  144.     /**
  145.      * get points
  146.      *
  147.      * @return Collection|Point[]
  148.      */
  149.     public function getPoints()
  150.     {
  151.         return $this->points;
  152.     }
  153.     public function addPoint(\App\Entity\Point $point)
  154.     {
  155.         if (!$this->points->contains($point)) {
  156.             $this->points[] = $point;
  157.             $point->setPointType($this);
  158.         }
  159.         return $this;
  160.     }
  161.     public function removePoint(\App\Entity\Point $point)
  162.     {
  163.         if ($this->points->contains($point)) {
  164.             $this->points->removeElement($point);
  165.             // set the owning side to null (unless already changed)
  166.             if ($point->getPointType() === $this) {
  167.                 $point->setPointType(null);
  168.             }
  169.         }
  170.         return $this;
  171.     }
  172. }