Skip to content

Commit

Permalink
feat(nova): attach audio to related videos action (#616)
Browse files Browse the repository at this point in the history
  • Loading branch information
Kyrch authored Feb 3, 2024
1 parent 55301d3 commit 1d1509b
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?php

declare(strict_types=1);

namespace App\Nova\Actions\Models\Wiki\Audio;

use App\Models\Wiki\Anime\Theme\AnimeThemeEntry;
use App\Models\Wiki\Audio;
use App\Models\Wiki\Video;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Log;
use Laravel\Nova\Actions\Action;
use Laravel\Nova\Fields\ActionFields;

/**
* Class AttachAudioToRelatedVideosAction.
*/
class AttachAudioToRelatedVideosAction extends Action implements ShouldQueue
{
/**
* Create a new action instance.
*/
public function __construct()
{
}

/**
* Get the displayable name of the action.
*
* @return string
*
* @noinspection PhpMissingParentCallCommonInspection
*/
public function name(): string
{
return __('nova.actions.audio.attach_related_videos.name');
}

/**
* Perform the action on the given models.
*
* @param ActionFields $fields
* @param Collection<int, Audio> $models
* @return Collection
*/
public function handle(ActionFields $fields, Collection $models): Collection
{
$audio = $models->first();
$video = $audio->videos()->first();

$video->animethemeentries()->each(function (AnimeThemeEntry $firstEntry) use ($audio) {
$theme = $firstEntry->animetheme()->first();

$theme->animethemeentries->each(function (AnimeThemeEntry $entry) use ($audio) {
$entry->videos->each(function (Video $video) use ($audio) {
Log::info("Associating Audio '{$audio->filename}' with Video '{$video->filename}'");
$video->audio()->associate($audio)->save();
});
});
});

return $models;
}
}
7 changes: 7 additions & 0 deletions app/Nova/Resources/Wiki/Audio.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace App\Nova\Resources\Wiki;

use App\Models\Wiki\Audio as AudioModel;
use App\Nova\Actions\Models\Wiki\Audio\AttachAudioToRelatedVideosAction;
use App\Nova\Actions\Repositories\Storage\Wiki\Audio\ReconcileAudioAction;
use App\Nova\Actions\Storage\Wiki\Audio\DeleteAudioAction;
use App\Nova\Actions\Storage\Wiki\Audio\MoveAudioAction;
Expand Down Expand Up @@ -208,6 +209,12 @@ public function actions(NovaRequest $request): array
->onlyOnIndex()
->standalone()
->canSeeWhen('create', AudioModel::class),

(new AttachAudioToRelatedVideosAction())
->confirmButtonText(__('nova.actions.base.confirmButtonText'))
->cancelButtonText(__('nova.actions.base.cancelButtonText'))
->exceptOnIndex()
->canSeeWhen('create', AudioModel::class),
]
);
}
Expand Down
3 changes: 3 additions & 0 deletions lang/en/nova.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@
'upload' => [
'name' => 'Upload Audio',
],
'attach_related_videos' => [
'name' => 'Attach Audio to Related Videos',
],
],
'base' => [
'cancelButtonText' => 'Cancel',
Expand Down

0 comments on commit 1d1509b

Please sign in to comment.