src/Entity/Point.php line 247

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use ApiPlatform\Core\Annotation\ApiFilter;
  4. use ApiPlatform\Core\Annotation\ApiSubresource;
  5. use Doctrine\ORM\PersistentCollection;
  6. use JsonSerializable;
  7. use ApiPlatform\Core\Annotation\ApiResource;
  8. use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter;
  9. use ApiPlatform\Core\Serializer\Filter\PropertyFilter;
  10. use Doctrine\Common\Collections\ArrayCollection;
  11. use Doctrine\Common\Collections\Collection;
  12. use Doctrine\ORM\Mapping as ORM;
  13. use Symfony\Component\Serializer\Annotation\Groups;
  14. /**
  15.  * @ApiResource(
  16.  *     collectionOperations={"get", "post"},
  17.  *     itemOperations={
  18.  *          "get"={
  19.  *              "normalization_context"={"groups"={"point:read", "point:item:get", "point_controller:item:get"}},
  20.  *          },
  21.  *          "put",
  22.  *     },
  23.  *     shortName="points",
  24.  *     normalizationContext={  "groups"={"point:read"},  "swagger_definition_name"="Read"},
  25.  *     denormalizationContext={"groups"={"point:write"}, "swagger_definition_name"="Write"},
  26.  *     attributes={
  27.  *          "pagination_items_per_page"=100,
  28.  *          "formats"={"jsonld", "json", "html", "csv"}
  29.  *     }
  30.  * )
  31.  * @ApiFilter(PropertyFilter::class)
  32.  * @ApiFilter(SearchFilter::class, properties={"networkInstallation.id": "exact", "pointController.id": "exact"})
  33.  * Class Point
  34.  * @package App\Entity
  35.  *
  36.  * @ORM\Entity(repositoryClass="App\Repository\PointRepository")
  37.  * @ORM\Table(name="points")
  38.  */
  39. class Point implements JsonSerializable
  40. {
  41.     /**
  42.      * @ORM\Id()
  43.      * @ORM\GeneratedValue()
  44.      * @ORM\Column(type="integer")
  45.      * @Groups({"point:read", "point_controller:item:get", "screen_point:read", "screen_point:item:get", "shape_point:read", "shape_point:item:get"})
  46.      */
  47.     private $id;
  48.     /**
  49.      * @ORM\Column(type="string", length=128, nullable=true)
  50.      * @Groups({"point:read", "point:write", "point_controller:item:get", "screen_point:read", "screen_point:item:get", "shape_point:read", "shape_point:item:get"})
  51.      */
  52.     private $name;
  53.     /**
  54.      * @ORM\Column(type="string", length=128, nullable=true)
  55.      */
  56.     private $nameLower;
  57.     /**
  58.      * @ORM\Column(type="string", length=232, nullable=true)
  59.      * @Groups({"point:read", "point:write", "point_controller:item:get", "screen_point:read", "screen_point:item:get", "shape_point:read", "shape_point:item:get"})
  60.      */
  61.     private $description;
  62.     /**
  63.      * @ORM\Column(type="string", length=32, nullable=true)
  64.      * @Groups({"point:read", "point:write", "point_controller:item:get", "screen_point:read", "shape_point:read", "shape_point:item:get"})
  65.      */
  66.     private $address;
  67.     /**
  68.      * @ORM\Column(type="boolean", nullable=true)
  69.      * @Groups({"point:read", "point:write", "point_controller:item:get"})
  70.      */
  71.     private $onOverview;
  72.     /**
  73.      * @ORM\Column(type="boolean", nullable=true)
  74.      * @Groups({"point:read", "point:write", "point_controller:item:get", "screen_point:read", "shape_point:read", "shape_point:item:get"})
  75.      */
  76.     private $isVisible;
  77.     /**
  78.      * @ORM\Column(type="string", length=128, nullable=true)
  79.      * @Groups({"point:read", "point:write", "point_controller:item:get", "screen_point:read", "shape_point:read", "shape_point:item:get"})
  80.      */
  81.     private $visibility;
  82.     /**
  83.      * @ORM\Column(type="boolean", nullable=true)
  84.      */
  85.     private $isGlobal;
  86.     /**
  87.      * @ORM\Column(type="boolean", nullable=true)
  88.      * @Groups({"point:read", "point:write", "point_controller:item:get", "screen_point:read", "shape_point:read", "shape_point:item:get"})
  89.      */
  90.     private $isAssigned;
  91.     /**
  92.      * @ORM\Column(type="string", length=128, nullable=true)
  93.      * @Groups({"point:read", "point:write", "point_controller:item:get", "screen_point:read", "shape_point:read", "shape_point:item:get"})
  94.      */
  95.     private $pointGroup;
  96.     /**
  97.      * @ORM\Column(type="string", length=16, nullable=true)
  98.      * @Groups({"point:read", "point:write", "point_controller:item:get"})
  99.      */
  100.     private $sourceType;
  101.     /**
  102.      * @ORM\Column(type="datetime", nullable=false)
  103.      * @Groups({"point:read", "point:write", "point_controller:item:get"})
  104.      */
  105.     private $dateAdded;
  106.     /**
  107.      * @ORM\Column(type="datetime", nullable=false)
  108.      * @Groups({"point:read", "point:write", "point_controller:item:get"})
  109.      */
  110.     private $dateModified;
  111.     /* ~~~~~~~~~~~~~~~~ OneToOne ~~~~~~~~~~~~~~~~ */
  112.     /**
  113.      * @ORM\OneToOne(targetEntity="App\Entity\PanelPoint", mappedBy="point", cascade={"persist"}, fetch="EXTRA_LAZY")
  114.      * @Groups({"point:read", "point:write", "point_controller:item:get"})
  115.      */
  116.     private $panelPoint;
  117.     /* ~~~~~~~~~~~~~~~~ OneToMany ~~~~~~~~~~~~~~~~ */
  118.     /**
  119.      * @ORM\OneToMany(targetEntity="App\Entity\ScreenPoint", mappedBy="point", cascade={"persist"}, fetch="EXTRA_LAZY")
  120.      * @Groups({"point:read", "point:write", "point:item:get", "point_controller:item:get"})
  121.      * @ApiSubresource()
  122.      */
  123.     private $screenPoints;
  124.     /**
  125.      * @ORM\OneToMany(targetEntity="App\Entity\ShapePoint", mappedBy="point", cascade={"persist"}, fetch="EXTRA_LAZY")
  126.      * @Groups({"point:read", "point:write", "point:item:get", "point_controller:item:get"})
  127.      * @ApiSubresource()
  128.      */
  129.     private $shapePoints;
  130.     /* ~~~~~~~~~~~~~~~~ ManyToOne ~~~~~~~~~~~~~~~~ */
  131.     /**
  132.      * @ORM\ManyToOne(targetEntity="App\Entity\PointType", inversedBy="points", cascade={"persist"}, fetch="EXTRA_LAZY")
  133.      * @Groups({"point:read", "point:write", "point:item:get", "point_controller:item:get"})
  134.      */
  135.     private $pointType;
  136.     /**
  137.      * @ORM\ManyToOne(targetEntity="App\Entity\PointController", inversedBy="points", cascade={"persist"}, fetch="EXTRA_LAZY")
  138.      * @Groups({"point:read", "point:write", "point:item:get"})
  139.      */
  140.     private $pointController;
  141.     /**
  142.      * @ORM\ManyToOne(targetEntity="App\Entity\Facility", inversedBy="points", cascade={"persist"}, fetch="EXTRA_LAZY")
  143.      */
  144.     private $facility;
  145.     /**
  146.      * @ORM\ManyToOne(targetEntity="App\Entity\NetworkInstallation", inversedBy="points", cascade={"persist"}, fetch="EXTRA_LAZY")
  147.      */
  148.     private $networkInstallation;
  149.     /* ~~~~~~~~~~~~~~~~ ManyToMany ~~~~~~~~~~~~~~~~ */
  150.     /**
  151.      * @ORM\ManyToMany(targetEntity=EquipmentGroup::class, mappedBy="points")
  152.      * @Groups({"point:read", "point:write", "point:item:get"})
  153.      */
  154.     private $equipmentGroups;
  155.     public function __construct()
  156.                    {
  157.                        $this->dateAdded = new \DateTime();
  158.                        $this->setDateModified();
  159.                        $this->screenPoints = new ArrayCollection();
  160.                        $this->shapePoints = new ArrayCollection();
  161.                        $this->equipmentGroups = new ArrayCollection();
  162.                    }
  163.     public function __toString()
  164.                    {
  165.                        return (string) $this->getName();
  166.                    }
  167.     /**
  168.      * @param string $property
  169.      * @return mixed
  170.      */
  171.     public function __get(string $property)
  172.     {
  173.         // attempt to use the method
  174.         $methodName 'get' ucfirst$property );
  175.         if( method_exists$this$methodName ) ){
  176.             return $this->{$methodName}( $property );
  177.         }
  178.         // attempt to use the method
  179.         if (property_exists($this$property)) {
  180.             return $this->$property;
  181.         }
  182.         return null;
  183.     }
  184.     /**
  185.      * @param string $property
  186.      * @param mixed $value
  187.      * @return bool
  188.      */
  189.     public function __set(string $property$value) {
  190.         // attempt to use the method
  191.         $methodName 'set' ucfirst$property );
  192.         if( method_exists$this$methodName ) ){
  193.             $this->{$methodName}( $property$value );
  194.             return true;
  195.         }
  196.         // attempt to use the method
  197.         if (property_exists($this$property)) {
  198.             $this->$property $value;
  199.             return true;
  200.         }
  201.         return false;
  202.     }
  203.     public function jsonSerialize()
  204.     {
  205.         return array(
  206.             'id'           => $this->id,
  207.             'name'         => $this->name,
  208.             'description'  => $this->description,
  209.             'address'      => $this->address,
  210.             'onOverview'   => $this->onOverview,
  211.             'isVisible'    => $this->isVisible,
  212.             'visibility'   => $this->visibility,
  213.             'isGlobal'     => $this->isGlobal,
  214.             'isAssigned'   => $this->isAssigned,
  215.             'pointGroup'   => $this->pointGroup,
  216.             'sourceType'   => $this->sourceType,
  217.             'dateAdded'    => $this->dateAdded,
  218.             'dateModified' => $this->dateModified,
  219.             'screenPoints' => $this->getScreenPoints()->toArray(),
  220.             'shapePoints'  => $this->getShapePoints()->toArray(),
  221.         );
  222.     }
  223.     
  224.     public function serializeForTable( array $pointsWithRules = array() )
  225.     {
  226.         return array(
  227.             "DT_RowId" => "row_" $this->getId(),
  228.             'point_id' => $this->getId(),
  229.             'dragBars' => "<i class='fas fa-bars grey'></i>",
  230.             'controllerName' => $this->getPointController()->getName(),
  231.             'pointDetail' => "<a data-toggle='modal' data-target='#pointDetailModal' data-pointid='" $this->getId() . "' data-pointname='" $this->getName() . "' href='#'>" $this->getName() . "</a>",
  232.             'pointName' => $this->getName(),
  233.             'pointDescription' => $this->getDescription(),
  234.             'pointType' => (!is_null$this->getPointType())) ? $this->getPointType()->getName() : 'Undefined',
  235.             'pointVisibility' => ($this->getIsVisible()) ? "Visible" "Hidden",
  236.             'pointGroup' => $this->getPointGroup(),
  237.             'pointAssigned' => ($this->getIsAssigned()) ? "A" "U",
  238.             'pointAssignedFull' => ($this->getIsAssigned()) ? "Assigned" "Unassigned",
  239.             'manualConfRulesApplied' => ( array_key_exists$this->getId(), $pointsWithRules ) ) ? "<span class='fa fas fa-exclamation-circle text-warning' tabindex='0' data-toggle='tooltip' title='Manual changes have been applied.'></span>" '',
  240.         );
  241.     }
  242.     /**
  243.      * get id
  244.      *
  245.      * @return integer
  246.      */
  247.     public function getId()
  248.     {
  249.         return $this->id;
  250.     }
  251.     /**
  252.      * get name
  253.      *
  254.      * @return string
  255.      */
  256.     public function getName()
  257.     {
  258.         return $this->name;
  259.     }
  260.     /**
  261.      * set name
  262.      *
  263.      * @param string $name
  264.      *
  265.      * @return Point
  266.      */
  267.     public function setName($name)
  268.     {
  269.         $this->name $name;
  270.         $this->nameLower strtolower$name );
  271.         return $this;
  272.     }
  273.     /**
  274.      * get nameLower
  275.      *
  276.      * @return string
  277.      */
  278.     public function getNameLower()
  279.     {
  280.         return $this->nameLower;
  281.     }
  282.     /**
  283.      * set nameLower
  284.      *
  285.      * @param string $nameLower
  286.      *
  287.      * @return Point
  288.      */
  289.     public function setNameLower($nameLower)
  290.     {
  291.         $this->nameLower strtolower($nameLower);
  292.         return $this;
  293.     }
  294.     
  295.     /**
  296.      * get description
  297.      *
  298.      * @return string
  299.      */
  300.     public function getDescription()
  301.     {
  302.         return $this->description;
  303.     }
  304.     /**
  305.      * set description
  306.      *
  307.      * @param string $description
  308.      *
  309.      * @return Point
  310.      */
  311.     public function setDescription($description)
  312.     {
  313.         $this->description $description;
  314.         return $this;
  315.     }
  316.     /**
  317.      * get address
  318.      *
  319.      * @return string
  320.      */
  321.     public function getAddress()
  322.     {
  323.         return $this->address;
  324.     }
  325.     /**
  326.      * set address
  327.      *
  328.      * @param string $address
  329.      *
  330.      * @return Point
  331.      */
  332.     public function setAddress($address)
  333.     {
  334.         $this->address $address;
  335.         return $this;
  336.     }
  337.     /**
  338.      * get onOverview
  339.      *
  340.      * @return boolean
  341.      */
  342.     public function getOnOverview()
  343.     {
  344.         return $this->onOverview;
  345.     }
  346.     /**
  347.      * set onOverview
  348.      *
  349.      * @param boolean $onOverview
  350.      *
  351.      * @return Point
  352.      */
  353.     public function setOnOverview($onOverview)
  354.     {
  355.         $this->onOverview $onOverview;
  356.         return $this;
  357.     }
  358.     /**
  359.      * get isVisible
  360.      *
  361.      * @return boolean
  362.      */
  363.     public function getIsVisible()
  364.     {
  365.         return $this->isVisible;
  366.     }
  367.     /**
  368.      * set isVisible
  369.      *
  370.      * @param boolean $isVisible
  371.      *
  372.      * @return Point
  373.      */
  374.     public function setIsVisible($isVisible)
  375.     {
  376.         $this->isVisible $isVisible;
  377.         return $this;
  378.     }
  379.     /**
  380.      * get isGlobal
  381.      *
  382.      * @return boolean
  383.      */
  384.     public function getIsGlobal()
  385.     {
  386.         return $this->isGlobal;
  387.     }
  388.     /**
  389.      * set isGlobal
  390.      *
  391.      * @param boolean $isGlobal
  392.      *
  393.      * @return Point
  394.      */
  395.     public function setIsGlobal($isGlobal)
  396.     {
  397.         $this->isGlobal $isGlobal;
  398.         return $this;
  399.     }
  400.     /**
  401.      * get isAssigned
  402.      *
  403.      * @return boolean
  404.      */
  405.     public function getIsAssigned()
  406.     {
  407.         return ($this->isAssigned === true);
  408.     }
  409.     /**
  410.      * set isAssigned
  411.      *
  412.      * @param boolean $isAssigned
  413.      *
  414.      * @return Point
  415.      */
  416.     public function setIsAssigned($isAssigned)
  417.     {
  418.         if( !is_null$isAssigned ) ){
  419.             $this->isAssigned $isAssigned;
  420.         } else {
  421.             if( count$this->getScreenPoints() ) > ){
  422.                 $this->isAssigned true;
  423.             } else {
  424.                 $this->isAssigned false;
  425.             }
  426.         }
  427.         return $this;
  428.     }
  429.     /**
  430.      * get sourceType
  431.      *
  432.      * @return string
  433.      */
  434.     public function getSourceType()
  435.                    {
  436.                        return $this->sourceType;
  437.                    }
  438.     /**
  439.      * set sourceType
  440.      *
  441.      * @param string $sourceType
  442.      *
  443.      * @return Point
  444.      */
  445.     public function setSourceType($sourceType)
  446.                    {
  447.                        $this->sourceType $sourceType;
  448.                
  449.                        return $this;
  450.                    }
  451.     /**
  452.      * get visibility
  453.      *
  454.      * @return string
  455.      */
  456.     public function getVisibility()
  457.     {
  458.         return $this->visibility;
  459.     }
  460.     /**
  461.      * set visibility
  462.      *
  463.      * @param string $visibility
  464.      *
  465.      * @return Point
  466.      */
  467.     public function setVisibility($visibility)
  468.     {
  469.         $this->visibility $visibility;
  470.         return $this;
  471.     }
  472.     /**
  473.      * get pointGroup
  474.      *
  475.      * @return string
  476.      */
  477.     public function getPointGroup()
  478.     {
  479.         return $this->pointGroup;
  480.     }
  481.     /**
  482.      * set pointGroup
  483.      *
  484.      * @param string $pointGroup
  485.      *
  486.      * @return Point
  487.      */
  488.     public function setPointGroup($pointGroup)
  489.     {
  490.         $this->pointGroup $pointGroup;
  491.         return $this;
  492.     }
  493.     /**
  494.      * get getDateAdded
  495.      *
  496.      * @return \DateTime
  497.      */
  498.     public function getDateAdded()
  499.     {
  500.         return $this->dateAdded;
  501.     }
  502.     /**
  503.      * get date modified
  504.      *
  505.      * @return \DateTime
  506.      */
  507.     public function getDateModified()
  508.                    {
  509.                        return $this->dateModified;
  510.                    }
  511.     /**
  512.      * set date modified
  513.      *
  514.      * @return \DateTime
  515.      */
  516.     public function setDateModified()
  517.                     {
  518.                         $this->dateModified = new \DateTime("now");
  519.                     }
  520.     /* ~~~~~~~~~~~~~~~~ OneToOne ~~~~~~~~~~~~~~~~ */
  521.     /**
  522.      * @return PanelPoint
  523.      */
  524.     public function getPanelPoint(): ?PanelPoint
  525.     {
  526.         return $this->panelPoint;
  527.     }
  528.     /**
  529.      * @param PanelPoint $panelPoint
  530.      * @return Point
  531.      */
  532.     public function setPanelPoint(PanelPoint $panelPoint): Point
  533.     {
  534.         $this->panelPoint $panelPoint;
  535.         if( $panelPoint->getPoint() !== $this ){
  536.             $panelPoint->setPoint($this);
  537.         }
  538.         return $this;
  539.     }
  540.     /* ~~~~~~~~~~~~~~~~ ManyToOne ~~~~~~~~~~~~~~~~ */
  541.     /**
  542.      * get pointType
  543.      *
  544.      * @return PointType
  545.      */
  546.     public function getPointType()
  547.     {
  548.         return $this->pointType;
  549.     }
  550.     /**
  551.      * set pointType
  552.      *
  553.      * @param PointType $pointType
  554.      *
  555.      * @return Point
  556.      */
  557.     public function setPointType(PointType $pointType)
  558.     {
  559.         $this->pointType $pointType;
  560.         return $this;
  561.     }
  562.     /**
  563.      * get pointController
  564.      *
  565.      * @return PointController
  566.      */
  567.     public function getPointController()
  568.     {
  569.         return $this->pointController;
  570.     }
  571.     /**
  572.      * set pointController
  573.      *
  574.      * @param PointController $pointController
  575.      *
  576.      * @return Point
  577.      */
  578.     public function setPointController(PointController $pointController)
  579.     {
  580.         $this->pointController $pointController;
  581.         $pointController->addPoint$this );
  582.         return $this;
  583.     }
  584.     /**
  585.      * get facility
  586.      *
  587.      * @return Facility
  588.      */
  589.     public function getFacility()
  590.     {
  591.         return $this->facility;
  592.     }
  593.     /**
  594.      * set facility
  595.      *
  596.      * @param Facility $facility
  597.      *
  598.      * @return Point
  599.      */
  600.     public function setFacility(Facility $facility)
  601.     {
  602.         if( !is_null$facility ) ){
  603.             // update the inverse side
  604.             $facility->addPoint$this );
  605.         } else {
  606.             $facility->addPointnull );
  607.         }
  608.         $this->facility $facility;
  609.         return $this;
  610.     }
  611.     /**
  612.      * get networkInstallation
  613.      *
  614.      * @return NetworkInstallation
  615.      */
  616.     public function getNetworkInstallation()
  617.     {
  618.         return $this->networkInstallation;
  619.     }
  620.     /**
  621.      * set networkInstallation
  622.      *
  623.      * @param NetworkInstallation $networkInstallation
  624.      *
  625.      * @return Point
  626.      */
  627.     public function setNetworkInstallation(NetworkInstallation $networkInstallation)
  628.     {
  629.         $this->networkInstallation $networkInstallation;
  630.         $networkInstallation->addPoint$this );
  631.         return $this;
  632.     }
  633.     /* ~~~~~~~~~~~~~~~~ ManyToMany ~~~~~~~~~~~~~~~~ */
  634.     /**
  635.      * Add screen point
  636.      *
  637.      * @param ScreenPoint $screenPoint
  638.      *
  639.      * @return Point
  640.      */
  641.     public function addScreenPoint(ScreenPoint $screenPoint)
  642.     {
  643.         if (!$this->screenPoints->contains($screenPoint)) {
  644.             $this->screenPoints[] = $screenPoint;
  645.             $screenPoint->setPoint($this);
  646.         }
  647.         if( $this->screenPoints->count() > $this->setIsAssigned(true);
  648.         return $this;
  649.     }
  650.     /**
  651.      * Remove screen point
  652.      *
  653.      * @param ScreenPoint $screenPoint
  654.      *
  655.      * @return Point
  656.      */
  657.     public function removeScreenPoint(ScreenPoint $screenPoint)
  658.     {
  659.         if ($this->screenPoints->contains($screenPoint)) {
  660.             $this->screenPoints->removeElement($screenPoint);
  661.             $screenPoint->removePoint();
  662.         }
  663.         if( $this->screenPoints->count() === $this->setIsAssigned(false);
  664.         return $this;
  665.     }
  666.     public function getScreenPoints()
  667.     {
  668.         return $this->screenPoints;
  669.     }
  670.     // todo: add addScreenPoints, removeScreenPoints
  671.     /**
  672.      * Add shape point
  673.      *
  674.      * @param ShapePoint $shapePoint
  675.      *
  676.      * @return Point
  677.      */
  678.     public function addShapePoint(ShapePoint $shapePoint)
  679.     {
  680.         if (!$this->shapePoints->contains($shapePoint)) {
  681.             $this->shapePoints[] = $shapePoint;
  682.             $shapePoint->setPoint($this);
  683.         }
  684.         return $this;
  685.     }
  686.     /**
  687.      * Remove shape point
  688.      *
  689.      * @param ShapePoint $shapePoint
  690.      *
  691.      * @return Point
  692.      */
  693.     public function removeShapePoint(ShapePoint $shapePoint)
  694.     {
  695.         if ($this->shapePoints->contains($shapePoint)) {
  696.             $this->shapePoints->removeElement($shapePoint);
  697.             $shapePoint->removePoint();
  698.         }
  699.         return $this;
  700.     }
  701.     public function getShapePoints()
  702.     {
  703.         return $this->shapePoints;
  704.     }
  705.     // todo: add addShapePoints, removeShapePoints
  706.     /**
  707.      * @return Collection|EquipmentGroup[]
  708.      */
  709.     public function getEquipmentGroups(): Collection
  710.     {
  711.         return $this->equipmentGroups;
  712.     }
  713.     public function addEquipmentGroup(EquipmentGroup $equipmentGroup): self
  714.     {
  715.         if (!$this->equipmentGroups->contains($equipmentGroup)) {
  716.             $this->equipmentGroups[] = $equipmentGroup;
  717.             $equipmentGroup->addPoint($this);
  718.         }
  719.         return $this;
  720.     }
  721.     public function removeEquipmentGroup(EquipmentGroup $equipmentGroup): self
  722.     {
  723.         if ($this->equipmentGroups->removeElement($equipmentGroup)) {
  724.             $equipmentGroup->removePoint($this);
  725.         }
  726.         return $this;
  727.     }
  728. }