コード例 #1
0
<?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;
?>
コード例 #2
0
ファイル: index.php プロジェクト: gpis88ce/Gpis88ce
use common\components\helpers\Show;
use yii\helpers\Html;
use yii\grid\GridView;
$this->title = 'Danh sách trạm';
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="station-index">

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

    <?php 
echo GridView::widget(['dataProvider' => $dataProvider, 'columns' => [['class' => 'yii\\grid\\SerialColumn', 'options' => ['width' => '6%']], 'code', 'name', ['attribute' => 'center_id', 'format' => 'text', 'value' => function ($model) {
    $center = Center::findOne($model->center_id);
    if ($center) {
        return $center->name;
    }
    return null;
}], ['attribute' => 'area_id', 'format' => 'text', 'value' => function ($model) {
    $area = Area::findOne($model->area_id);
    if ($area) {
        return $area->name;
    }
    return null;
}], ['attribute' => 'status', 'format' => 'html', 'value' => function ($model) {
    if ($model->status == Station::STATUS_CONNECTED) {
        $html = Show::decorateString($model->getStatus($model->status), 'good');
    }
    if ($model->status == Station::STATUS_LOST) {
コード例 #3
0
 /**
  * Finds the Center model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Center the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Center::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
コード例 #4
0
ファイル: Station.php プロジェクト: gpis88ce/Gpis88ce
 public function getCenter()
 {
     return $this->hasOne(Center::className(), ['id' => 'center_id']);
 }
コード例 #5
0
 protected function findModel($id)
 {
     // session
     $role = new Role();
     if (!$role->isAdministrator) {
         $position = $role->getPosition();
         $stationIds = Station::getByRole($position, Yii::$app->user->id);
         if (!empty($stationIds) && !in_array($id, $stationIds)) {
             $this->permissionDeny();
         }
     }
     if (($model = Station::findOne($id)) !== null) {
         // find area & center
         $model->area = Area::findOne($model->area_id);
         $model->center = Center::findOne($model->center_id);
         // get equipment
         $equipments = EquipmentStatus::findAll(['station_id' => $id]);
         if (!empty($equipments)) {
             foreach ($equipments as $equipment) {
                 $model->equipment[] = $equipment->equipment_id;
             }
         }
         // get power equipment
         $powerEquipments = PowerStatus::findAll(['station_id' => $id]);
         if (!empty($powerEquipments)) {
             foreach ($powerEquipments as $equipment) {
                 $model->power_equipment[] = $equipment->item_id;
             }
         }
         // get dc
         $dcEquips = DcEquipmentStatus::findByStation($id);
         if (!empty($dcEquips)) {
             foreach ($dcEquips as $dcEquip) {
                 $model->dc_equip_ids[] = $dcEquip['equipment_id'];
                 $model->dc_equip_status[] = ['equipment_id' => $dcEquip['equipment_id'], 'name' => $dcEquip['name'], 'amperage' => $dcEquip['amperage'], 'voltage' => $dcEquip['voltage'], 'unit_voltage' => $dcEquip['unit_voltage'], 'temperature' => $dcEquip['temperature'], 'unit_amperage' => $dcEquip['unit_amperage'], 'status' => $dcEquip['status']];
             }
         }
         // get sensor status
         $query = new Query();
         $sensorStatus = $query->select('sst.*, s.type, s.unit_type, s.name')->from('sensor_status sst')->leftJoin('sensor s', 's.id = sst.sensor_id')->where(['sst.station_id' => $id])->andWhere(['s.active' => Sensor::STATUS_ACTIVE])->all();
         if (!empty($sensorStatus)) {
             foreach ($sensorStatus as $sst) {
                 $model->sensor_status[] = ['type' => $sst['type'], 'sensor_id' => $sst['sensor_id'], 'name' => $sst['name'], 'unit' => $sst['unit_type'], 'value' => $sst['value'], 'status' => $sst['status']];
             }
         }
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }