Skip to content

Commit

Permalink
Merge branch 'develop' into release
Browse files Browse the repository at this point in the history
  • Loading branch information
MrKrisKrisu committed Nov 7, 2021
2 parents 40ddc77 + aa3314d commit e076b83
Show file tree
Hide file tree
Showing 23 changed files with 175 additions and 115 deletions.
65 changes: 39 additions & 26 deletions app/Http/Controllers/Backend/LeaderboardController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
namespace App\Http\Controllers\Backend;

use App\Http\Controllers\Controller;
use App\Models\Status;
use App\Models\User;
use Carbon\Carbon;
use Illuminate\Database\Query\Builder;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\DB;
use InvalidArgumentException;
Expand Down Expand Up @@ -39,8 +39,16 @@ public static function getLeaderboard(

$query = DB::table('statuses')
->join('train_checkins', 'train_checkins.status_id', '=', 'statuses.id')
->join('users', 'statuses.user_id', '=', 'users.id')
->where('train_checkins.departure', '>=', $since->toIso8601String())
->where('train_checkins.departure', '<=', $until->toIso8601String())
->where(function(Builder $query) {
$query->where('users.private_profile', 0);
if (auth()->check()) {
$query->orWhereIn('users.id', auth()->user()->follows->pluck('id'))
->orWhere('users.id', auth()->user()->id);
}
})
->groupBy('statuses.user_id')
->select([
'statuses.user_id',
Expand All @@ -64,42 +72,47 @@ public static function getLeaderboard(
//Fetch user models in ONE query and map it to the collection
$userCache = User::whereIn('id', $data->pluck('user_id'))->get();

// ToDo: Levin, das Leaderboard gibt jetzt Schnelligkeit und Distance in meter aus. Bitte in vue anpassen.
// ToDo: Probably re-sort for new distance-calculation, etc.
return $data->map(function($row) use ($userCache) {
$row->user = $userCache->where('id', $row->user_id)->first();
return $row;
});
}

public static function getMonthlyLeaderboard(Carbon $date): Collection {
$data = Status::with(['trainCheckin', 'user'])
->join('train_checkins', 'train_checkins.status_id', '=', 'statuses.id')
->where(
'train_checkins.departure',
'>=',
$date->clone()->firstOfMonth()->toIso8601String()
)
->where(
'train_checkins.departure',
'<=',
$date->clone()->lastOfMonth()->endOfDay()->toIso8601String()
)
->select([
'statuses.user_id',
DB::raw('SUM(train_checkins.points) AS points'),
DB::raw('SUM(train_checkins.distance) AS distance'),
DB::raw(self::getDurationSelector() . ' AS duration'),
DB::raw('SUM(train_checkins.distance) / (' . self::getDurationSelector() . ' / 60) AS speed'),
])
->groupBy('user_id')
->orderByDesc('points')
->get();
$data = DB::table('statuses')
->join('train_checkins', 'train_checkins.status_id', '=', 'statuses.id')
->join('users', 'statuses.user_id', '=', 'users.id')
->where(
'train_checkins.departure',
'>=',
$date->clone()->firstOfMonth()->toIso8601String()
)
->where(
'train_checkins.departure',
'<=',
$date->clone()->lastOfMonth()->endOfDay()->toIso8601String()
)
->where(function(Builder $query) {
$query->where('users.private_profile', 0);
if (auth()->check()) {
$query->orWhereIn('users.id', auth()->user()->follows->pluck('id'))
->orWhere('users.id', auth()->user()->id);
}
})
->select([
'statuses.user_id',
DB::raw('SUM(train_checkins.points) AS points'),
DB::raw('SUM(train_checkins.distance) AS distance'),
DB::raw(self::getDurationSelector() . ' AS duration'),
DB::raw('SUM(train_checkins.distance) / (' . self::getDurationSelector() . ' / 60) AS speed'),
])
->groupBy('user_id')
->orderByDesc('points')
->get();

//Fetch user models in ONE query and map it to the collection
$userCache = User::whereIn('id', $data->pluck('user_id'))->get();

// ToDo: Levin, das Leaderboard gibt jetzt Schnelligkeit und Distance in meter aus. Bitte in vue anpassen.
return $data->map(function($row) use ($userCache) {
$row->user = $userCache->where('id', $row->user_id)->first();
return $row;
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/FrontendUserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public function searchUser(Request $request): Renderable|RedirectResponse {
$userSearchResponse = UserBackend::searchUser($request['searchQuery']);

if ($userSearchResponse->count() === 1) {
return redirect()->route('account.show', ['username' => $userSearchResponse->first()->username]);
return redirect()->route('profile', ['username' => $userSearchResponse->first()->username]);
}
} catch (HttpException) {
return redirect()->back();
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/SitemapController.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ private function addProfiles(Sitemap $sitemap): void {
->get();

foreach ($profiles as $profile) {
$url = Url::create(route('account.show', ['username' => $profile->username]))
$url = Url::create(route('profile', ['username' => $profile->username]))
->setPriority(0.5)
->setLastModificationDate(Carbon::parse($profile->last_mod))
->setChangeFrequency('weekly');
Expand Down
6 changes: 5 additions & 1 deletion app/Models/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ class Event extends Model
'end' => 'datetime',
];

/**
* @return HasOne
* @todo rename to ->trainStation when variable is renamed in database to train_station_id
*/
public function station(): HasOne {
return $this->hasOne(TrainStation::class, 'id', 'trainstation');
}
Expand All @@ -42,7 +46,7 @@ public function statuses(): HasMany {

/**
* @return TrainStation
* @deprecated Use ->trainstation relationship instead
* @deprecated Use ->station relationship instead
*/
public function getTrainstation(): TrainStation {
return TrainStation::where("id", "=", $this->trainstation)->first() ?? new TrainStation();
Expand Down
2 changes: 1 addition & 1 deletion app/Notifications/FollowRequestApproved.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public static function render(mixed $notification): ?string {
'icon' => 'fas fa-user-plus',
'lead' => __('notifications.userApprovedFollow.lead',
['followerRequestUsername' => $detail->sender->username]),
'link' => route('account.show', ['username' => $detail->sender->username]),
'link' => route('profile', ['username' => $detail->sender->username]),
'notice' => '',
'date_for_humans' => $notification->created_at->diffForHumans(),
'read' => $notification->read_at != null,
Expand Down
2 changes: 1 addition & 1 deletion app/Notifications/UserFollowed.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public static function render($notification): ?string {
'lead' => __('notifications.userFollowed.lead', [
'followerUsername' => $detail->sender->username
]),
"link" => route('account.show', ['username' => $detail->sender->username]),
"link" => route('profile', ['username' => $detail->sender->username]),
'notice' => "",
'date_for_humans' => $notification->created_at->diffForHumans(),
'read' => $notification->read_at != null,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class MakeUrlNullableAtEvents extends Migration
{
public function up(): void {
Schema::table('events', function(Blueprint $table) {
$table->string('url')->nullable()->change();
$table->string('host')->nullable()->change();
$table->unsignedBigInteger('trainstation')->nullable()->change();
});
}

public function down(): void {
Schema::table('events', function(Blueprint $table) {
$table->string('url')->change();
$table->string('host')->change();
$table->unsignedBigInteger('trainstation')->change();
});
}
}
72 changes: 37 additions & 35 deletions resources/views/events/overview.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,41 +21,43 @@
{{__('events.request-question')}}
</p>
@else
<table class="table" aria-describedby="heading-live-upcoming">
<tbody>
@foreach($liveAndUpcomingEvents as $event)
<tr>
<td>
{{$event->name}}
@if($event->getTrainstation() != null)
<br/>
<small class="text-muted">
{{__('events.closestStation')}}:
<a href="{{route('trains.stationboard', ['station' => $event->getTrainstation()->name])}}">
{{$event->getTrainstation()->name}}
</a>
</small>
@endif
</td>
<td>
@if($event->begin->isSameDay($event->end))
{{$event->begin->format('d.m.Y')}}
@else
{{$event->begin->format('d.m.Y')}}
- {{$event->end->format('d.m.Y')}}
@endif
</td>
<td>
<a class="btn btn-primary btn-sm"
href="{{route('statuses.byEvent', ['eventSlug' => $event->slug])}}">
{{__('menu.show-more')}}
<em class="fas fa-angle-double-right"></em>
</a>
</td>
</tr>
@endforeach
</tbody>
</table>
<div class="table-responsive">
<table class="table" aria-describedby="heading-live-upcoming">
<tbody>
@foreach($liveAndUpcomingEvents as $event)
<tr>
<td>
{{$event->name}}
@isset($event->station)
<br/>
<small class="text-muted">
{{__('events.closestStation')}}:
<a href="{{route('trains.stationboard', ['station' => $event->station->name])}}">
{{$event->station->name}}
</a>
</small>
@endisset
</td>
<td>
@if($event->begin->isSameDay($event->end))
{{$event->begin->format('d.m.Y')}}
@else
{{$event->begin->format('d.m.Y')}}
- {{$event->end->format('d.m.Y')}}
@endif
</td>
<td>
<a class="btn btn-primary btn-sm"
href="{{route('statuses.byEvent', ['eventSlug' => $event->slug])}}">
{{__('menu.show-more')}}
<em class="fas fa-angle-double-right"></em>
</a>
</td>
</tr>
@endforeach
</tbody>
</table>
</div>
{{$liveAndUpcomingEvents->links()}}
@endif
</div>
Expand Down
35 changes: 23 additions & 12 deletions resources/views/eventsMap.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<div class="text-white col-md-8 col-lg-7">
<h1 class="card-title font-bold">
<strong>{{ __('events.header', ['name' => $event->name]) }} <code
class="text-white">#{{ $event->hashtag }}</code></strong>
class="text-white">#{{ $event->hashtag }}</code></strong>
</h1>
<h2 class="h2-responsive">
<span class="font-weight-bold"><i class="fa fa-route d-inline"></i>&nbsp;{{
Expand All @@ -26,18 +26,29 @@ class="text-white">#{{ $event->hashtag }}</code></strong>
)
) !!}</span>
<br class="d-block d-sm-none">
<span class="font-weight-bold ps-sm-2">
<i class="fa fa-user"></i>&nbsp;{{ $event->host }}
</span>
<span class="font-weight-bold ps-sm-2">
<i class="fa fa-link text-white"></i>&nbsp;<a href="{{ $event->url }}"
class="text-white">{{ parse_url($event->url)['host'] }}</a>
</span>
</h2>
<h2 class="h2-responsive">
<span class="font-weight-bold"><i class="fa fa-train"></i></span>
<span class="font-weight-bold">{!! stationLink($event->getTrainstation()->name, "text-white") !!}</span>
@isset($event->host)
<span class="font-weight-bold ps-sm-2">
<i class="fa fa-user"></i>&nbsp;{{ $event->host }}
</span>
@endisset
@isset($event->url)
<span class="font-weight-bold ps-sm-2">
<i class="fa fa-link text-white"></i>&nbsp;
<a href="{{ $event->url }}" class="text-white">
{{ parse_url($event->url)['host'] }}
</a>
</span>
@endisset
</h2>

@isset($event->station)
<h2 class="h2-responsive">
<span class="font-weight-bold"><i class="fa fa-train"></i></span>
<span class="font-weight-bold">
{!! stationLink($event->station->name, "text-white") !!}
</span>
</h2>
@endisset
</div>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<tr>
<td>
<i class="fas fa-user" aria-hidden="true"></i>
<a href="{{ route('account.show', ['username' => $otherStatus->user->username]) }}">
<a href="{{ route('profile', ['username' => $otherStatus->user->username]) }}">
{{ '@' . $otherStatus->user->username }}
</a>
</td>
Expand Down
Loading

0 comments on commit e076b83

Please sign in to comment.