3bc9af21
Yarik
Layout
|
1
2
3
|
<?php
namespace frontend\controllers;
|
8195fc24
Yarik
Models
|
4
|
use common\models\User;
|
b73541b6
Yarik
Property
|
5
|
use frontend\models\IntellectualProperty;
|
8195fc24
Yarik
Models
|
6
7
|
use frontend\models\UserData;
use frontend\models\UserPassport;
|
30e3d244
Yarik
Forms
|
8
|
use yii\filters\VerbFilter;
|
3bc9af21
Yarik
Layout
|
9
|
use yii\web\Controller;
|
b73541b6
Yarik
Property
|
10
11
|
use yii\web\NotFoundHttpException;
|
3bc9af21
Yarik
Layout
|
12
13
14
15
16
|
/**
* Cabinet controller
*/
class CabinetController extends Controller
{
|
7f0970a7
Yarik
Layout
|
17
18
19
|
public $layout = 'cabinet';
|
3bc9af21
Yarik
Layout
|
20
21
22
23
24
25
|
/**
* @inheritdoc
*/
public function behaviors()
{
return [
|
30e3d244
Yarik
Forms
|
26
27
28
29
|
'verbs' => [
'class' => VerbFilter::className(),
'actions' => [
'personal' => ['post'],
|
4ff64177
Yarik
Verb
|
30
|
'passport' => ['post'],
|
30e3d244
Yarik
Forms
|
31
32
|
],
],
|
3bc9af21
Yarik
Layout
|
33
34
35
36
37
38
39
40
41
42
|
];
}
/**
* Displays index page.
*
* @return mixed
*/
public function actionIndex()
{
|
8195fc24
Yarik
Models
|
43
44
45
46
47
48
49
50
51
52
53
|
\Yii::$app->user->login(User::findOne(1));
/**
* @var User $user
*/
$user = \Yii::$app->user->identity;
if(!$userData = $user->userData) {
$userData = new UserData();
}
if(!$userPassport = $user->userPassport) {
$userPassport = new UserPassport();
}
|
fb0f9630
Alexey Boroda
-Greed ready
|
54
55
56
57
58
|
$table = IntellectualProperty::find()->where([
'user_id' => \Yii::$app->user->identity->id,
])->all();
|
8195fc24
Yarik
Models
|
59
60
61
|
return $this->render('index', [
'userData' => $userData,
'userPassport' => $userPassport,
|
fb0f9630
Alexey Boroda
-Greed ready
|
62
|
'table' => $table,
|
8195fc24
Yarik
Models
|
63
|
]);
|
3bc9af21
Yarik
Layout
|
64
65
|
}
|
b73541b6
Yarik
Property
|
66
|
public function actionSales($id = null)
|
f1b535e4
Yarik
Datepicker
|
67
|
{
|
b73541b6
Yarik
Property
|
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
|
if($id) {
$property = $this->findProperty($id);
} else {
$property = new IntellectualProperty();
}
if($property->load(\Yii::$app->request->post()) && $property->save()) {
$response = \Yii::$app->response;
$response->format = $response::FORMAT_JSON;
return [
'success' => true,
'message' => 'Данные успешно сохранены',
];
}
return $this->render('sales', [
'property' => $property,
]);
|
f1b535e4
Yarik
Datepicker
|
84
85
|
}
|
30e3d244
Yarik
Forms
|
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
|
public function actionPersonal()
{
$request = \Yii::$app->request;
$response = \Yii::$app->response;
$response->format = $response::FORMAT_JSON;
/**
* @var User $user
*/
$user = \Yii::$app->user->identity;
if(!$userData = $user->userData) {
$userData = new UserData();
$userData->user_id = $user->id;
}
if($userData->load($request->post()) && $userData->save()) {
return [
'success' => true,
'message' => 'Данные успешно сохранены',
];
} else {
return [
'error' => true,
'message' => 'Ошибка сохранения данных',
];
}
}
public function actionPassport()
{
$request = \Yii::$app->request;
$response = \Yii::$app->response;
$response->format = $response::FORMAT_JSON;
/**
* @var User $user
*/
$user = \Yii::$app->user->identity;
if(!$userPassport = $user->userPassport) {
$userPassport = new UserPassport();
$userPassport->user_id = $user->id;
}
if($userPassport->load($request->post()) && $userPassport->save()) {
return [
'success' => true,
'message' => 'Данные успешно сохранены',
];
} else {
return [
'error' => true,
'message' => 'Ошибка сохранения данных',
];
}
}
|
dcfb3d5c
Alexey Boroda
-Form ajax ready
|
137
138
139
140
141
142
143
144
145
|
public function actionAddIntProp()
{
$request = \Yii::$app->request;
$response = \Yii::$app->response;
$response->format = $response::FORMAT_JSON;
$intProperty = new IntellectualProperty();
|
fb0f9630
Alexey Boroda
-Greed ready
|
146
147
|
$intProperty->user_id = \Yii::$app->user->identity->id;
|
dcfb3d5c
Alexey Boroda
-Form ajax ready
|
148
149
150
151
152
153
154
155
156
157
158
159
|
if($intProperty->load($request->post()) && $intProperty->save()) {
return [
'success' => true,
'message' => 'Данные успешно сохранены',
];
} else {
return [
'error' => true,
'message' => 'Ошибка сохранения данных',
];
}
}
|
b73541b6
Yarik
Property
|
160
161
162
163
164
165
166
167
168
|
public function findProperty($id)
{
$model = IntellectualProperty::findOne($id);
if(empty($model)) {
throw new NotFoundHttpException();
}
return $model;
}
|
3bc9af21
Yarik
Layout
|
169
|
}
|