b41d5459
Yarik
first commit
|
1
2
3
|
<?php
namespace frontend\controllers;
|
31f7c78a
Yarik
Yarik
|
4
|
use common\models\BusStop;
|
3d730a7c
Yarik
Yarik
|
5
|
use common\models\CrossSection;
|
b41d5459
Yarik
first commit
|
6
7
8
9
|
use common\models\FlowIntensity;
use common\models\Region;
use common\models\Road;
use common\models\RoadCategory;
|
31f7c78a
Yarik
Yarik
|
10
|
use common\models\RoadSurface;
|
53868b90
Eugeny Galkovskiy
120716
|
11
|
use common\models\RoadToCategory;
|
b41d5459
Yarik
first commit
|
12
|
use common\models\RoadType;
|
53868b90
Eugeny Galkovskiy
120716
|
13
|
use common\models\RoadWidth;
|
31f7c78a
Yarik
Yarik
|
14
|
use common\models\ServiceObject;
|
b41d5459
Yarik
first commit
|
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
|
use common\models\SettlementAddressLink;
use yii\data\ActiveDataProvider;
use yii\filters\VerbFilter;
use yii\web\Controller;
use yii\web\NotFoundHttpException;
class RoadController extends Controller
{
/**
* @inheritdoc
*/
public function behaviors()
{
return [
'verbs' => [
'class' => VerbFilter::className(),
'actions' => [
'delete' => [ 'post' ],
],
],
];
}
/**
* @inheritdoc
*/
public function actions()
{
return [
'error' => [
'class' => 'yii\web\ErrorAction',
],
];
}
/**
* @return mixed
*/
public function actionCreate()
{
$road = new Road();
$post = \Yii::$app->request->post();
if($road->load($post) && $road->save()) {
return $this->redirect([ 'index' ]);
} else {
$road_types = RoadType::find()
->select('value')
->indexBy('road_type_id')
->asArray()
->column();
$road_categories = RoadCategory::find()
->select('value')
->indexBy('road_category_id')
->asArray()
->column();
return $this->render('create', [
'road' => $road,
'road_types' => $road_types,
'road_categories' => $road_categories,
]);
}
}
/**
* @param int $id
*
* @return mixed
* @throws NotFoundHttpException
*/
public function actionDelete(int $id)
{
$road = Road::findOne($id);
if(empty( $road )) {
throw new NotFoundHttpException('Road not found');
}
$road->delete();
return $this->redirect([ 'index' ]);
}
/**
* @return mixed
*/
public function actionIndex()
{
$query = Road::find()
->with('roadCategory', 'roadType');
$dataProvider = new ActiveDataProvider([
'query' => $query,
'pagination' => [
'pageSize' => 20,
],
]);
return $this->render('index', [ 'dataProvider' => $dataProvider ]);
}
/**
* @param int $id
*
* @return mixed
* @throws NotFoundHttpException
*/
public function actionUpdate(int $id)
{
$road = Road::findOne($id);
if(empty( $road )) {
throw new NotFoundHttpException('Road not found');
}
$post = \Yii::$app->request->post();
if($road->load($post) && $road->save()) {
return $this->redirect([ 'index' ]);
} else {
$road_types = RoadType::find()
->select('value')
->indexBy('road_type_id')
->asArray()
->column();
$road_categories = RoadCategory::find()
->select('value')
->indexBy('road_category_id')
->asArray()
->column();
return $this->render('update', [
'road' => $road,
'road_types' => $road_types,
'road_categories' => $road_categories,
]);
}
}
public function actionView(int $id)
{
$road = Road::findOne($id);
if(empty( $road )) {
throw new NotFoundHttpException('Road not found');
}
|
3d730a7c
Yarik
Yarik
|
151
|
// Копируешь отсюда
|
b41d5459
Yarik
first commit
|
152
153
154
155
156
157
158
159
160
161
162
163
|
$settlement_regions = [ ];
$region_ids = [ ];
$region_ids = SettlementAddressLink::find()
->distinct()
->select('region_id')
->where([ 'road_id' => $id ])
->column();
if(!empty( $region_ids )) {
$settlement_regions = Region::find()
->where([ 'region_id' => $region_ids ])
->all();
}
|
3d730a7c
Yarik
Yarik
|
164
|
// До сюда заменяешь название своей моделью
|
b41d5459
Yarik
first commit
|
165
166
167
168
169
170
171
172
173
174
175
176
|
$flow_intensity_regions = [ ];
$region_ids = [ ];
$region_ids = FlowIntensity::find()
->distinct()
->select('region_id')
->where([ 'road_id' => $id ])
->column();
if(!empty( $region_ids )) {
$flow_intensity_regions = Region::find()
->where([ 'region_id' => $region_ids ])
->all();
}
|
3d730a7c
Yarik
Yarik
|
177
178
179
180
181
182
183
|
$cross_section_regions = [ ];
$region_ids = [ ];
$region_ids = CrossSection::find()
->distinct()
->select('region_id')
->where([ 'road_id' => $id ])
->column();
|
53868b90
Eugeny Galkovskiy
120716
|
184
|
|
3d730a7c
Yarik
Yarik
|
185
186
187
188
189
|
if(!empty( $region_ids )) {
$cross_section_regions = Region::find()
->where([ 'region_id' => $region_ids ])
->all();
}
|
31f7c78a
Yarik
Yarik
|
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
|
$road_surface_regions = [ ];
$region_ids = [ ];
$region_ids = RoadSurface::find()
->distinct()
->select('region_id')
->where([ 'road_id' => $id ])
->column();
if(!empty( $region_ids )) {
$road_surface_regions = Region::find()
->where([ 'region_id' => $region_ids ])
->all();
}
$service_object_regions = [ ];
$region_ids = [ ];
$region_ids = ServiceObject::find()
->distinct()
->select('region_id')
->where([ 'road_id' => $id ])
->column();
if(!empty( $region_ids )) {
$service_object_regions = Region::find()
->where([ 'region_id' => $region_ids ])
->all();
}
$bus_stop_regions = [ ];
$region_ids = [ ];
$region_ids = BusStop::find()
->distinct()
->select('region_id')
->where([ 'road_id' => $id ])
->column();
if(!empty( $region_ids )) {
$bus_stop_regions = Region::find()
->where([ 'region_id' => $region_ids ])
->all();
}
|
53868b90
Eugeny Galkovskiy
120716
|
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
|
$road_to_categories = [ ];
$region_ids = [ ];
$region_ids = RoadToCategory::find()
->distinct()
->select('region_id')
->where([ 'road_id' => $id ])
->column();
if(!empty( $region_ids )) {
$road_to_categories = Region::find()
->where([ 'region_id' => $region_ids ])
->all();
}
$road_width = [ ];
$region_ids = [ ];
$region_ids = RoadWidth::find()
->distinct()
->select('region_id')
->where([ 'road_id' => $id ])
->column();
if(!empty( $region_ids )) {
$road_width = Region::find()
->where([ 'region_id' => $region_ids ])
->all();
}
|
b41d5459
Yarik
first commit
|
250
251
252
253
|
return $this->render('view', [
'road' => $road,
'settlement_regions' => $settlement_regions,
'flow_intensity_regions' => $flow_intensity_regions,
|
3d730a7c
Yarik
Yarik
|
254
|
'cross_section_regions' => $cross_section_regions,
|
53868b90
Eugeny Galkovskiy
120716
|
255
256
|
'road_to_categories' => $road_to_categories,
'road_width' => $road_width,
|
31f7c78a
Yarik
Yarik
|
257
258
259
|
'road_surface_regions' => $road_surface_regions,
'service_object_regions' => $service_object_regions,
'bus_stop_regions' => $bus_stop_regions,
|
b41d5459
Yarik
first commit
|
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
|
]);
}
public function actionSettlement(int $id, int $region_id)
{
$road = Road::findOne($id);
if(empty( $road )) {
throw new NotFoundHttpException('Road not found');
}
$region = Region::findOne($region_id);
if(empty( $region )) {
throw new NotFoundHttpException('Region not found');
}
$dataProvider = new ActiveDataProvider([
'query' => SettlementAddressLink::find()
->where([
'road_id' => $id,
'region_id' => $region_id,
]),
'pagination' => false,
]);
return $this->render('settlement', [
'road' => $road,
'region' => $region,
'dataProvider' => $dataProvider,
]);
}
|
53868b90
Eugeny Galkovskiy
120716
|
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
|
public function actionRoadToCategory(int $id, int $region_id)
{
$road = Road::findOne($id);
if(empty( $road )) {
throw new NotFoundHttpException('Road not found');
}
$region = Region::findOne($region_id);
if(empty( $region )) {
throw new NotFoundHttpException('Region not found');
}
$dataProvider = new ActiveDataProvider([
'query' => RoadToCategory::find()
->where([
'road_id' => $id,
'region_id' => $region_id,
]),
'pagination' => false,
]);
return $this->render('road-to-category', [
'road' => $road,
'region' => $region,
'dataProvider' => $dataProvider,
]);
}
public function actionRoadWidth(int $id, int $region_id)
{
$road = Road::findOne($id);
if(empty( $road )) {
throw new NotFoundHttpException('Road not found');
}
$region = Region::findOne($region_id);
if(empty( $region )) {
throw new NotFoundHttpException('Region not found');
}
$dataProvider = new ActiveDataProvider([
'query' => RoadWidth::find()
->where([
'road_id' => $id,
'region_id' => $region_id,
]),
'pagination' => false,
]);
return $this->render('road-width', [
'road' => $road,
'region' => $region,
'dataProvider' => $dataProvider,
]);
}
|
b41d5459
Yarik
first commit
|
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
|
public function actionFlowIntensity(int $id, int $region_id)
{
$road = Road::findOne($id);
if(empty( $road )) {
throw new NotFoundHttpException('Road not found');
}
$region = Region::findOne($region_id);
if(empty( $region )) {
throw new NotFoundHttpException('Region not found');
}
$dataProvider = new ActiveDataProvider([
'query' => FlowIntensity::find()
->where([
'road_id' => $id,
'region_id' => $region_id,
]),
'pagination' => false,
]);
return $this->render('flow-intensity', [
'road' => $road,
'region' => $region,
'dataProvider' => $dataProvider,
]);
}
|
3d730a7c
Yarik
Yarik
|
361
|
|
31f7c78a
Yarik
Yarik
|
362
|
public function actionCrossSection(int $id, int $region_id)
|
3d730a7c
Yarik
Yarik
|
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
|
{
$road = Road::findOne($id);
if(empty( $road )) {
throw new NotFoundHttpException('Road not found');
}
$region = Region::findOne($region_id);
if(empty( $region )) {
throw new NotFoundHttpException('Region not found');
}
$dataProvider = new ActiveDataProvider([
'query' => CrossSection::find()
->where([
'road_id' => $id,
'region_id' => $region_id,
]),
'pagination' => false,
]);
return $this->render('cross-section', [
'road' => $road,
'region' => $region,
'dataProvider' => $dataProvider,
]);
}
|
31f7c78a
Yarik
Yarik
|
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
|
public function actionRoadSurface(int $id, int $region_id)
{
$road = Road::findOne($id);
if(empty( $road )) {
throw new NotFoundHttpException('Road not found');
}
$region = Region::findOne($region_id);
if(empty( $region )) {
throw new NotFoundHttpException('Region not found');
}
$dataProvider = new ActiveDataProvider([
'query' => RoadSurface::find()
->where([
'road_id' => $id,
'region_id' => $region_id,
]),
'pagination' => false,
]);
return $this->render('road-surface', [
'road' => $road,
'region' => $region,
'dataProvider' => $dataProvider,
]);
}
public function actionServiceObject(int $id, int $region_id)
{
$road = Road::findOne($id);
if(empty( $road )) {
throw new NotFoundHttpException('Road not found');
}
$region = Region::findOne($region_id);
if(empty( $region )) {
throw new NotFoundHttpException('Region not found');
}
$dataProvider = new ActiveDataProvider([
'query' => ServiceObject::find()
->where([
'road_id' => $id,
'region_id' => $region_id,
]),
'pagination' => false,
]);
return $this->render('service-object', [
'road' => $road,
'region' => $region,
'dataProvider' => $dataProvider,
]);
}
public function actionBusStop(int $id, int $region_id)
{
$road = Road::findOne($id);
if(empty( $road )) {
throw new NotFoundHttpException('Road not found');
}
$region = Region::findOne($region_id);
if(empty( $region )) {
throw new NotFoundHttpException('Region not found');
}
$dataProvider = new ActiveDataProvider([
'query' => BusStop::find()
->where([
'road_id' => $id,
'region_id' => $region_id,
]),
'pagination' => false,
]);
return $this->render('bus-stop', [
'road' => $road,
'region' => $region,
'dataProvider' => $dataProvider,
]);
}
|
b41d5459
Yarik
first commit
|
461
|
}
|