فهرست منبع

+ Added a review of the topic when replying

Visman 6 سال پیش
والد
کامیت
a8b9da2eb8
3فایلهای تغییر یافته به همراه56 افزوده شده و 18 حذف شده
  1. 9 7
      app/Models/Pages/Post.php
  2. 20 11
      app/Models/Post/View.php
  3. 27 0
      app/Models/Topic/Model.php

+ 9 - 7
app/Models/Pages/Post.php

@@ -101,13 +101,15 @@ class Post extends Page
             unset($args['quote']);
         }
 
-        $this->nameTpl   = 'post';
-        $this->onlinePos = 'topic-' . $topic->id;
-        $this->canonical = $this->c->Router->link('NewReply', ['id' => $topic->id]);
-        $this->robots    = 'noindex';
-        $this->crumbs    = $this->crumbs(\ForkBB\__('Post a reply'), $topic);
-        $this->formTitle = \ForkBB\__('Post a reply');
-        $this->form      = $this->messageForm($args, $topic, 'NewReply');
+        $this->nameTpl    = 'post';
+        $this->onlinePos  = 'topic-' . $topic->id;
+        $this->canonical  = $this->c->Router->link('NewReply', ['id' => $topic->id]);
+        $this->robots     = 'noindex';
+        $this->crumbs     = $this->crumbs(\ForkBB\__('Post a reply'), $topic);
+        $this->formTitle  = \ForkBB\__('Post a reply');
+        $this->form       = $this->messageForm($args, $topic, 'NewReply');
+        $this->postsTitle = \ForkBB\__('Topic review');
+        $this->posts      = $topic->review();
 
         return $this;
     }

+ 20 - 11
app/Models/Post/View.php

@@ -70,13 +70,14 @@ class View extends Action
      * Возвращает список сообщений
      *
      * @param mixed $arg
+     * @param bool $review
      *
      * @throws InvalidArgumentException
      * @throws RuntimeException
      *
      * @return array
      */
-    public function view($arg)
+    public function view($arg, $review = false)
     {
         if (! $arg instanceof Topic && ! $arg instanceof Search) {
             throw new InvalidArgumentException('Expected Topic or Search');
@@ -86,13 +87,15 @@ class View extends Action
             throw new RuntimeException('Model does not contain of posts list for display');
         }
 
-        $vars = [
-            ':ids' => $arg->idsList,
-        ];
-        $sql = 'SELECT w.id, w.message, w.poster, w.posted
-                FROM ::warnings AS w
-                WHERE w.id IN (?ai:ids)';
-        $warnings = $this->c->DB->query($sql, $vars)->fetchAll(PDO::FETCH_GROUP);
+        if (! $review) {
+            $vars = [
+                ':ids' => $arg->idsList,
+            ];
+            $sql = 'SELECT w.id, w.message, w.poster, w.posted
+                    FROM ::warnings AS w
+                    WHERE w.id IN (?ai:ids)';
+            $warnings = $this->c->DB->query($sql, $vars)->fetchAll(PDO::FETCH_GROUP);
+        }
 
         $userIds = [];
         $result  = \array_flip($arg->idsList);
@@ -174,11 +177,17 @@ class View extends Action
             }
         }
 
-        $this->c->users->load(array_keys($userIds));
+        $this->c->users->load(\array_keys($userIds));
 
         $offset    = ($arg->page - 1) * $this->c->user->disp_posts;
-        $postCount = 0;
         $timeMax   = 0;
+        if ($review) {
+            $postCount = $arg->num_replies + 2;
+            $sign      = -1;
+        } else {
+            $postCount = 0;
+            $sign      = 1;
+        }
 
         if ($arg instanceof Topic) {
             foreach ($result as $post) {
@@ -191,7 +200,7 @@ class View extends Action
                     }
                     $post->__postNumber = 1;
                 } else {
-                    ++$postCount;
+                    $postCount += $sign;
                     if (empty($post->id)) {
                         continue;
                     }

+ 27 - 0
app/Models/Topic/Model.php

@@ -259,6 +259,33 @@ class Model extends DataModel
         return empty($this->idsList) ? [] : $this->c->posts->view($this);
     }
 
+    /**
+     * Возвращает массив сообщений обзора темы
+     *
+     * @return array
+     */
+    public function review()
+    {
+        if ($this->c->config->o_topic_review < 1) {
+            return [];
+        }
+
+        $this->page = 1;
+
+        $vars = [
+            ':tid'    => $this->id,
+            ':rows'   => $this->c->config->o_topic_review,
+        ];
+        $sql = 'SELECT p.id
+                FROM ::posts AS p
+                WHERE p.topic_id=?i:tid
+                ORDER BY p.id DESC
+                LIMIT 0, ?i:rows';
+        $this->idsList = $this->c->DB->query($sql, $vars)->fetchAll(PDO::FETCH_COLUMN);
+
+        return empty($this->idsList) ? [] : $this->c->posts->view($this, true);
+    }
+
     /**
      * Вычисляет страницу темы на которой находится данное сообщение
      *