feat: implement issue #
This commit is contained in:
53
application/Measurement/Measurement.php
Normal file
53
application/Measurement/Measurement.php
Normal file
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
class Measurement extends mfBaseModel
|
||||
{
|
||||
private $device;
|
||||
private $sensor;
|
||||
|
||||
public function getProperty($name)
|
||||
{
|
||||
if ($this->$name == null) {
|
||||
if (!$this->id) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if($name == "device") {
|
||||
$this->device = mfValuecache::singleton()->get("Device-id-".$this->device_id);
|
||||
if($this->device === null) {
|
||||
$this->device = new Device($this->device_id);
|
||||
if($this->device->id) {
|
||||
mfValuecache::singleton()->set("Device-id-".$this->device_id, $this->device);
|
||||
}
|
||||
}
|
||||
return $this->device;
|
||||
}
|
||||
|
||||
if($name == "sensor") {
|
||||
// Sensor would be a separate entity if it exists
|
||||
// For now, just return the sensor_id
|
||||
return $this->sensor_id;
|
||||
}
|
||||
|
||||
$classname = ucfirst($name);
|
||||
$idfield = $name."_id";
|
||||
if(property_exists($this->data, $idfield)) {
|
||||
$this->$name = mfValuecache::singleton()->get("mfObjectmodel-$name-".$this->$idfield);
|
||||
if(!$this->$name) {
|
||||
$this->$name = new $classname($this->$idfield);
|
||||
}
|
||||
|
||||
if($this->$name->id) {
|
||||
mfValuecache::singleton()->set("mfObjectmodel-$name-".$this->$name->id, $this->$name);
|
||||
return $this->$name;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
return $this->$name;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user