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
|
}
|
b73541b6
Yarik
Property
|
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
84
85
86
87
88
89
90
91
92
93
|
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
|
94
|
}
|
0d91ef5d
Alexey Boroda
-Delete action added
|
95
96
97
98
99
|
$table = CreativeRole::find()->where([
'intellectual_property_id' => $id
])->all();
|
43cb22d0
Yarik
Property
|
100
101
102
103
|
return $this->render(
'sales',
[
'property' => $property,
|
0d91ef5d
Alexey Boroda
-Delete action added
|
104
|
'table' => $table
|
43cb22d0
Yarik
Property
|
105
106
|
]
);
|
f1b535e4
Yarik
Datepicker
|
107
108
|
}
|
caf85dfb
Yarik
Html
|
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
|
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
|
129
130
131
132
133
134
135
136
137
|
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
|
138
|
if (!$userData = $user->userData) {
|
30e3d244
Yarik
Forms
|
139
140
141
|
$userData = new UserData();
$userData->user_id = $user->id;
}
|
43cb22d0
Yarik
Property
|
142
|
if ($userData->load($request->post()) && $userData->save()) {
|
30e3d244
Yarik
Forms
|
143
144
145
146
147
148
|
return [
'success' => true,
'message' => 'Данные успешно сохранены',
];
} else {
return [
|
43cb22d0
Yarik
Property
|
149
|
'error' => true,
|
30e3d244
Yarik
Forms
|
150
151
152
153
|
'message' => 'Ошибка сохранения данных',
];
}
}
|
43cb22d0
Yarik
Property
|
154
|
|
30e3d244
Yarik
Forms
|
155
156
157
158
159
160
161
162
163
|
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
|
164
|
if (!$userPassport = $user->userPassport) {
|
30e3d244
Yarik
Forms
|
165
166
167
|
$userPassport = new UserPassport();
$userPassport->user_id = $user->id;
}
|
43cb22d0
Yarik
Property
|
168
|
if ($userPassport->load($request->post()) && $userPassport->save()) {
|
30e3d244
Yarik
Forms
|
169
170
171
172
173
174
|
return [
'success' => true,
'message' => 'Данные успешно сохранены',
];
} else {
return [
|
43cb22d0
Yarik
Property
|
175
|
'error' => true,
|
30e3d244
Yarik
Forms
|
176
177
178
179
|
'message' => 'Ошибка сохранения данных',
];
}
}
|
43cb22d0
Yarik
Property
|
180
|
|
dcfb3d5c
Alexey Boroda
-Form ajax ready
|
181
182
183
184
185
186
187
188
|
public function actionAddIntProp()
{
$request = \Yii::$app->request;
$response = \Yii::$app->response;
$response->format = $response::FORMAT_JSON;
$intProperty = new IntellectualProperty();
|
fb0f9630
Alexey Boroda
-Greed ready
|
189
190
|
$intProperty->user_id = \Yii::$app->user->identity->id;
|
43cb22d0
Yarik
Property
|
191
|
if ($intProperty->load($request->post()) && $intProperty->save()) {
|
dcfb3d5c
Alexey Boroda
-Form ajax ready
|
192
193
194
195
196
197
|
return [
'success' => true,
'message' => 'Данные успешно сохранены',
];
} else {
return [
|
43cb22d0
Yarik
Property
|
198
|
'error' => true,
|
dcfb3d5c
Alexey Boroda
-Form ajax ready
|
199
200
201
202
|
'message' => 'Ошибка сохранения данных',
];
}
}
|
0d91ef5d
Alexey Boroda
-Delete action added
|
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
|
public function actionAddRole()
{
$request = \Yii::$app->request;
$response = \Yii::$app->response;
$response->format = $response::FORMAT_JSON;
$role = new CreativeRole();
if ($role->load($request->post()) && $role->save()) {
return [
'success' => true,
'message' => 'Данные успешно сохранены',
];
} else {
return [
'error' => true,
'message' => 'Ошибка сохранения данных',
];
}
}
public function actionDeleteRole()
{
$request = \Yii::$app->request;
$response = \Yii::$app->response;
$response->format = $response::FORMAT_JSON;
return [
'message' => 'ok' . $request->post('id'),
];
}
|
b73541b6
Yarik
Property
|
236
237
238
239
|
public function findProperty($id)
{
$model = IntellectualProperty::findOne($id);
|
43cb22d0
Yarik
Property
|
240
|
if (empty( $model )) {
|
b73541b6
Yarik
Property
|
241
242
243
244
|
throw new NotFoundHttpException();
}
return $model;
}
|
3bc9af21
Yarik
Layout
|
245
|
}
|