|
@@ -20,6 +20,7 @@ use JMS\Serializer\Annotation as JMS;
|
|
|
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
|
|
|
use Symfony\Component\Validator\Constraints as Assert;
|
|
|
use Symfony\Component\Workflow\Exception\ExceptionInterface;
|
|
|
+use Doctrine\ORM\Mapping\HasLifecycleCallbacks;
|
|
|
|
|
|
/**
|
|
|
* ONU
|
|
@@ -34,6 +35,7 @@ use Symfony\Component\Workflow\Exception\ExceptionInterface;
|
|
|
* @ValidatorAssert\Device
|
|
|
*
|
|
|
* @FTTHAssert\Position
|
|
|
+ * @HasLifecycleCallbacks
|
|
|
*/
|
|
|
class ONU implements DeviceInterface, TenancyIdTraitInterface, LocationInterface, WorkflowInterface, SoftDeleteInterface
|
|
|
{
|
|
@@ -708,7 +710,7 @@ class ONU implements DeviceInterface, TenancyIdTraitInterface, LocationInterface
|
|
|
|
|
|
return $this;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
* Get ponSerialNumberAux
|
|
|
*
|
|
@@ -729,7 +731,7 @@ class ONU implements DeviceInterface, TenancyIdTraitInterface, LocationInterface
|
|
|
$servicePort->setOnu($this);
|
|
|
$servicePort->setOlt($this->olt);
|
|
|
$this->servicePorts[] = $servicePort;
|
|
|
-
|
|
|
+
|
|
|
return $this;
|
|
|
}
|
|
|
|
|
@@ -743,7 +745,7 @@ class ONU implements DeviceInterface, TenancyIdTraitInterface, LocationInterface
|
|
|
$servicePort->setOnu(null);
|
|
|
$servicePort->setOlt(null);
|
|
|
$this->servicePorts->removeElement($servicePort);
|
|
|
-
|
|
|
+
|
|
|
return $this;
|
|
|
}
|
|
|
|
|
@@ -767,7 +769,7 @@ class ONU implements DeviceInterface, TenancyIdTraitInterface, LocationInterface
|
|
|
$servicePort->setOlt($this->olt);
|
|
|
}
|
|
|
$this->servicePorts = $servicePorts;
|
|
|
-
|
|
|
+
|
|
|
return $this;
|
|
|
}
|
|
|
|
|
@@ -1028,7 +1030,7 @@ class ONU implements DeviceInterface, TenancyIdTraitInterface, LocationInterface
|
|
|
{
|
|
|
return $this->onuProfile;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
* @return string
|
|
|
*/
|
|
@@ -1039,4 +1041,88 @@ class ONU implements DeviceInterface, TenancyIdTraitInterface, LocationInterface
|
|
|
}, $this->servicePorts->toArray()));
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * @ORM\PrePersist()
|
|
|
+ */
|
|
|
+ public function prePersist()
|
|
|
+ {
|
|
|
+ $this->correctSerialNumber();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @ORM\PreUpdate()
|
|
|
+ */
|
|
|
+ public function preUpdate()
|
|
|
+ {
|
|
|
+ $this->correctSerialNumber();
|
|
|
+ }
|
|
|
+
|
|
|
+ public function correctSerialNumber() {
|
|
|
+
|
|
|
+ $ponSerialNumber = $this->getPonSerialNumber(); //Identificador
|
|
|
+
|
|
|
+ $serialNumber = $this->getSerialNumber();
|
|
|
+ $ponSerialNumberAux = $this->getPonSerialNumberAux();
|
|
|
+
|
|
|
+ if(strlen($ponSerialNumber) == 12 || strlen($ponSerialNumber) == 16) {
|
|
|
+
|
|
|
+ if(is_null($serialNumber) || empty($serialNumber)) {
|
|
|
+ if(strlen($ponSerialNumber) == 16) {
|
|
|
+ // It is a serial number > set serial number
|
|
|
+ $this->setSerialNumber($ponSerialNumber);
|
|
|
+ } else {
|
|
|
+ // It is a pon serial number > convert vendor id from string to hexa and set serial number
|
|
|
+ $vendoId = $this->str2hex(substr($ponSerialNumber,0,4));
|
|
|
+ $rest = substr($ponSerialNumber,4);
|
|
|
+ $sn = strtolower($vendoId.$rest);
|
|
|
+ $this->setSerialNumber($sn);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if(is_null($ponSerialNumberAux) || empty($ponSerialNumberAux)) {
|
|
|
+ if(strlen($ponSerialNumber) == 16) {
|
|
|
+ // It is a serial number > convert vendor id from hexa to string and set pon serial number
|
|
|
+ $_vendor = substr($ponSerialNumber,0,8);
|
|
|
+ $hex = strtoupper($_vendor);
|
|
|
+
|
|
|
+ $isNumeric = true;
|
|
|
+ for($i=0;$i<strlen($hex);$i+=2) {
|
|
|
+ if(!is_numeric(substr($hex,$i,2))) {
|
|
|
+ $isNumeric = false;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if($isNumeric) { //hexa check
|
|
|
+ $vendoId = $this->hex2str($hex);
|
|
|
+ $rest = substr($ponSerialNumber,8);
|
|
|
+ $psn = strtolower($vendoId.$rest);
|
|
|
+ $this->setPonSerialNumberAux($psn);
|
|
|
+ } else {
|
|
|
+ $this->setPonSerialNumberAux($ponSerialNumber);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ // It is a pon serial number > set pon serial number
|
|
|
+ $this->setPonSerialNumberAux($ponSerialNumber);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ function hex2str($hex) {
|
|
|
+ $hex = strtoupper($hex);
|
|
|
+ $str = "";
|
|
|
+ for($i=0;$i<strlen($hex);$i+=2)
|
|
|
+ $str .= chr(hexdec(substr($hex,$i,2)));
|
|
|
+
|
|
|
+ return $str;
|
|
|
+ }
|
|
|
+
|
|
|
+ function str2hex($string){
|
|
|
+ $string = strtoupper($string);
|
|
|
+ $hex = "";
|
|
|
+ for ($i=0; $i < strlen($string); $i++)
|
|
|
+ $hex .= dechex(ord($string[$i]));
|
|
|
+
|
|
|
+ return $hex;
|
|
|
+ }
|
|
|
}
|