private function _deleteIdAction($path) { $in_id = array_shift($path); if (empty($in_id)) { $this->_error("ID was not provided."); } if (null == ($sensor = DAO_Sensor::get($in_id))) { $this->_error("ID is not valid."); } DAO_Sensor::delete($sensor->id); $out_xml = new SimpleXMLElement('<success></success>'); $this->_render($out_xml->asXML()); }
protected function _getIdAction($path) { $in_id = array_shift($path); if (empty($in_id)) { $this->_error("ID was not provided."); } if (null == ($sensor = DAO_Sensor::get($in_id))) { $this->_error("ID not valid."); } $xml_out = new SimpleXMLElement("<sensor></sensor>"); $xml_out->addChild('id', $sensor->id); $xml_out->addChild('device_id', $sensor->device_id); $xml_out->addChild('monitor_id', $sensor->monitor_id); $xml_out->addChild('status', $sensor->status); $xml_out->addChild('output', $sensor->output); $xml_out->addChild('metric', $sensor->metric); $xml_out->addChild('last_updated', $sensor->last_updated); $this->_render($xml_out->asXML()); }
function showSensorExtensionConfigAction() { @($ext_id = DevblocksPlatform::importGPC($_REQUEST['ext_id'], 'string', '')); @($id = DevblocksPlatform::importGPC($_REQUEST['id'], 'integer', 0)); if (null == ($sensor = DAO_Sensor::get($id))) { $sensor = new Model_Sensor(); } if (!empty($ext_id)) { if (null != ($ext = DevblocksPlatform::getExtension($ext_id, true))) { if ($ext instanceof Extension_Sensor) { $ext->renderConfig($sensor); } } } }
function render() { $path = dirname(__FILE__); $tpl = DevblocksPlatform::getTemplateService(); $tpl->cache_lifetime = "0"; $tpl->assign('path', $path . '/templates/'); $visit = Application::getVisit(); /* @var $visit PortSensorVisit */ $response = DevblocksPlatform::getHttpResponse(); $stack = $response->path; @array_shift($stack); // events @($id = array_shift($stack)); // id if (empty($id)) { $tpl->assign('now_secs', time()); // Devices if (!$visit->is_admin && !empty($visit->is_feed)) { $devices = DAO_FeedItem::getFeedDevices($visit->is_feed->id); $tpl->assign('devices', $devices); // Events $plots = DAO_SensorEvent::getWhere(sprintf("%s IN (%s) ", "se.device_id", implode(',', array_keys($devices)))); $tpl->assign('plots', $plots); } elseif ($visit->is_admin) { $devices = DAO_Device::getWhere(); $tpl->assign('devices', $devices); // Events $plots = DAO_SensorEvent::getWhere(); $tpl->assign('plots', $plots); } $tpl->display('file:' . dirname(__FILE__) . '/templates/events/index.tpl.php'); } else { $db = DevblocksPlatform::getDatabaseService(); $tpl->assign('now_secs', time()); $sensor = DAO_Sensor::get($id); $tpl->assign('sensor', $sensor); $device = DAO_Device::getByID($sensor->device_id); $tpl->assign('device', $device); // Security check for device for current logged in user if (!$visit->is_admin && !empty($visit->is_feed)) { $feed_devices = DAO_FeedItem::getFeedDevices($visit->is_feed->id); if (!isset($feed_devices[$sensor->device_id])) { return; } } $events = DAO_SensorEvent::getWhere(sprintf("%s = %d", DAO_SensorEvent::SENSOR_ID, $sensor->id)); $tpl->assign('plots', $events); $tpl->display('file:' . dirname(__FILE__) . '/templates/events/sensor.tpl.php'); } }