public function actionReport($id_device) { //if (\Yii::$app->user->isGuest) { // return $this->goHome(); //} // задача по dev_id найти системный номер $dev_sys_n = Device::find()->where(['id' => $id_device])->one(); $searchModel = new EventsSearch(); $searchModel->sys_n = $dev_sys_n->sys_n; $dataProvider = $searchModel->search(Yii::$app->request->queryParams); // получить название устройства, которое мониторим $user_link_dev = UserLinkDev::find()->where(['id_user' => Yii::$app->user->identity->id])->andFilterWhere(['id_device' => $id_device])->one(); $device_name = $user_link_dev->dev_name; return $this->render('/events/index', ['dataProvider' => $dataProvider, 'searchModel' => $searchModel, 'device_name' => $device_name]); }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Device::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'kbd_type' => $this->kbd_type, 'created_at' => $this->created_at, 'update_at' => $this->update_at]); $query->andFilterWhere(['like', 'imei', $this->imei]); $query->andFilterWhere(['like', 'sys_n', $this->sys_n]); return $dataProvider; }
public function getmyCODE() { $device = Device::find()->where(['sys_n' => $this->sys_n])->one(); $id_device = $device->id; // $ut = DeviceEventCodeTxt::find()->where(['id_user' => Yii::$app->user->identity->id])->andFilterWhere(['id_device' => $id_device])->andFilterWhere(['code' => $this->code])->one(); if ($ut == null) { return '????'; } if (!empty($this->nzone)) { if (strcmp($this->tz, "0") == 0) { return $ut->txt . ' ' . $this->nzone . ' (норма)'; } if (strcmp($this->tz, "1") == 0) { return $ut->txt . ' ' . $this->nzone . ' (КЗ)'; } if (strcmp($this->tz, "2") == 0) { return $ut->txt . ' ' . $this->nzone . ' (норма)'; } if (strcmp($this->tz, "3") == 0) { return $ut->txt . ' ' . $this->nzone . ' (обрыв)'; } return $ut->txt . ' ' . $this->nzone; } if (!empty($this->nuser)) { return $ut->txt . ' Пользователь ' . $this->nuser; } if (!empty($this->balans)) { return $ut->txt . ' ' . $this->balans . ' ' . Yii::$app->user->identity->money; } // потом надо будет заменить номер карточки на ФИО пользователя (школьника) if (!empty($this->card)) { return $ut->txt . ' Пользователь ' . $this->card . ' [' . $this->cardcode . ']'; } //if( !empty($this->cardcode) ){ return $ut->txt . ' Пользователь ' . $this->card; } if ($this->modemerror > 0) { return $ut->txt . ' [' . $this->modemerror . ']'; } if ($this->temperature > 0) { return $ut->txt . ' ' . $this->temperature . ' C'; } return $ut->txt; }
<?php use yii\helpers\Html; use yii\widgets\DetailView; use yii\helpers\ArrayHelper; use frontend\models\Device; /* @var $this yii\web\View */ /* @var $model app\models\UserLinkDev */ $this->title = 'Параметры устройства'; $this->params['breadcrumbs'][] = ['label' => 'Список устройств', 'url' => ['index']]; $this->params['breadcrumbs'][] = $this->title; $device = Device::find()->where(['id' => $model->id_device])->one(); ?> <div class="user-link-dev-setup"> <h1></h1> <?php echo DetailView::widget(['model' => $model, 'attributes' => [['label' => 'Систетный номер', 'value' => $device->sys_n], ['label' => 'IMEI', 'value' => $device->imei], 'dev_name', 'createdAt']]); ?> <p> <?php echo Html::a('Настройка полей', ['/user-text/index', 'id_user' => $model->id_user, 'id_device' => $model->id_device, 'setup_id' => $model->id], ['class' => 'btn btn-primary']); ?> <?php echo Html::a('Настройка событий', ['/user-event-text/index', 'id_user' => $model->id_user, 'id_device' => $model->id_device, 'setup_id' => $model->id], ['class' => 'btn btn-primary']); ?>
/** * Создание новой связи a new UserLinkDev model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new UserLinkDev(); // нужно выполнить проверку запроса if ($model->load(Yii::$app->request->post())) { $device = Device::find()->where(['sys_n' => $model->sysn])->andFilterWhere(['imei' => $model->imei])->one(); if ($device == null) { // УСТРОЙСТВО С ТАКИМ SYSN И imei НЕ НАЙДЕНО!!! return $this->render('notdev', ['model' => $device]); } $model->created_at = time(); $model->id_user = Yii::$app->user->identity->id; // id текущего юзера $model->id_device = $device->id; if ($model->dev_name == null) { $model->dev_name = 'Устройство без названия (' . $device->sys_n . ')'; } $model->save(); // Устройство успешно добавленно!!! return $this->render('add-ok', ['model' => $device]); } else { return $this->render('create', ['model' => $model]); } }