Neues Modul Interne Stellenausschreibungen (0.28.0)
Some checks failed
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 6m18s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 7m1s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 5m33s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 5m8s
CI / PHP 8.3 / mysql:8.0 (pull_request) Failing after 6m42s
CI / PHP 8.4 / mysql:8.0 (pull_request) Failing after 6m37s
CI / PHP 8.3 / mysql:8.4 (pull_request) Failing after 5m43s
CI / PHP 8.4 / mysql:8.4 (pull_request) Failing after 5m38s
CI / Build-Artefakte aktuell (pull_request) Successful in 1m10s

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Friederich Loheide 2026-09-27 10:16:48 +00:00
parent b322b97f32
commit 993d49c99c
146 changed files with 1981 additions and 305 deletions

View file

@ -0,0 +1,40 @@
<?php
namespace Inhaus\Plugins\Stellen;
use App\Models\User;
use App\Notifications\PortalNotification;
use Illuminate\Support\Facades\Notification;
use Inhaus\Plugins\Stellen\Models\JobPosting;
/**
* Neue Stellen einmalig ankündigen (Glocke und Push an alle aktiven Personen).
* Geplante Stellen werden angekündigt, sobald sie erscheinen.
*/
class Announcer
{
public function announceIfDue(JobPosting $posting): void
{
if ($posting->announced_at !== null || ! $posting->isOpen()) {
return;
}
$posting->forceFill(['announced_at' => now()])->save();
$notification = new PortalNotification(
'Neue interne Stelle: '.$posting->title,
collect([$posting->department, $posting->location, $posting->summary()])->filter()->implode(' · '),
route('jobs.show', $posting, false),
'briefcase',
);
User::query()->active()->whereKeyNot($posting->created_by ?? 0)->chunkById(500, fn ($users) => Notification::send($users, $notification));
}
public function announceDue(): int
{
$due = JobPosting::query()->open()->whereNull('announced_at')->get();
$due->each(fn (JobPosting $posting) => $this->announceIfDue($posting));
return $due->count();
}
}

View file

