Kaynağa Gözat

Update Models\PM\PPost

For previous message.
Visman 4 yıl önce
ebeveyn
işleme
069ea4a96c
1 değiştirilmiş dosya ile 38 ekleme ve 2 silme
  1. 38 2
      app/Models/PM/PPost.php

+ 38 - 2
app/Models/PM/PPost.php

@@ -25,12 +25,12 @@ class PPost extends DataModel
         parent::__construct($container);
 
         $this->zDepend = [
-            'id'            => ['link', 'user', 'canDelete', 'linkDelete', 'linkEdit', 'linkQuote'],
+            'id'            => ['link', 'user', 'canDelete', 'linkDelete', 'linkEdit', 'linkQuote', 'previousId', 'linkPrevious'],
             'edited'        => ['editor'],
             'posted'        => ['canDelete', 'canEdit'],
             'poster'        => ['editor'],
             'poster_id'     => ['canDelete', 'canEdit'],
-            'topic_id'      => ['parent', 'linkQuote'],
+            'topic_id'      => ['parent', 'linkQuote', 'previousId', 'linkPrevious'],
         ];
     }
 
@@ -99,6 +99,22 @@ class PPost extends DataModel
         );
     }
 
+    /**
+     * Ссылка на предыдущий пост
+     */
+    protected function getlinkPrevious(): string
+    {
+        return $this->c->Router->link(
+            'PMAction',
+            [
+                'second'  => $this->c->pms->second,
+                'action'  => Cnst::ACTION_POST,
+                'more1'   => $this->previousId,
+                'numPost' => $this->previousId,
+            ]
+        );
+    }
+
     /**
      * Статус возможности удаления
      */
@@ -182,4 +198,24 @@ class PPost extends DataModel
     {
         return $this->c->censorship->censor($this->c->Parser->parseMessage($this->message, (bool) $this->hide_smilies));
     }
+
+    /**
+     * Вычисляет номер сообщения перед данным
+     */
+    public function getpreviousId(): ?int
+    {
+        $vars = [
+            ':pid' => $this->id,
+            ':tid' => $this->topic_id,
+        ];
+        $query = "SELECT pp.id
+            FROM ::pm_posts AS pp
+            WHERE pp.id < ?i:pid AND pp.topic_id=?i:tid
+            ORDER BY pp.id DESC
+            LIMIT 1";
+
+        $id = $this->c->DB->query($query, $vars)->fetchColumn();
+
+        return empty($id) ? null : $id;
+    }
 }