Commit 3d730a7c2ac77bee309c32e49a21d4999e165e51

Authored by Yarik
1 parent b41d5459

Yarik

common/models/CrossSection.php 0 → 100644
  1 +<?php
  2 +
  3 + namespace common\models;
  4 +
  5 + use Yii;
  6 +
  7 + /**
  8 + * This is the model class for table "cross_section".
  9 + * @property integer $cross_section_id
  10 + * @property integer $region_id
  11 + * @property integer $road_id
  12 + * @property double $location_left
  13 + * @property double $location_right
  14 + * @property string $direction
  15 + * @property integer $surface_type_id
  16 + * @property double $length_section
  17 + * @property double $length_surface
  18 + * @property double $distance_edge
  19 + * @property double $width
  20 + * @property double $angle
  21 + * @property integer $tube_availability
  22 + * @property integer $safety_availability
  23 + * @property integer $year_build
  24 + * @property integer $year_repair
  25 + * @property integer $state_common_id
  26 + * @property Region $region
  27 + * @property Road $road
  28 + * @property StateCommon $stateCommon
  29 + * @property SurfaceType $surfaceType
  30 + */
  31 + class CrossSection extends \yii\db\ActiveRecord
  32 + {
  33 +
  34 + /**
  35 + * @inheritdoc
  36 + */
  37 + public static function tableName()
  38 + {
  39 + return 'cross_section';
  40 + }
  41 +
  42 + /**
  43 + * @inheritdoc
  44 + */
  45 + public function rules()
  46 + {
  47 + return [
  48 + [
  49 + [
  50 + 'region_id',
  51 + 'road_id',
  52 + 'surface_type_id',
  53 + 'tube_availability',
  54 + 'safety_availability',
  55 + 'year_build',
  56 + 'year_repair',
  57 + 'state_common_id',
  58 + ],
  59 + 'integer',
  60 + ],
  61 + [
  62 + [
  63 + 'location_left',
  64 + 'location_right',
  65 + 'length_section',
  66 + 'length_surface',
  67 + 'distance_edge',
  68 + 'width',
  69 + 'angle',
  70 + ],
  71 + 'number',
  72 + ],
  73 + [
  74 + [ 'direction' ],
  75 + 'string',
  76 + 'max' => 255,
  77 + ],
  78 + [
  79 + [ 'region_id' ],
  80 + 'exist',
  81 + 'skipOnError' => true,
  82 + 'targetClass' => Region::className(),
  83 + 'targetAttribute' => [ 'region_id' => 'region_id' ],
  84 + ],
  85 + [
  86 + [ 'road_id' ],
  87 + 'exist',
  88 + 'skipOnError' => true,
  89 + 'targetClass' => Road::className(),
  90 + 'targetAttribute' => [ 'road_id' => 'road_id' ],
  91 + ],
  92 + [
  93 + [ 'state_common_id' ],
  94 + 'exist',
  95 + 'skipOnError' => true,
  96 + 'targetClass' => StateCommon::className(),
  97 + 'targetAttribute' => [ 'state_common_id' => 'state_common_id' ],
  98 + ],
  99 + [
  100 + [ 'surface_type_id' ],
  101 + 'exist',
  102 + 'skipOnError' => true,
  103 + 'targetClass' => SurfaceType::className(),
  104 + 'targetAttribute' => [ 'surface_type_id' => 'surface_type_id' ],
  105 + ],
  106 + ];
  107 + }
  108 +
  109 + /**
  110 + * @inheritdoc
  111 + */
  112 + public function attributeLabels()
  113 + {
  114 + return [
  115 + 'cross_section_id' => 'Індекс',
  116 + 'region_id' => 'Область',
  117 + 'road_id' => 'Дорога',
  118 + 'location_left' => 'Місцеположення, км+ зліва',
  119 + 'location_right' => 'Місцеположення, км+ справа',
  120 + 'direction' => 'Напрямок з\'їзду',
  121 + 'surface_type_id' => 'Тип покриття',
  122 + 'length_section' => 'Фактична довжина, м з\'їзду',
  123 + 'length_surface' => 'Фактична довжина, м покриття',
  124 + 'distance_edge' => 'Відстань від крайки проїзної частики, м',
  125 + 'width' => 'Ширина, м',
  126 + 'angle' => 'Кут примикання',
  127 + 'tube_availability' => 'Наявність облаштування, труба',
  128 + 'safety_availability' => 'Наявність облаштування, острівок безпеки',
  129 + 'year_build' => 'Рік спорудження',
  130 + 'year_repair' => 'Рік ремонту',
  131 + 'state_common_id' => 'Технічний стан',
  132 + ];
  133 + }
  134 +
  135 + /**
  136 + * @return \yii\db\ActiveQuery
  137 + */
  138 + public function getRegion()
  139 + {
  140 + return $this->hasOne(Region::className(), [ 'region_id' => 'region_id' ]);
  141 + }
  142 +
  143 + /**
  144 + * @return \yii\db\ActiveQuery
  145 + */
  146 + public function getRoad()
  147 + {
  148 + return $this->hasOne(Road::className(), [ 'road_id' => 'road_id' ]);
  149 + }
  150 +
  151 + /**
  152 + * @return \yii\db\ActiveQuery
  153 + */
  154 + public function getStateCommon()
  155 + {
  156 + return $this->hasOne(StateCommon::className(), [ 'state_common_id' => 'state_common_id' ]);
  157 + }
  158 +
  159 + /**
  160 + * @return \yii\db\ActiveQuery
  161 + */
  162 + public function getSurfaceType()
  163 + {
  164 + return $this->hasOne(SurfaceType::className(), [ 'surface_type_id' => 'surface_type_id' ]);
  165 + }
  166 +
  167 + public function getRightString()
  168 + {
  169 + return floor($this->location_right) . '+' . ( str_pad(round(( $this->location_right - floor($this->location_right) ) * 1000), 3, '0', STR_PAD_LEFT) );
  170 + }
  171 +
  172 + public function getLeftString()
  173 + {
  174 + return floor($this->location_left) . '+' . ( str_pad(round(( $this->location_left - floor($this->location_left) ) * 1000), 3, '0', STR_PAD_LEFT) );
  175 + }
  176 + }