@ -0,0 +1,143 @@
<?php
namespace Inhaus\Plugins\Stellen\Http\Controllers;
use App\Http\Controllers\Controller;
use App\Models\User;
use App\Notifications\PortalNotification;
use App\Support\Audit;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Mail;
use Illuminate\Support\Facades\Notification;
use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Str;
use Illuminate\Validation\Rules\File;
use Inertia\Inertia;
use Inertia\Response;
use Inhaus\Plugins\Stellen\Mail\ApplicationReceived;
use Inhaus\Plugins\Stellen\Models\JobApplication;
use Inhaus\Plugins\Stellen\Models\JobPosting;
use Inhaus\Plugins\Stellen\Presenter;
use Symfony\Component\HttpFoundation\StreamedResponse;
class JobController extends Controller
{
public const EXTENSIONS = ['pdf', 'doc', 'docx', 'odt'];
public function index(Request $request): Response
{
$postings = JobPosting::query()->open()->orderByDesc('published_at')->get();
$applied = JobApplication::query()->where('user_id', $request->user()->id)->pluck('posting_id')->all();
return Inertia::render('stellen::Index', [
'postings' => $postings->map(fn (JobPosting $p) => [...Presenter::card($p), 'applied' => in_array($p->id, $applied, true)])->values(),
'filters' => [
'departments' => $postings->pluck('department')->filter()->unique()->sort()->values(),
'locations' => $postings->pluck('location')->filter()->unique()->sort()->values(),
'employments' => collect(JobPosting::EMPLOYMENT)->only($postings->pluck('employment')->unique())->map(fn ($label, $value) => ['value' => $value, 'label' => $label])->values(),
],
'canManage' => $request->user()->can('jobs.manage'),
'myApplications' => count($applied),
]);
}
public function show(Request $request, JobPosting $posting): Response
{
$user = $request->user();
abort_unless($posting->isOpen() || $user->can('jobs.manage') || $posting->canSeeApplications($user), 404);
$mine = JobApplication::query()->where('posting_id', $posting->id)->where('user_id', $user->id)->first();
return Inertia::render('stellen::Show', [
'posting' => Presenter::detail($posting->load('contact'), $user),
'application' => $mine ? Presenter::application($mine) : null,
'canApply' => $posting->isOpen() && $posting->apply_mode === 'online' && ! $mine,
'editUrl' => $user->can('jobs.manage') ? route('jobs.edit', $posting) : null,
'applicationsUrl' => $posting->canSeeApplications($user) ? route('jobs.applications', $posting) : null,
'applicationsCount' => $posting->canSeeApplications($user) ? $posting->applications()->count() : null,
'accept' => '.'.implode(',.', self::EXTENSIONS),
]);
}
public function pdf(Request $request, JobPosting $posting): StreamedResponse
{
abort_unless($posting->pdf_path && ($posting->isOpen() || $request->user()->can('jobs.manage') || $posting->canSeeApplications($request->user())), 404);
return Storage::disk(JobPosting::DISK)->response($posting->pdf_path, $posting->pdf_name, ['Content-Type' => 'application/pdf', 'X-Content-Type-Options' => 'nosniff']);
}
public function apply(Request $request, JobPosting $posting): RedirectResponse
{
abort_unless($posting->isOpen() && $posting->apply_mode === 'online', 404);
$user = $request->user();
abort_if(JobApplication::query()->where('posting_id', $posting->id)->where('user_id', $user->id)->exists(), 422, 'Sie haben sich bereits beworben.');
$data = $request->validate([
'message' => ['nullable', 'string', 'max:5000', 'required_without:file'],
'file' => ['nullable', File::types(self::EXTENSIONS)->max(10 * 1024)],
], ['message.required_without' => 'Bitte eine Nachricht schreiben oder eine Datei anhängen.', 'file.mimes' => 'Bitte eine PDF-, Word- oder OpenDocument-Datei anhängen.'], ['message' => 'Nachricht', 'file' => 'Anhang']);
$file = $request->file('file');
$application = JobApplication::query()->create([
'posting_id' => $posting->id,
'user_id' => $user->id,
'message' => filled($data['message'] ?? null) ? trim($data['message']) : null,
'file_path' => $file?->storeAs('stellen/bewerbungen/'.$posting->id, Str::random(32).'.'.strtolower($file->getClientOriginalExtension()), JobPosting::DISK),
'file_name' => $file ? Str::limit(preg_replace('/[^\pL\pN ._()\-]+/u', '_', $file->getClientOriginalName()) ?: 'bewerbung', 180, '') : null,
]);
Audit::log('jobs.applied', ['posting' => $posting->id, 'application' => $application->id]);
$this->notifyRecipients($posting, $application, $user);
return back()->with('status', 'Danke – Ihre Bewerbung ist eingegangen. Den Stand sehen Sie hier und unter „Meine Bewerbungen“.');
}
public function withdraw(Request $request, JobApplication $application): RedirectResponse
{
abort_unless($application->user_id === $request->user()->id, 403);
$application->delete();
Audit::log('jobs.withdrawn', ['posting' => $application->posting_id]);
return back()->with('status', 'Ihre Bewerbung wurde zurückgezogen und gelöscht.');
}
public function mine(Request $request): Response
{
$applications = JobApplication::query()->where('user_id', $request->user()->id)->with('posting')->latest()->get();
return Inertia::render('stellen::Mine', [
'applications' => $applications->map(fn (JobApplication $a) => [...Presenter::application($a), 'posting' => Presenter::card($a->posting)])->values(),
]);
}
public function file(Request $request, JobApplication $application): StreamedResponse
{
$user = $request->user();
abort_unless($application->file_path && ($application->user_id === $user->id || $application->posting->canSeeApplications($user)), 404);
return Storage::disk(JobPosting::DISK)->download($application->file_path, $application->file_name, ['X-Content-Type-Options' => 'nosniff']);
}
/**
* Ansprechperson der Stelle – ohne sie alle mit „Bewerbungen einsehen“ – im Portal,
* dazu optional per E-Mail (ohne Anhang, nur mit Link ins Portal).
*/
private function notifyRecipients(JobPosting $posting, JobApplication $application, User $applicant): void
{
$recipients = $posting->contact?->is_active
? collect([$posting->contact])
: User::query()->active()->whereHas('roles.grants', fn ($g) => $g->where('ability', 'jobs.applications'))->get();
Notification::send($recipients, new PortalNotification(
'Neue Bewerbung: '.$posting->title,
$applicant->name.($applicant->department ? ' ('.$applicant->department.')' : '').' hat sich beworben.',
route('jobs.applications', $posting, false),
'briefcase',
));
if ($posting->notify_email) {
Mail::to($posting->notify_email)->queue(new ApplicationReceived($posting, $applicant));
}
}
}

View file

@ -0,0 +1,203 @@
<?php
namespace Inhaus\Plugins\Stellen\Http\Controllers;
use App\Http\Controllers\Controller;
use App\Notifications\PortalNotification;
use App\Pagebuilder\Field;
use App\Support\Audit;
use App\Support\RichText;
use Carbon\Carbon;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Str;
use Illuminate\Validation\Rule;
use Illuminate\Validation\Rules\File;
use Inertia\Inertia;
use Inertia\Response;
use Inhaus\Plugins\Stellen\Announcer;
use Inhaus\Plugins\Stellen\Models\JobApplication;
use Inhaus\Plugins\Stellen\Models\JobPosting;
use Inhaus\Plugins\Stellen\Presenter;
/**
* Stellen ausschreiben und Bewerbungen bearbeiten (Personalabteilung).
*/
class JobEditorController extends Controller
{
public function create(Request $request): Response
{
$this->authorizeManage($request);
return $this->editor(null);
}
public function edit(Request $request, JobPosting $posting): Response
{
$this->authorizeManage($request);
return $this->editor($posting->load('contact'));
}
public function store(Request $request, Announcer $announcer): RedirectResponse
{
$this->authorizeManage($request);
$posting = JobPosting::query()->create([...$this->validated($request), 'created_by' => $request->user()->id, 'updated_by' => $request->user()->id]);
$this->storePdf($request, $posting);
Audit::log('jobs.created', ['posting' => $posting->id, 'title' => $posting->title]);
$announcer->announceIfDue($posting);
return to_route('jobs.show', $posting)->with('status', $posting->isOpen() ? 'Stelle veröffentlicht – alle werden benachrichtigt.' : 'Stelle gespeichert.');
}
public function update(Request $request, JobPosting $posting, Announcer $announcer): RedirectResponse
{
$this->authorizeManage($request);
$posting->update([...$this->validated($request), 'updated_by' => $request->user()->id]);
$this->storePdf($request, $posting);
Audit::log('jobs.updated', ['posting' => $posting->id, 'title' => $posting->title]);
$announcer->announceIfDue($posting);
return to_route('jobs.show', $posting)->with('status', 'Stelle gespeichert.');
}
public function destroy(Request $request, JobPosting $posting): RedirectResponse
{
$this->authorizeManage($request);
$posting->delete();
Audit::log('jobs.deleted', ['posting' => $posting->id, 'title' => $posting->title]);
return to_route('jobs.index')->with('status', 'Stelle „'.$posting->title.'“ und ihre Bewerbungen gelöscht.');
}
public function applications(Request $request, JobPosting $posting): Response
{
abort_unless($posting->canSeeApplications($request->user()), 403);
return Inertia::render('stellen::Applications', [
'posting' => Presenter::card($posting),
'applications' => $posting->applications()->with('user')->latest()->get()->map(fn (JobApplication $a) => Presenter::application($a, withPerson: true))->values(),
'statuses' => collect(JobApplication::STATUSES)->map(fn ($label, $value) => ['value' => $value, 'label' => $label])->values(),
]);
}
public function updateApplication(Request $request, JobApplication $application): RedirectResponse
{
abort_unless($application->posting->canSeeApplications($request->user()), 403);
$data = $request->validate(['status' => ['required', Rule::in(array_keys(JobApplication::STATUSES))], 'note' => ['nullable', 'string', 'max:5000']]);
$changed = $application->status !== $data['status'];
$application->update($data);
Audit::log('jobs.application_updated', ['application' => $application->id, 'status' => $data['status']]);
// Die bewerbende Person sieht den neuen Stand (nicht die interne Notiz)
if ($changed) {
$application->user?->notify(new PortalNotification(
'Ihre Bewerbung: '.$application->posting->title,
'Neuer Stand: '.JobApplication::STATUSES[$data['status']].'.',
route('jobs.mine', [], false),
'briefcase',
));
}
return back()->with('status', 'Gespeichert.');
}
private function editor(?JobPosting $posting): Response
{
return Inertia::render('stellen::Editor', [
'posting' => $posting ? [
...$posting->only(['id', 'title', 'department', 'location', 'employment', 'hours', 'contract', 'contract_note', 'pay_grade', 'start', 'description', 'apply_mode', 'apply_url', 'notify_email']),
'deadline' => $posting->deadline?->toDateString(),
'published_at' => $posting->published_at?->format('Y-m-d\TH:i'),
'status' => $posting->status(),
'pdf_name' => $posting->pdf_name,
'contact' => $posting->contact ? ['id' => $posting->contact->id, 'name' => $posting->contact->name, 'initials' => $posting->contact->initials, 'job_title' => $posting->contact->job_title, 'avatar_url' => $posting->contact->avatarUrl(96)] : null,
'applications' => $posting->applications()->count(),
] : null,
'options' => [
'employment' => collect(JobPosting::EMPLOYMENT)->map(fn ($label, $value) => ['value' => $value, 'label' => $label])->values(),
'contract' => collect(JobPosting::CONTRACT)->map(fn ($label, $value) => ['value' => $value, 'label' => $label])->values(),
'apply_modes' => collect(JobPosting::APPLY_MODES)->map(fn ($label, $value) => ['value' => $value, 'label' => $label])->values(),
'departments' => JobPosting::query()->whereNotNull('department')->distinct()->orderBy('department')->pluck('department'),
'locations' => JobPosting::query()->whereNotNull('location')->distinct()->orderBy('location')->pluck('location'),
],
]);
}
/**
* @return array<string, mixed>
*/
private function validated(Request $request): array
{
$data = $request->validate([
'title' => ['required', 'string', 'max:200'],
'department' => ['nullable', 'string', 'max:150'],
'location' => ['nullable', 'string', 'max:150'],
'employment' => ['required', Rule::in(array_keys(JobPosting::EMPLOYMENT))],
'hours' => ['nullable', 'string', 'max:60'],
'contract' => ['required', Rule::in(array_keys(JobPosting::CONTRACT))],
'contract_note' => ['nullable', 'string', 'max:120'],
'pay_grade' => ['nullable', 'string', 'max:60'],
'start' => ['nullable', 'string', 'max:60'],
'deadline' => ['nullable', 'date'],
'description' => ['nullable', 'string', 'max:200000'],
'apply_mode' => ['required', Rule::in(array_keys(JobPosting::APPLY_MODES))],
'apply_url' => ['nullable', 'required_if:apply_mode,link', 'string', 'max:1000'],
'contact_id' => ['nullable', 'integer', Rule::exists('users', 'id')],
'notify_email' => ['nullable', 'email', 'max:190'],
'publish' => ['required', Rule::in(['draft', 'now', 'at'])],
'published_at' => ['nullable', 'required_if:publish,at', 'date'],
'pdf' => ['nullable', File::types(['pdf'])->max(20 * 1024)],
'remove_pdf' => ['boolean'],
], ['apply_url.required_if' => 'Bitte die Adresse angeben, unter der man sich bewirbt.', 'published_at.required_if' => 'Bitte Datum und Uhrzeit angeben.'], [
'title' => 'Titel', 'deadline' => 'Bewerbungsfrist', 'apply_url' => 'Link', 'notify_email' => 'E-Mail', 'pdf' => 'PDF',
]);
$url = $data['apply_mode'] === 'link' ? Field::safeUrl($data['apply_url'] ?? '') : '';
return [
'title' => trim($data['title']),
...collect($data)->only(['department', 'location', 'hours', 'contract_note', 'pay_grade', 'start'])->map(fn ($v) => filled($v) ? trim($v) : null)->all(),
'employment' => $data['employment'],
'contract' => $data['contract'],
'deadline' => $data['deadline'] ?? null,
'description' => filled($data['description'] ?? null) ? app(RichText::class)->sanitize($data['description']) : null,
'apply_mode' => $data['apply_mode'],
'apply_url' => $url !== '' ? $url : null,
'contact_id' => $data['contact_id'] ?? null,
'notify_email' => $data['notify_email'] ?? null,
'published_at' => match ($data['publish']) {
'now' => $request->route('posting')?->published_at?->isPast() ? $request->route('posting')->published_at : now(),
'at' => Carbon::parse($data['published_at']),
default => null,
},
];
}
private function storePdf(Request $request, JobPosting $posting): void
{
if ($request->boolean('remove_pdf') || $request->hasFile('pdf')) {
if ($posting->pdf_path) {
Storage::disk(JobPosting::DISK)->delete($posting->pdf_path);
}
$posting->forceFill(['pdf_path' => null, 'pdf_name' => null]);
}
if ($file = $request->file('pdf')) {
$posting->forceFill([
'pdf_path' => $file->storeAs('stellen/ausschreibungen', Str::random(32).'.pdf', JobPosting::DISK),
'pdf_name' => Str::limit(preg_replace('/[^\pL\pN ._()\-]+/u', '_', $file->getClientOriginalName()) ?: 'ausschreibung.pdf', 180, ''),
]);
}
$posting->save();
}
private function authorizeManage(Request $request): void
{
abort_unless($request->user()->can('jobs.manage'), 403);
}
}

View file

@ -0,0 +1,27 @@
<?php
namespace Inhaus\Plugins\Stellen;
use App\Models\User;
use App\Search\GlobalSearch;
use Inhaus\Plugins\Stellen\Models\JobPosting;
/** Suchquelle: offene Stellen */
class JobSearch
{
/**
* @return list<array<string, mixed>>
*/
public function __invoke(User $user, string $search, int $limit): array
{
$query = JobPosting::query()->open();
GlobalSearch::whereTerms($query, ['title', 'department', 'location', 'description'], $search);
return $query->orderByDesc('published_at')->limit($limit)->get()->map(fn (JobPosting $p) => [
'title' => $p->title,
'url' => '/stellen/'.$p->id,
'excerpt' => GlobalSearch::excerpt(strip_tags((string) $p->description), $search),
'meta' => collect([$p->department, $p->location, $p->deadline ? 'Frist '.$p->deadline->format('d.m.Y') : null])->filter()->implode(' · '),
])->all();
}
}

View file

@ -0,0 +1,37 @@
<?php
namespace Inhaus\Plugins\Stellen\Mail;
use App\Models\User;
use App\Support\Branding;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Mail\Mailable;
use Illuminate\Mail\Mailables\Content;
use Illuminate\Mail\Mailables\Envelope;
use Illuminate\Queue\SerializesModels;
use Inhaus\Plugins\Stellen\Models\JobPosting;
/**
* Hinweis auf eine neue Bewerbung – ohne Anhang, die Unterlagen liegen vertraulich im Portal.
*/
class ApplicationReceived extends Mailable implements ShouldQueue
{
use Queueable;
use SerializesModels;
public function __construct(public JobPosting $posting, public User $applicant) {}
public function envelope(): Envelope
{
return new Envelope(subject: 'Neue Bewerbung: '.$this->posting->title, replyTo: [$this->applicant->email]);
}
public function content(): Content
{
return new Content(view: 'stellen::mail.application', with: [
'portalName' => app(Branding::class)->portalName(),
'url' => route('jobs.applications', $this->posting),
]);
}
}

