diff --git a/frontend/controllers/CabinetController.php b/frontend/controllers/CabinetController.php index c1e8a53..994ef88 100755 --- a/frontend/controllers/CabinetController.php +++ b/frontend/controllers/CabinetController.php @@ -71,7 +71,7 @@ ); } - public function actionSales($id = null) + public function actionSales($id = NULL) { $newRecord = false; if ($id) { @@ -81,8 +81,13 @@ $newRecord = true; } if ($property->load(\Yii::$app->request->post()) && $property->save()) { - if($newRecord) { - return $this->redirect(['cabinet/sales', 'id' => $property->id]); + if ($newRecord) { + return $this->redirect( + [ + 'cabinet/sales', + 'id' => $property->id, + ] + ); } else { $response = \Yii::$app->response; $response->format = $response::FORMAT_JSON; @@ -93,34 +98,50 @@ } } - $table = CreativeRole::find()->where([ - 'intellectual_property_id' => $id - ])->all(); + $table = CreativeRole::find() + ->where( + [ + 'intellectual_property_id' => $id, + ] + ) + ->all(); return $this->render( 'sales', [ 'property' => $property, - 'table' => $table + 'table' => $table, ] ); } public function actionList() { - return $this->render('list'); + $table = IntellectualProperty::find() + ->where( + [ + 'user_id' => \Yii::$app->user->identity->id, + ] + ) + ->all(); + return $this->render( + 'list', + [ + 'table' => $table, + ] + ); } public function actionArrivals() { return $this->render('arrivals'); } - + public function actionNotifications() { return $this->render('notifications'); } - + public function actionUsers() { return $this->render('users'); @@ -201,14 +222,41 @@ } } - public function actionAddRole() + public function actionDeleteIntProperty() { $request = \Yii::$app->request; $response = \Yii::$app->response; $response->format = $response::FORMAT_JSON; - $role = new CreativeRole(); + 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' => 'Элемент не найден', + ]; + } + } + 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, @@ -227,17 +275,32 @@ $request = \Yii::$app->request; $response = \Yii::$app->response; $response->format = $response::FORMAT_JSON; - - return [ - 'message' => 'ok' . $request->post('id'), - ]; + 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' => 'Роль не найдена', + ]; + } } public function findProperty($id) { $model = IntellectualProperty::findOne($id); - if (empty( $model )) { + if (empty($model)) { throw new NotFoundHttpException(); } return $model; diff --git a/frontend/views/cabinet/list.php b/frontend/views/cabinet/list.php index 59f5a97..c133777 100755 --- a/frontend/views/cabinet/list.php +++ b/frontend/views/cabinet/list.php @@ -1,188 +1,60 @@