Skip to content

Commit

Permalink
Merge pull request #148 from Kurozora/anime-translations
Browse files Browse the repository at this point in the history
  • Loading branch information
kiritokatklian authored May 16, 2021
2 parents 292c9f0 + a78aea5 commit 417160c
Show file tree
Hide file tree
Showing 43 changed files with 1,079 additions and 308 deletions.
2 changes: 1 addition & 1 deletion app/Http/Controllers/AnimeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ public function search(SearchAnimeRequest $request): JsonResponse
$searchQuery = $request->input('query');

// Search for the Anime
$resultArr = Anime::kuroSearch($searchQuery, [
$resultArr = Anime::kSearch($searchQuery, [
'limit' => Anime::MAX_SEARCH_RESULTS
]);

Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/ForumThreadController.php
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ public function search(SearchThreadRequest $request): JsonResponse
$searchQuery = $request->input('query');

// Search for the thread
$threads = ForumThread::kuroSearch($searchQuery, [
$threads = ForumThread::kSearch($searchQuery, [
'limit' => ForumThread::MAX_SEARCH_RESULTS
]);

Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public function search(SearchUserRequest $request): JsonResponse
$searchQuery = $request->input('query');

// Search for the users
$users = User::kuroSearch($searchQuery, [
$users = User::kSearch($searchQuery, [
'limit' => User::MAX_SEARCH_RESULTS
]);

Expand Down
46 changes: 38 additions & 8 deletions app/Models/Anime.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@

use App\Enums\AnimeImageType;
use App\Enums\DayOfWeek;
use App\Traits\KuroSearchTrait;
use App\Traits\Searchable;
use Astrotomic\Translatable\Translatable;
use Auth;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Casts\AsArrayObject;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
Expand All @@ -23,8 +25,9 @@ class Anime extends KModel
{
use HasFactory,
HasSlug,
KuroSearchTrait,
LogsActivity;
LogsActivity,
Searchable,
Translatable;

// Maximum amount of returned search results
const MAX_SEARCH_RESULTS = 10;
Expand All @@ -50,6 +53,16 @@ class Anime extends KModel
const TABLE_NAME = 'animes';
protected $table = self::TABLE_NAME;

/**
* Translatable attributes.
*
* @var array
*/
public array $translatedAttributes = [
'title',
'synopsis',
];

/**
* Searchable rules.
*
Expand All @@ -58,8 +71,14 @@ class Anime extends KModel
protected $searchable = [
'columns' => [
'title' => 10,
'synopsis' => 5
]
'synopsis' => 5,
],
'joins' => [
'anime_translations' => [
'animes.id',
'anime_translations.anime_id'
],
],
];

/**
Expand All @@ -68,8 +87,9 @@ class Anime extends KModel
* @var array
*/
protected $casts = [
'synonym_title' => AsArrayObject::class,
'first_aired' => 'date',
'last_aired' => 'date'
'last_aired' => 'date',
];

/**
Expand All @@ -79,7 +99,7 @@ class Anime extends KModel
*/
protected $appends = [
'broadcast',
'information_summary'
'information_summary',
];

/**
Expand Down Expand Up @@ -111,7 +131,7 @@ protected static function boot()
public function getSlugOptions(): SlugOptions
{
return SlugOptions::create()
->generateSlugsFrom('title')
->generateSlugsFrom('original_title')
->saveSlugsTo('slug');
}

Expand Down Expand Up @@ -600,4 +620,14 @@ public function getStaff(?int $limit = null): mixed
return $this->staff()->limit($limit)->get();
});
}

/**
* The anime's translation relationship.
*
* @return HasMany
*/
public function anime_translations(): HasMany
{
return $this->hasMany(AnimeTranslation::class);
}
}
35 changes: 35 additions & 0 deletions app/Models/AnimeTranslation.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Relations\BelongsTo;

class AnimeTranslation extends KModel
{
use HasFactory;

// Table name
const TABLE_NAME = 'anime_translations';
protected $table = self::TABLE_NAME;

/**
* The language the translations belongs to.
*
* @return BelongsTo
*/
public function anime(): BelongsTo
{
return $this->belongsTo(Anime::class);
}

/**
* The language the translations belongs to.
*
* @return BelongsTo
*/
public function language(): BelongsTo
{
return $this->belongsTo(Language::class, 'locale', 'code');
}
}
6 changes: 3 additions & 3 deletions app/Models/ForumThread.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace App\Models;

use App\Traits\KuroSearchTrait;
use App\Traits\Searchable;
use Carbon\Carbon;
use Cog\Contracts\Love\Reactable\Models\Reactable as ReactableContract;
use Cog\Laravel\Love\Reactable\Models\Traits\Reactable;
Expand All @@ -13,8 +13,8 @@
class ForumThread extends KModel implements ReactableContract
{
use HasFactory,
KuroSearchTrait,
Reactable;
Reactable,
Searchable;

/**
* Searchable rules.
Expand Down
5 changes: 2 additions & 3 deletions app/Models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,12 @@
use App\Jobs\FetchSessionLocation;
use App\Notifications\NewSession;
use App\Traits\HeartActionTrait;
use App\Traits\KuroSearchTrait;
use App\Traits\MediaLibraryExtensionTrait;
use App\Traits\Searchable;
use App\Traits\User\HasBannerImage;
use App\Traits\User\HasProfileImage;
use App\Traits\VoteActionTrait;
use App\Traits\Web\Auth\TwoFactorAuthenticatable;
use Carbon\Carbon;
use Cog\Contracts\Love\Reacterable\Models\Reacterable as ReacterableContract;
use Cog\Laravel\Love\Reacterable\Models\Traits\Reacterable;
use App\Notifications\ResetPassword as ResetPasswordNotification;
Expand Down Expand Up @@ -49,11 +48,11 @@ class User extends Authenticatable implements HasMedia, MustVerifyEmail, Reacter
HasRoles,
HeartActionTrait,
InteractsWithMedia,
KuroSearchTrait,
LogsActivity,
MediaLibraryExtensionTrait,
Notifiable,
Reacterable,
Searchable,
TwoFactorAuthenticatable,
VoteActionTrait;

Expand Down
41 changes: 26 additions & 15 deletions app/Nova/Anime.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Laravel\Nova\Fields\BelongsTo;
use Laravel\Nova\Fields\BelongsToMany;
use Laravel\Nova\Fields\Boolean;
use Laravel\Nova\Fields\Code;
use Laravel\Nova\Fields\Date;
use Laravel\Nova\Fields\HasMany;
use Laravel\Nova\Fields\Heading;
Expand Down Expand Up @@ -101,18 +102,31 @@ public function fields(Request $request): array
->onlyOnForms()
->help('Used to identify the Anime in a URL: https://kurozora.app/anime/<strong>wolf-children</strong>. Leave empty to auto-generate from title.'),

Text::make('Title')
Text::make('Title', 'original_title')
->sortable()
->required(),

Code::make('Synonym Titles')
->json()
->sortable()
->help('Other names the anime is known by globally.')
->rules(['nullable', 'json']),

Text::make('Title Translations', 'title')
->hideFromIndex()
->sortable()
->rules('required')
->sortable(),
->translatable(),

Textarea::make('Synopsis Translations')
->help('A short description of the Anime.')
->rules('required')
->translatable(),

Text::make('Tagline')
->rules('max:255')
->hideFromIndex(),

Textarea::make('Synopsis')
->hideFromIndex()
->help('A short description of the Anime.'),

BelongsTo::make('Source')
->sortable()
->help('The adaptation source of the anime. For example Manga, Game, Original, etc. If no source is available, especially for older anime, then choose Unknown.')
Expand Down Expand Up @@ -176,7 +190,8 @@ public function fields(Request $request): array
Time::make('Air time')
->withTwelveHourTime()
->hideFromIndex()
->help('The exact time the show airs at. For example: 1:30 PM (13:30)'),
->help('The exact time the show airs at. For example: 1:30 PM (13:30)')
->nullable(),

Select::make('Air day')
->options(DayOfWeek::asSelectArray())
Expand All @@ -190,7 +205,9 @@ public function fields(Request $request): array
->hideFromIndex()
->help('For example: © ' . date('Y') . ' Kurozora B.V.'),

HasMany::make('Anime Images'),
HasMany::make('Translations', 'anime_translations', AnimeTranslation::class),

HasMany::make('Images', 'anime_images', AnimeImage::class),

HasMany::make('Genres', 'media_genres', MediaGenre::class),

Expand Down Expand Up @@ -226,13 +243,7 @@ public function fields(Request $request): array
*/
public function title(): string
{
$animeName = $this->title;

if (!is_string($animeName) || !strlen($animeName)) {
$animeName = 'No Anime title';
}

return $animeName . ' (ID: ' . $this->id . ')';
return $this->original_title . ' (ID: ' . $this->id . ')';
}

/**
Expand Down
Loading

0 comments on commit 417160c

Please sign in to comment.