View file

@ -0,0 +1,49 @@
<?php
namespace Inhaus\Plugins\Stellen\Models;
use App\Models\User;
use Illuminate\Database\Eloquent\Attributes\Fillable;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Support\Facades\Storage;
/**
* Bewerbung auf eine interne Stelle – vertraulich: sichtbar für die bewerbende Person,
* die Ansprechperson der Stelle und alle mit „Bewerbungen einsehen“.
*/
#[Fillable(['posting_id', 'user_id', 'message', 'file_path', 'file_name', 'status', 'note', 'withdrawn_at'])]
class JobApplication extends Model
{
public const STATUSES = ['received' => 'Eingegangen', 'review' => 'In Prüfung', 'interview' => 'Gespräch vereinbart', 'closed' => 'Abgeschlossen'];
protected static function booted(): void
{
static::deleting(function (JobApplication $application) {
if ($application->file_path) {
Storage::disk(JobPosting::DISK)->delete($application->file_path);
}
});
}
protected function casts(): array
{
return ['withdrawn_at' => 'datetime'];
}
/**
* @return BelongsTo<JobPosting, $this>
*/
public function posting(): BelongsTo
{
return $this->belongsTo(JobPosting::class, 'posting_id');
}
/**
* @return BelongsTo<User, $this>
*/
public function user(): BelongsTo
{
return $this->belongsTo(User::class);
}
}

