<?php
namespace App\Entity;
use ApiPlatform\Core\Annotation\ApiFilter;
use ApiPlatform\Core\Annotation\ApiSubresource;
use Doctrine\ORM\PersistentCollection;
use JsonSerializable;
use ApiPlatform\Core\Annotation\ApiResource;
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter;
use ApiPlatform\Core\Serializer\Filter\PropertyFilter;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Annotation\Groups;
/**
* @ApiResource(
* collectionOperations={"get", "post"},
* itemOperations={
* "get"={
* "normalization_context"={"groups"={"point:read", "point:item:get", "point_controller:item:get"}},
* },
* "put",
* },
* shortName="points",
* normalizationContext={ "groups"={"point:read"}, "swagger_definition_name"="Read"},
* denormalizationContext={"groups"={"point:write"}, "swagger_definition_name"="Write"},
* attributes={
* "pagination_items_per_page"=100,
* "formats"={"jsonld", "json", "html", "csv"}
* }
* )
* @ApiFilter(PropertyFilter::class)
* @ApiFilter(SearchFilter::class, properties={"networkInstallation.id": "exact", "pointController.id": "exact"})
* Class Point
* @package App\Entity
*
* @ORM\Entity(repositoryClass="App\Repository\PointRepository")
* @ORM\Table(name="points")
*/
class Point implements JsonSerializable
{
/**
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="integer")
* @Groups({"point:read", "point_controller:item:get", "screen_point:read", "screen_point:item:get", "shape_point:read", "shape_point:item:get"})
*/
private $id;
/**
* @ORM\Column(type="string", length=128, nullable=true)
* @Groups({"point:read", "point:write", "point_controller:item:get", "screen_point:read", "screen_point:item:get", "shape_point:read", "shape_point:item:get"})
*/
private $name;
/**
* @ORM\Column(type="string", length=128, nullable=true)
*/
private $nameLower;
/**
* @ORM\Column(type="string", length=232, nullable=true)
* @Groups({"point:read", "point:write", "point_controller:item:get", "screen_point:read", "screen_point:item:get", "shape_point:read", "shape_point:item:get"})
*/
private $description;
/**
* @ORM\Column(type="string", length=32, nullable=true)
* @Groups({"point:read", "point:write", "point_controller:item:get", "screen_point:read", "shape_point:read", "shape_point:item:get"})
*/
private $address;
/**
* @ORM\Column(type="boolean", nullable=true)
* @Groups({"point:read", "point:write", "point_controller:item:get"})
*/
private $onOverview;
/**
* @ORM\Column(type="boolean", nullable=true)
* @Groups({"point:read", "point:write", "point_controller:item:get", "screen_point:read", "shape_point:read", "shape_point:item:get"})
*/
private $isVisible;
/**
* @ORM\Column(type="string", length=128, nullable=true)
* @Groups({"point:read", "point:write", "point_controller:item:get", "screen_point:read", "shape_point:read", "shape_point:item:get"})
*/
private $visibility;
/**
* @ORM\Column(type="boolean", nullable=true)
*/
private $isGlobal;
/**
* @ORM\Column(type="boolean", nullable=true)
* @Groups({"point:read", "point:write", "point_controller:item:get", "screen_point:read", "shape_point:read", "shape_point:item:get"})
*/
private $isAssigned;
/**
* @ORM\Column(type="string", length=128, nullable=true)
* @Groups({"point:read", "point:write", "point_controller:item:get", "screen_point:read", "shape_point:read", "shape_point:item:get"})
*/
private $pointGroup;
/**
* @ORM\Column(type="string", length=16, nullable=true)
* @Groups({"point:read", "point:write", "point_controller:item:get"})
*/
private $sourceType;
/**
* @ORM\Column(type="datetime", nullable=false)
* @Groups({"point:read", "point:write", "point_controller:item:get"})
*/
private $dateAdded;
/**
* @ORM\Column(type="datetime", nullable=false)
* @Groups({"point:read", "point:write", "point_controller:item:get"})
*/
private $dateModified;
/* ~~~~~~~~~~~~~~~~ OneToOne ~~~~~~~~~~~~~~~~ */
/**
* @ORM\OneToOne(targetEntity="App\Entity\PanelPoint", mappedBy="point", cascade={"persist"}, fetch="EXTRA_LAZY")
* @Groups({"point:read", "point:write", "point_controller:item:get"})
*/
private $panelPoint;
/* ~~~~~~~~~~~~~~~~ OneToMany ~~~~~~~~~~~~~~~~ */
/**
* @ORM\OneToMany(targetEntity="App\Entity\ScreenPoint", mappedBy="point", cascade={"persist"}, fetch="EXTRA_LAZY")
* @Groups({"point:read", "point:write", "point:item:get", "point_controller:item:get"})
* @ApiSubresource()
*/
private $screenPoints;
/**
* @ORM\OneToMany(targetEntity="App\Entity\ShapePoint", mappedBy="point", cascade={"persist"}, fetch="EXTRA_LAZY")
* @Groups({"point:read", "point:write", "point:item:get", "point_controller:item:get"})
* @ApiSubresource()
*/
private $shapePoints;
/* ~~~~~~~~~~~~~~~~ ManyToOne ~~~~~~~~~~~~~~~~ */
/**
* @ORM\ManyToOne(targetEntity="App\Entity\PointType", inversedBy="points", cascade={"persist"}, fetch="EXTRA_LAZY")
* @Groups({"point:read", "point:write", "point:item:get", "point_controller:item:get"})
*/
private $pointType;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\PointController", inversedBy="points", cascade={"persist"}, fetch="EXTRA_LAZY")
* @Groups({"point:read", "point:write", "point:item:get"})
*/
private $pointController;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Facility", inversedBy="points", cascade={"persist"}, fetch="EXTRA_LAZY")
*/
private $facility;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\NetworkInstallation", inversedBy="points", cascade={"persist"}, fetch="EXTRA_LAZY")
*/
private $networkInstallation;
/* ~~~~~~~~~~~~~~~~ ManyToMany ~~~~~~~~~~~~~~~~ */
/**
* @ORM\ManyToMany(targetEntity=EquipmentGroup::class, mappedBy="points")
* @Groups({"point:read", "point:write", "point:item:get"})
*/
private $equipmentGroups;
public function __construct()
{
$this->dateAdded = new \DateTime();
$this->setDateModified();
$this->screenPoints = new ArrayCollection();
$this->shapePoints = new ArrayCollection();
$this->equipmentGroups = new ArrayCollection();
}
public function __toString()
{
return (string) $this->getName();
}
/**
* @param string $property
* @return mixed
*/
public function __get(string $property)
{
// attempt to use the method
$methodName = 'get' . ucfirst( $property );
if( method_exists( $this, $methodName ) ){
return $this->{$methodName}( $property );
}
// attempt to use the method
if (property_exists($this, $property)) {
return $this->$property;
}
return null;
}
/**
* @param string $property
* @param mixed $value
* @return bool
*/
public function __set(string $property, $value) {
// attempt to use the method
$methodName = 'set' . ucfirst( $property );
if( method_exists( $this, $methodName ) ){
$this->{$methodName}( $property, $value );
return true;
}
// attempt to use the method
if (property_exists($this, $property)) {
$this->$property = $value;
return true;
}
return false;
}
public function jsonSerialize()
{
return array(
'id' => $this->id,
'name' => $this->name,
'description' => $this->description,
'address' => $this->address,
'onOverview' => $this->onOverview,
'isVisible' => $this->isVisible,
'visibility' => $this->visibility,
'isGlobal' => $this->isGlobal,
'isAssigned' => $this->isAssigned,
'pointGroup' => $this->pointGroup,
'sourceType' => $this->sourceType,
'dateAdded' => $this->dateAdded,
'dateModified' => $this->dateModified,
'screenPoints' => $this->getScreenPoints()->toArray(),
'shapePoints' => $this->getShapePoints()->toArray(),
);
}
public function serializeForTable( array $pointsWithRules = array() )
{
return array(
"DT_RowId" => "row_" . $this->getId(),
'point_id' => $this->getId(),
'dragBars' => "<i class='fas fa-bars grey'></i>",
'controllerName' => $this->getPointController()->getName(),
'pointDetail' => "<a data-toggle='modal' data-target='#pointDetailModal' data-pointid='" . $this->getId() . "' data-pointname='" . $this->getName() . "' href='#'>" . $this->getName() . "</a>",
'pointName' => $this->getName(),
'pointDescription' => $this->getDescription(),
'pointType' => (!is_null( $this->getPointType())) ? $this->getPointType()->getName() : 'Undefined',
'pointVisibility' => ($this->getIsVisible()) ? "Visible" : "Hidden",
'pointGroup' => $this->getPointGroup(),
'pointAssigned' => ($this->getIsAssigned()) ? "A" : "U",
'pointAssignedFull' => ($this->getIsAssigned()) ? "Assigned" : "Unassigned",
'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>" : '',
);
}
/**
* get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* get name
*
* @return string
*/
public function getName()
{
return $this->name;
}
/**
* set name
*
* @param string $name
*
* @return Point
*/
public function setName($name)
{
$this->name = $name;
$this->nameLower = strtolower( $name );
return $this;
}
/**
* get nameLower
*
* @return string
*/
public function getNameLower()
{
return $this->nameLower;
}
/**
* set nameLower
*
* @param string $nameLower
*
* @return Point
*/
public function setNameLower($nameLower)
{
$this->nameLower = strtolower($nameLower);
return $this;
}
/**
* get description
*
* @return string
*/
public function getDescription()
{
return $this->description;
}
/**
* set description
*
* @param string $description
*
* @return Point
*/
public function setDescription($description)
{
$this->description = $description;
return $this;
}
/**
* get address
*
* @return string
*/
public function getAddress()
{
return $this->address;
}
/**
* set address
*
* @param string $address
*
* @return Point
*/
public function setAddress($address)
{
$this->address = $address;
return $this;
}
/**
* get onOverview
*
* @return boolean
*/
public function getOnOverview()
{
return $this->onOverview;
}
/**
* set onOverview
*
* @param boolean $onOverview
*
* @return Point
*/
public function setOnOverview($onOverview)
{
$this->onOverview = $onOverview;
return $this;
}
/**
* get isVisible
*
* @return boolean
*/
public function getIsVisible()
{
return $this->isVisible;
}
/**
* set isVisible
*
* @param boolean $isVisible
*
* @return Point
*/
public function setIsVisible($isVisible)
{
$this->isVisible = $isVisible;
return $this;
}
/**
* get isGlobal
*
* @return boolean
*/
public function getIsGlobal()
{
return $this->isGlobal;
}
/**
* set isGlobal
*
* @param boolean $isGlobal
*
* @return Point
*/
public function setIsGlobal($isGlobal)
{
$this->isGlobal = $isGlobal;
return $this;
}
/**
* get isAssigned
*
* @return boolean
*/
public function getIsAssigned()
{
return ($this->isAssigned === true);
}
/**
* set isAssigned
*
* @param boolean $isAssigned
*
* @return Point
*/
public function setIsAssigned($isAssigned)
{
if( !is_null( $isAssigned ) ){
$this->isAssigned = $isAssigned;
} else {
if( count( $this->getScreenPoints() ) > 0 ){
$this->isAssigned = true;
} else {
$this->isAssigned = false;
}
}
return $this;
}
/**
* get sourceType
*
* @return string
*/
public function getSourceType()
{
return $this->sourceType;
}
/**
* set sourceType
*
* @param string $sourceType
*
* @return Point
*/
public function setSourceType($sourceType)
{
$this->sourceType = $sourceType;
return $this;
}
/**
* get visibility
*
* @return string
*/
public function getVisibility()
{
return $this->visibility;
}
/**
* set visibility
*
* @param string $visibility
*
* @return Point
*/
public function setVisibility($visibility)
{
$this->visibility = $visibility;
return $this;
}
/**
* get pointGroup
*
* @return string
*/
public function getPointGroup()
{
return $this->pointGroup;
}
/**
* set pointGroup
*
* @param string $pointGroup
*
* @return Point
*/
public function setPointGroup($pointGroup)
{
$this->pointGroup = $pointGroup;
return $this;
}
/**
* get getDateAdded
*
* @return \DateTime
*/
public function getDateAdded()
{
return $this->dateAdded;
}
/**
* get date modified
*
* @return \DateTime
*/
public function getDateModified()
{
return $this->dateModified;
}
/**
* set date modified
*
* @return \DateTime
*/
public function setDateModified()
{
$this->dateModified = new \DateTime("now");
}
/* ~~~~~~~~~~~~~~~~ OneToOne ~~~~~~~~~~~~~~~~ */
/**
* @return PanelPoint
*/
public function getPanelPoint(): ?PanelPoint
{
return $this->panelPoint;
}
/**
* @param PanelPoint $panelPoint
* @return Point
*/
public function setPanelPoint(PanelPoint $panelPoint): Point
{
$this->panelPoint = $panelPoint;
if( $panelPoint->getPoint() !== $this ){
$panelPoint->setPoint($this);
}
return $this;
}
/* ~~~~~~~~~~~~~~~~ ManyToOne ~~~~~~~~~~~~~~~~ */
/**
* get pointType
*
* @return PointType
*/
public function getPointType()
{
return $this->pointType;
}
/**
* set pointType
*
* @param PointType $pointType
*
* @return Point
*/
public function setPointType(PointType $pointType)
{
$this->pointType = $pointType;
return $this;
}
/**
* get pointController
*
* @return PointController
*/
public function getPointController()
{
return $this->pointController;
}
/**
* set pointController
*
* @param PointController $pointController
*
* @return Point
*/
public function setPointController(PointController $pointController)
{
$this->pointController = $pointController;
$pointController->addPoint( $this );
return $this;
}
/**
* get facility
*
* @return Facility
*/
public function getFacility()
{
return $this->facility;
}
/**
* set facility
*
* @param Facility $facility
*
* @return Point
*/
public function setFacility(Facility $facility)
{
if( !is_null( $facility ) ){
// update the inverse side
$facility->addPoint( $this );
} else {
$facility->addPoint( null );
}
$this->facility = $facility;
return $this;
}
/**
* get networkInstallation
*
* @return NetworkInstallation
*/
public function getNetworkInstallation()
{
return $this->networkInstallation;
}
/**
* set networkInstallation
*
* @param NetworkInstallation $networkInstallation
*
* @return Point
*/
public function setNetworkInstallation(NetworkInstallation $networkInstallation)
{
$this->networkInstallation = $networkInstallation;
$networkInstallation->addPoint( $this );
return $this;
}
/* ~~~~~~~~~~~~~~~~ ManyToMany ~~~~~~~~~~~~~~~~ */
/**
* Add screen point
*
* @param ScreenPoint $screenPoint
*
* @return Point
*/
public function addScreenPoint(ScreenPoint $screenPoint)
{
if (!$this->screenPoints->contains($screenPoint)) {
$this->screenPoints[] = $screenPoint;
$screenPoint->setPoint($this);
}
if( $this->screenPoints->count() > 0 ) $this->setIsAssigned(true);
return $this;
}
/**
* Remove screen point
*
* @param ScreenPoint $screenPoint
*
* @return Point
*/
public function removeScreenPoint(ScreenPoint $screenPoint)
{
if ($this->screenPoints->contains($screenPoint)) {
$this->screenPoints->removeElement($screenPoint);
$screenPoint->removePoint();
}
if( $this->screenPoints->count() === 0 ) $this->setIsAssigned(false);
return $this;
}
public function getScreenPoints()
{
return $this->screenPoints;
}
// todo: add addScreenPoints, removeScreenPoints
/**
* Add shape point
*
* @param ShapePoint $shapePoint
*
* @return Point
*/
public function addShapePoint(ShapePoint $shapePoint)
{
if (!$this->shapePoints->contains($shapePoint)) {
$this->shapePoints[] = $shapePoint;
$shapePoint->setPoint($this);
}
return $this;
}
/**
* Remove shape point
*
* @param ShapePoint $shapePoint
*
* @return Point
*/
public function removeShapePoint(ShapePoint $shapePoint)
{
if ($this->shapePoints->contains($shapePoint)) {
$this->shapePoints->removeElement($shapePoint);
$shapePoint->removePoint();
}
return $this;
}
public function getShapePoints()
{
return $this->shapePoints;
}
// todo: add addShapePoints, removeShapePoints
/**
* @return Collection|EquipmentGroup[]
*/
public function getEquipmentGroups(): Collection
{
return $this->equipmentGroups;
}
public function addEquipmentGroup(EquipmentGroup $equipmentGroup): self
{
if (!$this->equipmentGroups->contains($equipmentGroup)) {
$this->equipmentGroups[] = $equipmentGroup;
$equipmentGroup->addPoint($this);
}
return $this;
}
public function removeEquipmentGroup(EquipmentGroup $equipmentGroup): self
{
if ($this->equipmentGroups->removeElement($equipmentGroup)) {
$equipmentGroup->removePoint($this);
}
return $this;
}
}