static function getFeedDevices($feed_id) { $db = DevblocksPlatform::getDatabaseService(); $rs = $db->Execute(sprintf("SELECT feed_id, device_id FROM feed_item WHERE feed_id=%d", $feed_id)); $device_ids = array(); while (!$rs->EOF) { $device_ids[] = intval($rs->fields['device_id']); $rs->MoveNext(); } if (empty($device_ids)) { return array(); } return DAO_Device::getWhere(sprintf("%s IN (%s)", DAO_Device::ID, implode(',', $device_ids))); }
protected function _getListAction($path) { $devices = DAO_Device::getWhere(); $xml = new SimpleXMLElement("<devices></devices>"); foreach ($devices as $device) { /* @var $device Model_Device */ $eDevice =& $xml->addChild('device'); $eDevice->addChild('id', $device->id); $eDevice->addChild('name', $device->name); $eDevice->addChild('guid', $device->guid); $eDevice->addChild('last_updated', $device->last_updated); } $this->_render($xml->asXML()); }
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'); } }