* initial commit
This commit is contained in:
99
src/App/Entity/DeviceGroup.php
Normal file
99
src/App/Entity/DeviceGroup.php
Normal file
@@ -0,0 +1,99 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace App\Entity;
|
||||
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
|
||||
class DeviceGroup implements \JsonSerializable
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $name;
|
||||
|
||||
/**
|
||||
* @var Device[]|ArrayCollection
|
||||
*/
|
||||
private $devices;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->devices = new ArrayCollection();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getName(): string
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
* @return DeviceGroup
|
||||
*/
|
||||
public function setName(string $name): DeviceGroup
|
||||
{
|
||||
$this->name = trim($name);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Device[]|ArrayCollection
|
||||
*/
|
||||
public function getDevices(): ArrayCollection
|
||||
{
|
||||
return $this->devices;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Device[]|ArrayCollection $devices
|
||||
* @return DeviceGroup
|
||||
*/
|
||||
public function setDevices($devices): DeviceGroup
|
||||
{
|
||||
$this->devices = $devices;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Device $device
|
||||
* @return DeviceGroup
|
||||
*/
|
||||
public function addDevice(Device $device): DeviceGroup
|
||||
{
|
||||
if (!$this->devices->contains($device)) {
|
||||
$this->devices->add($device);
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Device $device
|
||||
* @return DeviceGroup
|
||||
*/
|
||||
public function removeDevice(Device $device): DeviceGroup
|
||||
{
|
||||
if ($this->devices->contains($device)) {
|
||||
$this->devices->removeElement($device);
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Specify data which should be serialized to JSON
|
||||
* @link http://php.net/manual/en/jsonserializable.jsonserialize.php
|
||||
* @return mixed data which can be serialized by <b>json_encode</b>,
|
||||
* which is a value of any type other than a resource.
|
||||
* @since 5.4.0
|
||||
*/
|
||||
public function jsonSerialize()
|
||||
{
|
||||
return [
|
||||
'name' => $this->getName(),
|
||||
'devices' => $this->getDevices()->getValues(),
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user