From 90b0dbf1d0162d279a6a79db6619d0531c248411 Mon Sep 17 00:00:00 2001 From: Evg Date: Sun, 12 Jun 2022 17:06:45 +0300 Subject: [PATCH] =?UTF-8?q?DEV:=20=D0=9D=D0=B5=D0=B7=D0=BD=D0=B0=D1=87?= =?UTF-8?q?=D0=B8=D1=82=D0=B5=D0=BB=D1=8C=D0=BD=D1=8B=D0=B5=20=D0=B8=D0=B7?= =?UTF-8?q?=D0=BC=D0=B5=D0=BD=D0=B5=D0=BD=D0=B8=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Answer/EditAnswerController.php | 20 +++++++----------- app/Traits/Author.php | 21 +++++++++++++++++++ app/Traits/Page.php | 19 ----------------- 3 files changed, 28 insertions(+), 32 deletions(-) create mode 100644 app/Traits/Author.php delete mode 100644 app/Traits/Page.php diff --git a/app/Controllers/Answer/EditAnswerController.php b/app/Controllers/Answer/EditAnswerController.php index bed3e071..92e853c7 100644 --- a/app/Controllers/Answer/EditAnswerController.php +++ b/app/Controllers/Answer/EditAnswerController.php @@ -6,11 +6,15 @@ use Hleb\Constructor\Handlers\Request; use App\Controllers\Controller; use App\Models\{AnswerModel, PostModel}; use App\Models\User\UserModel; -use Validation, Meta, Access, UserData; +use Validation, Meta, Access; + +use App\Traits\Author; class EditAnswerController extends Controller { - // Форма редактирования answer + use Author; + + // Edit form answer public function index() { $answer_id = Request::getInt('id'); @@ -49,7 +53,6 @@ class EditAnswerController extends Controller $content = $_POST['content']; // для Markdown // Access check - // Проверка доступа $answer = AnswerModel::getAnswerId($answer_id); if (Access::author('answer', $answer['answer_user_id'], $answer['answer_date'], 30) == false) { return false; @@ -60,20 +63,11 @@ class EditAnswerController extends Controller Validation::Length($content, 6, 5000, 'content', url('content.edit', ['type' => 'answer', 'id' => $answer['answer_id']])); - $user_id = $answer['answer_user_id']; - if (UserData::checkAdmin()) { - $user_new = Request::getPost('user_id'); - if ($user_new) { - $answer_user_new = json_decode($user_new, true); - $user_id = $answer_user_new[0]['id']; - } - } - AnswerModel::edit( [ 'answer_id' => $answer_id, 'answer_content' => $content, - 'answer_user_id' => $user_id, + 'answer_user_id' => $this->edit($answer['answer_user_id'], Request::getPost('user_id')), 'answer_modified' => date("Y-m-d H:i:s"), ] ); diff --git a/app/Traits/Author.php b/app/Traits/Author.php new file mode 100644 index 00000000..06684e31 --- /dev/null +++ b/app/Traits/Author.php @@ -0,0 +1,21 @@ +