DEV: Незначительные изменения
This commit is contained in:
parent
6ccdbda42a
commit
90b0dbf1d0
3 changed files with 28 additions and 32 deletions
|
@ -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"),
|
||||
]
|
||||
);
|
||||
|
|
21
app/Traits/Author.php
Normal file
21
app/Traits/Author.php
Normal file
|
@ -0,0 +1,21 @@
|
|||
<?php
|
||||
|
||||
namespace App\Traits;
|
||||
|
||||
use UserData;
|
||||
|
||||
trait Author
|
||||
{
|
||||
public function edit($user_id, $user_new)
|
||||
{
|
||||
if (!$user_new) {
|
||||
return $user_id;
|
||||
}
|
||||
|
||||
if (UserData::checkAdmin()) {
|
||||
$answer_user_new = json_decode($user_new, true);
|
||||
return $answer_user_new[0]['id'];
|
||||
}
|
||||
return $user_id;
|
||||
}
|
||||
}
|
|
@ -1,19 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Traits;
|
||||
|
||||
use Html;
|
||||
|
||||
trait Page
|
||||
{
|
||||
public static function error404($values)
|
||||
{
|
||||
if (!$values) {
|
||||
include HLEB_GLOBAL_DIRECTORY . '/app/Optional/404.php';
|
||||
hl_preliminary_exit();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in a new issue