<?php /** * Created by PhpStorm. * User: JFog * Date: 7/16/2015 * Time: 12:33 AM */ use common\components\helpers\Show; use common\components\helpers\Convert; use common\models\Area; use common\models\Center; use common\models\Station; $areaList = Area::find()->all(); $centerList = Center::find()->all(); $query = Station::find()->select('id, name')->where([]); if (isset($_GET['area']) && $_GET['area'] > 0) { $query->andWhere(['area_id' => $_GET['area']]); } if (isset($_GET['center']) && $_GET['center'] > 0) { $query->andWhere(['center_id' => $_GET['center']]); } $collections = $query->all(); $stationList[] = ['id' => '0', 'name' => 'Chọn trạm']; if (!empty($collections)) { foreach ($collections as $col) { $stationList[] = ['id' => $col['id'], 'name' => $col['name']]; } } //print '<pre>'; print_r($stationList); die; ?>
"> </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');
/** * Lists all Center models. * @return mixed */ public function actionIndex() { $dataProvider = new ActiveDataProvider(['query' => Center::find()]); return $this->render('index', ['dataProvider' => $dataProvider]); }
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); }