Example #1
0
 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');
     }
 }