/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params, $id_dev = 0) { if ($id_dev == 0) { $query = Netints::find(); } else { $query = Netints::find()->where(['device_id' => $id_dev]); } $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->joinWith('devices'); $query->joinWith('deviceType'); $query->andFilterWhere(['netints.id' => $this->id, 'type' => $this->type, 'port_count' => $this->port_count, 'device_id' => $this->device_id]); $query->andFilterWhere(['like', 'mac', $this->mac])->andFilterWhere(['like', 'vendor', $this->vendor])->andFilterWhere(['like', 'ipaddr', $this->ipaddr])->andFilterWhere(['like', 'domain_name', $this->domain_name]); return $dataProvider; }
/** * @return $this */ public function getNetints() { return $this->hasMany(Netints::className(), ['device_id' => 'id'])->viaTable('devices', ['workplace_id' => 'id']); }
?> <?php echo $form->field($model, 'vendor')->textInput(['maxlength' => true]); ?> <?php echo $form->field($model, 'ipaddr')->textInput(); ?> <?php echo $form->field($model, 'domain_name')->textInput(['maxlength' => true]); ?> <?php echo $form->field($model, 'type')->dropDownList(Netints::arrTypes()); ?> <?php echo $form->field($model, 'port_count')->textInput(); ?> <?php echo $form->field($model, 'device_id')->textInput(); ?> <div class="form-group"> <?php echo Html::submitButton($model->isNewRecord ? 'Create' : 'Update', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']); ?> </div>
/** * массив доменных имен * @return array|\yii\db\ActiveRecord[] */ public static function arrayDomains() { return Netints::find()->select('domain_name as value, domain_name as label')->where("domain_name > ''")->orderBy('domain_name')->asArray()->all(); }
/** * Finds the Netints model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Netints the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Netints::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
use yii\helpers\Html; use yii\grid\GridView; use backend\models\Netints; /* @var $this yii\web\View */ /* @var $searchModel backend\models\NetintsSearch */ /* @var $dataProvider yii\data\ActiveDataProvider */ $this->title = 'Netints'; $this->params['breadcrumbs'][] = $this->title; ?> <div class="netints-index"> <h1><?php echo Html::encode($this->title); ?> </h1> <?php // echo $this->render('_search', ['model' => $searchModel]); ?> <p> <?php echo Html::a('Create Netints', ['create'], ['class' => 'btn btn-success']); ?> </p> <?php echo GridView::widget(['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'columns' => [['class' => 'yii\\grid\\SerialColumn'], 'id', 'mac', 'ipaddr', 'domain_name', 'port_count', 'vendor', ['attribute' => 'type', 'value' => 'type', 'filter' => Netints::arrTypes()], 'devices.device_note', 'deviceType.title', ['class' => 'yii\\grid\\ActionColumn']]]); ?> </div>
/** * Автоматически добавляем комплектующие */ public function actionAutocomp() { $models = Devices::findAll(['type_id' => 1]); $arr = [373, 363, 262, 202, 146]; $valid = false; $i = 0; $v = 0; $n = 0; foreach ($models as $model) { if (in_array($model->id, $arr)) { continue; } $count_comp = Devices::find()->where(['parent_device_id' => $model->id])->count(); //echo $model->id . ' ' . $count_comp . '<br>'; if ($count_comp > 0) { continue; } //отсеяли лишние системники, создаем комплектующие $i++; $comp = new Devices(); $comp->type_id = 18; $comp->device_note = 'Блок питания'; $comp->workplace_id = 119; $comp->parent_device_id = $model->id; if ($comp->validate()) { $comp->save(); $valid = true; $v++; } $comp = new Devices(); $comp->type_id = 25; $comp->device_note = 'Материнская плата'; $comp->workplace_id = 119; $comp->parent_device_id = $model->id; if ($comp->validate()) { $v++; if ($comp->save()) { $net = new Netints(); //создаем сетевой интефейс со значениями по умолчанию $net->device_id = $comp->id; if ($net->validate()) { $n++; $net->save(); } } } $comp = new Devices(); $comp->type_id = 28; $comp->device_note = 'Процессор'; $comp->workplace_id = 119; $comp->parent_device_id = $model->id; if ($comp->validate()) { $comp->save(); $v++; } $comp = new Devices(); $comp->type_id = 29; $comp->device_note = 'DDR'; $comp->workplace_id = 119; $comp->parent_device_id = $model->id; if ($comp->validate()) { $comp->save(); $v++; } $comp = new Devices(); $comp->type_id = 30; $comp->device_note = 'SSD'; $comp->workplace_id = 119; $comp->parent_device_id = $model->id; if ($comp->validate()) { $comp->save(); $v++; } $comp = null; } if ($valid) { Yii::$app->session->setFlash('success', 'Обработка прошла успешно! Добавлено ' . $v . ' устройств. ' . $n . ' сетевых интерфейсов для ' . $i . 'устройств'); } return $this->redirect(['index']); }
} $device = $wpModel['device_type_title'] . ' ' . $wpModel['devices_id']; if ($old_device != $device) { if ($table) { echo '</table>'; $table = false; } echo '<b>' . $device . '</b>'; $old_device = $device; if (!$table) { echo '<table class="table table-bordered table-condensed">'; } $table = true; } echo empty($wpModel['sub_type_title']) ? '' : '<tr><td colspan="7"><b>' . $wpModel['sub_type_title'] . '</b></td></tr>'; echo '<tr><td>' . Netints::arrTypes()[$wpModel['netints_type']] . '</td><td>' . $wpModel['netints_id'] . '</td><td>' . $wpModel['mac'] . '</td><td>' . $wpModel['domain_name'] . '</td><td>' . $wpModel['ip'] . '</td><td>' . $wpModel['ports'] . '</td></tr>'; } if ($table) { echo '</table>'; $table = false; } ?> </div> <?php } ?> </div> <?php if ($tab == 1) { ?>