protected function findModel($id)
 {
     if (($model = Equipment::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
 public function actionVar1step2()
 {
     $dataProvider = new ActiveDataProvider(['query' => Equipment::find()]);
     return $this->render('var1step2', ['dataProvider' => $dataProvider]);
 }
Beispiel #3
0
echo Html::encode($this->title);
?>
</h4>
    <?php 
// echo $this->render('_search', ['model' => $searchModel]);
?>

    <?php 
echo GridView::widget(['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'columns' => [['class' => 'yii\\grid\\SerialColumn'], ['attribute' => 'user_id', 'value' => function ($model) {
    $user = User::findOne($model->user_id);
    return $user->username;
}], ['attribute' => 'action', 'filter' => LogModel::_prepareDataSelect($actionList, 'key', 'name', false), 'value' => function ($model) {
    $actionList = Log::actions();
    foreach ($actionList as $action) {
        if ($model->action === $action['key']) {
            return $action['name'];
        }
    }
}], ['attribute' => 'station_id', 'value' => function ($model) {
    $station = Station::findOne($model->station_id);
    return $station ? $station->name : '';
}], ['attribute' => 'related_id', 'value' => function ($model) {
    $equip = Equipment::findOne($model->related_id);
    return $equip ? $equip['name'] : '';
}], ['attribute' => 'time', 'filter' => false, 'value' => function ($model) {
    return $model->time > 0 ? date('d/m/Y h:i A', $model->time) : '';
}]]]);
?>

</div>
 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);
 }