Loheide-eu-mitarbeiterplatt.../plugins-core/stellen/src/Announcer.php
Friederich Loheide f1202bea08
Some checks failed
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 7m50s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 7m34s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 5m45s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 5m30s
CI / PHP 8.3 / mysql:8.0 (pull_request) Failing after 7m7s
CI / PHP 8.4 / mysql:8.0 (pull_request) Failing after 7m9s
CI / PHP 8.3 / mysql:8.4 (pull_request) Failing after 6m8s
CI / PHP 8.4 / mysql:8.4 (pull_request) Failing after 6m5s
CI / Bekannte Sicherheitslücken in Paketen (pull_request) Successful in 48s
CI / Build-Artefakte aktuell (pull_request) Successful in 1m5s
Sicherheitsupdate nach Audit (0.29.0)
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-09-27 11:34:54 +00:00

46 lines
1.6 KiB
PHP

<?php
namespace Inhaus\Plugins\Stellen;
use App\Models\User;
use App\Notifications\PortalNotification;
use App\Plugins\PluginAccess;
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',
);
// Nicht an Rollen, die vom Modul „Stellen“ ausgeschlossen sind
$excluded = app(PluginAccess::class)->excludedRoles('stellen');
User::query()->active()->whereKeyNot($posting->created_by ?? 0)
->when($excluded !== [], fn ($q) => $q->whereDoesntHave('roles', fn ($r) => $r->whereIn('roles.id', $excluded)))
->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();
}
}