... ...
common/models/CrossSectionSearch.php 0 → 100644
  1 +<?php
  2 +
  3 +namespace common\models;
  4 +
  5 +use Yii;
  6 +use yii\base\Model;
  7 +use yii\data\ActiveDataProvider;
  8 +use common\models\CrossSection;
  9 +
  10 +/**
  11 + * CrossSectionSearch represents the model behind the search form about `common\models\CrossSection`.
  12 + */
  13 +class CrossSectionSearch extends CrossSection
  14 +{
  15 + /**
  16 + * @inheritdoc
  17 + */
  18 + public function rules()
  19 + {
  20 + return [
  21 + [['cross_section_id', 'region_id', 'road_id', 'surface_type_id', 'tube_availability', 'safety_availability', 'year_build', 'year_repair', 'state_common_id'], 'integer'],
  22 + [['location_left', 'location_right', 'length_section', 'length_surface', 'distance_edge', 'width', 'angle'], 'number'],
  23 + [['direction'], 'safe'],
  24 + ];
  25 + }
  26 +
  27 + /**
  28 + * @inheritdoc
  29 + */
  30 + public function scenarios()
  31 + {
  32 + // bypass scenarios() implementation in the parent class
  33 + return Model::scenarios();
  34 + }
  35 +
  36 + /**
  37 + * Creates data provider instance with search query applied
  38 + *
  39 + * @param array $params
  40 + *
  41 + * @return ActiveDataProvider
  42 + */
  43 + public function search($params)
  44 + {
  45 + $query = CrossSection::find();
  46 +
  47 + // add conditions that should always apply here
  48 +
  49 + $dataProvider = new ActiveDataProvider([
  50 + 'query' => $query,
  51 + ]);
  52 +
  53 + $this->load($params);
  54 +
  55 + if (!$this->validate()) {
  56 + // uncomment the following line if you do not want to return any records when validation fails
  57 + // $query->where('0=1');
  58 + return $dataProvider;
  59 + }
  60 +
  61 + // grid filtering conditions
  62 + $query->andFilterWhere([
  63 + 'cross_section_id' => $this->cross_section_id,
  64 + 'region_id' => $this->region_id,
  65 + 'road_id' => $this->road_id,
  66 + 'location_left' => $this->location_left,
  67 + 'location_right' => $this->location_right,
  68 + 'surface_type_id' => $this->surface_type_id,
  69 + 'length_section' => $this->length_section,
  70 + 'length_surface' => $this->length_surface,
  71 + 'distance_edge' => $this->distance_edge,
  72 + 'width' => $this->width,
  73 + 'angle' => $this->angle,
  74 + 'tube_availability' => $this->tube_availability,
  75 + 'safety_availability' => $this->safety_availability,
  76 + 'year_build' => $this->year_build,
  77 + 'year_repair' => $this->year_repair,
  78 + 'state_common_id' => $this->state_common_id,
  79 + ]);
  80 +
  81 + $query->andFilterWhere(['like', 'direction', $this->direction]);
  82 +
  83 + return $dataProvider;
  84 + }
  85 +}
... ...
common/models/StateCommon.php 0 → 100644
  1 +<?php
  2 +
  3 +namespace common\models;
  4 +
  5 +use Yii;
  6 +
  7 +/**
  8 + * This is the model class for table "state_common".
  9 + *
  10 + * @property integer $state_common_id
  11 + * @property string $value
  12 + *
  13 + * @property CrossSection[] $crossSections
  14 + */
  15 +class StateCommon extends \yii\db\ActiveRecord
  16 +{
  17 + /**
  18 + * @inheritdoc
  19 + */
  20 + public static function tableName()
  21 + {
  22 + return 'state_common';
  23 + }
  24 +
  25 + /**
  26 + * @inheritdoc
  27 + */
  28 + public function rules()
  29 + {
  30 + return [
  31 + [['value'], 'string', 'max' => 255],
  32 + ];
  33 + }
  34 +
  35 + /**
  36 + * @inheritdoc
  37 + */
  38 + public function attributeLabels()
  39 + {
  40 + return [
  41 + 'state_common_id' => 'Ідентифікатор',
  42 + 'value' => 'Значення',
  43 + ];
  44 + }
  45 +
  46 + /**
  47 + * @return \yii\db\ActiveQuery
  48 + */
  49 + public function getCrossSections()
  50 + {
  51 + return $this->hasMany(CrossSection::className(), ['state_common_id' => 'state_common_id']);
  52 + }
  53 +}
... ...
common/models/SurfaceType.php 0 → 100644
  1 +<?php
  2 +
  3 +namespace common\models;
  4 +
  5 +use Yii;
  6 +
  7 +/**
  8 + * This is the model class for table "surface_type".
  9 + *
  10 + * @property integer $surface_type_id
  11 + * @property string $name
  12 + *
  13 + * @property CrossSection[] $crossSections
  14 + */
  15 +class SurfaceType extends \yii\db\ActiveRecord
  16 +{
  17 + /**
  18 + * @inheritdoc
  19 + */
  20 + public static function tableName()
  21 + {
  22 + return 'surface_type';
  23 + }
  24 +
  25 + /**
  26 + * @inheritdoc
  27 + */
  28 + public function rules()
  29 + {
  30 + return [
  31 + [['name'], 'string', 'max' => 255],
  32 + ];
  33 + }
  34 +
  35 + /**
  36 + * @inheritdoc
  37 + */
  38 + public function attributeLabels()
  39 + {
  40 + return [
  41 + 'surface_type_id' => 'Surface Type ID',
  42 + 'name' => 'Name',
  43 + ];
  44 + }
  45 +
  46 + /**
  47 + * @return \yii\db\ActiveQuery
  48 + */
  49 + public function getCrossSections()
  50 + {
  51 + return $this->hasMany(CrossSection::className(), ['surface_type_id' => 'surface_type_id']);
  52 + }
  53 +}
... ...
console/migrations/m160712_104942_create_road_to_category.php 0 → 100644
  1 +<?php
  2 +
  3 +use yii\db\Migration;
  4 +
  5 +/**
  6 + * Handles the creation for table `road_to_category`.
  7 + */
  8 +class m160712_104942_create_road_to_category extends Migration
  9 +{
  10 + /**
  11 + * @inheritdoc
  12 + */
  13 + public function up()
  14 + {
  15 + $this->createTable('road_to_category', [
  16 + 'road_to_category_id' => $this->primaryKey()->comment('Індекс'),
  17 + 'region_id' => $this->integer()->comment('Область'),
  18 + 'road_id' => $this->integer()->comment('Дорога'),
  19 + 'begin' => $this->float()->comment('Місцезнаходження, км+ початок'),
  20 + 'end' => $this->float()->comment('Місцезнаходження, км+ кінець'),
  21 + 'distance' => $this->float()->comment('Протяжність, км'),
  22 + 'road_category_id' => $this->integer()->comment('Категорія'),
  23 + ]);
  24 + $this->addForeignKey('road_to_category_region', 'road_to_category', 'region_id', 'region', 'region_id', 'CASCADE', 'CASCADE');
  25 + $this->addForeignKey('road_to_category_road', 'road_to_category', 'road_id', 'road', 'road_id', 'CASCADE', 'CASCADE');
  26 + $this->addForeignKey('road_to_category_road_category', 'road_to_category', 'road_category_id', 'road_category', 'road_category_id', 'CASCADE', 'CASCADE');
  27 + }
  28 +
  29 + /**
  30 + * @inheritdoc
  31 + */
  32 + public function down()
  33 + {
  34 + $this->dropForeignKey('road_to_category_region', 'road_to_category');
  35 + $this->dropForeignKey('road_to_category_road', 'road_to_category');
  36 + $this->dropForeignKey('road_to_category_road_category', 'road_to_category');
  37 + $this->dropTable('road_to_category');
  38 + }
  39 +}
... ...
console/migrations/m160712_110146_create_cross_section.php 0 → 100644
  1 +<?php
  2 +
  3 + use yii\db\Migration;
  4 +
  5 + /**
  6 + * Handles the creation for table `cross_section`.
  7 + */
  8 + class m160712_110146_create_cross_section extends Migration
  9 + {
  10 +
  11 + /**
  12 + * @inheritdoc
  13 + */
  14 + public function up()
  15 + {
  16 + $this->createTable('cross_section', [
  17 + 'cross_section_id' => $this->primaryKey()
  18 + ->comment('Індекс'),
  19 + 'region_id' => $this->integer()
  20 + ->comment('Область'),
  21 + 'road_id' => $this->integer()
  22 + ->comment('Дорога'),
  23 + 'location_left' => $this->float()
  24 + ->comment('Місцеположення, км+ справа'),
  25 + 'location_right' => $this->float()
  26 + ->comment('Місцеположення, км+ зліва'),
  27 + 'direction' => $this->string()
  28 + ->comment('Напрямок з\'їзду'),
  29 + 'surface_type_id' => $this->integer()
  30 + ->comment('Тип покриття'),
  31 + 'length_section' => $this->float()
  32 + ->comment('Фактична довжина, м з\'їзду'),
  33 + 'length_surface' => $this->float()
  34 + ->comment('Фактична довжина, м покриття'),
  35 + 'distance_edge' => $this->float()
  36 + ->comment('Відстань від крайки проїзної частики, м'),
  37 + 'width' => $this->float()
  38 + ->comment('Ширина, м'),
  39 + 'angle' => $this->float()
  40 + ->comment('Кут примикання'),
  41 + 'tube_availability' => $this->integer()
  42 + ->comment('Наявність облаштування, труба'),
  43 + 'safety_availability' => $this->integer()
  44 + ->comment('Наявність облаштування, острівок безпеки'),
  45 + 'year_build' => $this->integer()
  46 + ->comment('Рік спорудження'),
  47 + 'year_repair' => $this->integer()
  48 + ->comment('Рік ремонту'),
  49 + 'state_common_id' => $this->integer()
  50 + ->comment('Технічний стан'),
  51 + ]);
  52 + $this->createTable('surface_type', [
  53 + 'surface_type_id' => $this->primaryKey(),
  54 + 'name' => $this->string(),
  55 + ]);
  56 + $this->createTable('state_common', [
  57 + 'state_common_id' => $this->primaryKey()->comment('Ідентифікатор'),
  58 + 'value' => $this->string()->comment('Значення'),
  59 + ]);
  60 + $this->addCommentOnTable('state_common', 'Стан простого об’єкту');
  61 + $this->batchInsert('state_common', [ 'value' ], [
  62 + [ 'добрий' ],
  63 + [ 'задовільний' ],
  64 + [ 'незадовільний' ],
  65 + [ 'непрацездатний' ],
  66 + [ 'аварійний' ],
  67 + ]);
  68 + $this->addForeignKey('cross_section_region', 'cross_section', 'region_id', 'region', 'region_id', 'CASCADE', 'CASCADE');
  69 + $this->addForeignKey('cross_section_road', 'cross_section', 'road_id', 'road', 'road_id', 'CASCADE', 'CASCADE');
  70 + $this->addForeignKey('cross_section_surface_type', 'cross_section', 'surface_type_id', 'surface_type', 'surface_type_id', 'CASCADE', 'CASCADE');
  71 + $this->addForeignKey('cross_section_state_common', 'cross_section', 'state_common_id', 'state_common', 'state_common_id', 'CASCADE', 'CASCADE');
  72 + }
  73 +
  74 + /**
  75 + * @inheritdoc
  76 + */
  77 + public function down()
  78 + {
  79 + $this->dropForeignKey('cross_section_region', 'cross_section');
  80 + $this->dropForeignKey('cross_section_road', 'cross_section');
  81 + $this->dropForeignKey('cross_section_surface_type', 'cross_section');
  82 + $this->dropForeignKey('cross_section_state_common', 'cross_section');
  83 + $this->dropTable('cross_section');
  84 + $this->dropTable('surface_type');
  85 + $this->dropTable('state_common');
  86 + }
  87 + }
