QM-Texterkennung: Imagick nur mit Ghostscript als verfügbar melden
Some checks failed
CI / PHP 8.3 / mariadb:10.6 (pull_request) Failing after 3m18s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Failing after 3m27s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Failing after 3m0s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Failing after 2m56s
CI / PHP 8.3 / mysql:8.0 (pull_request) Failing after 4m4s
CI / PHP 8.4 / mysql:8.0 (pull_request) Failing after 4m1s
CI / PHP 8.3 / mysql:8.4 (pull_request) Failing after 3m41s
CI / PHP 8.4 / mysql:8.4 (pull_request) Failing after 3m39s
CI / Build-Artefakte aktuell (pull_request) Failing after 1m10s
Some checks failed
CI / PHP 8.3 / mariadb:10.6 (pull_request) Failing after 3m18s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Failing after 3m27s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Failing after 3m0s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Failing after 2m56s
CI / PHP 8.3 / mysql:8.0 (pull_request) Failing after 4m4s
CI / PHP 8.4 / mysql:8.0 (pull_request) Failing after 4m1s
CI / PHP 8.3 / mysql:8.4 (pull_request) Failing after 3m41s
CI / PHP 8.4 / mysql:8.4 (pull_request) Failing after 3m39s
CI / Build-Artefakte aktuell (pull_request) Failing after 1m10s
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
5a360d3cc7
commit
b50d089946
117 changed files with 1747 additions and 2 deletions
16
plugins-core/gemeinsam/src/GemeinsamPlugin.php
Normal file
16
plugins-core/gemeinsam/src/GemeinsamPlugin.php
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
<?php
|
||||
|
||||
namespace Inhaus\Plugins\Gemeinsam;
|
||||
|
||||
use App\Plugins\Plugin;
|
||||
use App\Support\Abilities;
|
||||
use App\Support\Navigation;
|
||||
|
||||
class GemeinsamPlugin extends Plugin
|
||||
{
|
||||
public function register(): void
|
||||
{
|
||||
$this->app->make(Navigation::class)->add('gemeinsam', 'Gemeinsam', '/gemeinsam', active: 'gemeinsam.*', sort: 65);
|
||||
$this->app->make(Abilities::class)->define('gemeinsam.manage', 'Personalnachrichten pflegen (Gemeinsam feiern …)', 'Gemeinsam');
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,163 @@
|
|||
<?php
|
||||
|
||||
namespace Inhaus\Plugins\Gemeinsam\Http\Controllers;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Plugins\PluginManager;
|
||||
use App\Support\Audit;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Illuminate\Validation\Rule;
|
||||
use Inertia\Inertia;
|
||||
use Inertia\Response;
|
||||
use Inhaus\Plugins\Birthdays\BirthdayList;
|
||||
use Inhaus\Plugins\Gemeinsam\Models\Entry;
|
||||
|
||||
class GemeinsamController extends Controller
|
||||
{
|
||||
public function index(Request $request): Response
|
||||
{
|
||||
$month = $this->month((string) $request->query('monat', ''));
|
||||
$entries = Entry::query()->with('user')
|
||||
->whereBetween('date', [$month->copy()->startOfMonth()->toDateString(), $month->copy()->endOfMonth()->toDateString()])
|
||||
->orderBy('date')->orderBy('id')->get();
|
||||
|
||||
$sections = [];
|
||||
|
||||
foreach (Entry::SECTIONS as $key => $title) {
|
||||
if ($key === 'birthdays') {
|
||||
if (! app(PluginManager::class)->isLoaded('birthdays')) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$rows = app(BirthdayList::class)->inMonth($month->year, $month->month);
|
||||
$sections[] = ['key' => $key, 'title' => $title, 'automatic' => true, 'entries' => array_map(fn ($row) => [
|
||||
'id' => 'b'.$row['person']['id'],
|
||||
'date' => $row['date'],
|
||||
'person' => $row['person'] + ['url' => '/personen/'.$row['person']['id']],
|
||||
'name' => $row['person']['name'],
|
||||
'department' => $row['person']['department'] ?? null,
|
||||
'location' => $row['person']['location'] ?? null,
|
||||
], $rows)];
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
$sections[] = [
|
||||
'key' => $key,
|
||||
'title' => $title,
|
||||
'automatic' => false,
|
||||
'entries' => $entries->where('section', $key)->values()->map(fn (Entry $entry) => $this->present($entry))->all(),
|
||||
];
|
||||
}
|
||||
|
||||
return Inertia::render('gemeinsam::Index', [
|
||||
'month' => $month->format('Y-m'),
|
||||
'monthLabel' => $month->locale('de')->isoFormat('MMMM YYYY'),
|
||||
'previous' => $month->copy()->subMonth()->format('Y-m'),
|
||||
'next' => $month->copy()->addMonth()->format('Y-m'),
|
||||
'isCurrent' => $month->isSameMonth(now()),
|
||||
'sections' => $sections,
|
||||
'canManage' => (bool) $request->user()->can('gemeinsam.manage'),
|
||||
]);
|
||||
}
|
||||
|
||||
public function store(Request $request): RedirectResponse
|
||||
{
|
||||
abort_unless($request->user()->can('gemeinsam.manage'), 403);
|
||||
$entry = Entry::query()->create([...$this->validated($request), 'created_by' => $request->user()->id]);
|
||||
Audit::log('gemeinsam.created', ['section' => $entry->section, 'entry' => $entry->id]);
|
||||
|
||||
return redirect()->route('gemeinsam.index', ['monat' => $entry->date->format('Y-m')])->with('status', 'Eintrag gespeichert.');
|
||||
}
|
||||
|
||||
public function update(Request $request, Entry $entry): RedirectResponse
|
||||
{
|
||||
abort_unless($request->user()->can('gemeinsam.manage'), 403);
|
||||
$entry->update($this->validated($request));
|
||||
|
||||
return redirect()->route('gemeinsam.index', ['monat' => $entry->date->format('Y-m')])->with('status', 'Eintrag gespeichert.');
|
||||
}
|
||||
|
||||
public function destroy(Request $request, Entry $entry): RedirectResponse
|
||||
{
|
||||
abort_unless($request->user()->can('gemeinsam.manage'), 403);
|
||||
$entry->delete();
|
||||
Audit::log('gemeinsam.deleted', ['section' => $entry->section, 'entry' => $entry->id]);
|
||||
|
||||
return back()->with('status', 'Eintrag entfernt.');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
private function present(Entry $entry): array
|
||||
{
|
||||
$user = $entry->user;
|
||||
|
||||
return [
|
||||
'id' => $entry->id,
|
||||
'section' => $entry->section,
|
||||
'user_id' => $entry->user_id,
|
||||
'name' => $entry->displayName(),
|
||||
'free_name' => $entry->name,
|
||||
'person' => $user ? [
|
||||
'id' => $user->id,
|
||||
'name' => $user->name,
|
||||
'initials' => $user->initials,
|
||||
'avatar_url' => $user->avatarUrl(96),
|
||||
'job_title' => $user->job_title,
|
||||
'url' => '/personen/'.$user->id,
|
||||
] : null,
|
||||
'date' => $entry->date->toDateString(),
|
||||
'born_on' => $entry->born_on?->toDateString(),
|
||||
// Leere Felder aus dem Profil ergänzen
|
||||
'department' => $entry->department ?? $user?->department,
|
||||
'location' => $entry->location ?? $user?->location,
|
||||
'from' => $entry->from,
|
||||
'to' => $entry->to,
|
||||
'label' => $entry->label,
|
||||
'text' => $entry->text,
|
||||
'raw' => [
|
||||
'department' => $entry->department,
|
||||
'location' => $entry->location,
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
private function validated(Request $request): array
|
||||
{
|
||||
$data = $request->validate([
|
||||
'section' => ['required', Rule::in(Entry::MANUAL)],
|
||||
'user_id' => ['nullable', 'integer', Rule::exists('users', 'id')],
|
||||
'name' => ['required_without:user_id', 'nullable', 'string', 'max:150'],
|
||||
'date' => ['required', 'date'],
|
||||
'born_on' => ['nullable', 'date', 'before_or_equal:date'],
|
||||
'department' => ['nullable', 'string', 'max:150'],
|
||||
'location' => ['nullable', 'string', 'max:150'],
|
||||
'from' => ['nullable', 'string', 'max:150'],
|
||||
'to' => ['nullable', 'string', 'max:150'],
|
||||
'label' => ['nullable', 'string', 'max:150'],
|
||||
'text' => ['nullable', 'string', 'max:1000'],
|
||||
], ['name.required_without' => 'Bitte eine Person auswählen oder einen Namen eintragen.'], [
|
||||
'date' => 'Datum', 'born_on' => 'Geburtsdatum', 'department' => 'Bereich', 'location' => 'Standort', 'label' => 'Anlass',
|
||||
]);
|
||||
|
||||
if (! empty($data['user_id'])) {
|
||||
$data['name'] = null;
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
private function month(string $value): Carbon
|
||||
{
|
||||
return preg_match('/^\d{4}-\d{2}$/', $value) && checkdate((int) substr($value, 5, 2), 1, (int) substr($value, 0, 4))
|
||||
? Carbon::createFromFormat('Y-m-d', $value.'-01')->startOfDay()
|
||||
: Carbon::today()->startOfMonth();
|
||||
}
|
||||
}
|
||||
44
plugins-core/gemeinsam/src/Models/Entry.php
Normal file
44
plugins-core/gemeinsam/src/Models/Entry.php
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
<?php
|
||||
|
||||
namespace Inhaus\Plugins\Gemeinsam\Models;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Eloquent\Attributes\Fillable;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
#[Fillable(['section', 'user_id', 'name', 'date', 'born_on', 'department', 'location', 'from', 'to', 'label', 'text', 'created_by'])]
|
||||
class Entry extends Model
|
||||
{
|
||||
protected $table = 'gemeinsam_entries';
|
||||
|
||||
/** Abschnitte in der Reihenfolge der Seite (Geburtstage kommen aus dem Geburtstags-Plugin). */
|
||||
public const SECTIONS = [
|
||||
'welcome' => 'Wir begrüßen die neuen Mitarbeitenden',
|
||||
'transfer' => 'Den Einsatzort wechseln',
|
||||
'birthdays' => 'Geburtstage',
|
||||
'jubilee' => 'Jubilare',
|
||||
'farewell' => 'Wir verabschieden',
|
||||
'memoriam' => 'In Gedenken an',
|
||||
];
|
||||
|
||||
public const MANUAL = ['welcome', 'transfer', 'jubilee', 'farewell', 'memoriam'];
|
||||
|
||||
protected function casts(): array
|
||||
{
|
||||
return ['date' => 'date', 'born_on' => 'date'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return BelongsTo<User, $this>
|
||||
*/
|
||||
public function user(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
|
||||
public function displayName(): string
|
||||
{
|
||||
return $this->user?->name ?? (string) $this->name;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue