123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387 |
- <?php
- namespace CablemodemBundle\Entity;
- use Doctrine\ORM\Mapping as ORM;
- use Gedmo\Mapping\Annotation as Gedmo;
- use JMS\Serializer\Annotation as JMS;
- use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
- use Symfony\Component\Validator\Constraints as Assert;
- use Base\AdminBundle\Traits\TenancyIdTrait;
- use Base\AdminBundle\Traits\TenancyIdTraitInterface;
- use DeviceBundle\Interfaces\DeviceInterface;
- use DeviceBundle\Validator\Constraints as ValidatorAssert;
- use ExtraDataBundle\Entity\Traits\ExtraDataTrait;
- use MapBundle\Entity\Interfaces\LocationInterface;
- use MapBundle\Entity\Traits\LocationTrait;
- use WorkflowBundle\Entity\Interfaces\WorkflowInterface;
- use WorkflowBundle\Entity\Traits\WorkflowTrait;
- use Gedmo\SoftDeleteable\Traits\SoftDeleteableEntity as SoftDeleteable;
- use Base\AdminBundle\Interfaces\SoftDeleteInterface;
- /**
- * @ORM\Entity
- * @ORM\Table(indexes={@ORM\Index(name="mac", columns={"mac"})})
- *
- * @UniqueEntity(fields={"mac"})
- *
- * @Gedmo\Loggable
- * @Gedmo\SoftDeleteable(fieldName="deletedAt", timeAware=true)
- *
- * @ValidatorAssert\Device
- */
- class Cablemodem implements DeviceInterface, TenancyIdTraitInterface, LocationInterface, WorkflowInterface, SoftDeleteInterface
- {
- use ExtraDataTrait;
- use TenancyIdTrait;
- use LocationTrait;
- use WorkflowTrait;
- use SoftDeleteable;
- /**
- * @var bigint $id
- *
- * @ORM\Column(name="id", type="bigint", nullable=false)
- * @ORM\Id
- * @ORM\GeneratedValue(strategy="IDENTITY")
- */
- protected $id;
- /**
- * @var int
- *
- * @ORM\Column(type="integer")
- *
- * @Assert\NotNull
- */
- protected $clientId;
- /**
- * @var string $mac
- *
- * @ORM\Column(type="string", length=12, nullable=false, unique=true)
- *
- * @Gedmo\Versioned
- *
- * @Assert\Regex(pattern="/^[a-z0-9]+$/")
- * @Assert\Length(min=12, max=12)
- * @Assert\NotBlank()
- * @Assert\NotNull
- */
- protected $mac;
- /**
- * @ORM\Column(type="string", length=100, nullable=true)
- *
- * @Gedmo\Versioned
- */
- protected $activationCode;
- /**
- * @ORM\ManyToOne(targetEntity="Node", fetch="EXTRA_LAZY", cascade={"persist"})
- *
- * @JMS\MaxDepth(1)
- */
- protected $node;
- /**
- * @ORM\ManyToOne(targetEntity="Profile", fetch="EXTRA_LAZY")
- *
- * @JMS\MaxDepth(1)
- */
- protected $profile;
- /**
- * @ORM\ManyToOne(targetEntity="CablemodemModel", fetch="EXTRA_LAZY")
- *
- * @JMS\MaxDepth(1)
- */
- protected $model;
- /**
- * @Gedmo\Timestampable(on="create")
- *
- * @ORM\Column(type="datetime")
- */
- protected $created;
- /**
- * @Gedmo\Timestampable(on="update")
- *
- * @ORM\Column(type="datetime")
- */
- protected $updated;
- /**
- * @ORM\ManyToOne(targetEntity="\WorkflowBundle\Entity\Workflow", fetch="EXTRA_LAZY")
- * @ORM\JoinColumn(name="workflow_id", referencedColumnName="id", onDelete="SET NULL")
- *
- * @JMS\MaxDepth(1)
- */
- protected $workflow;
- /**
- * @ORM\Column(type="string", nullable=true)
- */
- protected $currentState = null;
- /**
- * @ORM\Column(type="string", nullable=true, options={"default": "active"})
- */
- protected $administrativeState = 'active';
- /**
- * @ORM\Column(type="string", options={"default": "success"})
- */
- protected $transitionState = 'success';
- /**
- * @ORM\Column(type="boolean", nullable=true)
- */
- protected $mtaEnabled = false;
- /**
- * @return string
- */
- public function __toString()
- {
- return (string) ($this->mac ?: $this->activationCode);
- }
- /**
- * @return int
- */
- public function getId()
- {
- return $this->id;
- }
- /**
- * @return int
- */
- public function getClientId()
- {
- return $this->clientId;
- }
- /**
- * @return string
- */
- public function getMac()
- {
- return $this->mac;
- }
- /**
- * @return string
- */
- public function getActivationCode()
- {
- return $this->activationCode;
- }
- /**
- * @return Node
- */
- public function getNode()
- {
- return $this->node;
- }
- /**
- * @return Profile
- */
- public function getProfile()
- {
- return $this->profile;
- }
- /**
- * @return CablemodemModel
- */
- public function getModel()
- {
- return $this->model;
- }
- /**
- * @return \DateTime
- */
- public function getCreated()
- {
- return $this->created;
- }
- /**
- * @return \DateTime
- */
- public function getUpdated()
- {
- return $this->updated;
- }
- /**
- * @param int $clientId
- *
- * @return $this
- */
- public function setClientId($clientId)
- {
- $this->clientId = $clientId;
- return $this;
- }
- /**
- * @param string $mac
- *
- * @return $this
- */
- public function setMac($mac)
- {
- $this->mac = $mac;
- return $this;
- }
- /**
- * @param string $activationCode
- *
- * @return $this
- */
- public function setActivationCode($activationCode)
- {
- $this->activationCode = $activationCode;
- return $this;
- }
- /**
- * @param Node $node
- *
- * @return $this
- */
- public function setNode($node)
- {
- $this->node = $node;
- return $this;
- }
- /**
- * @param Profile $profile
- *
- * @return $this
- */
- public function setProfile($profile)
- {
- $this->profile = $profile;
- return $this;
- }
- /**
- * @param CablemodemModel $model
- *
- * @return $this
- */
- public function setModel($model)
- {
- $this->model = $model;
- return $this;
- }
- /**
- * @param \DateTime $created
- *
- * @return $this
- */
- public function setCreated($created)
- {
- $this->created = $created;
- return $this;
- }
- /**
- * @param \DateTime $updated
- *
- * @return $this
- */
- public function setUpdated($updated)
- {
- $this->updated = $updated;
- return $this;
- }
- /**
- * @return array
- */
- public function getDeviceData()
- {
- $extraData = [
- 'mac' => $this->mac,
- 'activationCode' => $this->activationCode,
- 'clientId' => $this->clientId,
- 'modelId' => $this->model ? $this->model->getId() : null,
- 'nodeId' => $this->node ? $this->node->getId() : null,
- 'profileId' => $this->profile ? $this->profile->getId() : null,
- ];
- return [
- 'deviceType' => get_class($this),
- 'deviceId' => $this->id,
- 'tenancy' => $this->tenancyId,
- 'extraData' => json_encode($extraData),
- ];
- }
- /**
- * @return array
- */
- public function getSoftDeleteCriteria()
- {
- return array('mac' => $this->mac);
- }
- /**
- * @return boolean
- */
- public function getMtaEnabled()
- {
- return $this->mtaEnabled;
- }
- /**
- * @param boolean $mtaEnabled
- *
- * @return Cablemodem
- */
- public function setMtaEnabled($mtaEnabled)
- {
- $this->mtaEnabled = $mtaEnabled;
- return $this;
- }
- /**
- * @return string
- */
- public function getDHCPOptions()
- {
- $options = [
- 'filename' => $this->mac . '.bin',
- ];
- if ($this->mtaEnabled) {
- $options['option122_dhcp_server'] = "255.255.255.255";
- $options['option122_provisioning_type'] = "BASIC.1";
- }
- return $options;
- }
- }
|