rev.12 Add subscriptions 3

Add display the list of the user's subscriptions through search
This commit is contained in:
Visman 2020-09-01 23:54:57 +07:00
parent c55b439bc9
commit 116370a191
9 changed files with 150 additions and 14 deletions

View file

@ -617,4 +617,21 @@ class Update extends Admin
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;
}
}

View file

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

View file

@ -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;
}
}

View file

@ -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)
ORDER BY t.last_post DESC';
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:
throw new InvalidArgumentException('Unknown action: ' . $action);
}

View file

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

View file

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

View file

@ -117,8 +117,11 @@ msgstr "Topics by %s"
msgid "Quick search user posts"
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"
msgstr "Warnings for %s"

View file

@ -117,8 +117,11 @@ msgstr "Темы от %s"
msgid "Quick search user posts"
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"
msgstr "Предупреждения для %s"

View file

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