Esempio n. 1
0
">
</div>

<div class="row">

    <div class="col-sm-12 block-station div-station scrolling">
        <div class="panel panel-primary" id="panel-station">
            <div class="panel-heading">
                <h4 class="panel-title">
                    <i class="glyphicon glyphicon-phone"></i><span style="margin-right: 10px;">Danh sách trạm</span>
                </h4>
            </div>
        </div>

        <?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');
Esempio n. 2
0
 public function actionUpdate($id)
 {
     $model = $this->findModel($id);
     // parse data
     $parseData = ['model' => $model];
     // check if not has dc status and sensor status, then create them
     //if (!$model->dc_equip_status) $this->initDc($id);
     if (!$model->sensor_status) {
         $this->initSensor($id);
     }
     // get all equipment
     $parseData['equipments'] = Equipment::findAll(['active' => Equipment::STATUS_ACTIVE]);
     // get equipment of station
     $parseData['equipmentIds'] = $model->equipment;
     // get all power equipment
     $parseData['powerEquipments'] = PowerEquipment::find()->all();
     // get equipment of station
     $parseData['powerEquipmentIds'] = $model->power_equipment;
     // get dc equipment of this station
     $parseData['dcEquipmentIds'] = $model->dc_equip_ids;
     // get all dc equipment
     $parseData['dcEquipments'] = DcEquipment::find()->where(['active' => DcEquipment::STATUS_ACTIVE])->all();
     // get area
     $areaCollections = Area::find()->all();
     $parseData['areas'] = Area::_prepareDataSelect($areaCollections, 'id', 'name');
     // get center
     $centerCollections = Center::find()->all();
     $parseData['centers'] = Center::_prepareDataSelect($centerCollections, 'id', 'name');
     // get station types
     $typeCollection = StationType::findAll(['active' => StationType::STATUS_ACTIVE]);
     $parseData['types'] = Station::_prepareDataSelect($typeCollection, 'type', 'name');
     // change left menu
     $this->setDetailLeftMenu($id);
     $post = Yii::$app->request->post();
     if ($post) {
         $model->load($post);
         if ($model->validate()) {
             $model->save();
             // get new model
             $newModel = $this->findModel($id);
             // update equipment
             if (isset($post['equipments'])) {
                 $this->setEquipment($post['equipments'], $newModel);
             }
             // update power equipment
             if (isset($post['dc_equipments'])) {
                 $this->setPowerEquipment($post['power_equipments'], $newModel);
             }
             // update dc equipment
             if (isset($post['dc_equipments'])) {
                 $this->setDcEquipment($post['dc_equipments'], $newModel);
             }
             //write log action
             Log::logControl(Yii::$app->user->id, Log::ACTION_UPDATE_STATION, $id);
             return $this->redirect(['view', 'id' => $model->id]);
         }
     }
     return $this->render('update', $parseData);
 }