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
|
use yii\web\NotFoundHttpException;
|
43cb22d0
Yarik
Property
|
11
|
|
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
|
'verbs' => [
|
43cb22d0
Yarik
Property
|
27
|
'class' => VerbFilter::className(),
|
30e3d244
Yarik
Forms
|
28
|
'actions' => [
|
43cb22d0
Yarik
Property
|
29
30
|
'personal' => [ 'post' ],
'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
|
\Yii::$app->user->login(User::findOne(1));
/**
* @var User $user
*/
$user = \Yii::$app->user->identity;
|
43cb22d0
Yarik
Property
|
48
|
if (!$userData = $user->userData) {
|
8195fc24
Yarik
Models
|
49
50
|
$userData = new UserData();
}
|
43cb22d0
Yarik
Property
|
51
|
if (!$userPassport = $user->userPassport) {
|
8195fc24
Yarik
Models
|
52
53
|
$userPassport = new UserPassport();
}
|
fb0f9630
Alexey Boroda
-Greed ready
|
54
|
|
43cb22d0
Yarik
Property
|
55
56
57
58
59
60
61
|
$table = IntellectualProperty::find()
->where(
[
'user_id' => \Yii::$app->user->identity->id,
]
)
->all();
|
fb0f9630
Alexey Boroda
-Greed ready
|
62
|
|
43cb22d0
Yarik
Property
|
63
64
65
66
67
68
69
70
|
return $this->render(
'index',
[
'userData' => $userData,
'userPassport' => $userPassport,
'table' => $table,
]
);
|
3bc9af21
Yarik
Layout
|
71
72
|
}
|
b73541b6
Yarik
Property
|
73
|
public function actionSales($id = null)
|
f1b535e4
Yarik
Datepicker
|
74
|
{
|
43cb22d0
Yarik
Property
|
75
76
|
$newRecord = false;
if ($id) {
|
b73541b6
Yarik
Property
|
77
78
79
|
$property = $this->findProperty($id);
} else {
$property = new IntellectualProperty();
|
43cb22d0
Yarik
Property
|
80
|
$newRecord = true;
|
b73541b6
Yarik
Property
|
81
|
}
|
43cb22d0
Yarik
Property
|
82
83
84
85
86
87
88
89
90
91
92
|
if ($property->load(\Yii::$app->request->post()) && $property->save()) {
if($newRecord) {
return $this->redirect(['cabinet/sales', 'id' => $property->id]);
} else {
$response = \Yii::$app->response;
$response->format = $response::FORMAT_JSON;
return [
'success' => true,
'message' => 'Данные успешно сохранены',
];
}
|
b73541b6
Yarik
Property
|
93
|
}
|
43cb22d0
Yarik
Property
|
94
95
96
97
98
99
|
return $this->render(
'sales',
[
'property' => $property,
]
);
|
f1b535e4
Yarik
Datepicker
|
100
101
|
}
|
caf85dfb
Yarik
Html
|
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
|
public function actionList()
{
return $this->render('list');
}
public function actionArrivals()
{
return $this->render('arrivals');
}
public function actionNotifications()
{
return $this->render('notifications');
}
public function actionUsers()
{
return $this->render('users');
}
|
30e3d244
Yarik
Forms
|
122
123
124
125
126
127
128
129
130
|
public function actionPersonal()
{
$request = \Yii::$app->request;
$response = \Yii::$app->response;
$response->format = $response::FORMAT_JSON;
/**
* @var User $user
*/
$user = \Yii::$app->user->identity;
|
43cb22d0
Yarik
Property
|
131
|
if (!$userData = $user->userData) {
|
30e3d244
Yarik
Forms
|
132
133
134
|
$userData = new UserData();
$userData->user_id = $user->id;
}
|
43cb22d0
Yarik
Property
|
135
|
if ($userData->load($request->post()) && $userData->save()) {
|
30e3d244
Yarik
Forms
|
136
137
138
139
140
141
|
return [
'success' => true,
'message' => 'Данные успешно сохранены',
];
} else {
return [
|
43cb22d0
Yarik
Property
|
142
|
'error' => true,
|
30e3d244
Yarik
Forms
|
143
144
145
146
|
'message' => 'Ошибка сохранения данных',
];
}
}
|
43cb22d0
Yarik
Property
|
147
|
|
30e3d244
Yarik
Forms
|
148
149
150
151
152
153
154
155
156
|
public function actionPassport()
{
$request = \Yii::$app->request;
$response = \Yii::$app->response;
$response->format = $response::FORMAT_JSON;
/**
* @var User $user
*/
$user = \Yii::$app->user->identity;
|
43cb22d0
Yarik
Property
|
157
|
if (!$userPassport = $user->userPassport) {
|
30e3d244
Yarik
Forms
|
158
159
160
|
$userPassport = new UserPassport();
$userPassport->user_id = $user->id;
}
|
43cb22d0
Yarik
Property
|
161
|
if ($userPassport->load($request->post()) && $userPassport->save()) {
|
30e3d244
Yarik
Forms
|
162
163
164
165
166
167
|
return [
'success' => true,
'message' => 'Данные успешно сохранены',
];
} else {
return [
|
43cb22d0
Yarik
Property
|
168
|
'error' => true,
|
30e3d244
Yarik
Forms
|
169
170
171
172
|
'message' => 'Ошибка сохранения данных',
];
}
}
|
43cb22d0
Yarik
Property
|
173
|
|
dcfb3d5c
Alexey Boroda
-Form ajax ready
|
174
175
176
177
178
179
180
181
|
public function actionAddIntProp()
{
$request = \Yii::$app->request;
$response = \Yii::$app->response;
$response->format = $response::FORMAT_JSON;
$intProperty = new IntellectualProperty();
|
fb0f9630
Alexey Boroda
-Greed ready
|
182
183
|
$intProperty->user_id = \Yii::$app->user->identity->id;
|
43cb22d0
Yarik
Property
|
184
|
if ($intProperty->load($request->post()) && $intProperty->save()) {
|
dcfb3d5c
Alexey Boroda
-Form ajax ready
|
185
186
187
188
189
190
|
return [
'success' => true,
'message' => 'Данные успешно сохранены',
];
} else {
return [
|
43cb22d0
Yarik
Property
|
191
|
'error' => true,
|
dcfb3d5c
Alexey Boroda
-Form ajax ready
|
192
193
194
195
|
'message' => 'Ошибка сохранения данных',
];
}
}
|
b73541b6
Yarik
Property
|
196
197
198
199
|
public function findProperty($id)
{
$model = IntellectualProperty::findOne($id);
|
43cb22d0
Yarik
Property
|
200
|
if (empty( $model )) {
|
b73541b6
Yarik
Property
|
201
202
203
204
|
throw new NotFoundHttpException();
}
return $model;
}
|
3bc9af21
Yarik
Layout
|
205
|
}
|