... ...
frontend/controllers/CrossSectionController.php 0 → 100644
  1 +<?php
  2 +
  3 + namespace frontend\controllers;
  4 +
  5 + use common\models\Region;
  6 + use common\models\Road;
  7 + use common\models\StateCommon;
  8 + use common\models\SurfaceType;
  9 + use Yii;
  10 + use common\models\CrossSection;
  11 + use common\models\CrossSectionSearch;
  12 + use yii\web\Controller;
  13 + use yii\web\NotFoundHttpException;
  14 + use yii\filters\VerbFilter;
  15 +
  16 + /**
  17 + * CrossSectionController implements the CRUD actions for CrossSection model.
  18 + */
  19 + class CrossSectionController extends Controller
  20 + {
  21 +
  22 + /**
  23 + * @inheritdoc
  24 + */
  25 + public function behaviors()
  26 + {
  27 + return [
  28 + 'verbs' => [
  29 + 'class' => VerbFilter::className(),
  30 + 'actions' => [
  31 + 'delete' => [ 'POST' ],
  32 + ],
  33 + ],
  34 + ];
  35 + }
  36 +
  37 + /**
  38 + * Lists all CrossSection models.
  39 + * @return mixed
  40 + */
  41 + public function actionIndex()
  42 + {
  43 + $searchModel = new CrossSectionSearch();
  44 + $dataProvider = $searchModel->search(Yii::$app->request->queryParams);
  45 +
  46 + return $this->render('index', [
  47 + 'searchModel' => $searchModel,
  48 + 'dataProvider' => $dataProvider,
  49 + ]);
  50 + }
  51 +
  52 + /**
  53 + * Displays a single CrossSection model.
  54 + *
  55 + * @param integer $id
  56 + *
  57 + * @return mixed
  58 + */
  59 + public function actionView($id)
  60 + {
  61 + return $this->render('view', [
  62 + 'model' => $this->findModel($id),
  63 + ]);
  64 + }
  65 +
  66 + /**
  67 + * Creates a new CrossSection model.
  68 + * If creation is successful, the browser will be redirected to the 'view' page.
  69 + * @return mixed
  70 + */
  71 + public function actionCreate()
  72 + {
  73 + $model = new CrossSection();
  74 +
  75 + $regions = Region::find()
  76 + ->select([
  77 + 'name',
  78 + 'region_id',
  79 + ])
  80 + ->asArray()
  81 + ->indexBy('region_id')
  82 + ->column();
  83 +
  84 + $roads = Road::find()
  85 + ->select([
  86 + 'name',
  87 + 'road_id',
  88 + ])
  89 + ->asArray()
  90 + ->indexBy('road_id')
  91 + ->column();
  92 +
  93 + $surface_types = SurfaceType::find()
  94 + ->select([
  95 + 'name',
  96 + 'surface_type_id',
  97 + ])
  98 + ->asArray()
  99 + ->indexBy('surface_type_id')
  100 + ->column();
  101 +
  102 + $state_commons = StateCommon::find()
  103 + ->select([
  104 + 'value',
  105 + 'state_common_id',
  106 + ])
  107 + ->asArray()
  108 + ->indexBy('state_common_id')
  109 + ->column();
  110 +
  111 + if($model->load(Yii::$app->request->post()) && $model->save()) {
  112 + return $this->redirect([
  113 + 'view',
  114 + 'id' => $model->cross_section_id,
  115 + ]);
  116 + } else {
  117 + return $this->render('create', [
  118 + 'model' => $model,
  119 + 'regions' => $regions,
  120 + 'roads' => $roads,
  121 + 'surface_types' => $surface_types,
  122 + 'state_commons' => $state_commons,
  123 + ]);
  124 + }
  125 + }
  126 +
  127 + /**
  128 + * Updates an existing CrossSection model.
  129 + * If update is successful, the browser will be redirected to the 'view' page.
  130 + *
  131 + * @param integer $id
  132 + *
  133 + * @return mixed
  134 + */
  135 + public function actionUpdate($id)
  136 + {
  137 + $model = $this->findModel($id);
  138 +
  139 + $regions = Region::find()
  140 + ->select([
  141 + 'name',
  142 + 'region_id',
  143 + ])
  144 + ->asArray()
  145 + ->indexBy('region_id')
  146 + ->column();
  147 +
  148 + $roads = Road::find()
  149 + ->select([
  150 + 'name',
  151 + 'road_id',
  152 + ])
  153 + ->asArray()
  154 + ->indexBy('road_id')
  155 + ->column();
  156 +
  157 + $surface_types = SurfaceType::find()
  158 + ->select([
  159 + 'name',
  160 + 'surface_type_id',
  161 + ])
  162 + ->asArray()
  163 + ->indexBy('surface_type_id')
  164 + ->column();
  165 +
  166 + $state_commons = StateCommon::find()
  167 + ->select([
  168 + 'value',
  169 + 'state_common_id',
  170 + ])
  171 + ->asArray()
  172 + ->indexBy('state_common_id')
  173 + ->column();
  174 +
  175 + if($model->load(Yii::$app->request->post()) && $model->save()) {
  176 + return $this->redirect([
  177 + 'view',
  178 + 'id' => $model->cross_section_id,
  179 + ]);
  180 + } else {
  181 + return $this->render('update', [
  182 + 'model' => $model,
  183 + 'regions' => $regions,
  184 + 'roads' => $roads,
  185 + 'surface_types' => $surface_types,
  186 + 'state_commons' => $state_commons,
  187 + ]);
  188 + }
  189 + }
  190 +
  191 + /**
  192 + * Deletes an existing CrossSection model.
  193 + * If deletion is successful, the browser will be redirected to the 'index' page.
  194 + *
  195 + * @param integer $id
  196 + *
  197 + * @return mixed
  198 + */
  199 + public function actionDelete($id)
  200 + {
  201 + $this->findModel($id)
  202 + ->delete();
  203 +
  204 + return $this->redirect([ 'index' ]);
  205 + }
  206 +
  207 + /**
  208 + * Finds the CrossSection model based on its primary key value.
  209 + * If the model is not found, a 404 HTTP exception will be thrown.
  210 + *
  211 + * @param integer $id
  212 + *
  213 + * @return CrossSection the loaded model
  214 + * @throws NotFoundHttpException if the model cannot be found
  215 + */
  216 + protected function findModel($id)
  217 + {
  218 + if(( $model = CrossSection::findOne($id) ) !== NULL) {
  219 + return $model;
  220 + } else {
  221 + throw new NotFoundHttpException('The requested page does not exist.');
  222 + }
  223 + }
  224 + }
