<?php
/**
* Created by PhpStorm.
* User: hariharan
* Date: 6/18/19
* Time: 2:18 PM
*/
namespace App\Document\Device;
use App\Document\Common\Icon;
use App\Document\Common\LegalEntity;
use App\Document\Geo\DeviceGeoHistory;
use App\Document\Payment\DeviceBillingPaymentProfile;
use App\Document\Vehicle\Vehicle;
use App\Document\Vehicle\VehicleFuelFunction;
use Symfony\Component\Validator\Constraints as Assert;
use Doctrine\Bundle\MongoDBBundle\Validator\Constraints\Unique as MongoDBUnique;
use Doctrine\ODM\MongoDB\Mapping\Annotations as MongoDB;
/**
* @MongoDB\Document(repositoryClass="App\Repository\Device\DeviceRepository")
* @MongoDBUnique(fields="deviceCode")
*/
class Device implements \JsonSerializable
{
/**
* @MongoDB\Id
*/
protected $id;
/**
* @MongoDB\Field(type="string")
*/
protected $deviceName;
/**
* @MongoDB\Field(type="string")
*/
protected $deviceCode;
/**
* PENDING|INACTIVE|ACTIVE|REMOVED|
* @MongoDB\Field(type="string")
*/
protected $deviceStatus;
/**
* url
* @MongoDB\Field(type="string")
*/
protected $deviceIcon;
/**
* @MongoDB\Field(type="string")
*/
protected $imei;
/**
* @MongoDB\Field(type="string")
*/
protected $connectionNo;
/**
* @MongoDB\Field(type="string")
*/
protected $vehicleNo;
/**
* @MongoDB\Field(type="string")
*/
protected $vehicleCode;
/**
* @MongoDB\ReferenceOne(targetDocument=DeviceType::class)
*/
protected $deviceType;
/**
* @MongoDB\ReferenceOne(targetDocument="App\Document\Device\Sim")
*/
protected $activeSim;
/**
* @MongoDB\ReferenceOne(targetDocument="App\Document\Vehicle\Vehicle")
*/
protected $activeVehicle;
/**
* @MongoDB\Field(type="string")
* REGISTERED,UNREGISTERED,PENDING_REGISTRATION
*/
protected $registrationStatus;
/**
* Region/Sub Level
* @MongoDB\Field(type="string")
*/
protected $authLevel;
/**
* @MongoDB\ReferenceOne(targetDocument="App\Document\Common\LegalEntity")
*/
protected $legalEntity;
/**
* document id
* @MongoDB\Field(type="string")
*/
protected $legalEntityCode;
/**
* document code
* @MongoDB\Field(type="string")
*/
protected $registeredRegionCode;
/**
* @MongoDB\ReferenceOne(targetDocument="App\Document\Zone\Region")
*/
protected $region;
/**
* @MongoDB\ReferenceOne(targetDocument="App\Document\Zone\ChildLevel")
*/
protected $childLevel;
/**
* @MongoDB\Field(type="string")
*/
protected $childLevelCode;
/**
* @MongoDB\Field(type="integer")
*/
protected $levelDepth;
/**
* km/h
* @MongoDB\Field(type="float")
*/
protected $speedLimit;
/**
* km/l
* @MongoDB\Field(type="float")
*/
protected $averageFuel;
/**
* @MongoDB\Field(type="date")
*/
protected $createdAt;
/**
* @MongoDB\Field(type="date")
*/
protected $updatedAt;
/**
* @MongoDB\ReferenceOne(targetDocument="App\Document\Security\User",cascade={"persist"})
*/
protected $createdBy;
/**
* @MongoDB\ReferenceOne(targetDocument="App\Document\Security\User",cascade={"persist"})
*/
protected $updatedBy;
/**
* @MongoDB\Field(type="boolean")
*/
protected $status;
/**
* @MongoDB\Field(type="boolean")
*/
protected $isActive;
/**
* @MongoDB\EmbedMany(targetDocument=Sim::class)
*/
private $simHistory;
/**
* @MongoDB\Field(type="boolean")
*/
protected $isSyncStarted;
/**
* @MongoDB\ReferenceOne(targetDocument="App\Document\Geo\DeviceGeoHistory")
*/
protected $latestGeoHistory;
/**
* geo synced most recent date & time
* @MongoDB\Field(type="date")
*/
protected $lastGeoAt;
/**
* @MongoDB\Field(type="date")
*/
protected $renewalDate;
/**
* @MongoDB\Field(type="date")
*/
protected $topUpDate;
/**
* @MongoDB\Field(type="collection")
*/
protected $latestGeo;
/**
* @MongoDB\Field(type="date")
*/
protected $expireAt;
/**
* geo sync interval time in min <default 30 min>
* @MongoDB\Field(type="integer")
*/
protected $geoDiff;
/**
* min time for park (in min)
* @MongoDB\Field(type="integer")
*/
protected $idlingTime;
/**
* @MongoDB\EmbedOne (targetDocument=App\Document\Geo\TrackingInfo::class)
*/
protected $latestGeoData;
/**
* @MongoDB\Field(type="boolean")
*/
protected $engineMode;
/**
* min time for park (in min)
* @MongoDB\Field(type="integer")
*/
protected $parkingBar;
/**
* [username]
* @MongoDB\Field(type="collection")
*/
protected $accessUsers;
/**
* @MongoDB\ReferenceOne(targetDocument="App\Document\Payment\DeviceBillingPaymentProfile")
*/
protected $billingProfile;
/**
* @MongoDB\Field(type="string")
*/
protected $billingProfileCode;
/**
* @MongoDB\Field(type="string")
*/
protected $activeDeviceVehicleHistory;
/**
* @MongoDB\Field(type="boolean")
*/
protected $isIoSensorEnabled;
/**
* @MongoDB\Field(type="string")
*/
protected $defaultIndicationSensorCode;
/**
* @MongoDB\Field(type="float")
*/
protected $fuelFactor;
/**
* @MongoDB\EmbedOne(targetDocument=DeviceBatteryLevel::class)
*/
protected $batteryLevel;
/**
* @MongoDB\EmbedOne(targetDocument=VehicleFuelFunction::class)
*/
protected $fuelFunction;
/**
* @MongoDB\Field(type="boolean")
*/
protected $isBleTempSensorEnabled;
/**
* @MongoDB\EmbedOne(targetDocument=BleTempSensorConfig::class)
*/
protected $bleTempSensorConfig;
public function __construct()
{
$this->deviceCode = uniqid("D-");
$this->createdAt = new \DateTime('now', new \DateTimeZone('Asia/Colombo'));
$this->status = true;
$this->isActive = true;
$this->isSyncStarted = false;
$this->isIoSensorEnabled = false;
$this->isBleTempSensorEnabled = false;
$this->geoDiff = 30;
$this->idlingTime = 5;
$this->expireAt = new \DateTime('+1 years', new \DateTimeZone('Asia/Colombo'));
}
/**
* @return mixed
*/
public function getId()
{
return $this->id;
}
/**
* @return DeviceGeoHistory $latestGeoHistory
*/
public function getLatestGeoHistory()
{
return $this->latestGeoHistory;
}
/**
* @param ?DeviceGeoHistory $latestGeoHistory
* @return self
*/
public function setLatestGeoHistory($latestGeoHistory): Device
{
$this->latestGeoHistory = $latestGeoHistory;
return $this;
}
/**
* @return mixed
*/
public function getDeviceName()
{
return $this->deviceName;
}
/**
* @param mixed $deviceName
*/
public function setDeviceName($deviceName): void
{
$this->deviceName = $deviceName;
}
/**
* @return mixed
*/
public function getDeviceCode()
{
return $this->deviceCode;
}
/**
* @param mixed $deviceCode
*/
public function setDeviceCode($deviceCode): void
{
$this->deviceCode = $deviceCode;
}
/**
* @return mixed
*/
public function getDeviceStatus()
{
return $this->deviceStatus;
}
/**
* @param mixed $deviceStatus
*/
public function setDeviceStatus($deviceStatus): void
{
$this->deviceStatus = $deviceStatus;
}
/**
* @return mixed
*/
public function getImei()
{
return $this->imei;
}
/**
* @param mixed $imei
*/
public function setImei($imei): void
{
$this->imei = $imei;
}
/**
* @return Sim $activeSim
*/
public function getActiveSim()
{
return $this->activeSim;
}
/**
* @param Sim|null $activeSim
* @return $this
*/
public function setActiveSim($activeSim): Device
{
$this->activeSim = $activeSim;
return $this;
}
/**
* @return Vehicle|null $activeVehicle
*/
public function getActiveVehicle()
{
return $this->activeVehicle;
}
/**
* @param Vehicle|null $activeVehicle
* @return self
*/
public function setActiveVehicle($activeVehicle): Device
{
$this->activeVehicle = $activeVehicle;
return $this;
}
/**
* @return mixed
*/
public function getRegistrationStatus()
{
return $this->registrationStatus;
}
/**
* @param mixed $registrationStatus
*/
public function setRegistrationStatus($registrationStatus): void
{
$this->registrationStatus = $registrationStatus;
}
/**
* @return \DateTime
*/
public function getCreatedAt(): \DateTime
{
return $this->createdAt;
}
/**
* @param \DateTime $createdAt
*/
public function setCreatedAt(\DateTime $createdAt): void
{
$this->createdAt = $createdAt;
}
/**
* @return mixed
*/
public function getUpdatedAt()
{
return $this->updatedAt;
}
/**
* @param mixed $updatedAt
*/
public function setUpdatedAt($updatedAt): void
{
$this->updatedAt = $updatedAt;
}
/**
* @return mixed
*/
public function getCreatedBy()
{
return $this->createdBy;
}
/**
* @param mixed $createdBy
*/
public function setCreatedBy($createdBy): void
{
$this->createdBy = $createdBy;
}
/**
* @return mixed
*/
public function getUpdatedBy()
{
return $this->updatedBy;
}
/**
* @param mixed $updatedBy
*/
public function setUpdatedBy($updatedBy): void
{
$this->updatedBy = $updatedBy;
}
/**
* @return bool
*/
public function isStatus(): bool
{
return $this->status;
}
/**
* @param bool $status
*/
public function setStatus(bool $status): void
{
$this->status = $status;
}
/**
* @return bool
*/
public function isActive(): bool
{
return $this->isActive;
}
/**
* @param bool $isActive
*/
public function setIsActive(bool $isActive): void
{
$this->isActive = $isActive;
}
/**
* @return mixed
*/
public function getSimHistory()
{
return $this->simHistory;
}
/**
* @param mixed $simHistory
*/
public function setSimHistory($simHistory): void
{
$this->simHistory = $simHistory;
}
/**
* @return false
*/
public function getIsSyncStarted(): bool
{
return $this->isSyncStarted;
}
/**
* @param false $isSyncStarted
*/
public function setIsSyncStarted(bool $isSyncStarted): void
{
$this->isSyncStarted = $isSyncStarted;
}
/**
* @return mixed
*/
public function getAuthLevel()
{
return $this->authLevel;
}
/**
* @param mixed $authLevel
*/
public function setAuthLevel($authLevel): void
{
$this->authLevel = $authLevel;
}
/**
* @return mixed
*/
public function getLegalEntity(): ?LegalEntity
{
return $this->legalEntity;
}
/**
* @param mixed $legalEntity
*/
public function setLegalEntity($legalEntity): void
{
$this->legalEntity = $legalEntity;
}
/**
* @return mixed
*/
public function getLegalEntityCode()
{
return $this->legalEntityCode;
}
/**
* @param mixed $legalEntityCode
*/
public function setLegalEntityCode($legalEntityCode): void
{
$this->legalEntityCode = $legalEntityCode;
}
/**
* @return mixed
*/
public function getRegisteredRegionCode()
{
return $this->registeredRegionCode;
}
/**
* @param mixed $registeredRegionCode
*/
public function setRegisteredRegionCode($registeredRegionCode): void
{
$this->registeredRegionCode = $registeredRegionCode;
}
/**
* @return mixed
*/
public function getRegion()
{
return $this->region;
}
/**
* @param mixed $region
*/
public function setRegion($region): void
{
$this->region = $region;
}
/**
* @return mixed
*/
public function getChildLevel()
{
return $this->childLevel;
}
/**
* @param mixed $childLevel
*/
public function setChildLevel($childLevel): void
{
$this->childLevel = $childLevel;
}
/**
* @return mixed
*/
public function getChildLevelCode()
{
return $this->childLevelCode;
}
/**
* @param mixed $childLevelCode
*/
public function setChildLevelCode($childLevelCode): void
{
$this->childLevelCode = $childLevelCode;
}
/**
* @return mixed
*/
public function getLevelDepth()
{
return $this->levelDepth;
}
/**
* @param mixed $levelDepth
*/
public function setLevelDepth($levelDepth): void
{
$this->levelDepth = $levelDepth;
}
/**
* @return mixed
*/
public function getLastGeoAt()
{
return $this->lastGeoAt;
}
/**
* @param mixed $lastGeoAt
*/
public function setLastGeoAt($lastGeoAt): void
{
$this->lastGeoAt = $lastGeoAt;
}
public function jsonSerialize()
{
return $this->getImei();
}
/**
* @return mixed
*/
public function getDeviceType():?DeviceType
{
return $this->deviceType;
}
/**
* @param mixed $deviceType
*/
public function setDeviceType($deviceType): void
{
$this->deviceType = $deviceType;
}
/**
* @return mixed
*/
public function getRenewalDate()
{
return $this->renewalDate;
}
/**
* @param mixed $renewalDate
*/
public function setRenewalDate($renewalDate): void
{
$this->renewalDate = $renewalDate;
}
/**
* @return mixed
*/
public function getTopUpDate()
{
return $this->topUpDate;
}
/**
* @param mixed $topUpDate
*/
public function setTopUpDate($topUpDate): void
{
$this->topUpDate = $topUpDate;
}
/**
* @return mixed
*/
public function getConnectionNo()
{
return $this->connectionNo;
}
/**
* @param mixed $connectionNo
*/
public function setConnectionNo($connectionNo): void
{
$this->connectionNo = $connectionNo;
}
/**
* @return mixed
*/
public function getVehicleNo()
{
return $this->vehicleNo;
}
/**
* @param mixed $vehicleNo
*/
public function setVehicleNo($vehicleNo): void
{
$this->vehicleNo = $vehicleNo;
}
/**
* @return mixed
*/
public function getLatestGeo()
{
return $this->latestGeo;
}
/**
* @param mixed $latestGeo
*/
public function setLatestGeo($latestGeo): void
{
$this->latestGeo = $latestGeo;
}
/**
* @return false|string
*/
public function getExpireAt()
{
return $this->expireAt;
}
/**
* @param false|string $expireAt
*/
public function setExpireAt($expireAt): void
{
$this->expireAt = $expireAt;
}
/**
* @return mixed
*/
public function getDeviceIcon()
{
return $this->deviceIcon;
}
/**
* @param mixed $deviceIcon
*/
public function setDeviceIcon($deviceIcon): void
{
$this->deviceIcon = $deviceIcon;
}
/**
* @return mixed
*/
public function getSpeedLimit()
{
return $this->speedLimit;
}
/**
* @param mixed $speedLimit
*/
public function setSpeedLimit($speedLimit): void
{
$this->speedLimit = $speedLimit;
}
/**
* @return mixed
*/
public function getAverageFuel()
{
return $this->averageFuel;
}
/**
* @param mixed $averageFuel
*/
public function setAverageFuel($averageFuel): void
{
$this->averageFuel = $averageFuel;
}
/**
* @return int
*/
public function getGeoDiff(): int
{
return $this->geoDiff;
}
/**
* @param int $geoDiff
*/
public function setGeoDiff(int $geoDiff): void
{
$this->geoDiff = $geoDiff;
}
public function getDeviceSimplified(): array
{
return array(
'id'=>$this->getId(),
'vehicleNo'=>$this->getVehicleNo(),
'vehicleCode'=>$this->getVehicleCode(),
'deviceName'=>$this->getDeviceName(),
'deviceCode'=>$this->getDeviceCode(),
'imei'=>$this->getImei(),
'lastGeoAt'=>($this->getLastGeoAt() != null)?$this->getLastGeoAt()->format('Y-m-d H:i:s'):"",
'latestGeo'=>$this->getLatestGeo(),
'deviceTypeCode'=>$this->getDeviceType()->getMetaCode(),
'icon'=>$this->getDeviceIcon(),
'connectionNo'=>$this->getConnectionNo(),
'authLevel'=>$this->getAuthLevel(),
'childLevelCode'=>$this->getChildLevelCode(),
'geoDiff'=>$this->getGeoDiff(),
'legalEntityCode'=>$this->getLegalEntityCode(),
'levelDepth'=>$this->getLevelDepth(),
'registeredRegionCode'=>$this->getRegisteredRegionCode(),
'speedLimit'=>$this->getSpeedLimit(),
'idlingTime'=>$this->getIdlingTime(),
'engineMode'=>$this->getEngineMode(),
'parkingBar'=>$this->getParkingBar(),
'accessUsers'=>$this->getAccessUsers(),
'billingProfileCode'=>$this->getBillingProfileCode(),
'averageFuel'=>$this->getAverageFuel(),
);
}
/**
* @return mixed
*/
public function getLatestGeoData()
{
return $this->latestGeoData;
}
/**
* @param mixed $latestGeoData
*/
public function setLatestGeoData($latestGeoData): void
{
$this->latestGeoData = $latestGeoData;
}
/**
* @return mixed
*/
public function getIdlingTime()
{
return ($this->idlingTime != null)?$this->idlingTime:5;
}
/**
* @param mixed $idlingTime
*/
public function setIdlingTime($idlingTime)
{
$this->idlingTime = $idlingTime;
}
/**
* @return mixed
*/
public function getAccessUsers()
{
return $this->accessUsers;
}
/**
* @param mixed $accessUsers
*/
public function setAccessUsers($accessUsers)
{
$this->accessUsers = $accessUsers;
}
/**
* @return mixed
*/
public function getEngineMode()
{
return $this->engineMode;
}
/**
* @param mixed $engineMode
*/
public function setEngineMode($engineMode)
{
$this->engineMode = $engineMode;
}
/**
* @return mixed
*/
public function getParkingBar()
{
return $this->parkingBar;
}
/**
* @param mixed $parkingBar
*/
public function setParkingBar($parkingBar)
{
$this->parkingBar = $parkingBar;
}
/**
* @return null|DeviceBillingPaymentProfile
*/
public function getBillingProfile():?DeviceBillingPaymentProfile
{
return $this->billingProfile;
}
/**
* @param mixed $billingProfile
*/
public function setBillingProfile($billingProfile): void
{
$this->billingProfile = $billingProfile;
}
/**
* @return mixed
*/
public function getBillingProfileCode()
{
return $this->billingProfileCode;
}
/**
* @param mixed $billingProfileCode
*/
public function setBillingProfileCode($billingProfileCode): void
{
$this->billingProfileCode = $billingProfileCode;
}
/**
* @return mixed
*/
public function getVehicleCode():?string
{
return $this->vehicleCode;
}
/**
* @param mixed $vehicleCode
*/
public function setVehicleCode($vehicleCode): void
{
$this->vehicleCode = $vehicleCode;
}
/**
* @return mixed
*/
public function getActiveDeviceVehicleHistory()
{
return $this->activeDeviceVehicleHistory;
}
/**
* @param mixed $activeDeviceVehicleHistory
*/
public function setActiveDeviceVehicleHistory($activeDeviceVehicleHistory): void
{
$this->activeDeviceVehicleHistory = $activeDeviceVehicleHistory;
}
/**
* @return mixed
*/
public function getIsIoSensorEnabled()
{
return $this->isIoSensorEnabled;
}
/**
* @param mixed $isIoSensorEnabled
*/
public function setIsIoSensorEnabled($isIoSensorEnabled): void
{
$this->isIoSensorEnabled = $isIoSensorEnabled;
}
/**
* @return mixed
*/
public function getDefaultIndicationSensorCode()
{
return $this->defaultIndicationSensorCode;
}
/**
* @param mixed $defaultIndicationSensorCode
*/
public function setDefaultIndicationSensorCode($defaultIndicationSensorCode): void
{
$this->defaultIndicationSensorCode = $defaultIndicationSensorCode;
}
/**
* @return mixed
*/
public function getFuelFactor()
{
return $this->fuelFactor;
}
/**
* @param mixed $fuelFactor
*/
public function setFuelFactor($fuelFactor): void
{
$this->fuelFactor = $fuelFactor;
}
/**
* @return DeviceBatteryLevel|null
*/
public function getBatteryLevel() : ?DeviceBatteryLevel
{
return $this->batteryLevel;
}
/**
* @param mixed $batteryLevel
*/
public function setBatteryLevel($batteryLevel): void
{
$this->batteryLevel = $batteryLevel;
}
/**
* @return mixed
*/
public function getFuelFunction() : ?VehicleFuelFunction
{
return $this->fuelFunction;
}
/**
* @param mixed $fuelFunction
*/
public function setFuelFunction($fuelFunction): void
{
$this->fuelFunction = $fuelFunction;
}
/**
* @return false
*/
public function getIsBleTempSensorEnabled()
{
return $this->isBleTempSensorEnabled;
}
/**
* @param false $isBleTempSensorEnabled
*/
public function setIsBleTempSensorEnabled(bool $isBleTempSensorEnabled): void
{
$this->isBleTempSensorEnabled = $isBleTempSensorEnabled;
}
/**
* @return mixed
*/
public function getBleTempSensorConfig():?BleTempSensorConfig
{
return $this->bleTempSensorConfig;
}
/**
* @param mixed $bleTempSensorConfig
*/
public function setBleTempSensorConfig($bleTempSensorConfig): void
{
$this->bleTempSensorConfig = $bleTempSensorConfig;
}
}