the browser-facing portion of osu!
at master 2.2 kB view raw
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 6namespace App\Libraries; 7 8use App\Models\Forum\Forum; 9use App\Models\Forum\Post; 10use App\Models\Forum\TopicCover; 11use App\Models\User; 12use App\Transformers\Forum\TopicCoverTransformer; 13use Carbon\Carbon; 14 15class NewForumTopic 16{ 17 public function __construct(private Forum $forum, private ?User $user) 18 { 19 } 20 21 public function cover() 22 { 23 $cover = new TopicCover(); 24 $cover->newForumId = $this->forum->getKey(); 25 26 return json_item($cover, new TopicCoverTransformer()); 27 } 28 29 public function post() 30 { 31 $body = null; 32 33 if ($this->forum->isHelpForum()) { 34 $client = $this->user->clients()->last('timestamp'); 35 36 $buildName = ''; 37 38 if ($client !== null && $client->build !== null && $client->build->updateStream !== null) { 39 $build = $client->build; 40 $stream = $build->updateStream; 41 $buildName = $stream->pretty_name.' '.$build->displayVersion(); 42 if ($client->isLatest()) { 43 $buildName .= ' (latest)'; 44 } 45 } 46 47 // In English language forum, no localization. 48 $body = 'Problem details:'; 49 $body .= "\n\n\n"; 50 $body .= 'Video or screenshot showing the problem:'; 51 $body .= "\n\n\n"; 52 $body .= "osu! version: {$buildName}"; 53 } 54 55 return new Post([ 56 'post_text' => $body, 57 'user' => $this->user, 58 'post_time' => Carbon::now(), 59 ]); 60 } 61 62 public function titlePlaceholder(): ?string 63 { 64 return $this->forum->isHelpForum() 65 // In English language forum, no localization. 66 ? 'What is your problem (50 characters)' 67 : null; 68 } 69 70 public function toArray() 71 { 72 return [ 73 'cover' => $this->cover(), 74 'forum' => $this->forum, 75 'post' => $this->post(), 76 'titlePlaceholder' => $this->titlePlaceholder(), 77 ]; 78 } 79}