View file

@ -0,0 +1,102 @@
<?php
namespace Inhaus\Plugins\Stellen\Models;
use App\Models\User;
use Illuminate\Database\Eloquent\Attributes\Fillable;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Support\Facades\Storage;
/**
* Eine interne Stellenausschreibung. Sichtbar ab „published_at“ bis einschließlich zur Frist.
*/
#[Fillable(['title', 'department', 'location', 'employment', 'hours', 'contract', 'contract_note', 'pay_grade', 'start', 'deadline',
'description', 'pdf_path', 'pdf_name', 'apply_mode', 'apply_url', 'contact_id', 'notify_email', 'published_at', 'created_by', 'updated_by'])]
class JobPosting extends Model
{
public const DISK = 'local';
public const EMPLOYMENT = ['full' => 'Vollzeit', 'part' => 'Teilzeit', 'flex' => 'Voll- oder Teilzeit', 'mini' => 'Minijob', 'training' => 'Ausbildung / Studium', 'other' => 'Sonstiges'];
public const CONTRACT = ['permanent' => 'Unbefristet', 'fixed' => 'Befristet'];
public const APPLY_MODES = ['online' => 'Online im Portal', 'contact' => 'Über die Ansprechperson', 'link' => 'Über einen Link'];
protected static function booted(): void
{
static::deleting(function (JobPosting $posting) {
if ($posting->pdf_path) {
Storage::disk(self::DISK)->delete($posting->pdf_path);
}
$posting->applications()->get()->each->delete();
});
}
protected function casts(): array
{
return ['deadline' => 'date', 'published_at' => 'datetime', 'announced_at' => 'datetime'];
}
/**
* Offene Stellen: veröffentlicht und Frist nicht abgelaufen.
*
* @param Builder<JobPosting> $query
*/
public function scopeOpen(Builder $query): void
{
$query->whereNotNull('published_at')->where('published_at', '<=', now())
->where(fn (Builder $q) => $q->whereNull('deadline')->orWhereDate('deadline', '>=', today()));
}
public function isOpen(): bool
{
return $this->published_at !== null && $this->published_at->isPast() && ($this->deadline === null || ! $this->deadline->isBefore(today()));
}
public function status(): string
{
return match (true) {
$this->published_at === null => 'draft',
$this->published_at->isFuture() => 'scheduled',
$this->deadline !== null && $this->deadline->isBefore(today()) => 'expired',
default => 'open',
};
}
/**
* @return BelongsTo<User, $this>
*/
public function contact(): BelongsTo
{
return $this->belongsTo(User::class, 'contact_id');
}
/**
* @return HasMany<JobApplication, $this>
*/
public function applications(): HasMany
{
return $this->hasMany(JobApplication::class, 'posting_id');
}
/** Wer die Bewerbungen dieser Stelle sehen darf */
public function canSeeApplications(?User $user): bool
{
return $user !== null && ($user->can('jobs.applications') || ($this->contact_id !== null && $this->contact_id === $user->id));
}
/**
* Kurzfassung der Eckdaten, z. B. „Teilzeit (30 Std./Woche) · befristet bis 31.12.2027“.
*/
public function summary(): string
{
return collect([
self::EMPLOYMENT[$this->employment] ?? null,
$this->hours ? '('.$this->hours.')' : null,
])->filter()->implode(' ').($this->contract === 'fixed' ? ' · befristet'.($this->contract_note ? ' '.$this->contract_note : '') : '');
}
}

View file

