123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563 |
- <?php
- namespace FTTHBundle\Entity;
- use Base\AdminBundle\Traits\TenancyIdTrait;
- use Base\AdminBundle\Traits\TenancyIdTraitInterface;
- use Doctrine\ORM\Mapping as ORM;
- use ExtraDataBundle\Entity\Traits\ExtraDataTrait;
- use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
- use Symfony\Component\Validator\Constraints as Assert;
- use Symfony\Component\Workflow\Exception\ExceptionInterface;
- use DeviceBundle\Validator\Constraints as ValidatorAssert;
- use DeviceBundle\Interfaces\DeviceInterface;
- use JMS\Serializer\Annotation as JMS;
- 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 Gedmo\Mapping\Annotation as Gedmo;
- /**
- * ONU
- *
- * @ORM\Entity(repositoryClass="FTTHBundle\Repository\ONURepository")
- * @UniqueEntity(fields={"ponSerialNumber", "tenancyId"}, message="errors.duplicate_key")
- * @ORM\Table(uniqueConstraints={@ORM\UniqueConstraint(name="unique_idx", columns={"pon_serial_number", "tenancy_id"})})
- * @Gedmo\SoftDeleteable(fieldName="deletedAt", timeAware=true)
- *
- * @ValidatorAssert\Device
- */
- class ONU implements DeviceInterface, TenancyIdTraitInterface, LocationInterface, WorkflowInterface
- {
- use ExtraDataTrait;
- use TenancyIdTrait;
- use LocationTrait;
- use WorkflowTrait;
- use SoftDeleteable;
- /**
- * @var int
- *
- * @ORM\Column(name="id", type="integer", nullable=false)
- * @ORM\Id
- * @ORM\GeneratedValue(strategy="AUTO")
- */
- private $id;
- /**
- * @var string
- *
- * @ORM\Column(type="string", length=15, nullable=true)
- * @Assert\Ip
- */
- private $ip;
- /**
- * @var string
- *
- * @ORM\Column(type="string", length=12, nullable=true)
- */
- private $mac;
- /**
- * @var string
- *
- * @ORM\Column(type="string", length=11, nullable=true)
- */
- private $serialNumber;
- /**
- * @var string
- *
- * @ORM\Column(type="string", length=16, nullable=false, unique=true)
- */
- private $ponSerialNumber;
- /**
- * @var int
- *
- * @ORM\Column(type="integer", nullable=false)
- * @Assert\NotNull
- */
- private $clientId;
- /**
- * @Gedmo\Timestampable(on="create")
- * @ORM\Column(type="datetime")
- */
- protected $created;
- /**
- * @Gedmo\Timestampable(on="update")
- * @ORM\Column(type="datetime")
- */
- protected $updated;
- /**
- * @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", nullable=false, options={"default": "success"})
- */
- protected $transitionState = 'success';
- /**
- * @ORM\ManyToOne(targetEntity="OLT", inversedBy="onus", fetch="EXTRA_LAZY")
- * @JMS\MaxDepth(1)
- */
- protected $olt;
- /**
- * @ORM\ManyToOne(targetEntity="ONUModel", inversedBy="onus", fetch="EXTRA_LAZY")
- * @ORM\JoinColumn(name="model_id", referencedColumnName="id", onDelete="SET NULL")
- * @JMS\MaxDepth(1)
- */
- protected $model;
- /**
- * @ORM\ManyToOne(targetEntity="NAP", inversedBy="onus", fetch="EXTRA_LAZY")
- *
- * @JMS\MaxDepth(1)
- */
- protected $nap;
- /**
- * @ORM\ManyToOne(targetEntity="Profile", inversedBy="onus", fetch="EXTRA_LAZY")
- * @JMS\MaxDepth(1)
- */
- protected $profile;
- /**
- * @ORM\ManyToOne(targetEntity="\WorkflowBundle\Entity\Workflow", fetch="EXTRA_LAZY")
- * @ORM\JoinColumn(name="workflow_id", referencedColumnName="id", onDelete="SET NULL")
- * @JMS\MaxDepth(1)
- */
- protected $workflow;
- /**
- * @var int
- *
- * @ORM\Column(type="integer", nullable=false, options={"default": "0"})
- */
- private $position = 0;
- /**
- * @return string
- */
- public function __toString()
- {
- return (string) $this->ponSerialNumber;
- }
- /**
- * Get id
- *
- * @return int
- */
- public function getId()
- {
- return $this->id;
- }
- /**
- * Get id
- *
- * @param int
- *
- * @return ONU
- */
- public function setId($id)
- {
- $this->id = $id;
- return $this;
- }
- /**
- * Set ip
- *
- * @param string $ip
- *
- * @return ONU
- */
- public function setIp($ip)
- {
- $this->ip = $ip;
- return $this;
- }
- /**
- * Get ip
- *
- * @return string
- */
- public function getIp()
- {
- return $this->ip;
- }
- /**
- * Set mac
- *
- * @param string $mac
- *
- * @return ONU
- */
- public function setMac($mac)
- {
- $this->mac = $mac;
- return $this;
- }
- /**
- * Get mac
- *
- * @return string
- */
- public function getMac()
- {
- return $this->mac;
- }
- /**
- * Set serialNumber
- *
- * @param string $serialNumber
- *
- * @return ONU
- */
- public function setSerialNumber($serialNumber)
- {
- $this->serialNumber = $serialNumber;
- return $this;
- }
- /**
- * Get serialNumber
- *
- * @return string
- */
- public function getSerialNumber()
- {
- return $this->serialNumber;
- }
- /**
- * Set ponSerialNumber
- *
- * @param string $ponSerialNumber
- *
- * @return ONU
- */
- public function setPonSerialNumber($ponSerialNumber)
- {
- $this->ponSerialNumber = strtolower($ponSerialNumber);
- return $this;
- }
- /**
- * Get ponSerialNumber
- *
- * @return string
- */
- public function getPonSerialNumber()
- {
- return strtolower($this->ponSerialNumber);
- }
- /**
- * Set clientId
- *
- * @param integer $clientId
- *
- * @return ONU
- */
- public function setClientId($clientId)
- {
- $this->clientId = $clientId;
- return $this;
- }
- /**
- * Get clientId
- *
- * @return int
- */
- public function getClientId()
- {
- return $this->clientId;
- }
- /**
- * Get created
- *
- * @return \DateTime
- */
- public function getCreated()
- {
- return $this->created;
- }
- /**
- * Set created
- *
- * @param \DateTime
- *
- * @return ONU
- */
- public function setCreated($d)
- {
- $this->created = $d;
- return $this;
- }
- /**
- * Get updated
- *
- * @return \DateTime
- */
- public function getUpdated()
- {
- return $this->updated;
- }
- /**
- * Set updated
- *
- */
- public function setUpdated($updated)
- {
- $this->updated = $updated;
- return $this;
- }
- /**
- * Get administrativeState
- *
- */
- public function getAdministrativeState()
- {
- return $this->administrativeState;
- }
- /**
- * Set administrativeState
- *
- */
- public function setAdministrativeState($administrativeState)
- {
- $this->administrativeState = $administrativeState;
- return $this;
- }
- /**
- * @return OLT
- */
- public function getOlt()
- {
- return $this->olt;
- }
- /**
- * @param OLT $olt
- *
- * @return $this
- */
- public function setOlt($olt)
- {
- $this->olt = $olt;
- return $this;
- }
- /**
- * @return ONUModel
- */
- public function getModel()
- {
- return $this->model;
- }
- /**
- * @param ONUModel $model
- * @return $this
- */
- public function setModel($model)
- {
- $this->model = $model;
- return $this;
- }
- /**
- * @return NAP
- */
- public function getNap()
- {
- return $this->nap;
- }
- /**
- * @param NAP $nap
- *
- * @return $this
- */
- public function setNap($nap)
- {
- $this->nap = $nap;
- return $this;
- }
- /**
- * @return Profile
- */
- public function getProfile()
- {
- return $this->profile;
- }
- /**
- * @param Profile $profile
- * @return $this
- */
- public function setProfile($profile)
- {
- $this->profile = $profile;
- return $this;
- }
- /**
- * @global AppKernel $kernel
- *
- * @return string
- */
- public function getLog()
- {
- global $kernel;
- $env = $kernel->getEnvironment();
- $rootDir = $kernel->getRootDir();
- $log = $rootDir . "/../var/logs/" . $env . ".log";
- $out = array();
- exec("tail -400 {$log} | grep 'ONU_id_{$this->id}'", $out);
- return implode("\n", $out);
- }
- /* Va a quedar deprecate */
- public function getWorkflowObject()
- {
- return $this->workflow;
- }
- /**
- * @return string
- */
- public function getAdministrativeWorkflow()
- {
- return "administrative_state";
- }
- /**
- * Get getPosition
- *
- * @return int
- */
- public function getPosition()
- {
- return $this->position;
- }
- /**
- * Set getPosition
- *
- * No se recomienda usar este metodo, porque se debe calcular a partir del NAP
- *
- * @return $this
- */
- public function setPosition($position)
- {
- $this->position = $position;
- return $this;
- }
- /**
- * @return int
- */
- public function getSlot()
- {
- $olt = null;
- if ($this->nap) {
- $olt = $this->nap->getSlot();
- }
- return $olt;
- }
- /**
- * @return int
- */
- public function getLink()
- {
- $olt = null;
- if ($this->nap) {
- $olt = $this->nap->getLink();
- }
- return $olt;
- }
- /**
- * @return array
- */
- public function getDeviceData()
- {
- $deviceData = array();
- $deviceData['deviceType'] = get_class($this);
- $deviceData['deviceId'] = $this->id;
- $deviceData['ip'] = $this->ip;
- $deviceData['tenancy'] = $this->tenancyId;
- $deviceExtraData = array('mac' => $this->mac, 'serialNumber' => $this->serialNumber, 'ponSerialNumber' => $this->ponSerialNumber,
- 'clientId' => $this->clientId);
- ($this->olt) ? $olt = $this->getOlt()->getId() : $olt = null;
- ($this->model) ? $model = $this->getModel()->getId() : $model = null;
- ($this->nap) ? $nap = $this->getNap()->getId() : $nap = null;
- ($this->profile) ? $profile = $this->getProfile()->getId() : $profile = null;
- $deviceExtraData['oltId'] = $olt;
- $deviceExtraData['modelId'] = $model;
- $deviceExtraData['napId'] = $nap;
- $deviceExtraData['profileId'] = $profile;
- $deviceData['extraData'] = json_encode($deviceExtraData);
- return $deviceData;
- }
- }
|