Browse Source

rev.12 Add subscriptions 3

Add display the list of the user's subscriptions through search
Visman 4 years ago
parent
commit
116370a191

+ 17 - 0
app/Models/Pages/Admin/Update.php

@@ -617,4 +617,21 @@ class Update extends Admin
 
 
         return null;
         return null;
     }
     }
+
+    /**
+     * rev.11 to rev.12
+     */
+    protected function stageNumber11(array $args): ?int
+    {
+        $coreConfig = new CoreConfig($this->c->DIR_CONFIG . '/' . self::CONFIG_FILE);
+
+        $coreConfig->add(
+            'multiple=>SearchModelActionF',
+            '\\ForkBB\\Models\\Search\\ActionF::class',
+            'SearchModelActionT'
+        );
+        $coreConfig->save();
+
+        return null;
+    }
 }
 }

+ 19 - 8
app/Models/Pages/Search.php

@@ -502,20 +502,24 @@ class Search extends Page
             case 'posts':
             case 'posts':
                 $asTopicsList      = false;
                 $asTopicsList      = false;
             case 'topics':
             case 'topics':
+            case 'topics_subscriptions':
+            case 'forums_subscriptions':
                 if (! isset($uid)) {
                 if (! isset($uid)) {
                     break;
                     break;
                 }
                 }
-                $user              = $this->c->users->load($uid);
+                $user = $this->c->users->load($uid);
                 if (
                 if (
                     ! $user instanceof User
                     ! $user instanceof User
                     || $user->isGuest
                     || $user->isGuest
                 ) {
                 ) {
                     break;
                     break;
                 }
                 }
-                if ($asTopicsList) {
-                    $list          = $model->actionT($action, $forum, $user->id);
+                if ('forums_subscriptions' == $action) {
+                    $list = $model->actionF($action, $forum, $user->id);
+                } elseif ($asTopicsList) {
+                    $list = $model->actionT($action, $forum, $user->id);
                 } else {
                 } else {
-                    $list          = $model->actionP($action, $forum, $user->id);
+                    $list = $model->actionP($action, $forum, $user->id);
                 }
                 }
                 $model->name       = __('Quick search user ' . $action, $user->username);
                 $model->name       = __('Quick search user ' . $action, $user->username);
                 $model->linkMarker = 'SearchAction';
                 $model->linkMarker = 'SearchAction';
@@ -541,13 +545,20 @@ class Search extends Page
         if ($asTopicsList) {
         if ($asTopicsList) {
             $this->c->Lang->load('forum');
             $this->c->Lang->load('forum');
 
 
-            $this->nameTpl   = 'forum';
-            $this->topics    = $list;
+            $this->nameTpl = 'forum';
+
+            if ('forums_subscriptions' == $action) {
+                $this->c->Lang->load('subforums');
+
+                $model->subforums = $list;
+            } else {
+                $this->topics = $list;
+            }
         } else {
         } else {
             $this->c->Lang->load('topic');
             $this->c->Lang->load('topic');
 
 
-            $this->nameTpl   = 'topic_in_search';
-            $this->posts     = $list;
+            $this->nameTpl = 'topic_in_search';
+            $this->posts   = $list;
         }
         }
 
 
         $this->fIndex        = 'search';
         $this->fIndex        = 'search';

+ 84 - 0
app/Models/Search/ActionF.php

@@ -0,0 +1,84 @@
+<?php
+
+namespace ForkBB\Models\Search;
+
+use ForkBB\Models\Method;
+use ForkBB\Models\Forum\Model as Forum;
+use PDO;
+use InvalidArgumentException;
+
+class ActionF extends Method
+{
+    /**
+     * Поисковые действия по разделам (подписка на разделы)
+     *
+     * @param string $action
+     * @param Forum $root
+     * @param int $uid
+     *
+     * @throws InvalidArgumentException
+     *
+     * @return false|array
+     */
+    public function actionF(string $action, Forum $root, int $uid = null)
+    {
+        $forums = \array_keys($root->descendants);
+        if ($root->id) {
+            $forums[] = $root->id;
+        }
+        if (empty($forums)) {
+            return [];
+        }
+
+        $list = [];
+        switch ($action) {
+            case 'forums_subscriptions':
+                if (0 !== $root->id) {
+                    return false;
+                }
+
+                $user = $this->c->users->load($uid);
+
+                if (! $this->c->ProfileRules->setUser($user)->viewSubscription) {
+                    return false;
+                }
+
+                $subscr     = $this->c->subscriptions;
+                $subscrInfo = $subscr->info($user, $subscr::FORUMS_DATA);
+                $ids        = $subscrInfo[$subscr::FORUMS_DATA] ?? [];
+
+                if (empty($ids)) {
+                    break;
+                }
+
+                $all = $this->c->forums->loadTree(0)->descendants;
+
+                foreach ($ids as $id) {
+                    if (
+                        isset($all[$id])
+                        && $all[$id] instanceof Forum
+                    ) {
+                        $forum                  = clone $all[$id];
+                        $forum->parent_forum_id = 0;
+
+                        unset($forum->subforums, $forum->descendants);
+
+                        $list[$id] = $forum;
+                    }
+                }
+
+                break;
+            default:
+                throw new InvalidArgumentException('Unknown action: ' . $action);
+        }
+
+        $this->model->numPages = 1;
+
+        // нет такой страницы в результате поиска
+        if (! $this->model->hasPage()) {
+            return false;
+        }
+
+        return $list;
+    }
+}

