Kleinanzeigen-Plugin 1.0.0
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
commit
f05c44733f
50 changed files with 3854 additions and 0 deletions
68
src/KleinanzeigenPlugin.php
Normal file
68
src/KleinanzeigenPlugin.php
Normal file
|
|
@ -0,0 +1,68 @@
|
|||
<?php
|
||||
|
||||
namespace Inhaus\Plugins\Kleinanzeigen;
|
||||
|
||||
use App\Dashboard\Widgets;
|
||||
use App\Digest\Digest;
|
||||
use App\Editorial\Editorial;
|
||||
use App\Models\User;
|
||||
use App\Plugins\Plugin;
|
||||
use App\Search\GlobalSearch;
|
||||
use App\Support\Abilities;
|
||||
use App\Support\Navigation;
|
||||
use Carbon\CarbonImmutable;
|
||||
use Illuminate\Support\Facades\Schedule;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Inhaus\Plugins\Kleinanzeigen\Models\Listing;
|
||||
|
||||
/**
|
||||
* Kleinanzeigen – von Kolleginnen und Kollegen für Kolleginnen und Kollegen.
|
||||
*/
|
||||
class KleinanzeigenPlugin extends Plugin
|
||||
{
|
||||
public function register(): void
|
||||
{
|
||||
$this->app->make(Navigation::class)->add('kleinanzeigen', 'Kleinanzeigen', '/kleinanzeigen', active: 'kleinanzeigen.*', sort: 78);
|
||||
$this->app->make(Abilities::class)->define('kleinanzeigen.moderate', 'Kleinanzeigen freigeben und moderieren', 'Kleinanzeigen', portal: true);
|
||||
|
||||
$this->app->make(GlobalSearch::class)->add('kleinanzeigen', 'Kleinanzeigen', 'shopping-bag', function (User $user, string $search, int $limit) {
|
||||
$query = Listing::query()->visible();
|
||||
GlobalSearch::whereTerms($query, ['title', 'description', 'location'], $search);
|
||||
|
||||
return $query->latest('published_at')->limit($limit)->get()->map(fn (Listing $l) => [
|
||||
'title' => $l->title,
|
||||
'url' => '/kleinanzeigen/'.$l->id,
|
||||
'excerpt' => GlobalSearch::excerpt($l->description, $search),
|
||||
'meta' => collect([Listing::TYPES[$l->type], $l->priceLabel(), $l->location])->filter()->implode(' · '),
|
||||
])->all();
|
||||
}, sort: 70);
|
||||
|
||||
// Startseite: die neuesten Anzeigen
|
||||
$this->app->make(Widgets::class)->add('kleinanzeigen.latest', 'kleinanzeigen::Latest', 'aside', sort: 40, props: function () {
|
||||
$listings = Listing::query()->visible()->with('images')->latest('published_at')->limit(4)->get();
|
||||
|
||||
return $listings->isEmpty() ? null : ['listings' => $listings->map(fn (Listing $l) => Presenter::card($l))->all()];
|
||||
}, label: 'Kleinanzeigen', mobileSort: 45);
|
||||
|
||||
// Redaktion: was auf Freigabe wartet
|
||||
$this->app->make(Editorial::class)->add('kleinanzeigen', 'Kleinanzeigen', 'kleinanzeigen::EditorialListings', 36,
|
||||
fn (User $user) => $user->can('kleinanzeigen.moderate'),
|
||||
fn () => ['pending' => Listing::query()->where('status', 'pending')->with('images')->oldest('updated_at')->limit(20)->get()->map(fn (Listing $l) => Presenter::card($l))->all()]);
|
||||
|
||||
if (class_exists(Digest::class)) {
|
||||
$this->app->make(Digest::class)->add('kleinanzeigen', 'Neue Kleinanzeigen', 60, fn (User $user, CarbonImmutable $since) => Listing::query()
|
||||
->visible()->where('published_at', '>=', $since)->latest('published_at')->limit(6)->get()
|
||||
->map(fn (Listing $l) => ['title' => $l->title, 'url' => route('kleinanzeigen.show', $l), 'meta' => collect([Listing::TYPES[$l->type], $l->priceLabel()])->filter()->implode(' · ')])->all());
|
||||
}
|
||||
}
|
||||
|
||||
public function boot(): void
|
||||
{
|
||||
Schedule::call(fn () => $this->app->make(Market::class)->housekeeping())->dailyAt('06:10')->name('kleinanzeigen-housekeeping')->withoutOverlapping(30);
|
||||
}
|
||||
|
||||
public function uninstall(): void
|
||||
{
|
||||
Storage::disk(Photos::DISK)->deleteDirectory('kleinanzeigen');
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue