예제 #1
0
 public function actionCommand($id)
 {
     //get Scene Devices by Scene ID
     $sceneDevices = SceneDevices::model()->findAll('tbl_scene_idtbl_scene=:sceneID', array(':sceneID' => $id));
     foreach ($sceneDevices as $node) {
         //get node details and get device type
         $device = Devices::model()->find('idtbl_device=:deviceID', array(':deviceID' => $node["tbl_devices_idtbl_device"]));
         if ($_GET['state'] == "100") {
             $nodeLevel = $node["tbl_scene_device_level"];
         } else {
             $nodeLevel = 0;
         }
         $nodeID = $device["tbl_device_nodeid"];
         $nodeType = $device["tbl_device_type"];
         $url = Yii::app()->params['serverurl'] . "/server.php?command=control&node=" . $nodeID . "&type=" . urlencode($nodeType) . "&level=" . $nodeLevel;
         echo $url;
         // create a new cURL resource
         $ch = curl_init();
         // set URL and other appropriate options
         curl_setopt($ch, CURLOPT_URL, $url);
         curl_setopt($ch, CURLOPT_HEADER, 0);
         // grab URL and pass it to the browser
         curl_exec($ch);
         // close cURL resource, and free up system resources
         curl_close($ch);
     }
     $this->redirect(array('index'));
 }
 public function actionGetdevices()
 {
     $data = Devices::model()->findAll('tbl_rooms_idtbl_room=:room_id', array(':room_id' => (int) $_POST['room_id']));
     $data = CHtml::listData($data, 'idtbl_device', 'tbl_device_name');
     foreach ($data as $value => $name) {
         echo CHtml::tag('option', array('value' => $value), CHtml::encode($name), true);
     }
 }
 private function generateCronJob($min, $hr, $day, $month, $dayOfWeek, $devices, $state)
 {
     $jobs = array();
     $count = 0;
     //get all devices for this particualr scene
     foreach ($devices as $device) {
         //get device details
         $node = Devices::model()->find("idtbl_device=" . $device->tbl_devices_idtbl_device);
         if ($node) {
             if ($state == 'off') {
                 $level = 0;
             } else {
                 $level = $device->tbl_scene_device_level;
             }
             //build cron job string
             $jobs[$count] = $min . ' ' . $hr . ' ' . $day . ' ' . $month . ' ' . $dayOfWeek . ' curl "' . "http://localhost" . Yii::app()->createUrl("control/command", array("node" => $node->tbl_device_nodeid, "type" => $node->tbl_device_type, "level" => $level)) . '"';
             $count++;
         }
     }
     return $jobs;
 }
 /**
  * Returns the data model based on the primary key given in the GET variable.
  * If the data model is not found, an HTTP exception will be raised.
  * @param integer $id the ID of the model to be loaded
  * @return Monitor the loaded model
  * @throws CHttpException
  */
 public function loadModel($id)
 {
     $model = Devices::model()->findByPk($id);
     if ($model === null) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     return $model;
 }
예제 #5
0
    <div class="row">	
    <?php 
if (isset($_GET["sceneId"])) {
    $model->tbl_scene_idtbl_scene = $_GET["sceneId"];
}
echo $form->hiddenField($model, 'tbl_scene_idtbl_scene');
?>
    </div>

    <div class="row">
       <?php 
echo $form->labelEx($model, 'tbl_devices_idtbl_device');
?>
        <?php 
if (isset($_GET['id'])) {
    echo $form->dropDownList($model, 'tbl_devices_idtbl_device', CHtml::listData(Devices::model()->findAll(), 'idtbl_device', 'tbl_device_name'));
} else {
    echo $form->dropDownList($model, 'tbl_devices_idtbl_device', array());
}
?>
        <?php 
echo $form->error($model, 'tbl_devices_idtbl_device');
?>
    </div>

    <div class="row">
<?php 
echo $form->labelEx($model, 'tbl_scene_device_level');
echo $form->textField($model, 'tbl_scene_device_level');
?>
        <?php 
 public function getInfo()
 {
     /* Items allocated*/
     $commodity['consumable'] = Consumable::model()->findAll();
     $commodity['monitor'] = Monitor::model()->findAll();
     $commodity['printers'] = Printers::model()->findAll();
     $commodity['devices'] = Devices::model()->findAll();
     $dup = $commodity;
     /* Items available on Loan*/
     $availableOnLoan = 0;
     $thresholdItems = 0;
     $content = '';
     foreach ($commodity as $key => $commo) {
         foreach ($commo as $item) {
             if ($item['available_on_loan'] == 1 || $item['available_on_loan'] == 'Yes') {
                 ++$availableOnLoan;
             }
             if ($key == 'consumable') {
                 $commodity = Commodity::model()->findByAttributes(array('name' => $key));
                 $allocates = Allocate::model()->findAllByAttributes(array('commodity_id' => $commodity['id'], 'cons_id' => $item['id']));
                 if (count($allocates) < $item['threshold']) {
                     ++$thresholdItems;
                 }
             }
         }
     }
     /** Allocated and unallocated **/
     $countAllocated = 0;
     $countUnAllocated = 0;
     $commodity = $dup;
     $unAllocated = Allocate::model()->findAllByAttributes(array('date_out' => NULL));
     $allocated = Allocate::model()->findAll('date_out IS NOT NULL');
     $countAllocated += count($allocated);
     $countUnAllocated += count($unAllocated);
     $content .= '<b style="color:red">' . $availableOnLoan . '</b> item available on loan<br/>';
     $content .= '<b style="color:red">' . $thresholdItems . '</b> item below threshold<br/>';
     $content .= '<b style="color:red">' . $countAllocated . '</b> item allocated<br/>';
     $content .= '<b style="color:red">' . $countUnAllocated . '</b> item unallocated<br/>';
     /* Items below threshold*/
     return $content;
 }