コード例 #1
0
 /**
  * Finds the Sensor model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Sensor the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Sensor::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
コード例 #2
0
ファイル: index.php プロジェクト: gpis88ce/Gpis88ce
<?php

use common\models\Sensor;
use yii\helpers\Html;
use yii\grid\GridView;
$this->title = 'Danh sách thông báo';
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="message-index">

    <h4><?php 
echo Html::encode($this->title);
?>
</h4>

    <?php 
echo GridView::widget(['dataProvider' => $dataProvider, 'columns' => [['class' => 'yii\\grid\\SerialColumn', 'options' => ['width' => '6%']], ['attribute' => 'sensor_id', 'value' => function ($model) {
    $sensor = Sensor::findOne($model->sensor_id);
    return $sensor['name'];
}], 'message_0', 'message_1', ['class' => 'yii\\grid\\ActionColumn', 'template' => '{update} {delete}', 'options' => ['width' => '10%']]]]);
?>

</div>
コード例 #3
0
ファイル: SensorStatus.php プロジェクト: gpis88ce/Gpis88ce
 public function getSensor()
 {
     return $this->hasOne(Sensor::className(), ['id' => 'sensor_id']);
 }
コード例 #4
0
ファイル: station.php プロジェクト: gpis88ce/Gpis88ce
        <?php 
echo GridView::widget(['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'summary' => false, 'columns' => [['attribute' => 'name', 'options' => ['width' => '15%']], ['attribute' => 'center_id', 'format' => 'text', 'filter' => Center::_prepareDataSelect(Center::find()->all(), 'id', 'name', false), 'value' => function ($model) {
    if ($model->center_id > 0) {
        $center = Center::findOne($model->center_id);
        if ($center) {
            return $center->name;
        }
    }
    return null;
}, 'options' => ['width' => '10%']], ['attribute' => 'area_id', 'format' => 'text', 'filter' => Area::_prepareDataSelect(Area::find()->all(), 'id', 'name', false), 'value' => function ($model) {
    $area = Area::findOne($model->area_id);
    return $area->name;
}, 'options' => ['width' => '10%']], ['attribute' => 'address'], ['label' => 'Báo động', 'format' => 'html', 'value' => function ($model) {
    $securitySensor = SensorStatus::findOne(['station_id' => $model->id, 'sensor_id' => Sensor::ID_SECURITY]);
    $label = Sensor::getSecurityStatus($securitySensor['value']);
    if ($securitySensor['value'] == Sensor::SECURITY_ON) {
        return Show::decorateString($label, 'good');
    } else {
        if ($securitySensor['value'] == Sensor::SECURITY_OFF) {
            return Show::decorateString($label, 'bad');
        }
    }
}, 'options' => ['width' => '10%']], ['attribute' => 'status', 'format' => 'html', 'filter' => $statusData, 'value' => function ($model) {
    if ($model->status == Station::STATUS_CONNECTED) {
        $html = Show::decorateString($model->getStatus($model->status), 'good');
    }
    if ($model->status == Station::STATUS_LOST) {
        $html = Show::decorateString($model->getStatus($model->status), 'bad');
    }
    return $html;
コード例 #5
0
 public function initSensor($stationId)
 {
     if ($stationId > 0) {
         $sensors = Sensor::find()->all();
         if (!empty($sensors)) {
             foreach ($sensors as $sensor) {
                 $data[] = [$sensor->id, $stationId];
             }
             Yii::$app->db->createCommand()->batchInsert('sensor_status', ['sensor_id', 'station_id'], $data)->execute();
         }
     }
 }
コード例 #6
0
ファイル: view.php プロジェクト: gpis88ce/Gpis88ce
<table class="detail-view table table-hover table-bordered">
    <tr class="info">
        <th colspan="4">Trạng thái</th>
    </tr>

    <?php 
$no = 1;
if (!empty($model->sensor_status)) {
    foreach ($model->sensor_status as $status) {
        $value = $status['value'];
        $label = $value;
        $labelButton = '';
        if ($status['type'] == Sensor::TYPE_VALUE) {
            if ($status['sensor_id'] == Sensor::ID_SECURITY) {
                $label = Sensor::getSecurityStatus($value);
                if ($value == Sensor::SECURITY_ON) {
                    $label = Show::decorateString($label, 'good');
                    $labelButton = '<a href="' . $changeUrl . '?part=security&station_id=' . $model->id . '&status=' . Sensor::SECURITY_OFF . '" type="button" class="btn btn-primary btn-xs">Tắt báo động</a>';
                }
                if ($value == Sensor::SECURITY_OFF) {
                    $label = Show::decorateString($label, 'bad');
                    $labelButton = '<a href="' . $changeUrl . '?part=security&station_id=' . $model->id . '&status=' . Sensor::SECURITY_ON . '" type="button" class="btn btn-primary btn-xs">Bật báo động</a>';
                }
            }
        } else {
            continue;
        }
        if ($no == 1) {
            $connectStatus = $model->getStatus($model->status);
            if ($model->status == Station::STATUS_CONNECTED) {
コード例 #7
0
 private function getSensor()
 {
     $sensorCollections = Sensor::findAll(['type' => Sensor::TYPE_CONFIGURE]);
     return Sensor::_prepareDataSelect($sensorCollections, 'id', 'name');
 }