3bc9af21
Yarik
Layout
|
1
2
3
|
<?php
namespace frontend\controllers;
|
8195fc24
Yarik
Models
|
4
|
use common\models\User;
|
0d91ef5d
Alexey Boroda
-Delete action added
|
5
|
use frontend\models\CreativeRole;
|
b73541b6
Yarik
Property
|
6
|
use frontend\models\IntellectualProperty;
|
8195fc24
Yarik
Models
|
7
8
|
use frontend\models\UserData;
use frontend\models\UserPassport;
|
30e3d244
Yarik
Forms
|
9
|
use yii\filters\VerbFilter;
|
3bc9af21
Yarik
Layout
|
10
|
use yii\web\Controller;
|
b73541b6
Yarik
Property
|
11
|
use yii\web\NotFoundHttpException;
|
43cb22d0
Yarik
Property
|
12
|
|
3bc9af21
Yarik
Layout
|
13
14
15
16
17
|
/**
* Cabinet controller
*/
class CabinetController extends Controller
{
|
7f0970a7
Yarik
Layout
|
18
19
20
|
public $layout = 'cabinet';
|
3bc9af21
Yarik
Layout
|
21
22
23
24
25
26
|
/**
* @inheritdoc
*/
public function behaviors()
{
return [
|
30e3d244
Yarik
Forms
|
27
|
'verbs' => [
|
43cb22d0
Yarik
Property
|
28
|
'class' => VerbFilter::className(),
|
30e3d244
Yarik
Forms
|
29
|
'actions' => [
|
43cb22d0
Yarik
Property
|
30
31
|
'personal' => [ 'post' ],
'passport' => [ 'post' ],
|
30e3d244
Yarik
Forms
|
32
33
|
],
],
|
3bc9af21
Yarik
Layout
|
34
35
36
37
38
39
40
41
42
43
|
];
}
/**
* Displays index page.
*
* @return mixed
*/
public function actionIndex()
{
|
8195fc24
Yarik
Models
|
44
45
46
47
48
|
\Yii::$app->user->login(User::findOne(1));
/**
* @var User $user
*/
$user = \Yii::$app->user->identity;
|
43cb22d0
Yarik
Property
|
49
|
if (!$userData = $user->userData) {
|
8195fc24
Yarik
Models
|
50
51
|
$userData = new UserData();
}
|
43cb22d0
Yarik
Property
|
52
|
if (!$userPassport = $user->userPassport) {
|
8195fc24
Yarik
Models
|
53
54
|
$userPassport = new UserPassport();
}
|
fb0f9630
Alexey Boroda
-Greed ready
|
55
|
|
43cb22d0
Yarik
Property
|
56
57
58
59
60
61
62
|
$table = IntellectualProperty::find()
->where(
[
'user_id' => \Yii::$app->user->identity->id,
]
)
->all();
|
fb0f9630
Alexey Boroda
-Greed ready
|
63
|
|
43cb22d0
Yarik
Property
|
64
65
66
67
68
69
70
71
|
return $this->render(
'index',
[
'userData' => $userData,
'userPassport' => $userPassport,
'table' => $table,
]
);
|
3bc9af21
Yarik
Layout
|
72
73
|
}
|
aebb725c
Alexey Boroda
-List ready
|
74
|
public function actionSales($id = NULL)
|
f1b535e4
Yarik
Datepicker
|
75
|
{
|
43cb22d0
Yarik
Property
|
76
77
|
$newRecord = false;
if ($id) {
|
b73541b6
Yarik
Property
|
78
79
80
|
$property = $this->findProperty($id);
} else {
$property = new IntellectualProperty();
|
43cb22d0
Yarik
Property
|
81
|
$newRecord = true;
|
b73541b6
Yarik
Property
|
82
|
}
|
43cb22d0
Yarik
Property
|
83
|
if ($property->load(\Yii::$app->request->post()) && $property->save()) {
|
aebb725c
Alexey Boroda
-List ready
|
84
85
86
87
88
89
90
|
if ($newRecord) {
return $this->redirect(
[
'cabinet/sales',
'id' => $property->id,
]
);
|
43cb22d0
Yarik
Property
|
91
92
93
94
95
96
97
98
|
} else {
$response = \Yii::$app->response;
$response->format = $response::FORMAT_JSON;
return [
'success' => true,
'message' => 'Данные успешно сохранены',
];
}
|
b73541b6
Yarik
Property
|
99
|
}
|
0d91ef5d
Alexey Boroda
-Delete action added
|
100
|
|
aebb725c
Alexey Boroda
-List ready
|
101
102
103
104
105
106
107
|
$table = CreativeRole::find()
->where(
[
'intellectual_property_id' => $id,
]
)
->all();
|
0d91ef5d
Alexey Boroda
-Delete action added
|
108
|
|
43cb22d0
Yarik
Property
|
109
110
111
112
|
return $this->render(
'sales',
[
'property' => $property,
|
aebb725c
Alexey Boroda
-List ready
|
113
|
'table' => $table,
|
43cb22d0
Yarik
Property
|
114
115
|
]
);
|
f1b535e4
Yarik
Datepicker
|
116
117
|
}
|
caf85dfb
Yarik
Html
|
118
119
|
public function actionList()
{
|
aebb725c
Alexey Boroda
-List ready
|
120
121
122
123
124
125
126
127
128
129
130
131
132
|
$table = IntellectualProperty::find()
->where(
[
'user_id' => \Yii::$app->user->identity->id,
]
)
->all();
return $this->render(
'list',
[
'table' => $table,
]
);
|
caf85dfb
Yarik
Html
|
133
134
135
136
137
138
|
}
public function actionArrivals()
{
return $this->render('arrivals');
}
|
aebb725c
Alexey Boroda
-List ready
|
139
|
|
caf85dfb
Yarik
Html
|
140
141
142
143
|
public function actionNotifications()
{
return $this->render('notifications');
}
|
aebb725c
Alexey Boroda
-List ready
|
144
|
|
caf85dfb
Yarik
Html
|
145
146
147
148
149
|
public function actionUsers()
{
return $this->render('users');
}
|
30e3d244
Yarik
Forms
|
150
151
152
153
154
155
156
157
158
|
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
|
159
|
if (!$userData = $user->userData) {
|
30e3d244
Yarik
Forms
|
160
161
162
|
$userData = new UserData();
$userData->user_id = $user->id;
}
|
43cb22d0
Yarik
Property
|
163
|
if ($userData->load($request->post()) && $userData->save()) {
|
30e3d244
Yarik
Forms
|
164
165
166
167
168
169
|
return [
'success' => true,
'message' => 'Данные успешно сохранены',
];
} else {
return [
|
43cb22d0
Yarik
Property
|
170
|
'error' => true,
|
30e3d244
Yarik
Forms
|
171
172
173
174
|
'message' => 'Ошибка сохранения данных',
];
}
}
|
43cb22d0
Yarik
Property
|
175
|
|
30e3d244
Yarik
Forms
|
176
177
178
179
180
181
182
183
184
|
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
|
185
|
if (!$userPassport = $user->userPassport) {
|
30e3d244
Yarik
Forms
|
186
187
188
|
$userPassport = new UserPassport();
$userPassport->user_id = $user->id;
}
|
43cb22d0
Yarik
Property
|
189
|
if ($userPassport->load($request->post()) && $userPassport->save()) {
|
30e3d244
Yarik
Forms
|
190
191
192
193
194
195
|
return [
'success' => true,
'message' => 'Данные успешно сохранены',
];
} else {
return [
|
43cb22d0
Yarik
Property
|
196
|
'error' => true,
|
30e3d244
Yarik
Forms
|
197
198
199
200
|
'message' => 'Ошибка сохранения данных',
];
}
}
|
43cb22d0
Yarik
Property
|
201
|
|
dcfb3d5c
Alexey Boroda
-Form ajax ready
|
202
203
204
205
206
207
208
209
|
public function actionAddIntProp()
{
$request = \Yii::$app->request;
$response = \Yii::$app->response;
$response->format = $response::FORMAT_JSON;
$intProperty = new IntellectualProperty();
|
fb0f9630
Alexey Boroda
-Greed ready
|
210
211
|
$intProperty->user_id = \Yii::$app->user->identity->id;
|
43cb22d0
Yarik
Property
|
212
|
if ($intProperty->load($request->post()) && $intProperty->save()) {
|
dcfb3d5c
Alexey Boroda
-Form ajax ready
|
213
214
215
216
217
218
|
return [
'success' => true,
'message' => 'Данные успешно сохранены',
];
} else {
return [
|
43cb22d0
Yarik
Property
|
219
|
'error' => true,
|
dcfb3d5c
Alexey Boroda
-Form ajax ready
|
220
221
222
223
|
'message' => 'Ошибка сохранения данных',
];
}
}
|
0d91ef5d
Alexey Boroda
-Delete action added
|
224
|
|
aebb725c
Alexey Boroda
-List ready
|
225
|
public function actionDeleteIntProperty()
|
0d91ef5d
Alexey Boroda
-Delete action added
|
226
227
228
229
230
|
{
$request = \Yii::$app->request;
$response = \Yii::$app->response;
$response->format = $response::FORMAT_JSON;
|
aebb725c
Alexey Boroda
-List ready
|
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
|
if (!empty($request->post('id'))) {
$role = IntellectualProperty::findOne($request->post('id'));
if ($role->delete()) {
return [
'success' => true,
'message' => 'Данные успешно удалены',
];
} else {
return [
'error' => true,
'message' => 'Ошибка удаления данных',
];
}
} else {
return [
'error' => true,
'message' => 'Элемент не найден',
];
}
}
|
0d91ef5d
Alexey Boroda
-Delete action added
|
251
|
|
aebb725c
Alexey Boroda
-List ready
|
252
253
254
255
256
257
258
259
|
public function actionAddRole()
{
$request = \Yii::$app->request;
$response = \Yii::$app->response;
$response->format = $response::FORMAT_JSON;
$role = new CreativeRole();
|
0d91ef5d
Alexey Boroda
-Delete action added
|
260
261
262
263
264
265
266
267
268
269
270
271
|
if ($role->load($request->post()) && $role->save()) {
return [
'success' => true,
'message' => 'Данные успешно сохранены',
];
} else {
return [
'error' => true,
'message' => 'Ошибка сохранения данных',
];
}
}
|
9e523ea9
Alexey Boroda
-Update ready
|
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
|
public function actionUpdateRole()
{
$request = \Yii::$app->request;
$response = \Yii::$app->response;
$response->format = $response::FORMAT_JSON;
$role = CreativeRole::findOne($request->get('id'));
if ($role->load($request->post()) && $role->save()) {
return [
'success' => true,
'message' => 'Данные успешно сохранены',
];
} else {
return [
'error' => true,
'message' => 'Ошибка сохранения данных',
];
}
}
public function actionGetRoleForm()
{
$request = \Yii::$app->request;
$response = \Yii::$app->response;
$response->format = $response::FORMAT_JSON;
$model = CreativeRole::findOne($request->post('id'));
return [
'answer' => $this->renderPartial('_update_form', ['model' => $model])
];
}
|
0d91ef5d
Alexey Boroda
-Delete action added
|
306
307
308
309
310
311
|
public function actionDeleteRole()
{
$request = \Yii::$app->request;
$response = \Yii::$app->response;
$response->format = $response::FORMAT_JSON;
|
0d91ef5d
Alexey Boroda
-Delete action added
|
312
|
|
aebb725c
Alexey Boroda
-List ready
|
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
|
if (!empty($request->post('id'))) {
$role = CreativeRole::findOne($request->post('id'));
if ($role->delete()) {
return [
'success' => true,
'message' => 'Данные успешно удалены',
];
} else {
return [
'error' => true,
'message' => 'Ошибка удаления данных',
];
}
} else {
return [
'error' => true,
'message' => 'Роль не найдена',
];
}
|
0d91ef5d
Alexey Boroda
-Delete action added
|
332
|
}
|
b73541b6
Yarik
Property
|
333
334
335
336
|
public function findProperty($id)
{
$model = IntellectualProperty::findOne($id);
|
aebb725c
Alexey Boroda
-List ready
|
337
|
if (empty($model)) {
|
b73541b6
Yarik
Property
|
338
339
340
341
|
throw new NotFoundHttpException();
}
return $model;
}
|
3bc9af21
Yarik
Layout
|
342
|
}
|