diff --git a/app/Controllers/ActionController.php b/app/Controllers/ActionController.php index 23990214..958e24e0 100644 --- a/app/Controllers/ActionController.php +++ b/app/Controllers/ActionController.php @@ -15,7 +15,7 @@ class ActionController extends Controller $content_id = Request::getPostInt('content_id'); $type = Request::getPost('type'); - $allowed = ['post', 'comment', 'answer', 'reply', 'item']; + $allowed = ['post', 'comment', 'reply', 'item']; if (!in_array($type, $allowed)) { return false; } @@ -23,6 +23,7 @@ class ActionController extends Controller // Access check // Проверка доступа $info_type = ActionModel::getInfoTypeContent($content_id, $type); + if (Access::author($type, $info_type) == false) { redirect('/'); } @@ -37,11 +38,6 @@ class ActionController extends Controller $url = post_slug($info_type['comment_post_id'], $post['post_slug']) . '#comment_' . $info_type['comment_id']; $action_type = 'comment'; break; - case 'answer': - $post = PostModel::getPost($info_type['answer_post_id'], 'id', $this->user); - $url = post_slug($info_type['answer_post_id'], $post['post_slug']) . '#answer_' . $info_type['answer_id']; - $action_type = 'answer'; - break; case 'reply': $url = '/'; $action_type = 'reply'; diff --git a/app/Controllers/Answer/AddAnswerController.php b/app/Controllers/Answer/AddAnswerController.php deleted file mode 100644 index 88281c09..00000000 --- a/app/Controllers/Answer/AddAnswerController.php +++ /dev/null @@ -1,97 +0,0 @@ -prohibitedContent($content); - - $this->union($post, $url_post, $content); - - $last_id = AnswerModel::add($post['post_id'], $content, $trigger); - - // Add an audit entry and an alert to the admin - // Аудит и оповещение персоналу - if ($trigger === false) { - (new \App\Services\Audit())->create('answer', $last_id, url('admin.audits')); - } - - $url = $url_post . '#answer_' . $last_id; - - $this->notif($content, $post, $url); - - ActionModel::addLogs( - [ - 'id_content' => $last_id, - 'action_type' => 'answer', - 'action_name' => 'added', - 'url_content' => $url, - ] - ); - - redirect($url); - } - - public function union($post, $url_post, $content) - { - if (config('publication.merge_answer_post') == false) { - return true; - } - - // Staff can write a response under their post - // Персонал может писать ответ под своим постом - if (UserData::checkAdmin()) { - return true; - } - - // If there are no replies to the post and the author of the post = the author of the answer, then add the answer to the end of the post - // Если ответов на пост нет и автор поста = автора ответа, то дописываем ответ в конец поста - if ((AnswerModel::getNumberAnswers($post['post_id']) == null) && ($post['post_user_id'] == $this->user['id'])) { - - AnswerModel::mergePost($post['post_id'], $content); - - redirect($url_post); - } - - return true; - } - - - // Notifications when adding a answer - // Уведомления при добавлении ответа - public function notif($content, $post, $url) - { - // Contact via @ - // Обращение через @ - if ($message = \App\Services\Parser\Content::parseUsers($content, true, true)) { - (new \App\Controllers\NotificationController())->mention(NotificationModel::TYPE_ADDRESSED_ANSWER, $message, $url, $post['post_user_id']); - } - - // Who is following this question/post - // Кто подписан на данный вопрос / пост - if ($focus_all = PostModel::getFocusUsersPost($post['post_id'])) { - foreach ($focus_all as $focus_user) { - if ($focus_user['signed_user_id'] != $this->user['id']) { - NotificationModel::send($focus_user['signed_user_id'], NotificationModel::TYPE_AMSWER_POST, $url); - } - } - } - } -} diff --git a/app/Controllers/Answer/EditAnswerController.php b/app/Controllers/Answer/EditAnswerController.php deleted file mode 100644 index 20cbea9b..00000000 --- a/app/Controllers/Answer/EditAnswerController.php +++ /dev/null @@ -1,74 +0,0 @@ -render( - '/answer/edit', - [ - 'meta' => Meta::get(__('app.edit_answer')), - 'data' => [ - 'post' => $post, - 'answer' => $answer, - 'user' => UserModel::getUser($answer['answer_user_id'], 'id'), - 'sheet' => 'edit-answers', - 'type' => 'answer', - ] - ] - ); - } - - public function change() - { - $answer_id = Request::getPostInt('answer_id'); - $content = $_POST['content']; // для Markdown - - // Access check - $answer = AnswerModel::getAnswerId($answer_id); - - if (Access::author('answer', $answer) == false) { - return false; - } - - $post = PostPresence::index($answer['answer_post_id'], 'id'); - - $url_post = post_slug($answer['answer_post_id'], $post['post_slug']); - - Validator::Length($content, 6, 5000, 'content', url('content.edit', ['type' => 'answer', 'id' => $answer['answer_id']])); - - AnswerModel::edit( - [ - 'answer_id' => $answer['answer_id'], - 'answer_content' => $content, - 'answer_user_id' => $this->selectAuthor($answer['answer_user_id'], Request::getPost('user_id')), - 'answer_modified' => date("Y-m-d H:i:s"), - ] - ); - - is_return(__('msg.change_saved'), 'success', $url_post . '#answer_' . $answer['answer_id']); - } -} diff --git a/app/Controllers/Comment/AddCommentController.php b/app/Controllers/Comment/AddCommentController.php index d8bf3ffa..c4f88d69 100644 --- a/app/Controllers/Comment/AddCommentController.php +++ b/app/Controllers/Comment/AddCommentController.php @@ -4,47 +4,42 @@ namespace App\Controllers\Comment; use Hleb\Constructor\Handlers\Request; use App\Controllers\Controller; -use App\Services\Сheck\PostPresence; -use App\Services\Сheck\AnswerPresence; -use App\Models\{NotificationModel, ActionModel, AnswerModel, CommentModel}; +use App\Services\Сheck\{PostPresence, CommentPresence}; +use App\Models\{NotificationModel, ActionModel, CommentModel, PostModel}; use App\Validate\Validator; +use UserData; class AddCommentController extends Controller { - // Show the form for adding a comment + // Show the form for adding a комментария // Покажем форму добавление комментария public function index() { - insert( - '/_block/form/add-comment', - [ - 'data' => [ - 'answer_id' => Request::getPostInt('answer_id'), - 'comment_id' => Request::getPostInt('comment_id'), - ], - ] - ); + insert('/_block/form/add-comment'); } - - // Adding a comment + public function create() - { - $answer_id = Request::getPostInt('answer_id'); // на какой ответ - $comment_id = Request::getPostInt('comment_id'); // на какой комментарий - - $answer = AnswerPresence::index($answer_id); - - $post = PostPresence::index($answer['answer_post_id'], 'id'); - + { + if ($post_id = Request::getPostInt('post_id')) { + $post = PostPresence::index($post_id, 'id'); + } + + if ($comment_id = Request::getPostInt('comment_id')) { + $comment = CommentPresence::index($comment_id); + $post = PostPresence::index($comment['comment_post_id'], 'id'); + } + $url_post = post_slug($post['post_id'], $post['post_slug']); - - Validator::Length($content = $_POST['comment'], 6, 2024, 'content', $url_post); + + Validator::Length($content = $_POST['content'], 6, 5000, 'content', $url_post); // Let's check the stop words, url - // Проверим стоп слова, url + // Проверим стоп слова и url $trigger = (new \App\Services\Audit())->prohibitedContent($content); - $last_id = CommentModel::add($post['post_id'], $answer_id, $comment_id, $content, $trigger); + $this->union($post, $url_post, $content); + + $last_id = CommentModel::add($post['post_id'], $comment_id, $content, $trigger); // Add an audit entry and an alert to the admin // Аудит и оповещение персоналу @@ -54,13 +49,13 @@ class AddCommentController extends Controller $url = $url_post . '#comment_' . $last_id; - $this->notif($answer_id, $comment_id, $content, $url); + $this->notifPost($content, $post, $comment_id, $url); ActionModel::addLogs( [ 'id_content' => $last_id, 'action_type' => 'comment', - 'action_name' => 'added', + 'action_name' => 'comment', 'url_content' => $url, ] ); @@ -68,30 +63,57 @@ class AddCommentController extends Controller redirect($url); } - // Notifications when adding a comment - // Уведомления при добавлении комментария - public function notif($answer_id, $comment_id, $content, $url) + public function union($post, $url_post, $content) { - // Notification to the author of the answer that there is a comment (do not write to ourselves) - // Оповещение автору ответа, что есть комментарий (себе не записываем) - $answ = AnswerModel::getAnswerId($answer_id); - if ($this->user['id'] != $answ['answer_user_id']) { - NotificationModel::send($answ['answer_user_id'], NotificationModel::TYPE_COMMENT_ANSWER, $url); + if (config('publication.merge_answer_post') == false) { + return true; } - if ($comment_id) { - $comment = CommentModel::getCommentsId($comment_id); - if ($this->user['id'] != $comment['comment_user_id']) { - if ($answ['answer_user_id'] != $comment['comment_user_id']) { - NotificationModel::send($comment['comment_user_id'], NotificationModel::TYPE_COMMENT_COMMENT, $url); - } - } + // Staff can write a response under their post + // Персонал может писать ответ под своим постом + if (UserData::checkAdmin()) { + return true; } + // If there are no replies to the post and the author of the post = the author of the comment, then add the comment to the end of the post + // Если ответов на пост нет и автор поста = автора ответа, то дописываем ответ в конец поста + if ((CommentModel::getNumberComment($post['post_id']) == null) && ($post['post_user_id'] == $this->user['id'])) { + + CommentModel::mergePost($post['post_id'], $content); + + redirect($url_post); + } + + return true; + } + + // Notifications when adding a answer + // Уведомления при добавлении ответа + public function notifPost($content, $post, $comment_id, $url) + { // Contact via @ // Обращение через @ if ($message = \App\Services\Parser\Content::parseUsers($content, true, true)) { - (new \App\Controllers\NotificationController())->mention(NotificationModel::TYPE_ADDRESSED_COMMENT, $message, $url, $comment['comment_user_id']); + (new \App\Controllers\NotificationController())->mention(NotificationModel::TYPE_ADDRESSED_ANSWER, $message, $url, $post['post_user_id']); + } + + // Who is following this question/post + // Кто подписан на данный вопрос / пост + if ($focus_all = PostModel::getFocusUsersPost($post['post_id'])) { + foreach ($focus_all as $focus_user) { + if ($focus_user['signed_user_id'] != $this->user['id']) { + NotificationModel::send($focus_user['signed_user_id'], NotificationModel::TYPE_AMSWER_POST, $url); + } + } + } + + // Notifications when adding a comment + // Уведомления при добавлении комментария + if ($comment_id) { + $comment = CommentModel::getCommentId($comment_id); + if ($this->user['id'] != $comment['comment_user_id']) { + NotificationModel::send($comment['comment_user_id'], NotificationModel::TYPE_COMMENT_COMMENT, $url); + } } } } diff --git a/app/Controllers/Comment/CommentController.php b/app/Controllers/Comment/CommentController.php index 3a4c71ad..2414617e 100644 --- a/app/Controllers/Comment/CommentController.php +++ b/app/Controllers/Comment/CommentController.php @@ -3,35 +3,27 @@ namespace App\Controllers\Comment; use App\Controllers\Controller; -use App\Models\{CommentModel, AnswerModel}; +use App\Models\CommentModel; use Meta, Html; class CommentController extends Controller { protected $limit = 10; - // All comments (combining answers and comments for UX) - // Все комментарии (объединение ответов и комментариев для UX) + // All comments + // Все комменатрии public function index($sheet) { $pagesCount = CommentModel::getCommentsCount($sheet); - $comments = CommentModel::getComments($this->pageNumber, $this->limit, $sheet); - - $pagesCount = AnswerModel::getAnswersCount($sheet); - $answers = AnswerModel::getAnswers($this->pageNumber, $this->limit, $sheet); + $comments = CommentModel::getComments($this->pageNumber, $sheet); $m = [ 'og' => false, 'url' => url('comments'), ]; - $mergedArr = array_merge($comments, $answers); - usort($mergedArr, function ($a, $b) { - return ($b['comment_date'] ?? $b['answer_date']) <=> ($a['comment_date'] ?? $a['answer_date']); - }); - return $this->render( - '/comment/comments', + '/comments/all', [ 'meta' => Meta::get(__('meta.all_comments'), __('meta.comments_desc'), $m), 'data' => [ @@ -39,25 +31,10 @@ class CommentController extends Controller 'pNum' => $this->pageNumber, 'sheet' => $sheet, 'type' => 'comments', - 'comments' => $mergedArr, + 'comments' => $comments, ] ] ); } - // On the home page - // На главной странице - public function lastComment() - { - $comments = CommentModel::getComments(1, 5, 'all'); - - $result = []; - foreach ($comments as $ind => $row) { - $row['content'] = fragment($row['comment_content'], 98); - $row['date'] = Html::langDate($row['comment_date']); - $result[$ind] = $row; - } - - return json_encode($result, JSON_PRETTY_PRINT); - } } diff --git a/app/Controllers/Comment/EditCommentController.php b/app/Controllers/Comment/EditCommentController.php index aa92ac11..d65deafe 100644 --- a/app/Controllers/Comment/EditCommentController.php +++ b/app/Controllers/Comment/EditCommentController.php @@ -4,59 +4,71 @@ namespace App\Controllers\Comment; use Hleb\Constructor\Handlers\Request; use App\Controllers\Controller; -use App\Services\Сheck\{PostPresence, CommentPresence}; +use App\Services\Сheck\PostPresence; +use App\Services\Сheck\CommentPresence; use App\Models\CommentModel; +use App\Models\User\UserModel; use App\Validate\Validator; -use Access; +use Meta, Access; + +use App\Traits\Author; class EditCommentController extends Controller { - // Comment Editing Form - // Форма редактирования комментария + use Author; + + // Edit form comment public function index() { - // Access verification - // Проверка доступа - $comment = CommentPresence::index(Request::getPostInt('comment_id')); + $comment = CommentPresence::index(Request::getInt('id')); if (Access::author('comment', $comment) == false) { return false; } - insert( - '/_block/form/edit-comment', + $post = PostPresence::index($comment['comment_post_id'], 'id'); + + return $this->render( + '/comments/edit', [ + 'meta' => Meta::get(__('app.edit_comment')), 'data' => [ - 'comment_id' => $comment['comment_id'], - 'comment_content' => $comment['comment_content'], - ], - 'user' => $this->user + 'post' => $post, + 'comment' => $comment, + 'user' => UserModel::getUser($comment['comment_user_id'], 'id'), + 'sheet' => 'edit-answers', + 'type' => 'comment', + ] ] ); } public function change() { - // Access verification - $comment = CommentPresence::index(Request::getPostInt('comment_id')); + $comment_id = Request::getPostInt('comment_id'); + $content = $_POST['content']; // для Markdown + + // Access check + $comment = CommentModel::getCommentId($comment_id); + if (Access::author('comment', $comment) == false) { - redirect('/'); + return false; } $post = PostPresence::index($comment['comment_post_id'], 'id'); - $redirect = post_slug($post['post_id'], $post['post_slug']) . '#comment_' . $comment['comment_id']; + $url_post = post_slug($comment['comment_post_id'], $post['post_slug']); - $content = $_POST['comment']; // для Markdown - Validator::length($content, 3, 5500, 'content', $redirect); + Validator::Length($content, 6, 5000, 'content', url('content.edit', ['type' => 'comment', 'id' => $comment['comment_id']])); CommentModel::edit( [ - 'comment_id' => $comment['comment_id'], - 'comment_content' => $content, - 'comment_modified' => date("Y-m-d H:i:s"), + 'comment_id' => $comment['comment_id'], + 'comment_content' => $content, + 'comment_user_id' => $this->selectAuthor($comment['comment_user_id'], Request::getPost('user_id')), + 'comment_modified' => date("Y-m-d H:i:s"), ] ); - redirect($redirect); + is_return(__('msg.change_saved'), 'success', $url_post . '#comment_' . $comment['comment_id']); } } diff --git a/app/Controllers/FormController.php b/app/Controllers/FormController.php index a89c1c21..f2beb46c 100644 --- a/app/Controllers/FormController.php +++ b/app/Controllers/FormController.php @@ -55,8 +55,8 @@ class FormController extends Controller return (new Poll\EditPollController)->index(); } - if ($this->type === 'answer') { - return (new Answer\EditAnswerController)->index(); + if ($this->type === 'comment') { + return (new Comment\EditCommentController)->index(); } if ($this->type === 'item') { @@ -83,10 +83,6 @@ class FormController extends Controller return (new Facets\AddFacetController)->create($this->type); } - if ($this->type === 'answer') { - return (new Answer\AddAnswerController)->create(); - } - if ($this->type === 'comment') { return (new Comment\AddCommentController)->create(); } @@ -131,10 +127,6 @@ class FormController extends Controller return (new Poll\EditPollController)->change(); } - if ($this->type === 'answer') { - return (new Answer\EditAnswerController)->change(); - } - if ($this->type === 'comment') { return (new Comment\EditCommentController)->change(); } diff --git a/app/Controllers/HomeController.php b/app/Controllers/HomeController.php index ff062195..50bda3c4 100644 --- a/app/Controllers/HomeController.php +++ b/app/Controllers/HomeController.php @@ -24,7 +24,7 @@ class HomeController extends Controller 'sheet' => $sheet, 'topics' => $topics, 'type' => 'main', - 'latest_answers' => HomeModel::latestAnswers(), + 'latest_comments' => HomeModel::latestComments(), 'topics_user' => HomeModel::subscription(), 'posts' => HomeModel::feed($this->pageNumber, $sheet), 'items' => HomeModel::latestItems(), diff --git a/app/Controllers/Post/EditPostController.php b/app/Controllers/Post/EditPostController.php index 12c59662..0f9fe076 100644 --- a/app/Controllers/Post/EditPostController.php +++ b/app/Controllers/Post/EditPostController.php @@ -183,7 +183,7 @@ class EditPostController extends Controller $type = Request::get('type'); $id = Request::getInt('id'); - if (!in_array($type, ['post-telo', 'answer'])) { + if (!in_array($type, ['post-telo', 'comment'])) { return false; } diff --git a/app/Controllers/Post/PostController.php b/app/Controllers/Post/PostController.php index 6f66f2a7..9d616a65 100644 --- a/app/Controllers/Post/PostController.php +++ b/app/Controllers/Post/PostController.php @@ -7,7 +7,8 @@ use App\Controllers\Controller; use App\Services\Сheck\PostPresence; use App\Services\Сheck\FacetPresence; use App\Services\Meta\Post; -use App\Models\{PostModel, AnswerModel, CommentModel, SubscriptionModel, FeedModel}; +use App\Services\Tree\BuildTree; +use App\Models\{PostModel, CommentModel, SubscriptionModel, FeedModel}; use Meta, UserData; use App\Traits\Views; @@ -28,6 +29,7 @@ class PostController extends Controller { $slug = Request::get('slug'); $id = Request::getInt('id'); + $sorting = Request::getGet('sort'); $content = self::presence($type, $id, $slug); @@ -48,12 +50,6 @@ class PostController extends Controller redirect(url('facet.article', ['facet_slug' => 'info', 'slug' => $content['post_slug']])); } - // Q&A (post_feature == 1) or Discussiona - $content['amount_content'] = ($content['post_feature'] == 0) ? $content['post_comments_count'] + $content['post_answers_count'] : $content['post_answers_count']; - - // Get replies and comments on the post - $answers = $this->answersPost($content['post_id'], $content['post_feature'], $sorting = Request::getGet('sort')); - if ($content['post_related']) { $related_posts = PostModel::postRelated($content['post_related']); } @@ -61,6 +57,8 @@ class PostController extends Controller // Sending Last-Modified and handling HTTP_IF_MODIFIED_SINCE $this->getDataModified($content['post_modified']); + $comments = CommentModel::getCommentsPost($content['post_id'], $content['post_feature'], $sorting); + if ($type == 'post') { return $this->render( '/post/post-view', @@ -68,7 +66,7 @@ class PostController extends Controller 'meta' => Post::metadata($content), 'data' => [ 'post' => $content, - 'answers' => $answers, + 'comments' => BuildTree::index(0, $comments), 'recommend' => PostModel::postSimilars($content['post_id'], $facets[0]['facet_id'] ?? null), 'related_posts' => $related_posts ?? '', 'post_signed' => SubscriptionModel::getFocus($content['post_id'], 'post'), @@ -103,26 +101,6 @@ class PostController extends Controller ); } - // Get replies and comments on the post - // Получим ответы и комментарии на пост - public function answersPost($post_id, $post_feature, $sorting) - { - $post_answers = AnswerModel::getAnswersPost($post_id, $post_feature, $sorting); - - $answers = []; - foreach ($post_answers as $ind => $row) { - - if (strtotime($row['answer_modified']) < strtotime($row['answer_date'])) { - $row['edit'] = 1; - } - // TODO: N+1 см. AnswerModel() - $row['comments'] = CommentModel::getCommentsAnswer($row['answer_id']); - $answers[$ind] = $row; - } - - return $answers; - } - public static function presence($type, $id, $slug) { // Check id and get content data diff --git a/app/Controllers/SearchController.php b/app/Controllers/SearchController.php index 9c68106f..9102cd28 100644 --- a/app/Controllers/SearchController.php +++ b/app/Controllers/SearchController.php @@ -30,7 +30,7 @@ class SearchController extends Controller $q = Request::getGet('q'); $type = Request::getGet('cat'); - if (!in_array($type, ['post', 'website', 'answer'])) { + if (!in_array($type, ['post', 'website', 'comment'])) { $type = 'post'; } @@ -44,6 +44,7 @@ class SearchController extends Controller } $results = SearchModel::getSearch($this->pageNumber, $this->limit, $q, $type); + $count_results = SearchModel::getSearchCount($q, $type); $user_id = UserData::getUserId(); diff --git a/app/Controllers/User/ProfileController.php b/app/Controllers/User/ProfileController.php index c7a2321b..a3f9f1f8 100644 --- a/app/Controllers/User/ProfileController.php +++ b/app/Controllers/User/ProfileController.php @@ -6,7 +6,7 @@ use Hleb\Constructor\Handlers\Request; use App\Services\Meta\Profile; use App\Controllers\Controller; use App\Models\User\{UserModel, BadgeModel}; -use App\Models\{FacetModel, FeedModel, AnswerModel, CommentModel, PostModel, IgnoredModel}; +use App\Models\{FacetModel, FeedModel, CommentModel, PostModel, IgnoredModel}; use UserData; use App\Traits\Views; @@ -71,18 +71,8 @@ class ProfileController extends Controller { $profile = $this->profile(); - $answers = AnswerModel::userAnswers($this->pageNumber, $this->limit, $profile['id'], $this->user['id']); - $answerCount = AnswerModel::userAnswersCount($profile['id']); - - $comments = CommentModel::userComments($this->pageNumber, $this->limit, $profile['id'], $this->user['id']); - $commentCount = CommentModel::userCommentsCount($profile['id']); - - $pagesCount = $answerCount + $commentCount; - - $mergedArr = array_merge($comments, $answers); - usort($mergedArr, function ($a, $b) { - return ($b['comment_date'] ?? $b['answer_date']) <=> ($a['comment_date'] ?? $a['answer_date']); - }); + $comments = CommentModel::userComments($this->pageNumber, $profile['id'], $this->user['id']); + $commentsCount = CommentModel::userCommentsCount($profile['id']); $this->indexing($profile['id']); @@ -90,7 +80,7 @@ class ProfileController extends Controller '/user/profile/comments', [ 'meta' => Profile::metadata('profile_comments', $profile), - 'data' => array_merge($this->sidebar($pagesCount, $profile), ['comments' => $mergedArr]), + 'data' => array_merge($this->sidebar($commentsCount, $profile), ['comments' => $comments]), ] ); } @@ -151,7 +141,7 @@ class ProfileController extends Controller public function indexing($profile_id) { $amount = UserModel::contentCount($profile_id, 'active'); - if (($amount['count_answers'] + $amount['count_comments']) < 3) { + if (($amount['count_comments']) < 3) { Request::getHead()->addMeta('robots', 'noindex'); } diff --git a/app/Controllers/User/SettingController.php b/app/Controllers/User/SettingController.php index 2617f4da..98912712 100644 --- a/app/Controllers/User/SettingController.php +++ b/app/Controllers/User/SettingController.php @@ -250,7 +250,6 @@ class SettingController extends Controller 'setting_email_appealed' => Request::getPostInt('setting_email_appealed'), 'setting_email_post' => 0, 'setting_email_answer' => 0, - 'setting_email_comment' => 0, ] ); diff --git a/app/Controllers/User/UserController.php b/app/Controllers/User/UserController.php index 7a0def2c..393161f5 100644 --- a/app/Controllers/User/UserController.php +++ b/app/Controllers/User/UserController.php @@ -49,10 +49,10 @@ class UserController extends Controller $result = []; foreach ($favorites as $ind => $row) { if ($row['action_type'] == 'post') { - $row['answer_post_id'] = $row['post_id']; + $row['comment_post_id'] = $row['post_id']; } - $row['post'] = PostModel::getPost($row['answer_post_id'], 'id', $this->user); + $row['post'] = PostModel::getPost($row['comment_post_id'], 'id', $this->user); $result[$ind] = $row; } diff --git a/app/Core/Html.php b/app/Core/Html.php index 9acc699c..1a489f97 100644 --- a/app/Core/Html.php +++ b/app/Core/Html.php @@ -76,7 +76,7 @@ class Html return ((int)$a[2] . " " . $months[$later] . " " . $a[0]); } - // Voting for posts, replies, comments and sites + // Voting for posts, replies, answer and sites public static function votes($content, $type, $icon = 'heart') { $count = $content[$type . '_votes'] > 0 ? $content[$type . '_votes'] : ''; diff --git a/app/Languages/ar/app.php b/app/Languages/ar/app.php index a8df66ea..9ee5439f 100644 --- a/app/Languages/ar/app.php +++ b/app/Languages/ar/app.php @@ -311,6 +311,7 @@ return [ 'num_message' => ['رسالة', 'رسائل', 'رسائل'], 'num_answer' => ['اجابة', 'اجابات', 'اجابات'], + 'num_comment' => ['تعليق', 'تعليقات', 'تعليقات'], 'num_post' => ['منشور', 'منشورات', 'منشورات'], 'num_view' => ['مشاهدة', 'مشاهدات', 'مشاهدات'], 'num_up' => ['اعجابات', 'اعجابات', 'اعجابات'], @@ -356,7 +357,7 @@ return [ 'slug' => 'اختصار', 'email' => 'بريد الكتروني', 'wiki' => 'ويكي', - 'edit_answer' => 'لـ\'تعديل الاجابة', + 'edit_comment' => 'دعونا نغير التعليق', 'enter' => 'ادخل', 'enter_password' => 'ادخل كلمة السر', diff --git a/app/Languages/ar/search.php b/app/Languages/ar/search.php index e3a80283..5a49b34b 100644 --- a/app/Languages/ar/search.php +++ b/app/Languages/ar/search.php @@ -10,7 +10,7 @@ return [ 'all' => 'الكل', 'posts' => 'المنشورات', 'websites' => 'المواقع', - 'answers' => 'اجابات', + 'comments' => 'تعليقات', 'registration' => 'التسجيل', 'sign_in' => 'تسجيل الدخول', 'find' => 'البحث...', diff --git a/app/Languages/en/app.php b/app/Languages/en/app.php index 955ae02a..6e2484e4 100644 --- a/app/Languages/en/app.php +++ b/app/Languages/en/app.php @@ -315,6 +315,7 @@ return [ 'num_message' => ['Message', 'Messages', 'Messages'], 'num_answer' => ['Answer', 'Answers', 'Answers'], + 'num_comment' => ['Comment', 'Comments', 'Comments'], 'num_post' => ['Post', 'Posts', 'Posts'], 'num_view' => ['View', 'Views', 'Views'], 'num_up' => ['likes', 'likes', 'likes'], @@ -360,7 +361,7 @@ return [ 'slug' => 'SLUG', 'email' => 'Email', 'wiki' => 'Wiki', - 'edit_answer' => 'Let\'s change the answer', + 'edit_comment' => 'Change the comment', 'enter' => 'Enter', 'enter_password' => 'Enter password', diff --git a/app/Languages/en/search.php b/app/Languages/en/search.php index bf449b2b..e42d1696 100644 --- a/app/Languages/en/search.php +++ b/app/Languages/en/search.php @@ -9,7 +9,7 @@ return [ 'all' => 'All', 'posts' => 'Posts', - 'answers' => 'Answers', + 'comments' => 'Comments', 'websites' => 'Sites', 'registration' => 'Registration', 'sign_in' => 'To come in', diff --git a/app/Languages/ro/app.php b/app/Languages/ro/app.php index 3ca37852..709218fd 100644 --- a/app/Languages/ro/app.php +++ b/app/Languages/ro/app.php @@ -314,6 +314,7 @@ return [ 'num_message' => ['Mesaj', 'Mesaje', 'Mesaje'], 'num_answer' => ['Răspuns', 'Răspuns', 'Răspunsuri'], + 'num_comment' => ['Comentariu', 'Comentariu', 'Comentarii'], 'num_post' => ['Postează', 'Postează', 'Postează'], 'num_view' => ['Vizualizare', 'Vizualizare', 'Vizualizare'], 'num_up' => ['Voce', 'Voci', 'Voci'], @@ -359,7 +360,7 @@ return [ 'slug' => 'SLUG', 'email' => 'Email', 'wiki' => 'Wiki', - 'edit_answer' => 'Să schimbăm răspunsul', + 'edit_comment' => 'Schimbă comentariul', 'enter' => 'Introduce', 'enter_password' => 'Introdu parola', diff --git a/app/Languages/ro/search.php b/app/Languages/ro/search.php index dd195089..6f7a32f5 100644 --- a/app/Languages/ro/search.php +++ b/app/Languages/ro/search.php @@ -9,7 +9,7 @@ return [ 'all' => 'Toate', 'posts' => 'Postări', - 'answers' => 'Răspunsuri', + 'comments' => 'Comentarii', 'websites' => 'Site-uri', 'registration' => 'Înregistrare', 'sign_in' => 'Conectare', diff --git a/app/Languages/ru/app.php b/app/Languages/ru/app.php index deda48a3..2d6e32c6 100644 --- a/app/Languages/ru/app.php +++ b/app/Languages/ru/app.php @@ -245,7 +245,7 @@ return [ 'default' => '(по умолчанию)', 'qa' => 'Вопросы и ответы', 'best_answer' => 'Лучший ответ', - 'raise_answer' => 'Поднять ответ', + 'raise_answer' => 'Поднять ответ', 'answered' => 'Ответили', 'post_translation' => 'Пост является переводом?', 'translation' => 'Перевод', @@ -314,6 +314,7 @@ return [ 'num_message' => ['Сообщение', 'Сообщения', 'Сообщений'], 'num_answer' => ['Ответ', 'Ответа', 'Ответов'], + 'num_comment' => ['Комментарий', 'Комментария', 'Комментариев'], 'num_post' => ['Пост', 'Поста', 'Постов'], 'num_view' => ['Просмотр', 'Просмотра', 'Просмотров'], 'num_up' => ['Голос', 'Голоса', 'Голосов'], @@ -359,7 +360,7 @@ return [ 'slug' => 'SLUG', 'email' => 'Email', 'wiki' => 'Wiki', - 'edit_answer' => 'Изменим ответ', + 'edit_comment' => 'Изменим комментарий', 'enter' => 'Введите', 'enter_password' => 'Введите пароль', diff --git a/app/Languages/ru/search.php b/app/Languages/ru/search.php index d330be0e..a2780e79 100644 --- a/app/Languages/ru/search.php +++ b/app/Languages/ru/search.php @@ -9,7 +9,7 @@ return [ 'all' => 'Все', 'posts' => 'Посты', - 'answers' => 'Ответы', + 'comments' => 'Комментарии', 'websites' => 'Сайты', 'registration' => 'Регистрация', 'sign_in' => 'Войти', diff --git a/app/Languages/ua/app.php b/app/Languages/ua/app.php index 20a3c031..752409c1 100644 --- a/app/Languages/ua/app.php +++ b/app/Languages/ua/app.php @@ -314,6 +314,7 @@ return [ 'num_message' => ['Повідомлення', 'Повідомлення', 'Повідомлень'], 'num_answer' => ['Відповідь', 'Відповіді', 'Відповідей'], + 'num_comment' => ['Коментар', 'Коментаря', 'Коментарів'], 'num_post' => ['Пост', 'Поста', 'Постів'], 'num_view' => ['Перегляд', 'Перегляду', 'Переглядів'], 'num_up' => ['Голос', 'Голосу', 'Голосів'], @@ -359,7 +360,7 @@ return [ 'slug' => 'SLUG', 'email' => 'Email', 'wiki' => 'Wiki', - 'edit_answer' => 'Змінимо відповідь', + 'edit_comment' => 'Змінимо коментар', 'enter' => 'Введіть', 'enter_password' => 'Введіть пароль', diff --git a/app/Languages/ua/search.php b/app/Languages/ua/search.php index e5a2ef1e..50c5b17b 100644 --- a/app/Languages/ua/search.php +++ b/app/Languages/ua/search.php @@ -9,7 +9,7 @@ return [ 'all' => 'Всі', 'posts' => 'Пости', - 'answers' => 'Відповіді', + 'comments' => 'Коментарі', 'websites' => 'Сайти', 'registration' => 'Реєстрація', 'sign_in' => 'Увійти', diff --git a/app/Languages/vi/app.php b/app/Languages/vi/app.php index 12cbd1f0..22593ceb 100644 --- a/app/Languages/vi/app.php +++ b/app/Languages/vi/app.php @@ -314,6 +314,7 @@ return [ 'num_message' => ['Tin nhắn', 'Tin nhắn', 'Tin nhắn'], 'num_answer' => ['Trả lời', 'Trả lời', 'Câu trả lời'], + 'num_comment' => ['Bình Luận', 'Bình Luận', 'Bình Luận'], 'num_post' => ['Bài đăng', 'Bài đăng', 'Postov'], 'num_view' => ['Chế độ xem', 'Lượt xem', 'Lượt xem'], 'num_up' => ['Giọng nói', 'Giọng nói', 'Giọng nói'], @@ -359,7 +360,7 @@ return [ 'slug' => 'SLUG', 'email' => 'Email', 'wiki' => 'Wiki', - 'edit_answer' => 'Hãy thay đổi câu trả lời', + 'edit_comment' => 'Thay đổi nhận xé', 'enter' => 'Đi vào', 'enter_password' => 'Nhập mật khẩu', diff --git a/app/Languages/vi/search.php b/app/Languages/vi/search.php index 50d6cb74..eb85cb0a 100644 --- a/app/Languages/vi/search.php +++ b/app/Languages/vi/search.php @@ -9,7 +9,7 @@ return [ 'all' => 'Tất cả', 'posts' => 'Bài viết', - 'answers' => 'Trả lời', + 'comments' => 'Bình luận', 'websites' => 'Trang', 'registration' => 'Đăng ký', 'sign_in' => 'Cần đi vào', diff --git a/app/Languages/zh_CN/app.php b/app/Languages/zh_CN/app.php index d17b9380..8c75c6a2 100644 --- a/app/Languages/zh_CN/app.php +++ b/app/Languages/zh_CN/app.php @@ -312,11 +312,12 @@ return [ 'today' => '今天', 'yesterday' => '昨天', - 'num_message' => ['消息', '消息', '消息'], - 'num_answer' => ['回复', '回复', '回复'], - 'num_post' => ['帖子', '帖子', '帖子'], - 'num_view' => ['查看', '查看', '查看'], - 'num_up' => ['喜欢', '喜欢', '喜欢'], + 'num_message' => ['消息', '消息', '消息'], + 'num_answer' => ['回复', '回复', '回复'], + 'num_comment' => ['注释','注释','注释'], + 'num_post' => ['帖子', '帖子', '帖子'], + 'num_view' => ['查看', '查看', '查看'], + 'num_up' => ['喜欢', '喜欢', '喜欢'], 'comment' => '评论', 'comments' => '评论', @@ -360,7 +361,7 @@ return [ 'slug' => '别名', 'email' => '邮箱', 'wiki' => 'Wiki', - 'edit_answer' => '让我们更改答复', + 'edit_comment' => '更改注释', 'enter' => '输入', 'enter_password' => '输入密码', diff --git a/app/Languages/zh_CN/search.php b/app/Languages/zh_CN/search.php index 910db803..f47068c0 100644 --- a/app/Languages/zh_CN/search.php +++ b/app/Languages/zh_CN/search.php @@ -9,7 +9,7 @@ return [ 'all' => '全部', 'posts' => '帖子', - 'answers' => '答案', + 'comments' => '评论', 'websites' => '网站', 'registration' => '注册', 'sign_in' => '登录', diff --git a/app/Languages/zh_TW/app.php b/app/Languages/zh_TW/app.php index 6779df4d..5d3ea99e 100644 --- a/app/Languages/zh_TW/app.php +++ b/app/Languages/zh_TW/app.php @@ -313,11 +313,12 @@ return [ 'today' => '今天', 'yesterday' => '昨天', - 'num_message' => ['消息', '消息', '消息'], - 'num_answer' => ['答案', '答案', '答案'], - 'num_post' => ['后', '后', '后'], - 'num_view' => ['视图', '视图', '视图'], - 'num_up' => ['声音', '声音', '声音'], + 'num_message' => ['消息', '消息', '消息'], + 'num_answer' => ['答案', '答案', '答案'], + 'num_comment' => ['注释','注释','注释'], + 'num_post' => ['后', '后', '后'], + 'num_view' => ['视图', '视图', '视图'], + 'num_up' => ['声音', '声音', '声音'], 'comment' => '评论', 'comments' => '评论', @@ -360,7 +361,7 @@ return [ 'slug' => 'SLUG', 'email' => 'Email', 'wiki' => 'Wiki', - 'edit_answer' => '让我们改变答案', + 'edit_comment' => '更改注释', 'enter' => '进入', 'enter_password' => '输入密码', diff --git a/app/Languages/zh_TW/search.php b/app/Languages/zh_TW/search.php index 8984f032..a8f2abcd 100644 --- a/app/Languages/zh_TW/search.php +++ b/app/Languages/zh_TW/search.php @@ -9,7 +9,7 @@ return [ 'all' => '全部', 'posts' => '帖子', - 'answers' => '答案', + 'comments' => '评论', 'websites' => '網站', 'registration' => '登記', 'sign_in' => '進來', diff --git a/app/Models/ActionModel.php b/app/Models/ActionModel.php index 05e610ad..bc221772 100644 --- a/app/Models/ActionModel.php +++ b/app/Models/ActionModel.php @@ -72,13 +72,11 @@ class ActionModel extends \Hleb\Scheme\App\Models\MainModel (SELECT COUNT(*) FROM posts WHERE post_user_id = $user_id and post_is_deleted = 0) AS t1Count, (SELECT COUNT(*) FROM - answers WHERE answer_user_id = $user_id and answer_is_deleted = 0) AS t2Count, - (SELECT COUNT(*) FROM - comments WHERE comment_user_id = $user_id and comment_is_deleted = 0) AS t3Count"; + comments WHERE comment_user_id = $user_id and comment_is_deleted = 0) AS t2Count"; $lists = DB::run($sql)->fetch(); - return $lists['t1Count'] + $lists['t2Count'] + $lists['t3Count']; + return $lists['t1Count'] + $lists['t2Count']; } // Member Content Posting Frequency diff --git a/app/Models/AnswerModel.php b/app/Models/AnswerModel.php deleted file mode 100644 index 09f7aa9c..00000000 --- a/app/Models/AnswerModel.php +++ /dev/null @@ -1,324 +0,0 @@ - $post_id, - 'answer_content' => $content, - 'answer_published' => ($trigger === false) ? 0 : 1, - 'answer_ip' => Request::getRemoteAddress(), - 'answer_user_id' => UserData::getUserId(), - ]; - - $sql = "INSERT INTO answers(answer_post_id, - answer_content, - answer_published, - answer_ip, - answer_user_id) - VALUES(:answer_post_id, - :answer_content, - :answer_published, - :answer_ip, - :answer_user_id)"; - - DB::run($sql, $params); - - $sql_last_id = DB::run("SELECT LAST_INSERT_ID() as last_id")->fetch(); - - // Recalculating the number of responses for the post + 1 - // Пересчитываем количество ответов для поста + 1 - PostModel::updateCount($post_id, 'answers'); - - return $sql_last_id['last_id']; - } - - // Editing the answer - // Редактируем ответ - public static function edit($params) - { - $sql_two = "UPDATE answers SET answer_content = :answer_content, - answer_modified = :answer_modified, answer_user_id = :answer_user_id - WHERE answer_id = :answer_id"; - - return DB::run($sql_two, $params); - } - - // All answers - // Все ответы - public static function getAnswers($page, $limit, $sheet) - { - $user_id = UserData::getUserId(); - $sort = self::sorts($sheet); - $start = ($page - 1) * $limit; - $sql = "SELECT - post_id, - post_title, - post_slug, - post_user_id, - post_closed, - post_feature, - post_is_deleted, - answer_id, - answer_content, - answer_date, - answer_after, - answer_user_id, - answer_ip, - answer_post_id, - answer_votes, - answer_is_deleted, - answer_published, - votes_answer_item_id, - votes_answer_user_id, - fav.tid, - fav.user_id, - fav.action_type, - u.id, - u.login, - u.avatar - FROM answers - INNER JOIN users u ON u.id = answer_user_id - INNER JOIN posts ON answer_post_id = post_id - LEFT JOIN votes_answer ON votes_answer_item_id = answer_id - AND votes_answer_user_id = $user_id - LEFT JOIN favorites fav ON fav.tid = answer_id - AND fav.user_id = $user_id - AND fav.action_type = 'answer' - $sort - ORDER BY answer_id DESC LIMIT :start, :limit "; - - return DB::run($sql, ['start' => $start, 'limit' => $limit])->fetchAll(); - } - - public static function getAnswersCount($sheet) - { - $sort = self::sorts($sheet); - - $sql = "SELECT answer_id FROM answers INNER JOIN posts ON answer_post_id = post_id $sort"; - - return DB::run($sql)->rowCount(); - } - - public static function sorts($sheet) - { - $hidden = UserData::checkAdmin() ? "" : "AND post_hidden = 0"; - - switch ($sheet) { - case 'all': - $sort = "WHERE answer_is_deleted = 0 AND post_tl = 0 AND post_is_deleted = 0 $hidden"; - break; - case 'deleted': - $sort = "WHERE answer_is_deleted = 1"; - break; - } - - return $sort; - } - - // Number of replies per post - // Количество ответов на пост - public static function getNumberAnswers($post_id) - { - $sql = "SELECT answer_id FROM answers WHERE answer_post_id = :id AND answer_is_deleted = 0"; - - return DB::run($sql, ['id' => $post_id])->rowCount(); - } - - // Add the answer to the end of the post - // Добавим ответ в конец поста - public static function mergePost($post_id, $content) - { - $sql = "UPDATE posts SET post_content = CONCAT(post_content, :content) WHERE post_id = :post_id"; - - $content = "\n\n `+` " . $content; - - return DB::run($sql, ['post_id' => $post_id, 'content' => $content]); - } - - // Getting answers in a post - // Получаем ответы в посте - public static function getAnswersPost($post_id, $type, $sorting = 'new') - { - $user_id = UserData::getUserId(); - - if ($type == 1) { - $sorting = 'top'; - } - - switch ($sorting) { - case 'top': - $sort = 'ORDER BY answer_lo DESC, answer_votes DESC'; - break; - case 'old': - $sort = 'ORDER BY answer_id DESC'; - break; - // new - default: - $sort = ''; - break; - } - - // TODO: Сгруппировать комментарии по ответу (избавимся N+1) - // LEFT JOIN comments ON comment_answer_id = answer_id - // comment_answer_id, - // comment_user_id, - // comment_date, - // comment_ip, - // comment_content, - $sql = "SELECT - answer_id, - answer_user_id, - answer_post_id, - answer_date, - answer_content, - answer_modified, - answer_published, - answer_ip, - answer_votes, - answer_after, - answer_lo, - answer_is_deleted, - votes_answer_item_id, - votes_answer_user_id, - fav.tid, - fav.user_id, - fav.action_type, - u.id, - u.login, - u.avatar, - u.created_at - FROM answers - LEFT JOIN users u ON u.id = answer_user_id - LEFT JOIN votes_answer ON votes_answer_item_id = answer_id - AND votes_answer_user_id = $user_id - LEFT JOIN favorites fav ON fav.tid = answer_id - AND fav.user_id = $user_id - AND fav.action_type = 'answer' - WHERE answer_post_id = $post_id - $sort "; - - return DB::run($sql)->fetchAll(); - } - - // User responses - // Ответы участника - public static function userAnswers($page, $limit, $user_id, $uid_vote) - { - $start = ($page - 1) * $limit; - $sql = "SELECT - answer_id, - answer_user_id, - answer_post_id, - answer_date, - answer_content, - answer_modified, - answer_published, - answer_ip, - answer_votes, - answer_after, - answer_is_deleted, - votes_answer_item_id, - votes_answer_user_id, - post_id, - post_title, - post_slug, - post_user_id, - post_closed, - post_is_deleted, - id, - login, - avatar - FROM answers - LEFT JOIN users ON id = answer_user_id - LEFT JOIN posts ON answer_post_id = post_id - LEFT JOIN votes_answer ON votes_answer_item_id = answer_id - AND votes_answer_user_id = :uid_vote - WHERE answer_user_id = :user_id AND post_hidden = 0 - AND answer_is_deleted = 0 AND post_is_deleted = 0 AND post_tl = 0 AND post_tl = 0 - ORDER BY answer_id DESC LIMIT :start, :limit "; - - return DB::run($sql, ['user_id' => $user_id, 'uid_vote' => $uid_vote, 'start' => $start, 'limit' => $limit])->fetchAll(); - } - - public static function userAnswersCount($user_id) - { - $sql = "SELECT - answer_id - FROM answers - LEFT JOIN posts ON answer_post_id = post_id - WHERE answer_user_id = :user_id AND answer_is_deleted = 0 - AND post_is_deleted = 0 AND post_tl = 0 AND post_tl = 0"; - - return DB::run($sql, ['user_id' => $user_id])->rowCount(); - } - - // Information on the id of the answer - // Информацию по id ответа - public static function getAnswerId($answer_id) - { - $sql = "SELECT - answer_id, - answer_post_id, - answer_user_id, - answer_date, - answer_modified, - answer_published, - answer_ip, - answer_order, - answer_after, - answer_votes, - answer_content, - answer_lo, - answer_is_deleted - FROM answers - WHERE answer_id = :answer_id"; - - return DB::run($sql, ['answer_id' => $answer_id])->fetch(); - } - - /* - * Best answer - */ - - // Choice of the best answer - // Выбор лучшего ответа - public static function setBest($post_id, $answer_id, $selected_best_answer) - { - if ($selected_best_answer) { - DB::run("UPDATE answers SET answer_lo = 0 WHERE answer_id = :id", ['id' => $selected_best_answer]); - } - - self::setAnswerBest($answer_id); - - self::answerPostBest($post_id, $answer_id); - } - - // Let's write down the id of the participant who chose the best answer - // Запишем id участника выбравший лучший ответ - public static function setAnswerBest($answer_id) - { - $sql = "UPDATE answers SET answer_lo = :user_id WHERE answer_id = :answer_id"; - - return DB::run($sql, ['answer_id' => $answer_id, 'user_id' => UserData::getUserId()]); - } - - // Rewriting the number of the selected best answer in the post - // Переписываем номер выбранного лучший ответ в посте - public static function answerPostBest($post_id, $answer_id) - { - $sql_two = "UPDATE posts SET post_lo = :answer_id WHERE post_id = :post_id"; - - return DB::run($sql_two, ['post_id' => $post_id, 'answer_id' => $answer_id]); - } -} diff --git a/app/Models/CommentModel.php b/app/Models/CommentModel.php index d9d41abe..2e04cbc7 100644 --- a/app/Models/CommentModel.php +++ b/app/Models/CommentModel.php @@ -9,246 +9,309 @@ use DB; class CommentModel extends \Hleb\Scheme\App\Models\MainModel { - // Adding a comment - // Добавляем комментарий - public static function add($post_id, $answer_id, $comment_id, $content, $trigger) + public static $limit = 15; + + // Add an comment + // Добавим ответ + public static function add($post_id, $comment_id, $content, $trigger) { - $params = [ - 'comment_post_id' => $post_id, - 'comment_answer_id' => $answer_id, - 'comment_parent_id' => $comment_id, - 'comment_content' => $content, - 'comment_published' => ($trigger === false) ? 0 : 1, - 'comment_ip' => Request::getRemoteAddress(), - 'comment_user_id' => UserData::getUserId(), + 'comment_post_id' => $post_id, + 'comment_parent_id' => $comment_id, + 'comment_content' => $content, + 'comment_published' => ($trigger === false) ? 0 : 1, + 'comment_ip' => Request::getRemoteAddress(), + 'comment_user_id' => UserData::getUserId(), ]; $sql = "INSERT INTO comments(comment_post_id, - comment_answer_id, - comment_parent_id, - comment_content, - comment_published, - comment_ip, - comment_user_id) - - VALUES(:comment_post_id, - :comment_answer_id, - :comment_parent_id, - :comment_content, - :comment_published, - :comment_ip, - :comment_user_id)"; + comment_parent_id, + comment_content, + comment_published, + comment_ip, + comment_user_id) + VALUES(:comment_post_id, + :comment_parent_id, + :comment_content, + :comment_published, + :comment_ip, + :comment_user_id)"; DB::run($sql, $params); - $sql_last_id = DB::run("SELECT LAST_INSERT_ID() as last_id")->fetch(); - $last_id = $sql_last_id['last_id']; + $sql_last_id = DB::run("SELECT LAST_INSERT_ID() as last_id")->fetch(); - // Отмечаем комментарий, что за ним есть ответ - self::setThereComment($last_id, $params['comment_parent_id']); - - $sql = "SELECT * FROM answers WHERE answer_id = :comment_answer_id"; - $answer = DB::run($sql, ['comment_answer_id' => $params['comment_answer_id']])->fetch(); - - if ($answer['answer_after'] == 0) { - self::setThereAnswer($last_id, $params['comment_answer_id']); - } - - // Add the number of comments for the post + 1 + // Recalculating the number of responses for the post + 1 + // Пересчитываем количество ответов для поста + 1 PostModel::updateCount($post_id, 'comments'); - return $last_id; + return $sql_last_id['last_id']; } - // Editing a comment - // Редактируем комментарий + // Editing the comment + // Редактируем ответ public static function edit($params) { - $sql = "UPDATE comments SET - comment_content = :comment_content, - comment_modified = :comment_modified - WHERE comment_id = :comment_id"; + $sql_two = "UPDATE comments SET comment_content = :comment_content, + comment_modified = :comment_modified, comment_user_id = :comment_user_id + WHERE comment_id = :comment_id"; - return DB::run($sql, $params); + return DB::run($sql_two, $params); } - // Отметим комментарий, что за ним есть ответ - public static function setThereComment($last_id, $comment_id) + // All comments + // Все ответы + public static function getComments($page, $sheet) { - $sql = "UPDATE comments SET comment_after = :last_id WHERE comment_id = :comment_id"; - - return DB::run($sql, ['last_id' => $last_id, 'comment_id' => $comment_id]); - } - - - // Отмечаем ответ, что за ним есть комментарии - public static function setThereAnswer($last_id, $answer_id) - { - $sql = "UPDATE answers SET answer_after = :last_id WHERE answer_id = :answer_id"; - - return DB::run($sql, ['last_id' => $last_id, 'answer_id' => $answer_id]); - } - - // Все комментарии - public static function getComments($page, $limit, $sheet) - { - $hidden = UserData::checkAdmin() ? "" : "AND post_hidden = 0"; + $user_id = UserData::getUserId(); $sort = self::sorts($sheet); - $start = ($page - 1) * $limit; - - $sql = "SELECT + $start = ($page - 1) * self::$limit; + $sql = "SELECT post_id, post_title, post_slug, - post_tl, - post_hidden, - post_feature, post_user_id, post_closed, + post_feature, post_is_deleted, comment_id, - comment_ip, - comment_date, comment_content, - comment_post_id, + comment_date, comment_user_id, - comment_parent_id, - comment_published, + comment_ip, + comment_post_id, comment_votes, - comment_after, comment_is_deleted, + comment_published, votes_comment_item_id, votes_comment_user_id, - id, - login, - avatar, - created_at - FROM comments - JOIN users ON id = comment_user_id - JOIN posts ON comment_post_id = post_id AND post_tl <= :tl - LEFT JOIN votes_comment ON votes_comment_item_id = comment_id - AND votes_comment_user_id = :uid - WHERE $sort $hidden - ORDER BY comment_id DESC LIMIT :start, :limit"; + fav.tid, + fav.user_id, + fav.action_type, + u.id, + u.login, + u.avatar + FROM comments + INNER JOIN users u ON u.id = comment_user_id + INNER JOIN posts ON comment_post_id = post_id + LEFT JOIN votes_comment ON votes_comment_item_id = comment_id + AND votes_comment_user_id = $user_id + LEFT JOIN favorites fav ON fav.tid = comment_id + AND fav.user_id = $user_id + AND fav.action_type = 'comment' + $sort + ORDER BY comment_id DESC LIMIT :start, :limit "; - return DB::run($sql, ['uid' => UserData::getUserId(), 'start' => $start, 'limit' => $limit, 'tl' => UserData::getUserTl()])->fetchAll(); + return DB::run($sql, ['start' => $start, 'limit' => self::$limit])->fetchAll(); } - // Количество комментариев public static function getCommentsCount($sheet) { $sort = self::sorts($sheet); - $sql = "SELECT - comment_id, - comment_is_deleted - FROM comments - JOIN posts ON comment_post_id = post_id AND post_tl <= :tl - WHERE $sort"; + $sql = "SELECT comment_id FROM comments INNER JOIN posts ON comment_post_id = post_id $sort"; - return DB::run($sql, ['tl' => UserData::getUserTl()])->rowCount(); + return DB::run($sql)->rowCount(); } public static function sorts($sheet) { - return $sheet == 'all' ? "comment_is_deleted = 0" : "comment_is_deleted = 1"; + $hidden = UserData::checkAdmin() ? "" : "AND post_hidden = 0"; + + switch ($sheet) { + case 'all': + $sort = "WHERE comment_is_deleted = 0 AND post_tl = 0 AND post_is_deleted = 0 $hidden"; + break; + case 'deleted': + $sort = "WHERE comment_is_deleted = 1"; + break; + } + + return $sort; } - // Получаем комментарии к ответу - public static function getCommentsAnswer($answer_id) + // Number of replies per post + // Количество ответов на пост + public static function getNumberComment($post_id) { + $sql = "SELECT comment_id FROM comments WHERE comment_post_id = :id AND comment_is_deleted = 0"; + + return DB::run($sql, ['id' => $post_id])->rowCount(); + } + + // Add the comment to the end of the post + // Добавим ответ в конец поста + public static function mergePost($post_id, $content) + { + $sql = "UPDATE posts SET post_content = CONCAT(post_content, :content) WHERE post_id = :post_id"; + + $content = "\n\n `+` " . $content; + + return DB::run($sql, ['post_id' => $post_id, 'content' => $content]); + } + + // Getting comments in a post + // Получаем ответы в посте + public static function getCommentsPost($post_id, $type, $sorting = 'new') + { + $user_id = UserData::getUserId(); + + if ($type == 1) { + $sorting = 'top'; + } + + switch ($sorting) { + case 'top': + $sort = 'ORDER BY comment_lo DESC, comment_votes DESC'; + break; + case 'old': + $sort = 'ORDER BY comment_id DESC'; + break; + // new + default: + $sort = ''; + break; + } + $sql = "SELECT comment_id, - comment_user_id, - comment_answer_id, - comment_parent_id, - comment_content, + comment_user_id, + comment_post_id, + comment_parent_id, comment_date, - comment_votes, + comment_content, + comment_modified, comment_published, comment_ip, - comment_after, + comment_votes, + comment_lo, comment_is_deleted, votes_comment_item_id, votes_comment_user_id, - id, - login, - avatar, - created_at - FROM comments - LEFT JOIN users ON id = comment_user_id - LEFT JOIN votes_comment ON votes_comment_item_id = comment_id - AND votes_comment_user_id = :user_id - WHERE comment_answer_id = :answer_id"; + fav.tid, + fav.user_id, + fav.action_type, + u.id, + u.login, + u.avatar, + u.created_at + FROM comments + LEFT JOIN users u ON u.id = comment_user_id + LEFT JOIN votes_comment ON votes_comment_item_id = comment_id + AND votes_comment_user_id = $user_id + LEFT JOIN favorites fav ON fav.tid = comment_id + AND fav.user_id = $user_id + AND fav.action_type = 'comment' + WHERE comment_post_id = $post_id $sort"; - return DB::run($sql, ['user_id' => UserData::getUserId(), 'answer_id' => $answer_id])->fetchAll(); + return DB::run($sql)->fetchAll(); } - // Страница комментариев участника - public static function userComments($page, $limit, $user_id, $id) + // User responses + // Ответы участника + public static function userComments($page, $user_id, $uid_vote) { - $start = ($page - 1) * $limit; + $start = ($page - 1) * self::$limit; $sql = "SELECT comment_id, - comment_user_id, - comment_answer_id, - comment_parent_id, - comment_content, + comment_user_id, + comment_post_id, comment_date, + comment_content, + comment_modified, comment_published, - comment_votes, comment_ip, - comment_after, + comment_votes, comment_is_deleted, votes_comment_item_id, votes_comment_user_id, - post_id, - post_slug, + post_id, post_title, + post_slug, post_user_id, post_closed, post_is_deleted, id, login, avatar - FROM comments - LEFT JOIN users ON id = comment_user_id - LEFT JOIN posts ON comment_post_id = post_id - LEFT JOIN votes_comment ON votes_comment_item_id = comment_id - AND votes_comment_user_id = :id - WHERE comment_user_id = :user_id AND comment_is_deleted = 0 - AND post_is_deleted = 0 AND post_tl = 0 AND post_hidden = 0 - ORDER BY comment_id DESC LIMIT :start, :limit"; + FROM comments + LEFT JOIN users ON id = comment_user_id + LEFT JOIN posts ON comment_post_id = post_id + LEFT JOIN votes_comment ON votes_comment_item_id = comment_id + AND votes_comment_user_id = :uid_vote + WHERE comment_user_id = :user_id AND post_hidden = 0 + AND comment_is_deleted = 0 AND post_is_deleted = 0 AND post_tl = 0 AND post_tl = 0 + ORDER BY comment_id DESC LIMIT :start, :limit "; - return DB::run($sql, ['user_id' => $user_id, 'id' => $id, 'start' => $start, 'limit' => $limit])->fetchAll(); + return DB::run($sql, ['user_id' => $user_id, 'uid_vote' => $uid_vote, 'start' => $start, 'limit' => self::$limit])->fetchAll(); } - // Количество комментариев участника public static function userCommentsCount($user_id) { $sql = "SELECT comment_id - FROM comments - LEFT JOIN posts ON comment_post_id = post_id + FROM comments + LEFT JOIN posts ON comment_post_id = post_id WHERE comment_user_id = :user_id AND comment_is_deleted = 0 - AND post_is_deleted = 0 AND post_tl = 0"; + AND post_is_deleted = 0 AND post_tl = 0 AND post_tl = 0"; return DB::run($sql, ['user_id' => $user_id])->rowCount(); } - // Получаем комментарий по id комментария - public static function getCommentsId($comment_id) + // Information on the id of the comment + // Информацию по id ответа + public static function getCommentId($comment_id) { $sql = "SELECT comment_id, - comment_content, + comment_post_id, comment_user_id, comment_date, - comment_post_id, + comment_modified, + comment_published, + comment_ip, + comment_votes, + comment_content, + comment_lo, comment_is_deleted - FROM comments WHERE comment_id = :comment_id"; + FROM comments + WHERE comment_id = :comment_id"; - return DB::run($sql, ['comment_id' => $comment_id])->fetch(); + return DB::run($sql, ['comment_id' => $comment_id])->fetch(); + } + + /* + * Best comment + */ + + // Choice of the best comment + // Выбор лучшего ответа + public static function setBest($post_id, $comment_id, $selected_best_comment) + { + if ($selected_best_comment) { + DB::run("UPDATE comments SET comment_lo = 0 WHERE comment_id = :id", ['id' => $selected_best_comment]); + } + + self::setCommentBest($comment_id); + + self::commentPostBest($post_id, $comment_id); + } + + // Let's write down the id of the participant who chose the best comment + // Запишем id участника выбравший лучший ответ + public static function setCommentBest($comment_id) + { + $sql = "UPDATE comments SET comment_lo = :user_id WHERE comment_id = :comment_id"; + + return DB::run($sql, ['comment_id' => $comment_id, 'user_id' => UserData::getUserId()]); + } + + // Rewriting the number of the selected best comment in the post + // Переписываем номер выбранного лучший ответ в посте + public static function commentPostBest($post_id, $comment_id) + { + $sql_two = "UPDATE posts SET post_lo = :comment_id WHERE post_id = :post_id"; + + return DB::run($sql_two, ['post_id' => $post_id, 'comment_id' => $comment_id]); } } diff --git a/app/Models/FeedModel.php b/app/Models/FeedModel.php index f06b527f..9fe48de6 100644 --- a/app/Models/FeedModel.php +++ b/app/Models/FeedModel.php @@ -19,7 +19,7 @@ class FeedModel extends \Hleb\Scheme\App\Models\MainModel // Sorting posts by conditions // Сортировка постов по условиям - $sort = "ORDER BY post_answers_count DESC"; + $sort = "ORDER BY post_comments_count DESC"; if (in_array($sheet, ['facet.feed', 'web.feed', 'questions', 'posts'])) { $sort = "ORDER BY post_top DESC, post_date DESC"; } elseif (in_array($sheet, ['admin.posts.all', 'admin.posts.ban', 'profile.posts'])) { @@ -41,7 +41,6 @@ class FeedModel extends \Hleb\Scheme\App\Models\MainModel post_user_id, post_votes, post_hits_count, - post_answers_count, post_comments_count, post_content, post_content_img, diff --git a/app/Models/HomeModel.php b/app/Models/HomeModel.php index 32d4df29..38fc4100 100644 --- a/app/Models/HomeModel.php +++ b/app/Models/HomeModel.php @@ -59,7 +59,6 @@ class HomeModel extends \Hleb\Scheme\App\Models\MainModel post_user_id, post_votes, post_hits_count, - post_answers_count, post_comments_count, post_content, post_content_img, @@ -172,33 +171,33 @@ class HomeModel extends \Hleb\Scheme\App\Models\MainModel // The last 5 responses on the main page // Последние 5 ответа на главной - public static function latestAnswers() + public static function latestComments() { $trust_level = UserData::getUserTl(); - $user_answer = "AND post_tl = 0"; + $user_comment = "AND post_tl = 0"; if ($user_id = UserData::getUserId()) { - $user_answer = "AND answer_user_id != $user_id AND post_tl <= $trust_level"; + $user_comment = "AND comment_user_id != $user_id AND post_tl <= $trust_level"; } $hidden = UserData::checkAdmin() ? "" : "AND post_hidden = 0"; $sql = "SELECT - answer_id, - answer_post_id, - answer_content, - answer_date, + comment_id, + comment_post_id, + comment_content, + comment_date, post_id, post_slug, post_hidden, login, avatar - FROM answers - LEFT JOIN users ON id = answer_user_id - RIGHT JOIN posts ON post_id = answer_post_id - WHERE answer_is_deleted = 0 AND post_is_deleted = 0 $hidden - $user_answer AND post_type = 'post' - ORDER BY answer_id DESC LIMIT 5"; + FROM comments + LEFT JOIN users ON id = comment_user_id + RIGHT JOIN posts ON post_id = comment_post_id + WHERE comment_is_deleted = 0 AND post_is_deleted = 0 $hidden + $user_comment AND post_type = 'post' + ORDER BY comment_id DESC LIMIT 5"; return DB::run($sql)->fetchAll(); } diff --git a/app/Models/PostModel.php b/app/Models/PostModel.php index 69529c94..d094ed77 100644 --- a/app/Models/PostModel.php +++ b/app/Models/PostModel.php @@ -94,7 +94,6 @@ class PostModel extends \Hleb\Scheme\App\Models\MainModel post_user_id, post_ip, post_votes, - post_answers_count, post_comments_count, post_content, post_content_img, @@ -147,7 +146,7 @@ class PostModel extends \Hleb\Scheme\App\Models\MainModel post_title, post_slug, post_feature, - post_answers_count, + post_comments_count, post_type FROM posts LEFT JOIN facets_posts_relation on post_id = relation_post_id @@ -163,7 +162,7 @@ class PostModel extends \Hleb\Scheme\App\Models\MainModel return DB::run($sql, ['post_id' => $post_id, 'user_id' => UserData::getUserId(), 'tl' => $tl, 'limit' => $limit, 'facet_id' => $facet_id])->fetchAll(); } - // $type (comments / answers / hits) + // $type (comments / hits) public static function updateCount($post_id, $type) { $sql = "UPDATE posts SET post_" . $type . "_count = (post_" . $type . "_count + 1) WHERE post_id = :post_id"; @@ -397,7 +396,6 @@ class PostModel extends \Hleb\Scheme\App\Models\MainModel post_user_id, post_votes, post_hits_count, - post_answers_count, post_comments_count, post_content, post_content_img, diff --git a/app/Models/RssModel.php b/app/Models/RssModel.php index 7a05b08f..c0b2b403 100644 --- a/app/Models/RssModel.php +++ b/app/Models/RssModel.php @@ -41,7 +41,6 @@ class RssModel extends \Hleb\Scheme\App\Models\MainModel post_published, post_user_id, post_votes, - post_answers_count, post_comments_count, post_content, post_content_img, diff --git a/app/Models/SearchModel.php b/app/Models/SearchModel.php index 2a166bbe..fa9541ee 100644 --- a/app/Models/SearchModel.php +++ b/app/Models/SearchModel.php @@ -14,8 +14,8 @@ class SearchModel extends \Hleb\Scheme\App\Models\MainModel return self::getWebsite($page, $limit, $query); } - if ($type == 'answer') { - return self::getAnswers($page, $limit, $query); + if ($type == 'comment') { + return self::getComments($page, $limit, $query); } return self::getPosts($page, $limit, $query); @@ -52,14 +52,14 @@ class SearchModel extends \Hleb\Scheme\App\Models\MainModel return DB::run($sql, ['qa' => $query, 'start' => $start, 'limit' => $limit])->fetchAll(); } - public static function getAnswers($page, $limit, $query) + public static function getComments($page, $limit, $query) { $start = ($page - 1) * $limit; - $sql = "SELECT answer_id, answer_content, post_id, post_slug, post_title as title - FROM answers - LEFT JOIN posts ON answer_post_id = post_id + $sql = "SELECT comment_id, comment_content, post_id, post_slug, post_title as title + FROM comments + LEFT JOIN posts ON comment_post_id = post_id WHERE post_is_deleted = 0 - AND answer_content LIKE :qa LIMIT :start, :limit"; + AND comment_content LIKE :qa LIMIT :start, :limit"; return DB::run($sql, ['qa' => "%" . $query . "%", 'start' => $start, 'limit' => $limit])->fetchAll(); } @@ -94,8 +94,8 @@ class SearchModel extends \Hleb\Scheme\App\Models\MainModel public static function getSearchCount($query, $type) { - if ($type == 'answer') { - $sql = "SELECT answer_id FROM answers LEFT JOIN posts ON answer_post_id = post_id WHERE post_is_deleted = 0 AND answer_content LIKE :qa"; + if ($type == 'comment') { + $sql = "SELECT comment_id FROM comments LEFT JOIN posts ON comment_post_id = post_id WHERE post_is_deleted = 0 AND comment_content LIKE :qa"; return DB::run($sql, ['qa' => "%" . $query . "%"])->rowCount(); } diff --git a/app/Models/User/SettingModel.php b/app/Models/User/SettingModel.php index 61cd6c6c..d111cd82 100644 --- a/app/Models/User/SettingModel.php +++ b/app/Models/User/SettingModel.php @@ -89,8 +89,7 @@ class SettingModel extends \Hleb\Scheme\App\Models\MainModel setting_email_pm = :setting_email_pm, setting_email_appealed = :setting_email_appealed, setting_email_post = :setting_email_post, - setting_email_answer = :setting_email_answer, - setting_email_comment = :setting_email_comment + setting_email_answer = :setting_email_answer WHERE setting_user_id = :setting_user_id"; if (!self::countNotifications($params['setting_user_id'])) { @@ -99,14 +98,12 @@ class SettingModel extends \Hleb\Scheme\App\Models\MainModel setting_email_pm, setting_email_appealed, setting_email_post, - setting_email_answer, - setting_email_comment) + setting_email_answer) VALUES(:setting_user_id, :setting_email_pm, :setting_email_appealed, :setting_email_post, - :setting_email_answer, - :setting_email_comment)"; + :setting_email_answer)"; } return DB::run($sql, $params); diff --git a/app/Models/User/UserModel.php b/app/Models/User/UserModel.php index 97ae84ec..ecaea8b8 100644 --- a/app/Models/User/UserModel.php +++ b/app/Models/User/UserModel.php @@ -145,9 +145,9 @@ class UserModel extends \Hleb\Scheme\App\Models\MainModel post_id, post_title, post_slug, - answer_id, - answer_post_id, - answer_content, + comment_id, + comment_post_id, + comment_content, item_id, item_title, item_url, @@ -156,7 +156,7 @@ class UserModel extends \Hleb\Scheme\App\Models\MainModel item_domain FROM favorites fav LEFT JOIN posts ON post_id = fav.tid AND fav.action_type = 'post' - LEFT JOIN answers ON answer_id = fav.tid AND fav.action_type = 'answer' + LEFT JOIN comments ON comment_id = fav.tid AND fav.action_type = 'comment' LEFT JOIN items ON item_id = fav.tid AND fav.action_type = 'website' LEFT JOIN folders_relation fr ON fr.tid = fav.tid LEFT JOIN folders fol ON folder_id = fol.id AND fol.user_id = :uid2 @@ -219,8 +219,6 @@ class UserModel extends \Hleb\Scheme\App\Models\MainModel $sql = "SELECT (SELECT COUNT(post_id) FROM posts WHERE post_user_id = $user_id and post_draft = 0 and post_is_deleted = $condition) AS count_posts, - (SELECT COUNT(answer_id) FROM answers WHERE answer_user_id = $user_id and answer_is_deleted = $condition) AS count_answers, - (SELECT COUNT(comment_id) FROM comments WHERE comment_user_id = $user_id and comment_is_deleted = $condition) AS count_comments, (SELECT COUNT(item_id) FROM items WHERE item_user_id = $user_id and item_is_deleted = $condition) AS count_items"; diff --git a/app/Services/Audit.php b/app/Services/Audit.php index c1682526..9649454e 100644 --- a/app/Services/Audit.php +++ b/app/Services/Audit.php @@ -23,20 +23,17 @@ class Audit extends Base $content_type = Request::getPost('type'); $post_id = Request::getPostInt('post_id'); $content_id = Request::getPostInt('content_id'); - + // Limit the flags if ($this->user['trust_level'] < config('trust-levels.tl_add_report')) return 1; if (AuditModel::getSpeedReport($this->user['id']) > config('trust-levels.perDay_report')) return 1; - + $post = PostPresence::index($post_id, 'id'); + + if (!in_array($content_type, ['post', 'comment'])) return false; - if (!in_array($content_type, ['post', 'answer', 'comment'])) return false; - - $type_id = $content_type == 'answer' ? 'answer_' . $content_id : 'comment_' . $content_id; - $url = post_slug($post['post_id'], $post['post_slug']) . '#' . $type_id; - - $this->create($content_type, $content_id, $url, 'report'); + $this->create($content_type, $content_id, $post, 'report'); return true; } @@ -127,7 +124,7 @@ class Audit extends Base return false; } - public function create(string $type, int $last_content_id, string $url, string $type_notification = 'audit') + public function create(string $type, int $last_content_id, array $post, string $type_notification = 'audit') { $action_type = ($type_notification == 'audit') ? NotificationModel::TYPE_AUDIT : NotificationModel::TYPE_REPORT; @@ -140,6 +137,8 @@ class Audit extends Base ] ); + $url = '/post/' . $post['post_id'] . '/' . $post['post_slug'] . '#' . 'comment_' . $last_content_id; + // Send notification type 21 (audit) to administrator (id 1) // Отправим тип уведомления 21 (аудит) администратору (id 1) NotificationModel::send(UserData::REGISTERED_ADMIN_ID, $action_type, $url); diff --git a/app/Services/AnswerBest.php b/app/Services/CommentBest.php similarity index 61% rename from app/Services/AnswerBest.php rename to app/Services/CommentBest.php index 024f6fa4..cdeb81f5 100644 --- a/app/Services/AnswerBest.php +++ b/app/Services/CommentBest.php @@ -6,42 +6,42 @@ namespace App\Services; use Hleb\Constructor\Handlers\Request; use App\Services\Сheck\PostPresence; -use App\Services\Сheck\AnswerPresence; -use App\Models\AnswerModel; +use App\Services\Сheck\CommentPresence; +use App\Models\CommentModel; use UserData, Access; -class AnswerBest extends Base +class CommentBest extends Base { public function index() { - // Get the answer data (for which the "best answer" is selected) - // Получим данные ответа (на который выбирается "лучший ответ") - $answer = AnswerPresence::index(Request::getPostInt('answer_id')); + // Get the comment data (for which the "best comment" is selected) + // Получим данные комментария (на который выбирается "лучший ответ") + $comment = CommentPresence::index(Request::getPostInt('comment_id')); - // Get the data of the post that has this answer + // Get the data of the post that has this comment // Получим данные поста в котором есть этот ответ - $post = PostPresence::index($answer['answer_post_id'], 'id'); + $post = PostPresence::index($comment['comment_post_id'], 'id'); - // Let's check the access. Only the staff and the author of the post can choose the best answer (without regard to time) + // Let's check the access. Only the staff and the author of the post can choose the best comment (without regard to time) // Проверим доступ. Только персонал и автор поста может выбирать лучший ответ (без учета времени) if ($post['post_user_id'] != UserData::getUserId() && !UserData::checkAdmin()) { return false; } - // If the number of answers is less than 2, then we will not let you choose the best answer + // If the number of answers is less than 2, then we will not let you choose the best comment // Если количество ответов меньше 2, то не дадим выбирать лучший ответ - if ($post['post_answers_count'] < 2) { + if ($post['post_comments_count'] < 2) { return false; } // Если Лучший Ответ уже выбран, то переписываем... if ($post['post_lo']) { - AnswerModel::setBest($post['post_id'], $answer['answer_id'], $post['post_lo']); + CommentModel::setBest($post['post_id'], $comment['comment_id'], $post['post_lo']); return true; } // Если Лучшего ответа нет, то первичная запись - AnswerModel::setBest($post['post_id'], $answer['answer_id'], false); + CommentModel::setBest($post['post_id'], $comment['comment_id'], false); return true; } } diff --git a/app/Services/Favorite.php b/app/Services/Favorite.php index 62cea3dc..cb836e63 100644 --- a/app/Services/Favorite.php +++ b/app/Services/Favorite.php @@ -6,7 +6,7 @@ namespace App\Services; use Hleb\Constructor\Handlers\Request; use App\Models\Item\WebModel; -use App\Models\{FavoriteModel, PostModel, AnswerModel}; +use App\Models\{FavoriteModel, PostModel, CommentModel}; class Favorite extends Base { @@ -15,7 +15,7 @@ class Favorite extends Base $content_id = Request::getPostInt('content_id'); $type = Request::getPost('type'); - $allowed = ['post', 'website', 'answer']; + $allowed = ['post', 'website', 'comment']; if (!in_array($type, $allowed)) { return false; } @@ -36,8 +36,8 @@ class Favorite extends Base case 'website': $content = WebModel::getItemId($content_id); break; - case 'answer': - $content = AnswerModel::getAnswerId($content_id); + case 'comment': + $content = CommentModel::getCommentId($content_id); break; } diff --git a/app/Services/Tree/BuildTree.php b/app/Services/Tree/BuildTree.php index d4512b04..14d50d71 100644 --- a/app/Services/Tree/BuildTree.php +++ b/app/Services/Tree/BuildTree.php @@ -27,10 +27,9 @@ class BuildTree return $siblings; }; + $tree = []; if (isset($grouped[$group])) { $tree = $fnBuilder($grouped[$group]); - } else { - $tree = []; } return $tree; diff --git a/app/Services/Сheck/AnswerPresence.php b/app/Services/Сheck/AnswerPresence.php deleted file mode 100644 index 181cc9a8..00000000 --- a/app/Services/Сheck/AnswerPresence.php +++ /dev/null @@ -1,19 +0,0 @@ -user); - } elseif ($row['action_type'] == 'answer') { - $row['content'] = AnswerModel::getAnswerId($row['content_id']); - - $row['post'] = PostModel::getPost($row['content']['answer_post_id'], 'id', $this->user); } elseif ($row['action_type'] == 'comment') { - $row['content'] = CommentModel::getCommentsId($row['content_id']); - } + $row['content'] = CommentModel::getCommentId($row['content_id']); + + $row['post'] = PostModel::getPost($row['content']['comment_post_id'], 'id', $this->user); + } $result[$ind] = $row; } diff --git a/modules/admin/App/Console.php b/modules/admin/App/Console.php index 0bfd01bc..b76e8c12 100644 --- a/modules/admin/App/Console.php +++ b/modules/admin/App/Console.php @@ -11,7 +11,7 @@ class Console public static function index() { $choice = Request::getPost('type'); - $allowed = ['css', 'topic', 'up', 'tl', 'indexer']; + $allowed = ['css', 'topic', 'post', 'up', 'tl']; if (!in_array($choice, $allowed)) { redirect(url('admin.tools')); } @@ -25,6 +25,13 @@ class Console self::consoleRedirect(); } + public static function post() + { + ConsoleModel::recalculateCountCommentPost(); + + self::consoleRedirect(); + } + public static function up() { $users = ConsoleModel::allUsers(); diff --git a/modules/admin/App/Models/ConsoleModel.php b/modules/admin/App/Models/ConsoleModel.php index 3c5ad939..30055a8f 100644 --- a/modules/admin/App/Models/ConsoleModel.php +++ b/modules/admin/App/Models/ConsoleModel.php @@ -6,28 +6,36 @@ use DB; class ConsoleModel extends \Hleb\Scheme\App\Models\MainModel { + // Let's recalculate the number of posts in the Topics + // Пересчитаем количество постов в Темах public static function recalculateTopic() { $sql = "UPDATE facets SET facet_count = (SELECT count(relation_post_id) FROM facets_posts_relation - LEFT JOIN posts ON relation_post_id = post_id WHERE relation_facet_id = facet_id AND post_is_deleted = 0)"; return DB::run($sql); } + // Let's recalculate the number of сщььутеы in the Posts + // Пересчитаем количество комментариев в Постах + public static function recalculateCountCommentPost() + { + $sql = "UPDATE posts SET post_comments_count = (SELECT count(comment_post_id) FROM comments WHERE comment_post_id = post_id AND comment_is_deleted = 0)"; + + return DB::run($sql); + } + public static function allUp($uid) { $sql = "SELECT (SELECT SUM(post_votes) FROM posts WHERE post_user_id = $uid) AS count_posts, - (SELECT SUM(answer_votes) FROM answers WHERE answer_user_id = $uid) - AS count_answers, (SELECT SUM(comment_votes) FROM comments WHERE comment_user_id = $uid) AS count_comments"; $user = DB::run($sql)->fetch(); - // Вернем сумму, но этот запрос необходим будет далее именно по отдельным типам - return $user['count_posts'] + $user['count_answers'] + $user['count_comments']; + + return $user['count_posts'] + $user['count_comments']; } public static function allUsers() diff --git a/modules/admin/view/default/audit/audits.php b/modules/admin/view/default/audit/audits.php index 55d5c867..769fd93e 100644 --- a/modules/admin/view/default/audit/audits.php +++ b/modules/admin/view/default/audit/audits.php @@ -38,7 +38,7 @@