Files
einundzwanzig-portal/app/Observers/LibraryItemObserver.php
HolgerHatGarKeineNode 235ce774f9 nostr events added
2023-02-24 11:13:43 +01:00

70 lines
1.6 KiB
PHP

<?php
namespace App\Observers;
use App\Enums\LibraryItemType;
use App\Models\LibraryItem;
use App\Traits\NostrTrait;
use Exception;
use Illuminate\Support\Facades\Log;
class LibraryItemObserver
{
use NostrTrait;
/**
* Handle the LibraryItem "created" event.
*/
public function created(LibraryItem $libraryItem): void
{
try {
$libraryItem->setStatus('published');
$from = $libraryItem->name;
$from .= ' von '.$libraryItem->lecturer->name;
if ($libraryItem->type !== LibraryItemType::MarkdownArticle()) {
if ($libraryItem->whereDoesntHave('libraries',
fn($query) => $query->where('libraries.is_public', false))
->exists()) {
$this->publishOnNostr($libraryItem, $this->getText('LibraryItem', $from));
}
}
} catch (Exception $e) {
Log::error($e->getMessage());
}
}
/**
* Handle the LibraryItem "updated" event.
*/
public function updated(LibraryItem $libraryItem): void
{
//
}
/**
* Handle the LibraryItem "deleted" event.
*/
public function deleted(LibraryItem $libraryItem): void
{
//
}
/**
* Handle the LibraryItem "restored" event.
*/
public function restored(LibraryItem $libraryItem): void
{
//
}
/**
* Handle the LibraryItem "force deleted" event.
*/
public function forceDeleted(LibraryItem $libraryItem): void
{
//
}
}