/** * Lists all StationType models. * @return mixed */ public function actionIndex() { $dataProvider = new ActiveDataProvider(['query' => StationType::find()]); return $this->render('index', ['dataProvider' => $dataProvider]); }
public function actionCreate() { $model = new Station(); // parse data $parseData = ['model' => $model]; // get all equipment $parseData['equipments'] = Equipment::findAll(['active' => Equipment::STATUS_ACTIVE]); if (!empty($parseData['equipments'])) { foreach ($parseData['equipments'] as $equipment) { $parseData['equipmentIds'][] = $equipment->id; } } // get all power equipment $parseData['powerEquipments'] = PowerEquipment::find()->all(); if (!empty($parseData['powerEquipments'])) { foreach ($parseData['powerEquipments'] as $equipment) { $parseData['powerEquipmentIds'][] = $equipment->id; } } // get all dc equipment $parseData['dcEquipmentIds'] = []; $parseData['dcEquipments'] = DcEquipment::find()->where(['active' => DcEquipment::STATUS_ACTIVE])->all(); if (!empty($parseData['dcEquipments'])) { foreach ($parseData['dcEquipments'] as $equip) { $parseData['dcEquipmentIds'][] = $equip->id; } } // 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::find()->where(['active' => StationType::STATUS_ACTIVE])->all(); $parseData['types'] = Station::_prepareDataSelect($typeCollection, 'id', 'name'); $post = Yii::$app->request->post(); if ($post) { $model->load($post); if ($model->validate()) { // created by logged in user $model->user_id = Yii::$app->user->id; $model->save(); // get station id $stationId = Yii::$app->db->lastInsertID; // initial dc $this->initDc($stationId); // insert equipments for station $this->setEquipment($post['equipments'], $model); // insert power equipments for station $this->setPowerEquipment($post['power_equipments'], $model); // initial sensors $this->initSensor($stationId); //write log action Log::logControl(Yii::$app->user->id, Log::ACTION_CREATE_STATION, $stationId); return $this->redirect(['index']); } } return $this->render('create', $parseData); }