+ 17 - 0
app/Models/Search/ActionT.php

@@ -74,6 +74,23 @@ class ActionT extends Method
                         AND (mof.mf_mark_all_read IS NULL OR t.last_post>mof.mf_mark_all_read)
                         AND (mof.mf_mark_all_read IS NULL OR t.last_post>mof.mf_mark_all_read)
                     ORDER BY t.last_post DESC';
                     ORDER BY t.last_post DESC';
                 break;
                 break;
+            case 'topics_subscriptions':
+                if (0 !== $root->id) {
+                    return false;
+                }
+
+                $user = $this->c->users->load($uid);
+
+                if (! $this->c->ProfileRules->setUser($user)->viewSubscription) {
+                    return false;
+                }
+
+                $subscr     = $this->c->subscriptions;
+                $subscrInfo = $subscr->info($user, $subscr::TOPICS_DATA);
+                $list       = $subscrInfo[$subscr::TOPICS_DATA] ?? [];
+
+                \arsort($list, \SORT_NUMERIC); // ???? или по последнему сообщению делать?
+                break;
             default:
             default:
                 throw new InvalidArgumentException('Unknown action: ' . $action);
                 throw new InvalidArgumentException('Unknown action: ' . $action);
         }
         }

+ 1 - 1
app/bootstrap.php

@@ -42,7 +42,7 @@ if (
 }
 }
 $c->PUBLIC_URL = $c->BASE_URL . $forkPublicPrefix;
 $c->PUBLIC_URL = $c->BASE_URL . $forkPublicPrefix;
 
 
-$c->FORK_REVISION = 11;
+$c->FORK_REVISION = 12;
 $c->START         = $forkStart;
 $c->START         = $forkStart;
 $c->DIR_APP       = __DIR__;
 $c->DIR_APP       = __DIR__;
 $c->DIR_PUBLIC    = $forkPublic;
 $c->DIR_PUBLIC    = $forkPublic;

+ 1 - 0
app/config/main.dist.php

@@ -284,6 +284,7 @@ return [
 
 
         'SearchModelActionP' => \ForkBB\Models\Search\ActionP::class,
         'SearchModelActionP' => \ForkBB\Models\Search\ActionP::class,
         'SearchModelActionT' => \ForkBB\Models\Search\ActionT::class,
         'SearchModelActionT' => \ForkBB\Models\Search\ActionT::class,
+        'SearchModelActionF' => \ForkBB\Models\Search\ActionF::class,
         'SearchModelDelete'  => \ForkBB\Models\Search\Delete::class,
         'SearchModelDelete'  => \ForkBB\Models\Search\Delete::class,
         'SearchModelIndex'   => \ForkBB\Models\Search\Index::class,
         'SearchModelIndex'   => \ForkBB\Models\Search\Index::class,
         'SearchModelTruncateIndex'   => \ForkBB\Models\Search\TruncateIndex::class,
         'SearchModelTruncateIndex'   => \ForkBB\Models\Search\TruncateIndex::class,

+ 5 - 2
app/lang/en/search.po

@@ -117,8 +117,11 @@ msgstr "Topics by %s"
 msgid "Quick search user posts"
 msgid "Quick search user posts"
 msgstr "Posts by %s"
 msgstr "Posts by %s"
 
 
-msgid "Quick search show_subscriptions"
-msgstr "Subscribed by %s"
+msgid "Quick search user topics_subscriptions"
+msgstr "Topics subscribed by %s"
+
+msgid "Quick search user forums_subscriptions"
+msgstr "Forums subscribed by %s"
 
 
 msgid "Quick search show_user_warn"
 msgid "Quick search show_user_warn"
 msgstr "Warnings for %s"
 msgstr "Warnings for %s"

+ 5 - 2
app/lang/ru/search.po

@@ -117,8 +117,11 @@ msgstr "Темы от %s"
 msgid "Quick search user posts"
 msgid "Quick search user posts"
 msgstr "Сообщения от %s"
 msgstr "Сообщения от %s"
 
 
-msgid "Quick search show_subscriptions"
-msgstr "Подписки пользователя %s"
+msgid "Quick search user topics_subscriptions"
+msgstr "Темы с подпиской от %s"
+
+msgid "Quick search user forums_subscriptions"
+msgstr "Разделы с подпиской от %s"
 
 
 msgid "Quick search show_user_warn"
 msgid "Quick search show_user_warn"
 msgstr "Предупреждения для %s"
 msgstr "Предупреждения для %s"

+ 1 - 1
readme.md

@@ -1,4 +1,4 @@
-# ForkBB rev 11 Pre-Alpha Readme
+# ForkBB rev 12 Pre-Alpha Readme
 
 
 ## About
 ## About