Ejemplo n.º 1
0
 /**
  * Finds the StationType model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return StationType the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = StationType::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Ejemplo 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);
 }