This commit is contained in:
@@ -3,7 +3,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace App;
|
||||
|
||||
use App\Avatar\Lorelei;
|
||||
use App\Avatar\AvatarManager;
|
||||
|
||||
final class Community
|
||||
{
|
||||
@@ -152,8 +152,9 @@ final class Community
|
||||
|
||||
$where = $conditions ? ('AND ' . implode(' AND ', $conditions)) : '';
|
||||
|
||||
$avatarSelect = $this->hasColumn('user_profiles', 'avatar_preset')
|
||||
? ', ' . Lorelei::selectColumns('p')
|
||||
$avatarColumns = $this->avatarProfileSelect('p');
|
||||
$avatarSelect = $avatarColumns !== ''
|
||||
? ', ' . $avatarColumns
|
||||
: '';
|
||||
$sql = "SELECT ft.id, ft.title, ft.body, ft.created_at, ft.updated_at,
|
||||
u.id as uid, u.created_at as user_created,
|
||||
@@ -208,8 +209,9 @@ final class Community
|
||||
public function getThread(int $id): ?array
|
||||
{
|
||||
$select = 'ft.*, p.display_name';
|
||||
if ($this->hasColumn('user_profiles', 'avatar_preset')) {
|
||||
$select .= ', ' . Lorelei::selectColumns('p');
|
||||
$avatarColumns = $this->avatarProfileSelect('p');
|
||||
if ($avatarColumns !== '') {
|
||||
$select .= ', ' . $avatarColumns;
|
||||
}
|
||||
$join = '';
|
||||
if ($this->hasColumn('forum_threads', 'board_id') && $this->hasTable('forum_boards') && $this->hasTable('forum_categories')) {
|
||||
@@ -228,8 +230,9 @@ final class Community
|
||||
public function listPosts(int $threadId): array
|
||||
{
|
||||
$select = 'fp.*, p.display_name';
|
||||
if ($this->hasColumn('user_profiles', 'avatar_preset')) {
|
||||
$select .= ', ' . Lorelei::selectColumns('p');
|
||||
$avatarColumns = $this->avatarProfileSelect('p');
|
||||
if ($avatarColumns !== '') {
|
||||
$select .= ', ' . $avatarColumns;
|
||||
}
|
||||
if ($this->hasColumn('forum_posts', 'highlighted_at')) {
|
||||
$select .= ', hp.display_name AS highlighted_by_name';
|
||||
@@ -538,4 +541,17 @@ final class Community
|
||||
return $this->columnCache[$key] = false;
|
||||
}
|
||||
}
|
||||
|
||||
private function avatarProfileSelect(string $alias): string
|
||||
{
|
||||
$columns = [];
|
||||
|
||||
foreach (AvatarManager::allProfileColumns() as $column) {
|
||||
if ($this->hasColumn('user_profiles', $column)) {
|
||||
$columns[] = $alias . '.' . $column;
|
||||
}
|
||||
}
|
||||
|
||||
return implode(', ', $columns);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user