@ -0,0 +1,81 @@
<?php
namespace Inhaus\Plugins\Stellen;
use App\Models\User;
use Inhaus\Plugins\Stellen\Models\JobApplication;
use Inhaus\Plugins\Stellen\Models\JobPosting;
/**
* Daten der Stellen für das Portal.
*/
class Presenter
{
/**
* @return array<string, mixed>
*/
public static function card(JobPosting $posting): array
{
return [
'id' => $posting->id,
'title' => $posting->title,
'department' => $posting->department,
'location' => $posting->location,
'employment' => $posting->employment,
'employment_label' => JobPosting::EMPLOYMENT[$posting->employment] ?? null,
'summary' => $posting->summary(),
'deadline' => $posting->deadline?->toDateString(),
'published_at' => $posting->published_at?->toIso8601String(),
'status' => $posting->status(),
'url' => route('jobs.show', $posting),
];
}
/**
* @return array<string, mixed>
*/
public static function detail(JobPosting $posting, User $viewer): array
{
$contact = $posting->contact?->is_active ? $posting->contact : null;
return [
...self::card($posting),
'hours' => $posting->hours,
'contract' => $posting->contract,
'contract_label' => JobPosting::CONTRACT[$posting->contract] ?? null,
'contract_note' => $posting->contract_note,
'pay_grade' => $posting->pay_grade,
'start' => $posting->start,
'description' => $posting->description,
'pdf' => $posting->pdf_path ? ['name' => $posting->pdf_name, 'url' => route('jobs.pdf', $posting)] : null,
'apply_mode' => $posting->apply_mode,
'apply_url' => $posting->apply_mode === 'link' ? $posting->apply_url : null,
'contact' => $contact ? [
'id' => $contact->id, 'name' => $contact->name, 'initials' => $contact->initials, 'job_title' => $contact->job_title,
'email' => $contact->email, 'phone' => $contact->phone, 'avatar_url' => $contact->avatarUrl(96),
] : null,
];
}
/**
* @return array<string, mixed>
*/
public static function application(JobApplication $application, bool $withPerson = false): array
{
return [
'id' => $application->id,
'status' => $application->status,
'status_label' => JobApplication::STATUSES[$application->status] ?? $application->status,
'message' => $application->message,
'file' => $application->file_path ? ['name' => $application->file_name, 'url' => route('jobs.applications.file', $application)] : null,
'created_at' => $application->created_at?->toIso8601String(),
'updated_at' => $application->updated_at?->toIso8601String(),
'note' => $withPerson ? $application->note : null,
'person' => $withPerson && $application->user ? [
'id' => $application->user->id, 'name' => $application->user->name, 'initials' => $application->user->initials,
'job_title' => $application->user->job_title, 'department' => $application->user->department,
'email' => $application->user->email, 'avatar_url' => $application->user->avatarUrl(96),
] : null,
];
}
}

View file

@ -0,0 +1,40 @@
<?php
namespace Inhaus\Plugins\Stellen;
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 Illuminate\Support\Facades\Schedule;
use Inhaus\Plugins\Stellen\Models\JobPosting;
class StellenPlugin extends Plugin
{
public function register(): void
{
$this->app->make(Navigation::class)->add('stellen', 'Stellen', '/stellen', active: 'jobs.*', sort: 72);
$abilities = $this->app->make(Abilities::class);
$abilities->define('jobs.manage', 'Stellen ausschreiben und bearbeiten', 'Stellen', portal: true);
$abilities->define('jobs.applications', 'Bewerbungen aller Stellen einsehen und bearbeiten', 'Stellen', portal: true);
$this->app->make(GlobalSearch::class)->add('stellen', 'Stellen', 'briefcase', fn (...$args) => app(JobSearch::class)(...$args), sort: 55);
$this->app->make(Editorial::class)->add('stellen', 'Stellen', 'stellen::EditorialJobs', 35,
fn (User $user) => $user->can('jobs.manage') || $user->can('jobs.applications'),
fn (User $user) => [
'postings' => JobPosting::query()->withCount('applications')->orderByRaw('published_at IS NULL DESC')->orderByDesc('published_at')->limit(50)->get()
->map(fn (JobPosting $p) => [...Presenter::card($p), 'applications' => $p->applications_count, 'edit_url' => route('jobs.edit', $p), 'applications_url' => route('jobs.applications', $p)])->all(),
'canCreate' => $user->can('jobs.manage'),
]);
}
public function boot(): void
{
// Geplante Stellen ankündigen, sobald sie erscheinen
Schedule::call(fn () => $this->app->make(Announcer::class)->announceDue())->everyTenMinutes()->name('stellen-announce')->withoutOverlapping(10);
}
}