Ejemplo n.º 1
0
        <?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;
Ejemplo n.º 2
0
<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) {