the browser-facing portion of osu!
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Allow sorting forum topics by creation date

nanaya bbbd76e9 ba99656e

+73 -30
+4 -1
app/Models/Forum/Topic.php
··· 424 424 $tieBreakerOrder = 'desc'; 425 425 426 426 switch ($sort) { 427 + case 'created': 428 + $query->orderBy('topic_time', 'desc'); 429 + break; 427 430 case 'feature-votes': 428 431 $query->orderBy('osu_starpriority', 'desc'); 429 432 break; 430 433 } 431 434 432 - $query->orderBy('topic_last_post_time', $tieBreakerOrder); 435 + return $query->orderBy('topic_last_post_time', $tieBreakerOrder); 433 436 } 434 437 435 438 public function scopeRecent($query, $params = null)
+38
database/migrations/2023_02_22_103305_add_create_time_index_to_forum_topics.php
··· 1 + <?php 2 + 3 + // Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the GNU Affero General Public License v3.0. 4 + // See the LICENCE file in the repository root for full licence text. 5 + 6 + declare(strict_types=1); 7 + 8 + use Illuminate\Database\Migrations\Migration; 9 + use Illuminate\Database\Schema\Blueprint; 10 + use Illuminate\Support\Facades\Schema; 11 + 12 + return new class extends Migration 13 + { 14 + /** 15 + * Run the migrations. 16 + */ 17 + public function up(): void 18 + { 19 + Schema::table('phpbb_topics', function (Blueprint $table) { 20 + $table->index([ 21 + 'forum_id', 22 + 'topic_type', 23 + DB::raw('topic_time DESC'), 24 + DB::raw('topic_last_post_time DESC'), 25 + ], 'created_sort'); 26 + }); 27 + } 28 + 29 + /** 30 + * Reverse the migrations. 31 + */ 32 + public function down(): void 33 + { 34 + Schema::table('phpbb_topics', function (Blueprint $table) { 35 + $table->dropIndex('created_sort'); 36 + }); 37 + } 38 + };
+1
resources/lang/en/sort.php
··· 32 32 ], 33 33 34 34 'forum_topics' => [ 35 + 'created' => 'Created', 35 36 'feature_votes' => 'Star priority', 36 37 'new' => 'Last reply', 37 38 ],
+30 -29
resources/views/forum/forums/_topics_sort.blade.php
··· 3 3 See the LICENCE file in the repository root for full licence text. 4 4 --}} 5 5 @php 6 - $menu = []; 6 + $menu = [ 7 + 'new' => [ 8 + 'url' => route('forum.forums.show', ['forum' => $forum]), 9 + 'title' => osu_trans('sort.forum_topics.new'), 10 + ], 11 + 'created' => [ 12 + 'url' => route('forum.forums.show', ['forum' => $forum, 'sort' => 'created']), 13 + 'title' => osu_trans('sort.forum_topics.created'), 14 + ] 15 + ]; 7 16 8 - if (optional($forum ?? null)->isFeatureForum()) { 17 + if ($forum?->isFeatureForum()) { 9 18 $menu['feature-votes'] = [ 10 19 'url' => route('forum.forums.show', ['forum' => $forum, 'sort' => 'feature-votes']), 11 20 'title' => osu_trans('sort.forum_topics.feature_votes'), 12 21 ]; 13 22 } 23 + 24 + if (!isset($sort) || !isset($menu[$sort])) { 25 + $sort = 'new'; 26 + } 14 27 @endphp 15 - @if (count($menu) > 0) 16 - @php 17 - $defaultMenu = ['new' => [ 18 - 'url' => route('forum.forums.show', ['forum' => $forum]), 19 - 'title' => osu_trans('sort.forum_topics.new'), 20 - ]]; 28 + <div class="sort sort--forum-topics"> 29 + <div class="sort__items"> 30 + <span class="sort__item sort__item--title">{{ osu_trans('sort._') }}</span> 21 31 22 - if (!isset($sort) || !isset($menu[$sort])) { 23 - $sort = 'new'; 24 - } 25 - @endphp 26 - <div class="sort sort--forum-topics"> 27 - <div class="sort__items"> 28 - <span class="sort__item sort__item--title">{{ osu_trans('sort._') }}</span> 29 - 30 - @foreach ($defaultMenu + $menu as $menuSort => $menuItem) 31 - <a 32 - class=" 33 - sort__item 34 - sort__item--button 35 - {{ ($sort ?? null) === $menuSort ? 'sort__item--active u-forum--link-text' : '' }} 36 - " 37 - href="{{ $menuItem['url'] }}#topics" 38 - >{{ $menuItem['title'] }} 39 - </a> 40 - @endforeach 41 - </div> 32 + @foreach ($menu as $menuSort => $menuItem) 33 + <a 34 + class=" 35 + sort__item 36 + sort__item--button 37 + {{ ($sort ?? null) === $menuSort ? 'sort__item--active u-forum--link-text' : '' }} 38 + " 39 + href="{{ $menuItem['url'] }}#topics" 40 + >{{ $menuItem['title'] }} 41 + </a> 42 + @endforeach 42 43 </div> 43 - @endif 44 + </div>