... ...
frontend/controllers/RoadController.php
1 1 <?php
2 2 namespace frontend\controllers;
3 3  
  4 + use common\models\CrossSection;
4 5 use common\models\FlowIntensity;
5 6 use common\models\Region;
6 7 use common\models\Road;
... ... @@ -142,6 +143,7 @@
142 143 if(empty( $road )) {
143 144 throw new NotFoundHttpException('Road not found');
144 145 }
  146 + // Копируешь отсюда
145 147 $settlement_regions = [ ];
146 148 $region_ids = [ ];
147 149 $region_ids = SettlementAddressLink::find()
... ... @@ -154,6 +156,7 @@
154 156 ->where([ 'region_id' => $region_ids ])
155 157 ->all();
156 158 }
  159 + // До сюда заменяешь название своей моделью
157 160 $flow_intensity_regions = [ ];
158 161 $region_ids = [ ];
159 162 $region_ids = FlowIntensity::find()
... ... @@ -166,10 +169,23 @@
166 169 ->where([ 'region_id' => $region_ids ])
167 170 ->all();
168 171 }
  172 + $cross_section_regions = [ ];
  173 + $region_ids = [ ];
  174 + $region_ids = CrossSection::find()
  175 + ->distinct()
  176 + ->select('region_id')
  177 + ->where([ 'road_id' => $id ])
  178 + ->column();
  179 + if(!empty( $region_ids )) {
  180 + $cross_section_regions = Region::find()
  181 + ->where([ 'region_id' => $region_ids ])
  182 + ->all();
  183 + }
169 184 return $this->render('view', [
170 185 'road' => $road,
171 186 'settlement_regions' => $settlement_regions,
172 187 'flow_intensity_regions' => $flow_intensity_regions,
  188 + 'cross_section_regions' => $cross_section_regions,
173 189 ]);
174 190 }
175 191  
... ... @@ -222,4 +238,29 @@
222 238 'dataProvider' => $dataProvider,
223 239 ]);
224 240 }
  241 +
  242 + public function actionCrossSection($id, $region_id)
  243 + {
  244 + $road = Road::findOne($id);
  245 + if(empty( $road )) {
  246 + throw new NotFoundHttpException('Road not found');
  247 + }
  248 + $region = Region::findOne($region_id);
  249 + if(empty( $region )) {
  250 + throw new NotFoundHttpException('Region not found');
  251 + }
  252 + $dataProvider = new ActiveDataProvider([
  253 + 'query' => CrossSection::find()
  254 + ->where([
  255 + 'road_id' => $id,
  256 + 'region_id' => $region_id,
  257 + ]),
  258 + 'pagination' => false,
  259 + ]);
  260 + return $this->render('cross-section', [
  261 + 'road' => $road,
  262 + 'region' => $region,
  263 + 'dataProvider' => $dataProvider,
  264 + ]);
  265 + }
