Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 7 additions & 31 deletions Sources/Actions/Admin/Maintenance.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
namespace SMF\Actions\Admin;

use SMF\ActionInterface;
use SMF\Actions\MessageIndex;
use SMF\Actions\TopicRemove;
use SMF\ActionTrait;
use SMF\Cache\CacheApi;
Expand Down Expand Up @@ -233,37 +234,10 @@ public function members(): void
public function topics(): void
{
// Let's load up the boards in case they are useful.
Utils::$context['categories'] = [];

$result = Db::$db->query(
'SELECT b.id_board, b.name, b.child_level, c.name AS cat_name, c.id_cat
FROM {db_prefix}boards AS b
LEFT JOIN {db_prefix}categories AS c ON (c.id_cat = b.id_cat)
WHERE {query_see_board}
AND redirect = {string:blank_redirect}',
[
'blank_redirect' => '',
],
identifier: 'order_by_board_order',
);

while ($row = Db::$db->fetch_assoc($result)) {
if (!isset(Utils::$context['categories'][$row['id_cat']])) {
Utils::$context['categories'][$row['id_cat']] = [
'name' => $row['cat_name'],
'boards' => [],
];
}

Utils::$context['categories'][$row['id_cat']]['boards'][$row['id_board']] = [
'id' => $row['id_board'],
'name' => $row['name'],
'child_level' => $row['child_level'],
];
}
Db::$db->free_result($result);

Category::sort(Utils::$context['categories']);
Utils::$context['categories'] = MessageIndex::getBoardList([
'use_permissions' => true,
'not_redirection' => true,
]);

if (isset($_GET['done']) && $_GET['done'] == 'purgeold') {
Utils::$context['maintenance_finished'] = Lang::getTxt('maintain_old', file: 'ManageMaintenance');
Expand All @@ -274,6 +248,8 @@ public function topics(): void

/**
* Oh noes! I'd document this but that would give it away.
*
* @internal
*/
public function destroy(): void
{
Expand Down
71 changes: 40 additions & 31 deletions Sources/Actions/MessageIndex.php
Original file line number Diff line number Diff line change
Expand Up @@ -188,16 +188,16 @@ public static function getBoardList(array $boardListOptions = []): array
}

$where = [];
$where_parameters = [];
$params = [];

if (isset($boardListOptions['excluded_boards'])) {
$where[] = 'b.id_board NOT IN ({array_int:excluded_boards})';
$where_parameters['excluded_boards'] = $boardListOptions['excluded_boards'];
$params['excluded_boards'] = $boardListOptions['excluded_boards'];
}

if (isset($boardListOptions['included_boards'])) {
$where[] = 'b.id_board IN ({array_int:included_boards})';
$where_parameters['included_boards'] = $boardListOptions['included_boards'];
$params['included_boards'] = $boardListOptions['included_boards'];
}

if (!empty($boardListOptions['ignore_boards'])) {
Expand All @@ -208,43 +208,52 @@ public static function getBoardList(array $boardListOptions = []): array

if (!empty($boardListOptions['not_redirection'])) {
$where[] = 'b.redirect = {string:blank_redirect}';
$where_parameters['blank_redirect'] = '';
$params['blank_redirect'] = '';
}

$request = Db::$db->query(
'SELECT c.name AS cat_name, c.id_cat, b.id_board, b.name AS board_name, b.child_level, b.redirect
FROM {db_prefix}boards AS b
LEFT JOIN {db_prefix}categories AS c ON (c.id_cat = b.id_cat)' . (empty($where) ? '' : '
WHERE ' . implode('
AND ', $where)),
$where_parameters,
identifier: 'order_by_board_order',
);
$selects = [
'c.name AS cat_name',
'c.id_cat',
'b.id_board',
'b.name AS board_name',
'b.child_level',
'b.redirect',
];

$joins = [
'LEFT JOIN {db_prefix}categories AS c ON (c.id_cat = b.id_cat)',
];

$order = [
'b.board_order',
];

$return_value = [];
$selected = null;

if (Db::$db->num_rows($request) !== 0) {
while ($row = Db::$db->fetch_assoc($request)) {
if (!isset($return_value[$row['id_cat']])) {
$return_value[$row['id_cat']] = [
'id' => $row['id_cat'],
'name' => $row['cat_name'],
'boards' => [],
];
}
if (isset($boardListOptions['selected_boards']) && \is_array($boardListOptions['selected_boards'])) {
$selected = array_flip($boardListOptions['selected_boards']);
} elseif (isset($boardListOptions['selected_board'])) {
$selected = [$boardListOptions['selected_board'] => true];
}

$return_value[$row['id_cat']]['boards'][$row['id_board']] = [
'id' => $row['id_board'],
'name' => $row['board_name'],
'child_level' => $row['child_level'],
'redirect' => $row['redirect'],
'selected' => isset($boardListOptions['selected_board']) && $boardListOptions['selected_board'] == $row['id_board'],
foreach (Board::queryData($selects, $params, $joins, $where, $order) as $row) {
if (!isset($return_value[$row['id_cat']])) {
$return_value[$row['id_cat']] = [
'id' => $row['id_cat'],
'name' => $row['cat_name'],
'boards' => [],
];
}
}
Db::$db->free_result($request);

Category::sort($return_value);
$return_value[$row['id_cat']]['boards'][$row['id_board']] = [
'id' => $row['id_board'],
'name' => $row['board_name'],
'child_level' => $row['child_level'],
'redirect' => $row['redirect'],
'selected' => $selected !== null && isset($selected[$row['id_board']]),
];
}

return $return_value;
}
Expand Down
53 changes: 12 additions & 41 deletions Sources/Actions/Profile/IgnoreBoards.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

use SMF\ActionInterface;
use SMF\ActionTrait;
use SMF\Actions\MessageIndex;
use SMF\Category;
use SMF\Config;
use SMF\Db\DatabaseApi as Db;
Expand Down Expand Up @@ -47,59 +48,29 @@ public function execute(): void

// Find all the boards this user is allowed to see.
Utils::$context['num_boards'] = 0;
Utils::$context['categories'] = [];

$request = Db::$db->query(
'SELECT b.id_cat, c.name AS cat_name, b.id_board, b.name, b.child_level,
' . (!empty(Profile::$member->data['ignore_boards']) ? 'b.id_board IN ({array_int:ignore_boards})' : '0') . ' AS is_ignored
FROM {db_prefix}boards AS b
LEFT JOIN {db_prefix}categories AS c ON (c.id_cat = b.id_cat)
WHERE {query_see_board}
AND redirect = {string:empty_string}',
[
'ignore_boards' => !empty(Profile::$member->data['ignore_boards']) ? explode(',', Profile::$member->data['ignore_boards']) : [],
'empty_string' => '',
],
identifier: 'order_by_board_order',
);

while ($row = Db::$db->fetch_assoc($request)) {
Utils::$context['num_boards']++;

// This category hasn't been set up yet..
if (!isset(Utils::$context['categories'][$row['id_cat']])) {
Utils::$context['categories'][$row['id_cat']] = [
'id' => $row['id_cat'],
'name' => $row['cat_name'],
'boards' => [],
];
}

// Set this board up, and let the template know when it's a child. (indent them..)
Utils::$context['categories'][$row['id_cat']]['boards'][$row['id_board']] = [
'id' => $row['id_board'],
'name' => $row['name'],
'child_level' => $row['child_level'],
'selected' => $row['is_ignored'],
];
}
Db::$db->free_result($request);

Category::sort(Utils::$context['categories']);
Utils::$context['categories'] = MessageIndex::getBoardList([
'use_permissions' => true,
'not_redirection' => true,
'selected_boards' = !empty(Profile::$member->data['ignore_boards'])
Comment thread
live627 marked this conversation as resolved.
Outdated
? explode(',', Profile::$member->data['ignore_boards'])
: [],
]);

// Now, let's sort the list of categories into the boards for templates that like that.
$temp_boards = [];

foreach (Utils::$context['categories'] as $category) {
foreach (Utils::$context['categories'] as $cat_id => $category) {
// Include a list of boards per category for easy toggling.
Utils::$context['categories'][$category['id']]['child_ids'] = array_keys($category['boards']);
Utils::$context['categories'][$cat_id]['child_ids'] = array_keys($category['boards']);

$temp_boards[] = [
'name' => $category['name'],
'child_ids' => array_keys($category['boards']),
];

$temp_boards = array_merge($temp_boards, array_values($category['boards']));

Utils::$context['num_boards'] += \count($category['boards']);
}

$max_boards = max(2, ceil(\count($temp_boards) / 2));
Expand Down
Loading