Esempio n. 1
0
 protected function findModel($id)
 {
     if (($model = PowerEquipment::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Esempio n. 2
0
 public function getItem()
 {
     return $this->hasOne(PowerEquipment::className(), ['id' => 'item_id']);
 }
Esempio n. 3
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);
 }