public function getSensorStatuses() { return $this->hasMany(SensorStatus::className(), ['sensor_id' => 'id']); }
</div> <?php echo GridView::widget(['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'summary' => false, 'columns' => [['attribute' => 'name', 'options' => ['width' => '15%']], ['attribute' => 'center_id', 'format' => 'text', 'filter' => Center::_prepareDataSelect(Center::find()->all(), 'id', 'name', false), 'value' => function ($model) { if ($model->center_id > 0) { $center = Center::findOne($model->center_id); if ($center) { return $center->name; } } return null; }, 'options' => ['width' => '10%']], ['attribute' => 'area_id', 'format' => 'text', 'filter' => Area::_prepareDataSelect(Area::find()->all(), 'id', 'name', false), 'value' => function ($model) { $area = Area::findOne($model->area_id); return $area->name; }, 'options' => ['width' => '10%']], ['attribute' => 'address'], ['label' => 'Báo động', 'format' => 'html', 'value' => function ($model) { $securitySensor = SensorStatus::findOne(['station_id' => $model->id, 'sensor_id' => Sensor::ID_SECURITY]); $label = Sensor::getSecurityStatus($securitySensor['value']); if ($securitySensor['value'] == Sensor::SECURITY_ON) { return Show::decorateString($label, 'good'); } else { if ($securitySensor['value'] == Sensor::SECURITY_OFF) { return Show::decorateString($label, 'bad'); } } }, 'options' => ['width' => '10%']], ['attribute' => 'status', 'format' => 'html', 'filter' => $statusData, 'value' => function ($model) { if ($model->status == Station::STATUS_CONNECTED) { $html = Show::decorateString($model->getStatus($model->status), 'good'); } if ($model->status == Station::STATUS_LOST) { $html = Show::decorateString($model->getStatus($model->status), 'bad'); }
public function bindStatus() { // return data $return = []; // get security mode $sen = SensorStatus::findOne(['station_id' => $this->info['id'], 'sensor_id' => Sensor::ID_SECURITY]); $securityMode = $sen['value']; // status & configure $status = []; $configure = []; $query = new Query(); $equipStatus = $query->select('es.*, e.binary_pos')->from('equipment_status es')->leftJoin('equipment e', 'e.id = es.equipment_id')->where(['es.station_id' => $this->info['id']])->orderBy('e.binary_pos DESC')->all(); if (!empty($equipStatus)) { foreach ($equipStatus as $e) { $status[] = $e['status']; $configure[] = $e['configure']; } } // send $return['status'] = bindec(implode('', $status)); $return['configure'] = bindec(implode('', $configure)); $return['security_mode'] = $securityMode; return $return; }
public function actionDelete($id) { $id = Yii::$app->request->get('id'); if ($id > 0) { // delete equipment status DcEquipmentStatus::deleteAll(['station_id' => $id]); // delete sensor status SensorStatus::deleteAll(['station_id' => $id]); // delete dc equipment status DcEquipmentStatus::deleteAll(['station_id' => $id]); // delete power status PowerStatus::deleteAll(['station_id' => $id]); // delete station status StationStatus::deleteAll(['station_id' => $id]); // delete station status controller StationStatusHandler::deleteAll(['station_id' => $id]); // delete warning $warnings = Warning::findAll(['station_id' => $id]); if (!empty($warnings)) { foreach ($warnings as $w) { Yii::$app->db->createCommand()->delete('warning_picture', ['warning_id' => $w['id']])->execute(); } } Warning::deleteAll(['station_id' => $id]); // delete station Station::deleteAll(['id' => $id]); //write log action Log::logControl(Yii::$app->user->id, Log::ACTION_DELETE_STATION, $id); } return $this->redirect(['index']); }