225 266 }
... ...
frontend/views/cross-section/_form.php 0 → 100644
  1 +<?php
  2 +
  3 +use yii\helpers\Html;
  4 +use yii\widgets\ActiveForm;
  5 +
  6 + /**
  7 + * @var yii\web\View $this
  8 + * @var common\models\CrossSection $model
  9 + * @var array $regions
  10 + * @var array $roads
  11 + * @var array $surface_types
  12 + * @var array $state_commons
  13 + * @var yii\widgets\ActiveForm $form
  14 + */
  15 +?>
  16 +
  17 +<div class="cross-section-form">
  18 +
  19 + <?php $form = ActiveForm::begin(); ?>
  20 +
  21 + <?= $form->field($model, 'region_id')->dropDownList($regions) ?>
  22 +
  23 + <?= $form->field($model, 'road_id')->dropDownList($roads) ?>
  24 +
  25 + <?= $form->field($model, 'location_left')->textInput() ?>
  26 +
  27 + <?= $form->field($model, 'location_right')->textInput() ?>
  28 +
  29 + <?= $form->field($model, 'direction')->textInput(['maxlength' => true]) ?>
  30 +
  31 + <?= $form->field($model, 'surface_type_id')->dropDownList($surface_types) ?>
  32 +
  33 + <?= $form->field($model, 'length_section')->textInput() ?>
  34 +
  35 + <?= $form->field($model, 'length_surface')->textInput() ?>
  36 +
  37 + <?= $form->field($model, 'distance_edge')->textInput() ?>
  38 +
  39 + <?= $form->field($model, 'width')->textInput() ?>
  40 +
  41 + <?= $form->field($model, 'angle')->textInput() ?>
  42 +
  43 + <?= $form->field($model, 'tube_availability')->dropDownList([0 => 'немає', 1 => 'є']) ?>
  44 +
  45 + <?= $form->field($model, 'safety_availability')->dropDownList([0 => 'немає', 1 => 'є']) ?>
  46 +
  47 + <?= $form->field($model, 'year_build')->textInput() ?>
  48 +
  49 + <?= $form->field($model, 'year_repair')->textInput() ?>
  50 +
  51 + <?= $form->field($model, 'state_common_id')->dropDownList($state_commons) ?>
  52 +
  53 + <div class="form-group">
  54 + <?= Html::submitButton($model->isNewRecord ? 'Create' : 'Update', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>
  55 + </div>
  56 +
  57 + <?php ActiveForm::end(); ?>
  58 +
  59 +</div>
... ...
frontend/views/cross-section/_search.php 0 → 100644
  1 +<?php
  2 +
  3 +use yii\helpers\Html;
  4 +use yii\widgets\ActiveForm;
  5 +
  6 +/* @var $this yii\web\View */
  7 +/* @var $model common\models\CrossSectionSearch */
  8 +/* @var $form yii\widgets\ActiveForm */
  9 +?>
  10 +
  11 +<div class="cross-section-search">
  12 +
  13 + <?php $form = ActiveForm::begin([
  14 + 'action' => ['index'],
  15 + 'method' => 'get',
  16 + ]); ?>
  17 +
  18 + <?= $form->field($model, 'cross_section_id') ?>
  19 +
  20 + <?= $form->field($model, 'region_id') ?>
  21 +
  22 + <?= $form->field($model, 'road_id') ?>
  23 +
  24 + <?= $form->field($model, 'location_left') ?>
  25 +
  26 + <?= $form->field($model, 'location_right') ?>
  27 +
  28 + <?php // echo $form->field($model, 'direction') ?>
  29 +
  30 + <?php // echo $form->field($model, 'surface_type_id') ?>
  31 +
  32 + <?php // echo $form->field($model, 'length_section') ?>
  33 +
  34 + <?php // echo $form->field($model, 'length_surface') ?>
  35 +
  36 + <?php // echo $form->field($model, 'distance_edge') ?>
  37 +
  38 + <?php // echo $form->field($model, 'width') ?>
  39 +
  40 + <?php // echo $form->field($model, 'angle') ?>
  41 +
  42 + <?php // echo $form->field($model, 'tube_availability') ?>
  43 +
  44 + <?php // echo $form->field($model, 'safety_availability') ?>
  45 +
  46 + <?php // echo $form->field($model, 'year_build') ?>
  47 +
  48 + <?php // echo $form->field($model, 'year_repair') ?>
  49 +
  50 + <?php // echo $form->field($model, 'state_common_id') ?>
  51 +
  52 + <div class="form-group">
  53 + <?= Html::submitButton('Search', ['class' => 'btn btn-primary']) ?>
  54 + <?= Html::resetButton('Reset', ['class' => 'btn btn-default']) ?>
  55 + </div>
  56 +
  57 + <?php ActiveForm::end(); ?>
  58 +
  59 +</div>
... ...
frontend/views/cross-section/create.php 0 → 100644
  1 +<?php
  2 +
  3 + use yii\helpers\Html;
  4 +
  5 + /**
  6 + * @var yii\web\View $this
  7 + * @var common\models\CrossSection $model
  8 + * @var array $regions
  9 + * @var array $roads
  10 + * @var array $surface_types
  11 + * @var array $state_commons
  12 + */
  13 +
  14 + $this->title = 'Create Cross Section';
  15 + $this->params[ 'breadcrumbs' ][] = [
  16 + 'label' => 'Cross Sections',
  17 + 'url' => [ 'index' ],
  18 + ];
  19 + $this->params[ 'breadcrumbs' ][] = $this->title;
  20 +?>
  21 +<div class="cross-section-create">
  22 +
  23 + <h1><?= Html::encode($this->title) ?></h1>
  24 +
  25 + <?= $this->render('_form', [
  26 + 'model' => $model,
  27 + 'regions' => $regions,
  28 + 'roads' => $roads,
  29 + 'surface_types' => $surface_types,
  30 + 'state_commons' => $state_commons,
  31 + ]) ?>
  32 +
  33 +</div>
... ...
frontend/views/cross-section/index.php 0 → 100644
  1 +<?php
  2 +
  3 +use yii\helpers\Html;
  4 +use yii\grid\GridView;
  5 +
  6 +/* @var $this yii\web\View */
  7 +/* @var $searchModel common\models\CrossSectionSearch */
  8 +/* @var $dataProvider yii\data\ActiveDataProvider */
  9 +
  10 +$this->title = 'Наявність та технічний стан з\'їздів';
  11 +$this->params['breadcrumbs'][] = $this->title;
  12 +?>
  13 +<div class="cross-section-index">
  14 +
  15 + <h1><?= Html::encode($this->title) ?></h1>
  16 + <?php // echo $this->render('_search', ['model' => $searchModel]); ?>
  17 +
  18 + <p>
  19 + <?= Html::a('Create Cross Section', ['create'], ['class' => 'btn btn-success']) ?>
  20 + </p>
  21 + <?= GridView::widget([
  22 + 'dataProvider' => $dataProvider,
  23 + 'filterModel' => $searchModel,
  24 + 'columns' => [
  25 + ['class' => 'yii\grid\SerialColumn'],
  26 +
  27 + 'cross_section_id',
  28 + 'region_id',
  29 + 'road_id',
  30 + 'location_left',
  31 + 'location_right',
  32 + // 'direction',
  33 + // 'surface_type_id',
  34 + // 'length_section',
  35 + // 'length_surface',
  36 + // 'distance_edge',
  37 + // 'width',
  38 + // 'angle',
  39 + // 'tube_availability',
  40 + // 'safety_availability',
  41 + // 'year_build',
  42 + // 'year_repair',
  43 + // 'state_common_id',
  44 +
  45 + ['class' => 'yii\grid\ActionColumn'],
  46 + ],
  47 + ]); ?>
  48 +</div>
... ...
frontend/views/cross-section/update.php 0 → 100644
  1 +<?php
  2 +
  3 +use yii\helpers\Html;
  4 +
  5 + /**
  6 + * @var yii\web\View $this
  7 + * @var common\models\CrossSection $model
  8 + * @var array $regions
  9 + * @var array $roads
  10 + * @var array $surface_types
  11 + * @var array $state_commons
  12 + */
  13 +
  14 +$this->title = 'Update Cross Section: ' . $model->cross_section_id;
  15 +$this->params['breadcrumbs'][] = ['label' => 'Cross Sections', 'url' => ['index']];
  16 +$this->params['breadcrumbs'][] = ['label' => $model->cross_section_id, 'url' => ['view', 'id' => $model->cross_section_id]];
  17 +$this->params['breadcrumbs'][] = 'Update';
  18 +?>
  19 +<div class="cross-section-update">
  20 +
  21 + <h1><?= Html::encode($this->title) ?></h1>
  22 +
  23 + <?= $this->render('_form', [
  24 + 'model' => $model,
  25 + 'regions' => $regions,
  26 + 'roads' => $roads,
  27 + 'surface_types' => $surface_types,
  28 + 'state_commons' => $state_commons,
  29 + ]) ?>
  30 +
  31 +</div>
... ...
frontend/views/cross-section/view.php 0 → 100644
  1 +<?php
  2 +
  3 +use yii\helpers\Html;
  4 +use yii\widgets\DetailView;
  5 +
  6 +/* @var $this yii\web\View */
  7 +/* @var $model common\models\CrossSection */
  8 +
  9 +$this->title = $model->cross_section_id;
  10 +$this->params['breadcrumbs'][] = ['label' => 'Cross Sections', 'url' => ['index']];
  11 +$this->params['breadcrumbs'][] = $this->title;
  12 +?>
  13 +<div class="cross-section-view">
  14 +
  15 + <h1><?= Html::encode($this->title) ?></h1>
  16 +
  17 + <p>
  18 + <?= Html::a('Update', ['update', 'id' => $model->cross_section_id], ['class' => 'btn btn-primary']) ?>
  19 + <?= Html::a('Delete', ['delete', 'id' => $model->cross_section_id], [
  20 + 'class' => 'btn btn-danger',
  21 + 'data' => [
  22 + 'confirm' => 'Are you sure you want to delete this item?',
  23 + 'method' => 'post',
  24 + ],
  25 + ]) ?>
  26 + </p>
  27 +
  28 + <?= DetailView::widget([
  29 + 'model' => $model,
  30 + 'attributes' => [
  31 + 'cross_section_id',
  32 + 'region_id',
  33 + 'road_id',
  34 + 'location_left',
  35 + 'location_right',
  36 + 'direction',
  37 + 'surface_type_id',
  38 + 'length_section',
  39 + 'length_surface',
  40 + 'distance_edge',
  41 + 'width',
  42 + 'angle',
  43 + 'tube_availability',
  44 + 'safety_availability',
  45 + 'year_build',
  46 + 'year_repair',
  47 + 'state_common_id',
  48 + ],
  49 + ]) ?>
  50 +
  51 +</div>
... ...
frontend/views/road/cross-section.php 0 → 100755
  1 +<?php
  2 +
  3 + /**
  4 + * @var Road $road
  5 + * @var Region $region
  6 + * @var ActiveDataProvider $dataProvider
  7 + */
  8 +
  9 + use common\models\CrossSection;
  10 + use common\models\Region;
  11 + use common\models\Road;
  12 + use yii\data\ActiveDataProvider;
  13 + use yii\grid\GridView;
  14 +
  15 + $this->title = $road->name;
  16 + $this->params[ 'breadcrumbs' ][] = [
  17 + 'label' => 'Дороги',
  18 + 'url' => [ 'index' ],
  19 + ];
  20 + $this->params[ 'breadcrumbs' ][] = [
  21 + 'label' => $this->title,
  22 + 'url' => [
  23 + 'view',
  24 + 'id' => $road->road_id,
  25 + ],
  26 + ];
  27 + $this->params[ 'breadcrumbs' ][] = 'Відомість інтенсивності руху та склад транспортного потоку - ' . ucfirst($region->name). ' область';
  28 +?>
  29 +<div class="site-index">
  30 + <div class="col-xs-6 text-center">
  31 + Міністрество транспорту України <br>
  32 + Державна служба автомобільних доріг <br>
  33 + України
  34 + </div>
  35 + <div class="col-xs-6 text-center">
  36 + Служба автомобільних доріг у <?php echo $region->name; ?> області
  37 + </div>
  38 + <div class="clearfix"></div>
  39 + <div class="col-xs-12 text-center">
  40 + <p class="h3">Відомість</p>
  41 + <p class="text-center"><b>інтенсивності руху та склад транспортного потоку</b></p>
  42 + <p>на автомобільній дорозі</p>
  43 + <p><ins><?php echo $road->name; ?></ins></p>
  44 + <p><ins><?php echo $road->roadType->definition;?></ins> значення станом на <ins><?php echo date('d F Y');?> р.</ins></p>
  45 + </div>
  46 + <div class="col-xs-12 text-center">
  47 + <?php
  48 + echo GridView::widget([
  49 + 'dataProvider' => $dataProvider,
  50 + 'layout' => "{items}",
  51 + 'columns' => [
  52 + [
  53 + 'attribute' => 'location_right',
  54 + 'value' => function($model) {
  55 + /**
  56 + * @var CrossSection $model
  57 + */
  58 + return $model->getRightString();
  59 + }
  60 + ],
  61 + [
  62 + 'attribute' => 'location_left',
  63 + 'value' => function($model) {
  64 + /**
  65 + * @var CrossSection $model
  66 + */
  67 + return $model->getLeftString();
  68 + }
  69 + ],
  70 + 'direction',
  71 + [
  72 + 'attribute' => 'surface_type_id',
  73 + 'value' => function($model) {
  74 + /**
  75 + * @var CrossSection $model
  76 + */
  77 + return $model->surfaceType->name;
  78 + }
  79 + ],
  80 + 'length_section',
  81 + 'length_surface',
  82 + 'distance_edge',
  83 + 'width',
  84 + 'angle',
  85 + 'tube_availability:boolean',
  86 + 'safety_availability:boolean',
  87 + 'year_build',
  88 + 'year_repair',
  89 + 'state_common_id',
  90 + ],
  91 + ]);
  92 + ?>
  93 + </div>
  94 +</div>
... ...
frontend/views/road/view.php
... ... @@ -4,6 +4,7 @@
4 4 * @var Road $road
5 5 * @var Region[] $settlement_regions
6 6 * @var Region[] $flow_intensity_regions
  7 + * @var Region[] $cross_section_regions
7 8 */
8 9  
9 10 use common\models\Region;
... ... @@ -39,6 +40,9 @@
39 40 </div>
40 41 <div class="col-xs-12">
41 42 <p class="text-center">Відомості:</p>
  43 + <?php
  44 + // Копируешь отсюда
  45 + ?>
42 46 <div class="panel panel-default">
43 47 <div class="panel-heading">
44 48 <a href="#settlements" data-toggle="collapse" aria-expanded="false" aria-controls="settlements">Адресна прив'язка населених пунктів</a>
... ... @@ -65,6 +69,9 @@
65 69 ?>
66 70 </div>
67 71 </div>
  72 + <?php
  73 + // До сюда
  74 + ?>
68 75 <div class="panel panel-default">
69 76 <div class="panel-heading">
70 77 <a href="#flow_intensities" data-toggle="collapse" aria-expanded="false" aria-controls="flow_intensities">Інтенсивність руху та склад транспортного потоку</a>
... ... @@ -91,6 +98,32 @@
91 98 ?>
92 99 </div>
93 100 </div>
  101 + <div class="panel panel-default">
  102 + <div class="panel-heading">
  103 + <a href="#cross_sections" data-toggle="collapse" aria-expanded="false" aria-controls="cross_sections">Наявність та технічний стан з'їздів</a>
  104 + </div>
  105 + <div class="panel-body collapse" id="cross_sections">
  106 + <?php
  107 + if(!empty( $cross_section_regions )) {
  108 + ?>
  109 + <div class="list-group">
  110 + <?php
  111 + foreach($cross_section_regions as $region) {
  112 + echo Html::a($region->name . ' область', [
  113 + 'cross-section',
  114 + 'id' => $road->road_id,
  115 + 'region_id' => $region->region_id,
  116 + ]);
  117 + }
  118 + ?>
  119 + </div>
  120 + <?php
  121 + } else {
  122 + echo Html::tag('p', 'Відомості не знайдені.');
  123 + }
  124 + ?>
  125 + </div>
  126 + </div>
94 127 </div>
95 128 <div class="clearfix"></div>
96 129 </div>
... ...