Compare commits

..

1 Commits

Author SHA1 Message Date
philipp lang 8fcbec95b0 Add Caldav for member birthdays
continuous-integration/drone/push Build is failing Details
2024-05-15 01:36:36 +02:00
388 changed files with 7198 additions and 12251 deletions

View File

@ -1,14 +1,13 @@
FROM php:8.3.11-fpm as php
FROM php:8.1.6-fpm as php
WORKDIR /app
RUN ls /app
RUN apt-get update
RUN apt-get install -y rsync libcurl3-dev apt-utils zlib1g-dev libpng-dev libicu-dev libonig-dev unzip poppler-utils libpng-dev libjpeg-dev default-mysql-client libzip-dev imagemagick libmagickwand-dev
RUN apt-get install -y rsync libcurl3-dev apt-utils zlib1g-dev libpng-dev libicu-dev libonig-dev unzip poppler-utils libpng-dev libjpeg-dev default-mysql-client
RUN apt-get install -y --no-install-recommends texlive-base texlive-latex-base texlive-pictures texlive-latex-extra texlive-lang-german texlive-plain-generic texlive-fonts-recommended texlive-fonts-extra texlive-extra-utils
RUN docker-php-ext-install pdo_mysql curl exif intl mbstring pcntl zip
RUN docker-php-ext-install pdo_mysql curl gd exif intl mbstring pcntl
RUN pecl install redis && docker-php-ext-enable redis
RUN pecl install imagick && docker-php-ext-enable imagick
RUN docker-php-ext-configure gd --with-jpeg
RUN docker-php-ext-install gd
RUN docker-php-ext-enable gd
RUN usermod -s /bin/bash www-data
RUN echo 'memory_limit = 2G' >> /usr/local/etc/php/conf.d/99-custom-php-memlimit.ini

View File

@ -1,6 +0,0 @@
#!/bin/bash
docker buildx build -f .docker/base.Dockerfile .
docker image tag sha256:... zoomyboy/adrema-base
docker push zoomyboy/adrema-base

View File

@ -1,11 +1,11 @@
FROM composer:2.7.9 as composer
FROM composer:2.2.7 as composer
WORKDIR /app
COPY . /app
RUN composer install --ignore-platform-reqs --no-dev
RUN php artisan telescope:publish
RUN php artisan horizon:publish
FROM node:20.15.0-slim as node
FROM node:18.13.0-slim as node
WORKDIR /app
COPY . /app
RUN npm install && npm run prod && npm run img && rm -R node_modules

View File

@ -1,9 +1,9 @@
FROM composer:2.7.9 as composer
FROM composer:2.2.7 as composer
WORKDIR /app
COPY . /app
RUN composer install --ignore-platform-reqs --no-dev
FROM node:20.15.0-slim as node
FROM node:17.9.0-slim as node
WORKDIR /app
COPY . /app
RUN npm install && npm run prod && npm run img && rm -R node_modules
@ -20,7 +20,7 @@ RUN php artisan horizon:publish
USER root
COPY ./.docker/php /bin
VOLUME ["/app/packages/laravel-nami/.cookies", "/app/storage/app", "/app/resources/views/tex/invoice"]
VOLUME ["/app/packages/laravel-nami/.cookies", "/app/storage/app"]
EXPOSE 9000

View File

@ -15,11 +15,6 @@ mkdir -p /app/storage/app/public || true
chown -R www-data:www-data /app/packages/laravel-nami/.cookies
chown -R www-data:www-data /app/storage/app
if [ $APP_KEY = "YOUR_APP_KEY" ]; then
echo "----------------------- Keinen APP KEY gefunden. Key wird generiert: $(su www-data -c 'php artisan key:generate --show') ----------------------- Füge diesen Key als APP_KEY ein ---------------------"
exit 1
fi
if [ $1 == "horizon" ]; then
wait_for_db
su www-data -c 'php artisan horizon'
@ -27,6 +22,10 @@ fi
if [ $1 == "app" ]; then
# --------------------------- ensure appkey is set ----------------------------
if [ $APP_KEY = "YOUR_APP_KEY" ]; then
echo "----------------------- Keinen APP KEY gefunden. Key wird generiert: $(su www-data -c 'php artisan key:generate --show') ----------------------- Füge diesen Key als APP_KEY ein ---------------------"
exit 1
fi
wait_for_db
php -r '$connection = new PDO("mysql:host='$DB_HOST';dbname='$DB_DATABASE'", "'$DB_USERNAME'", "'$DB_PASSWORD'"); $connection->query("DESCRIBE migrations");' > /dev/null || php artisan migrate --seed --force
su www-data -c 'php artisan migrate --force'

View File

@ -12,7 +12,7 @@ steps:
- git submodule update --init --recursive
- name: composer_dev
image: composer:2.7.9
image: composer:2.2.7
commands:
- composer install --ignore-platform-reqs --dev
@ -21,25 +21,14 @@ steps:
commands:
- while ! mysqladmin ping -h db -u db -pdb --silent; do sleep 1; done
- name: ocdb_healthcheck
image: mysql:oracle
commands:
- while ! mysqladmin ping -h ownclouddb -u owncloud -powncloud --silent; do sleep 1; done
- name: oc_healthcheck
image: zoomyboy/adrema-base:latest
commands:
- while ! curl --silent 'http://owncloudserver:8080/ocs/v1.php/cloud/capabilities?format=json' -u admin:admin | grep '"status":"ok"'; do sleep 1; done
- name: node
image: node:20.15.0-slim
image: node:18.13.0-slim
commands:
- npm ci && cd packages/adrema-form && npm ci && npm run build && rm -R node_modules && cd ../../ && npm run img && npm run prod && rm -R node_modules
- npm ci && cd packages/adrema-form && npm ci && npm run build && cd ../../ && npm run img && npm run prod && rm -R node_modules
- name: tests
image: zoomyboy/adrema-base:latest
commands:
- touch .env
- php artisan migrate
- php artisan test
- rm -f .env
@ -69,8 +58,6 @@ steps:
XELATEX_BIN: /usr/bin/xelatex
SCOUT_DRIVER: database
MEILI_MASTER_KEY: abc
TEST_OWNCLOUD_DOMAIN: http://owncloudserver:8080
TEST_NEXTCLOUD_DOMAIN: http://nextcloudserver:80
- name: docker_app_push
image: plugins/docker
@ -103,7 +90,7 @@ steps:
event: tag
- name: deploy
image: zoomyboy/adrema-base:latest
image: php:8.1.6
environment:
SSH_KEY:
from_secret: deploy_private_key
@ -136,7 +123,7 @@ steps:
event: push
- name: composer_no_dev
image: composer:2.7.9
image: composer:2.2.7
commands:
- composer install --ignore-platform-reqs --no-dev
@ -173,47 +160,6 @@ services:
image: getmeili/meilisearch:v1.6
commands:
- meilisearch --master-key="abc"
- name: ownclouddb
image: mariadb:10.11
environment:
MYSQL_ROOT_PASSWORD: owncloud
MYSQL_USER: owncloud
MYSQL_PASSWORD: owncloud
MYSQL_DATABASE: owncloud
MARIADB_AUTO_UPGRADE: 1
- name: owncloudserver
image: owncloud/server:10.10.0
environment:
OWNCLOUD_DOMAIN: http://owncloudserver:8080
OWNCLOUD_TRUSTED_DOMAINS: owncloudserver
OWNCLOUD_DB_TYPE: mysql
OWNCLOUD_DB_NAME: owncloud
OWNCLOUD_DB_USERNAME: owncloud
OWNCLOUD_DB_PASSWORD: owncloud
OWNCLOUD_DB_HOST: ownclouddb
OWNCLOUD_ADMIN_USERNAME: admin
OWNCLOUD_ADMIN_PASSWORD: admin
OWNCLOUD_MYSQL_UTF8MB4: true
OWNCLOUD_REDIS_ENABLED: false
OWNCLOUD_REDIS_HOST: false
- name: nextclouddb
image: mariadb:10.11
environment:
MYSQL_ROOT_PASSWORD: nextcloud
MYSQL_USER: nextcloud
MYSQL_PASSWORD: nextcloud
MYSQL_DATABASE: nextcloud
MARIADB_AUTO_UPGRADE: 1
- name: nextcloudserver
image: nextcloud
environment:
MYSQL_PASSWORD: nextcloud
MYSQL_DATABASE: nextcloud
MYSQL_USER: nextcloud
MYSQL_HOST: nextclouddb
NEXTCLOUD_ADMIN_USER: admin
NEXTCLOUD_ADMIN_PASSWORD: admin
NEXTCLOUD_TRUSTED_DOMAINS: nextcloudserver
trigger:
event:

3
.gitignore vendored
View File

@ -8,7 +8,6 @@ yarn-error.log
/public/build
/public/vendor
storage/*.key
/storage/media-library/*
/vendor/
Homestead.yaml
Homestead.json
@ -16,7 +15,6 @@ Homestead.json
.phpunit.result.cache
/storage/temp/
/storage/debugbar/
/tests/Fileshare/oc_tmp/*
# User data files
/data/
@ -40,4 +38,3 @@ Homestead.json
/public/sprite.svg
/.php-cs-fixer.cache
/groups.sql
/.phpunit.cache

9
.gitmodules vendored
View File

@ -1,3 +1,6 @@
[submodule "packages/silvaletter"]
path = packages/silvaletter
url = https://git.zoomyboy.de/silva/silvaletter.git
[submodule "packages/laravel-nami"]
path = packages/laravel-nami
url = https://git.zoomyboy.de/silva/laravel-nami-api
@ -11,9 +14,3 @@
path = packages/medialibrary-helper
url = https://git.zoomyboy.de/zoomyboy/medialibrary-helper.git
branch = version2
[submodule "packages/flysystem-webdav"]
path = packages/flysystem-webdav
url = https://github.com/zoomyboy/flysystem-webdav.git
[submodule "packages/table-document"]
path = packages/table-document
url = https://git.zoomyboy.de/zoomyboy/table-document.git

View File

@ -1,94 +0,0 @@
# Letzte Änderungen
### 1.12.2
- Zuschussliste Gallier
### 1.12.1
- In Teilnehmer-Liste von Veranstaltungen kann nun sortiert und gefiltert werden.
- Formulare: Feld Registrierung von / bis
### 1.11.5
- Fix: Synchronisation von NaMi-Mitgliedern
### 1.11.4
- Fix: Nicht an Präventions-Unterlagen für vergangene Veranstaltungen erinnern
### 1.11.1
- Es kann nun auch das Feld "Datenweiterverwendung" über Adrema gepflegt werden.
### 1.10.20
- Fixed: Bei Textfeldern wird nun die Einleitung dargestellt
### 1.10.19
- Fixed: Erweiterte Führungszeugnisse und Präventionsschulungen nur für aktive Mitgliedschaften auf Dashboard anzeigen
### 1.10.18
- Fixed: All Gruppen als Option anbieten bei Bedingungen
### 1.10.17
- Es können nun auch Bedingungen für Felder vom Typ Gruppierung definiert werden
### 1.10.16
- Rechnungen und Erinnerungen werden nun automatisch täglich um 10 Uhr verschickt
- Es kann eingestellt werden, nach wie vielen Wochen an Rechnungen erinnert werden soll (Standard: 12)
- Name und Profilbild des angemeldeten Benutzers wird nun oben rechts angezeigt
### 1.10.15
- "Für Mitglieder zusätzlich abfragen" kann nun im Formular auch gesetzt werden, wenn ein NaMi Feld ausgewählt ist.
### 1.10.14
- Fixed: Ist eine Präventionsschulung älter als 5 Jahre, so ist nur eine Auffrischungs-Schulung erforderlich
### 1.10.13
- Bei Veranstaltungs-Übersicht alle Veranstaltungen anzeigen
- Download von Teilnehmern als Tabellen-Dokument
- Spalte "Prävention" bei TN-Liste eingefügt für benötigte Unterlagen
### 1.10.11
- Bei Prävention auch an Verhaltenskodex erinnern
### 1.10.10
- Eine Formular-Vorlage kann nun auch Mail-Inhalte enthalten, die für die Formulare übernommen werden
### 1.10.9
- Nextcloud als neuen Type bei Datei-Verbindungen angelegt
### 1.10.8
- Anmeldeformulare: Bearbeiten von Teilnehmer\*innen ist nun möglich
### 1.10.7
- Anmeldeformulare: Versenden von Präventions-Unterlagen können nun an eine Feld-Bedingung geknüpft werden innerhalb der Veranstaltung
### 1.10.6
- Kleinere Fehler behoben
### 1.10.5
- Kleinere Fehler behoben
### 1.10.4
- Anmeldeformular: Erinnerung an Präventions-Unterlagen bei Teilnehmer\*innnen
### 1.10.3
- Anmeldeformulare: Ist NaMi-Feld "E-Mail" ausgewählt bei Formular-Feldern, muss die E-Mail-Adresse nun nicht mehr auf das Mitglied matchen. Dies ist nur noch bei Formular-Feldern mit NaMi-Feldern "Vorname", "Nachname" und "Geburtsdatum" der Fall.

View File

@ -85,12 +85,6 @@ Außerdem ist AdReMa auch problemlos auf Handys und Tablets bedienbar ("mobiles
7. Nach kurzer Zeit ist AdReMa über <http://localhost:8000> erreichbar und es kann sich mit dem zuvor festgelegten Login eingeloggt werden
### Individuelle anpassungen
#### Rechnungswesen
Bei dem Setup wird im Daten-Verzeichniss ein Ordner `./data/setup` angelegt. Hier kann das Logo des Stammes in den Briefkopf eingefügt werden. Zusätzlich kann der Text der Rechnung und der Zahlungserinnerung angepasst werden, dafür ist ein grundlegendes Verständnis für `.tex` Datein erforderlich.
## Nutzen des Entwicklungssystmes
1. Klonen des Reposetories

View File

@ -1,23 +0,0 @@
<?php
namespace App\Actions;
use DB;
use Illuminate\Support\Facades\Artisan;
use Illuminate\Support\Facades\Http;
use Laravel\Telescope\Console\PruneCommand;
use Lorisleiva\Actions\Concerns\AsAction;
class DbMaintainAction
{
use AsAction;
public string $commandSignature = 'db:maintain';
public function handle(): void
{
Artisan::call(PruneCommand::class, ['--hours' => 168]); // 168h = 7 Tage
DB::select('optimize table telescope_entries');
Http::post('https://zoomyboy.de/maintain', ['url' => url()->current()]);
}
}

View File

@ -50,7 +50,6 @@ class InsertMemberAction
'nationality_id' => Nationality::where('nami_id', $member->nationalityId)->firstOrFail()->id,
'mitgliedsnr' => $member->memberId,
'version' => $member->version,
'keepdata' => $member->keepdata,
]);
}

View File

@ -4,14 +4,12 @@ namespace App;
use App\Nami\HasNamiField;
use Cviebrock\EloquentSluggable\Sluggable;
use Database\Factories\ActivityFactory;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
class Activity extends Model
{
/** @use HasFactory<ActivityFactory> */
use HasFactory;
use HasNamiField;
use Sluggable;

View File

@ -2,13 +2,11 @@
namespace App;
use Database\Factories\ConfessionFactory;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Confession extends Model
{
/** @use HasFactory<ConfessionFactory> */
use HasFactory;
public $fillable = ['name', 'nami_id', 'is_null'];

View File

@ -2,12 +2,11 @@
namespace App\Console;
use App\Actions\DbMaintainAction;
use App\Form\Actions\PreventionRememberAction;
use App\Initialize\InitializeMembers;
use App\Invoice\Actions\InvoiceSendAction;
use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
use Laravel\Telescope\Console\PruneCommand;
class Kernel extends ConsoleKernel
{
@ -19,8 +18,6 @@ class Kernel extends ConsoleKernel
protected $commands = [
InvoiceSendAction::class,
InitializeMembers::class,
DbMaintainAction::class,
PreventionRememberAction::class,
];
/**
@ -30,10 +27,8 @@ class Kernel extends ConsoleKernel
*/
protected function schedule(Schedule $schedule)
{
$schedule->command(DbMaintainAction::class)->daily();
$schedule->command(PruneCommand::class, ['--hours' => 168])->daily(); // 168h = 7 Tage
$schedule->command(InitializeMembers::class)->dailyAt('03:00');
$schedule->command(PreventionRememberAction::class)->dailyAt('11:00');
$schedule->command(InvoiceSendAction::class)->dailyAt('10:00');
}
/**

View File

@ -8,7 +8,6 @@ use App\Contribution\Documents\RdpNrwDocument;
use App\Contribution\Documents\CityRemscheidDocument;
use App\Contribution\Documents\CitySolingenDocument;
use App\Contribution\Documents\CityFrankfurtMainDocument;
use App\Contribution\Documents\WuppertalDocument;
use Illuminate\Support\Collection;
use Illuminate\Validation\Rule;
@ -23,16 +22,15 @@ class ContributionFactory
CityRemscheidDocument::class,
CityFrankfurtMainDocument::class,
BdkjHesse::class,
WuppertalDocument::class,
];
/**
* @return Collection<int, array{title: string, class: class-string<ContributionDocument>}>
* @return Collection<int, array{title: mixed, class: mixed}>
*/
public function compilerSelect(): Collection
{
return collect($this->documents)->map(fn ($document) => [
'title' => $document::buttonName(),
'title' => $document::getName(),
'class' => $document,
]);
}

View File

@ -29,7 +29,7 @@ class MemberData extends Data
*/
public static function fromModels(array $ids): Collection
{
return Member::whereIn('id', $ids)->orderByRaw('lastname, firstname')->get()->map(fn ($member) => self::factory()->withoutMagicalCreation()->from([
return Member::whereIn('id', $ids)->orderByRaw('lastname, firstname')->get()->map(fn ($member) => self::withoutMagicalCreationFrom([
...$member->toArray(),
'birthday' => $member->birthday->toAtomString(),
'isLeader' => $member->isLeader(),
@ -44,7 +44,7 @@ class MemberData extends Data
*/
public static function fromApi(array $data): Collection
{
return collect($data)->map(fn ($member) => self::factory()->withoutMagicalCreation()->from([
return collect($data)->map(fn ($member) => self::withoutMagicalCreationFrom([
...$member,
'birthday' => Carbon::parse($member['birthday'])->toAtomString(),
'gender' => Gender::fromString($member['gender']),
@ -54,41 +54,31 @@ class MemberData extends Data
public function fullname(): string
{
return $this->firstname . ' ' . $this->lastname;
return $this->firstname.' '.$this->lastname;
}
public function separatedName(): string
{
return $this->lastname . ', ' . $this->firstname;
return $this->lastname.', '.$this->firstname;
}
public function fullAddress(): string
{
return $this->address . ', ' . $this->zip . ' ' . $this->location;
return $this->address.', '.$this->zip.' '.$this->location;
}
public function city(): string
{
return $this->zip . ' ' . $this->location;
return $this->zip.' '.$this->location;
}
public function age(): int
public function age(): string
{
return intval($this->birthday->diffInYears(now()));
return (string) $this->birthday->diffInYears(now()) ?: '';
}
public function birthYear(): string
{
return (string) $this->birthday->year;
}
public function birthdayHuman(): string
{
return $this->birthday->format('d.m.Y');
}
public function genderLetter(): string
{
return $this->gender->short;
}
}

View File

@ -3,16 +3,15 @@
namespace App\Contribution\Documents;
use App\Contribution\Data\MemberData;
use App\Contribution\Traits\HasPdfBackground;
use App\Country;
use Carbon\Carbon;
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
use Zoomyboy\Tex\Engine;
use Zoomyboy\Tex\Template;
class BdkjHesse extends ContributionDocument
{
use HasPdfBackground;
/**
* @param Collection<int, Collection<int, MemberData>> $members
*/
@ -26,7 +25,6 @@ class BdkjHesse extends ContributionDocument
public ?string $filename = '',
public string $type = 'F',
) {
$this->setEventName($eventName);
}
public function dateFrom(): string
@ -76,7 +74,7 @@ class BdkjHesse extends ContributionDocument
public function durationDays(): int
{
return intVal(Carbon::parse($this->dateUntil)->diffInDays(Carbon::parse($this->dateFrom))) + 1;
return Carbon::parse($this->dateUntil)->diffInDays(Carbon::parse($this->dateFrom)) + 1;
}
/**
@ -116,9 +114,36 @@ class BdkjHesse extends ContributionDocument
return $member->birthYear();
}
public function basename(): string
{
return 'zuschuesse-bdkj-hessen' . Str::slug($this->eventName);
}
public function view(): string
{
return 'tex.contribution.bdkj-hesse';
}
public function template(): Template
{
return Template::make('tex.templates.contribution');
}
public function setFilename(string $filename): static
{
$this->filename = $filename;
return $this;
}
public function getEngine(): Engine
{
return Engine::PDFLATEX;
}
public static function getName(): string
{
return 'BDKJ Hessen';
return 'Für BDKJ Hessen erstellen';
}
/**
@ -131,6 +156,7 @@ class BdkjHesse extends ContributionDocument
'dateUntil' => 'required|string|date_format:Y-m-d',
'country' => 'required|integer|exists:countries,id',
'zipLocation' => 'required|string',
'eventName' => 'required|string',
];
}
}

View File

@ -3,17 +3,16 @@
namespace App\Contribution\Documents;
use App\Contribution\Data\MemberData;
use App\Contribution\Traits\FormatsDates;
use App\Contribution\Traits\HasPdfBackground;
use App\Country;
use App\Invoice\InvoiceSettings;
use Carbon\Carbon;
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
use Zoomyboy\Tex\Engine;
use Zoomyboy\Tex\Template;
class CityFrankfurtMainDocument extends ContributionDocument
{
use HasPdfBackground;
use FormatsDates;
public string $fromName;
/**
@ -29,7 +28,6 @@ class CityFrankfurtMainDocument extends ContributionDocument
public ?string $filename = '',
public string $type = 'F',
) {
$this->setEventName($eventName);
$this->fromName = app(InvoiceSettings::class)->from_long;
}
@ -63,6 +61,17 @@ class CityFrankfurtMainDocument extends ContributionDocument
);
}
public function dateFromHuman(): string
{
return Carbon::parse($this->dateFrom)->format('d.m.Y');
}
public function dateUntilHuman(): string
{
return Carbon::parse($this->dateUntil)->format('d.m.Y');
}
public function countryName(): string
{
return $this->country->name;
@ -73,9 +82,56 @@ class CityFrankfurtMainDocument extends ContributionDocument
return count($this->members);
}
public function memberShort(MemberData $member): string
{
return $member->isLeader ? 'L' : '';
}
public function memberName(MemberData $member): string
{
return $member->separatedName();
}
public function memberAddress(MemberData $member): string
{
return $member->fullAddress();
}
public function memberAge(MemberData $member): string
{
return $member->age();
}
public function basename(): string
{
return 'zuschuesse-frankfurt-' . Str::slug($this->eventName);
}
public function view(): string
{
return 'tex.contribution.city-frankfurt-main';
}
public function template(): Template
{
return Template::make('tex.templates.contribution');
}
public function setFilename(string $filename): static
{
$this->filename = $filename;
return $this;
}
public function getEngine(): Engine
{
return Engine::PDFLATEX;
}
public static function getName(): string
{
return 'Frankfurt';
return 'Für Frankfurt erstellen';
}
/**
@ -88,6 +144,7 @@ class CityFrankfurtMainDocument extends ContributionDocument
'dateUntil' => 'required|string|date_format:Y-m-d',
'country' => 'required|integer|exists:countries,id',
'zipLocation' => 'required|string',
'eventName' => 'required|string',
];
}
}

View File

@ -3,17 +3,15 @@
namespace App\Contribution\Documents;
use App\Contribution\Data\MemberData;
use App\Contribution\Traits\FormatsDates;
use App\Contribution\Traits\HasPdfBackground;
use App\Country;
use App\Member\Member;
use Carbon\Carbon;
use Illuminate\Support\Collection;
use Zoomyboy\Tex\Engine;
use Zoomyboy\Tex\Template;
class CityRemscheidDocument extends ContributionDocument
{
use HasPdfBackground;
use FormatsDates;
/**
* @param Collection<int, Collection<int, Member>> $leaders
* @param Collection<int, Collection<int, Member>> $children
@ -27,9 +25,17 @@ class CityRemscheidDocument extends ContributionDocument
public Collection $children,
public ?string $filename = '',
public string $type = 'F',
public string $eventName = '',
) {
$this->setEventName($eventName);
}
public function niceDateFrom(): string
{
return Carbon::parse($this->dateFrom)->format('d.m.Y');
}
public function niceDateUntil(): string
{
return Carbon::parse($this->dateUntil)->format('d.m.Y');
}
/**
@ -46,7 +52,6 @@ class CityRemscheidDocument extends ContributionDocument
country: Country::where('id', $request['country'])->firstOrFail(),
leaders: $leaders->values()->toBase()->chunk(6),
children: $children->values()->toBase()->chunk(20),
eventName: $request['eventName'],
);
}
@ -65,13 +70,39 @@ class CityRemscheidDocument extends ContributionDocument
country: Country::where('id', $request['country'])->firstOrFail(),
leaders: $leaders->values()->toBase()->chunk(6),
children: $children->values()->toBase()->chunk(20),
eventName: $request['eventName'],
);
}
public function basename(): string
{
return 'zuschuesse-remscheid';
}
public function view(): string
{
return 'tex.contribution.city-remscheid';
}
public function template(): Template
{
return Template::make('tex.templates.contribution');
}
public function setFilename(string $filename): static
{
$this->filename = $filename;
return $this;
}
public function getEngine(): Engine
{
return Engine::PDFLATEX;
}
public static function getName(): string
{
return 'Remscheid';
return 'Für Remscheid erstellen';
}
/**

View File

@ -6,7 +6,9 @@ use App\Contribution\Data\MemberData;
use App\Invoice\InvoiceSettings;
use Carbon\Carbon;
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
use Zoomyboy\Tex\Engine;
use Zoomyboy\Tex\Template;
class CitySolingenDocument extends ContributionDocument
{
@ -23,7 +25,6 @@ class CitySolingenDocument extends ContributionDocument
public string $eventName,
public string $type = 'F',
) {
$this->setEventName($eventName);
$this->fromName = app(InvoiceSettings::class)->from_long;
}
@ -73,6 +74,11 @@ class CitySolingenDocument extends ContributionDocument
return Carbon::parse($this->dateUntil)->format('d.m.Y');
}
public function template(): Template
{
return Template::make('tex.templates.contribution');
}
public function checkboxes(): string
{
$output = '';
@ -88,6 +94,16 @@ class CitySolingenDocument extends ContributionDocument
return $firstRow . "\n" . $secondRow;
}
public function basename(): string
{
return 'zuschuesse-solingen-' . Str::slug($this->eventName);
}
public function view(): string
{
return 'tex.contribution.city-solingen';
}
public function getEngine(): Engine
{
return Engine::PDFLATEX;
@ -95,7 +111,7 @@ class CitySolingenDocument extends ContributionDocument
public static function getName(): string
{
return 'Stadt Solingen';
return 'Für Stadt Solingen erstellen';
}
/**
@ -107,6 +123,7 @@ class CitySolingenDocument extends ContributionDocument
'dateFrom' => 'required|string|date_format:Y-m-d',
'dateUntil' => 'required|string|date_format:Y-m-d',
'zipLocation' => 'required|string',
'eventName' => 'required|string',
];
}
}

View File

@ -3,12 +3,9 @@
namespace App\Contribution\Documents;
use Zoomyboy\Tex\Document;
use Zoomyboy\Tex\Template;
abstract class ContributionDocument extends Document
{
private string $eventName;
abstract public static function getName(): string;
/**
@ -32,34 +29,8 @@ abstract class ContributionDocument extends Document
public static function globalRules(): array
{
return [
'eventName' => 'required|string',
'members' => 'present|array|min:1',
'members.*' => 'integer|exists:members,id',
];
}
public static function buttonName(): string
{
return 'Für ' . static::getName() . ' erstellen';;
}
public function setEventName(string $eventName): void
{
$this->eventName = $eventName;
}
public function basename(): string
{
return str('Zuschüsse ')->append($this->getName())->append(' ')->append($this->eventName)->slug();
}
public function template(): Template
{
return Template::make('tex.templates.contribution');
}
public function view(): string
{
return 'tex.contribution.' . str(class_basename(static::class))->replace('Document', '')->kebab()->toString();
}
}

View File

@ -3,16 +3,14 @@
namespace App\Contribution\Documents;
use App\Contribution\Data\MemberData;
use App\Contribution\Traits\FormatsDates;
use App\Contribution\Traits\HasPdfBackground;
use App\Country;
use Carbon\Carbon;
use Illuminate\Support\Collection;
use Zoomyboy\Tex\Engine;
use Zoomyboy\Tex\Template;
class RdpNrwDocument extends ContributionDocument
{
use HasPdfBackground;
use FormatsDates;
/**
* @param Collection<int, Collection<int, MemberData>> $members
*/
@ -24,9 +22,14 @@ class RdpNrwDocument extends ContributionDocument
public Collection $members,
public ?string $filename = '',
public string $type = 'F',
public string $eventName = '',
) {
$this->setEventName($eventName);
}
public function dateRange(): string
{
return Carbon::parse($this->dateFrom)->format('d.m.Y')
. ' - '
. Carbon::parse($this->dateUntil)->format('d.m.Y');
}
/**
@ -40,7 +43,6 @@ class RdpNrwDocument extends ContributionDocument
zipLocation: $request['zipLocation'],
country: Country::where('id', $request['country'])->firstOrFail(),
members: MemberData::fromModels($request['members'])->chunk(17),
eventName: $request['eventName'],
);
}
@ -55,7 +57,6 @@ class RdpNrwDocument extends ContributionDocument
zipLocation: $request['zipLocation'],
country: Country::where('id', $request['country'])->firstOrFail(),
members: MemberData::fromApi($request['member_data'])->chunk(17),
eventName: $request['eventName'],
);
}
@ -64,9 +65,65 @@ class RdpNrwDocument extends ContributionDocument
return $this->country->name;
}
public function memberShort(MemberData $member): string
{
return $member->isLeader ? 'L' : '';
}
public function memberName(MemberData $member): string
{
return $member->separatedName();
}
public function memberAddress(MemberData $member): string
{
return $member->fullAddress();
}
public function memberGender(MemberData $member): string
{
if (!$member->gender) {
return '';
}
return strtolower(substr($member->gender->name, 0, 1));
}
public function memberAge(MemberData $member): string
{
return $member->age();
}
public function basename(): string
{
return 'zuschuesse-rdp-nrw';
}
public function view(): string
{
return 'tex.contribution.rdp-nrw';
}
public function template(): Template
{
return Template::make('tex.templates.contribution');
}
public function setFilename(string $filename): static
{
$this->filename = $filename;
return $this;
}
public function getEngine(): Engine
{
return Engine::PDFLATEX;
}
public static function getName(): string
{
return 'RdP NRW';
return 'Für RdP NRW erstellen';
}
/**
@ -79,6 +136,7 @@ class RdpNrwDocument extends ContributionDocument
'dateUntil' => 'required|string|date_format:Y-m-d',
'country' => 'required|integer|exists:countries,id',
'zipLocation' => 'required|string',
'eventName' => 'required|string',
];
}
}

View File

@ -1,79 +0,0 @@
<?php
namespace App\Contribution\Documents;
use App\Contribution\Data\MemberData;
use App\Contribution\Traits\FormatsDates;
use App\Contribution\Traits\HasPdfBackground;
use App\Country;
use Illuminate\Support\Collection;
class WuppertalDocument extends ContributionDocument
{
use HasPdfBackground;
use FormatsDates;
/**
* @param Collection<int, Collection<int, MemberData>> $members
*/
public function __construct(
public string $dateFrom,
public string $dateUntil,
public string $zipLocation,
public ?Country $country,
public Collection $members,
public ?string $filename = '',
public string $type = 'F',
public string $eventName = '',
) {
$this->setEventName($eventName);
}
/**
* {@inheritdoc}
*/
public static function fromRequest(array $request): self
{
return new self(
dateFrom: $request['dateFrom'],
dateUntil: $request['dateUntil'],
zipLocation: $request['zipLocation'],
country: Country::where('id', $request['country'])->firstOrFail(),
members: MemberData::fromModels($request['members'])->chunk(14),
eventName: $request['eventName'],
);
}
/**
* {@inheritdoc}
*/
public static function fromApiRequest(array $request): self
{
return new self(
dateFrom: $request['dateFrom'],
dateUntil: $request['dateUntil'],
zipLocation: $request['zipLocation'],
country: Country::where('id', $request['country'])->firstOrFail(),
members: MemberData::fromApi($request['member_data'])->chunk(14),
eventName: $request['eventName'],
);
}
public static function getName(): string
{
return 'Wuppertal';
}
/**
* @return array<string, mixed>
*/
public static function rules(): array
{
return [
'dateFrom' => 'required|string|date_format:Y-m-d',
'dateUntil' => 'required|string|date_format:Y-m-d',
'zipLocation' => 'required|string',
];
}
}

View File

@ -1,24 +0,0 @@
<?php
namespace App\Contribution\Traits;
use Carbon\Carbon;
trait FormatsDates
{
public function niceDateFrom(): string
{
return Carbon::parse($this->dateFrom)->format('d.m.Y');
}
public function niceDateUntil(): string
{
return Carbon::parse($this->dateUntil)->format('d.m.Y');
}
public function dateRange(): string
{
return implode(' - ', [$this->niceDateFrom(), $this->niceDateUntil()]);
}
}

View File

@ -1,13 +0,0 @@
<?php
namespace App\Contribution\Traits;
use Zoomyboy\Tex\Engine;
trait HasPdfBackground
{
public function getEngine(): Engine
{
return Engine::PDFLATEX;
}
}

View File

@ -3,13 +3,11 @@
namespace App;
use App\Nami\HasNamiField;
use Database\Factories\CountryFactory;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Country extends Model
{
/** @use HasFactory<CountryFactory> */
use HasFactory;
use HasNamiField;

View File

@ -3,13 +3,11 @@
namespace App\Course\Models;
use App\Nami\HasNamiField;
use Database\Factories\Course\Models\CourseFactory;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Course extends Model
{
/** @use HasFactory<CourseFactory> */
use HasFactory;
use HasNamiField;

View File

@ -3,14 +3,12 @@
namespace App\Course\Models;
use App\Member\Member;
use Database\Factories\Course\Models\CourseMemberFactory;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
class CourseMember extends Model
{
/** @use HasFactory<CourseMemberFactory> */
use HasFactory;
/** @var array<int, string> */

View File

@ -2,9 +2,7 @@
namespace App\Dashboard;
use Illuminate\Routing\Router;
use Illuminate\Support\ServiceProvider;
use App\Dashboard\Actions\IndexAction as DashboardIndexAction;
class DashboardServiceProvider extends ServiceProvider
{
@ -25,8 +23,5 @@ class DashboardServiceProvider extends ServiceProvider
*/
public function boot()
{
app(Router::class)->middleware(['web', 'auth:web'])->group(function ($router) {
$router->get('/', DashboardIndexAction::class)->name('home');
});
}
}

View File

@ -8,6 +8,9 @@ use Sabre\CardDAV\Backend\AbstractBackend;
use Sabre\DAV\PropPatch;
use Sabre\VObject\Component\VCard;
/**
* @template M as array{lastmodified: int, etag: string, uri: string, id: int, size: int}
*/
class AddressBookBackend extends AbstractBackend
{
/**
@ -112,7 +115,7 @@ class AddressBookBackend extends AbstractBackend
*
* @param mixed $addressbookId
*
* @return array<int, AddressBookCard>
* @return array<int, M>
*/
public function getCards($addressbookId): array
{
@ -130,7 +133,7 @@ class AddressBookBackend extends AbstractBackend
* @param mixed $addressBookId
* @param string $cardUri
*
* @return AddressBookCard|bool
* @return M
*/
public function getCard($addressBookId, $cardUri)
{
@ -155,9 +158,8 @@ class AddressBookBackend extends AbstractBackend
* If the backend supports this, it may allow for some speed-ups.
*
* @param mixed $addressBookId
* @param array<int, string> $uris
*
* @return array<int, mixed>
* @return array
*/
public function getMultipleCards($addressBookId, array $uris)
{
@ -246,7 +248,7 @@ class AddressBookBackend extends AbstractBackend
}
/**
* @return AddressBookCard
* @return M
*/
private function cardMeta(Member $member): array
{

339
app/Dav/CalendarBackend.php Normal file
View File

@ -0,0 +1,339 @@
<?php
namespace App\Dav;
use App\Member\Member;
use App\User;
use Sabre\CalDAV\Backend\AbstractBackend;
use Sabre\DAV\PropPatch;
use Sabre\VObject\Component\VCard;
/**
* @template M as array{lastmodified: int, etag: string, uri: string, id: int, size: int}
*/
class CalendarBackend extends AbstractBackend
{
/**
* Returns a list of calendars for a principal.
*
* Every project is an array with the following keys:
* * id, a unique id that will be used by other functions to modify the
* calendar. This can be the same as the uri or a database key.
* * uri, which is the basename of the uri with which the calendar is
* accessed.
* * principaluri. The owner of the calendar. Almost always the same as
* principalUri passed to this method.
*
* Furthermore it can contain webdav properties in clark notation. A very
* common one is '{DAV:}displayname'.
*
* Many clients also require:
* {urn:ietf:params:xml:ns:caldav}supported-calendar-component-set
* For this property, you can just return an instance of
* Sabre\CalDAV\Property\SupportedCalendarComponentSet.
*
* If you return {http://sabredav.org/ns}read-only and set the value to 1,
* ACL will automatically be put in read-only mode.
*
* @param string $principalUri
*
* @return array<int, array<string, mixed>>
*/
public function getCalendarsForUser($principalUri)
{
if (1 !== preg_match('/^principals\/(.*)$/', $principalUri, $matches)) {
return [];
}
User::where('email', $matches[1])->firstOrFail();
return [
[
'id' => 'birthdays',
'principaluri' => $principalUri,
'uri' => 'birthdays',
'{DAV:}displayname' => 'Geburtstage',
],
];
}
/**
* Creates a new calendar for a principal.
*
* If the creation was a success, an id must be returned that can be used to
* reference this calendar in other methods, such as updateCalendar.
*
* The id can be any type, including ints, strings, objects or array.
*
* @param string $principalUri
* @param string $calendarUri
* @param array<string, mixed> $properties
*
* @return mixed
*/
public function createCalendar($principalUri, $calendarUri, array $properties)
{
}
/**
* Updates properties for a calendar.
*
* The list of mutations is stored in a Sabre\DAV\PropPatch object.
* To do the actual updates, you must tell this object which properties
* you're going to process with the handle() method.
*
* Calling the handle method is like telling the PropPatch object "I
* promise I can handle updating this property".
*
* Read the PropPatch documentation for more info and examples.
*
* @param mixed $calendarId
* @return void
*/
public function updateCalendar($calendarId, \Sabre\DAV\PropPatch $propPatch)
{
}
/**
* Delete a calendar and all its objects.
*
* @param mixed $calendarId
* @return void
*/
public function deleteCalendar($calendarId)
{
}
/**
* Returns all calendar objects within a calendar.
*
* Every item contains an array with the following keys:
* * calendardata - The iCalendar-compatible calendar data
* * uri - a unique key which will be used to construct the uri. This can
* be any arbitrary string, but making sure it ends with '.ics' is a
* good idea. This is only the basename, or filename, not the full
* path.
* * lastmodified - a timestamp of the last modification time
* * etag - An arbitrary string, surrounded by double-quotes. (e.g.:
* '"abcdef"')
* * size - The size of the calendar objects, in bytes.
* * component - optional, a string containing the type of object, such
* as 'vevent' or 'vtodo'. If specified, this will be used to populate
* the Content-Type header.
*
* Note that the etag is optional, but it's highly encouraged to return for
* speed reasons.
*
* The calendardata is also optional. If it's not returned
* 'getCalendarObject' will be called later, which *is* expected to return
* calendardata.
*
* If neither etag or size are specified, the calendardata will be
* used/fetched to determine these numbers. If both are specified the
* amount of times this is needed is reduced by a great degree.
*
* @param mixed $calendarId
*
* @return array
* @return void
*/
public function getCalendarObjects($calendarId)
{
return Member::whereNotNull('birthday')->get()->map(fn ($member) => $this->calendarObjectMeta($member))->toArray();
}
private function calendarObjectMeta(Member $member): array
{
return [
'calendardata' => $member->toCalendarObject()->serialize(),
'uri' => $member->slug . '.ics',
'lastmodified' => $member->updated_at->timestamp,
'etag' => '"' . $member->etag . '"',
'size' => strlen($member->toCalendarObject()->serialize()),
'component' => 'vevent',
];
}
/**
* Returns information from a single calendar object, based on it's object
* uri.
*
* The object uri is only the basename, or filename and not a full path.
*
* The returned array must have the same keys as getCalendarObjects. The
* 'calendardata' object is required here though, while it's not required
* for getCalendarObjects.
*
* This method must return null if the object did not exist.
*
* @param mixed $calendarId
* @param string $objectUri
*
* @return array|null
*/
public function getCalendarObject($calendarId, $objectUri)
{
$member = Member::where('slug', str($objectUri)->replace('.ics', ''))->first();
if (!$member || !$member->toCalendarObject()) {
return null;
}
return [
...$this->calendarObjectMeta($member),
'calendardata' => $member->toCalendarObject()->serialize(),
];
}
/**
* Returns a list of calendar objects.
*
* This method should work identical to getCalendarObject, but instead
* return all the calendar objects in the list as an array.
*
* If the backend supports this, it may allow for some speed-ups.
*
* @param mixed $calendarId
*
* @return array
*/
public function getMultipleCalendarObjects($calendarId, array $uris)
{
return Member::whereNotNull('birthday')->get()->map(fn ($member) => $this->getCalendarObject($calendarId, $member->slug . '.ics'))->toArray();
}
/**
* Creates a new calendar object.
*
* The object uri is only the basename, or filename and not a full path.
*
* It is possible to return an etag from this function, which will be used
* in the response to this PUT request. Note that the ETag must be
* surrounded by double-quotes.
*
* However, you should only really return this ETag if you don't mangle the
* calendar-data. If the result of a subsequent GET to this object is not
* the exact same as this request body, you should omit the ETag.
*
* @param mixed $calendarId
* @param string $objectUri
* @param string $calendarData
*
* @return string|null
*/
public function createCalendarObject($calendarId, $objectUri, $calendarData)
{
}
/**
* Updates an existing calendarobject, based on it's uri.
*
* The object uri is only the basename, or filename and not a full path.
*
* It is possible return an etag from this function, which will be used in
* the response to this PUT request. Note that the ETag must be surrounded
* by double-quotes.
*
* However, you should only really return this ETag if you don't mangle the
* calendar-data. If the result of a subsequent GET to this object is not
* the exact same as this request body, you should omit the ETag.
*
* @param mixed $calendarId
* @param string $objectUri
* @param string $calendarData
*
* @return string|null
*/
public function updateCalendarObject($calendarId, $objectUri, $calendarData)
{
}
/**
* Deletes an existing calendar object.
*
* The object uri is only the basename, or filename and not a full path.
*
* @param mixed $calendarId
* @param string $objectUri
*/
public function deleteCalendarObject($calendarId, $objectUri)
{
}
/**
* Performs a calendar-query on the contents of this calendar.
*
* The calendar-query is defined in RFC4791 : CalDAV. Using the
* calendar-query it is possible for a client to request a specific set of
* object, based on contents of iCalendar properties, date-ranges and
* iCalendar component types (VTODO, VEVENT).
*
* This method should just return a list of (relative) urls that match this
* query.
*
* The list of filters are specified as an array. The exact array is
* documented by Sabre\CalDAV\CalendarQueryParser.
*
* Note that it is extremely likely that getCalendarObject for every path
* returned from this method will be called almost immediately after. You
* may want to anticipate this to speed up these requests.
*
* This method provides a default implementation, which parses *all* the
* iCalendar objects in the specified calendar.
*
* This default may well be good enough for personal use, and calendars
* that aren't very large. But if you anticipate high usage, big calendars
* or high loads, you are strongly adviced to optimize certain paths.
*
* The best way to do so is override this method and to optimize
* specifically for 'common filters'.
*
* Requests that are extremely common are:
* * requests for just VEVENTS
* * requests for just VTODO
* * requests with a time-range-filter on either VEVENT or VTODO.
*
* ..and combinations of these requests. It may not be worth it to try to
* handle every possible situation and just rely on the (relatively
* easy to use) CalendarQueryValidator to handle the rest.
*
* Note that especially time-range-filters may be difficult to parse. A
* time-range filter specified on a VEVENT must for instance also handle
* recurrence rules correctly.
* A good example of how to interprete all these filters can also simply
* be found in Sabre\CalDAV\CalendarQueryFilter. This class is as correct
* as possible, so it gives you a good idea on what type of stuff you need
* to think of.
*
* @param mixed $calendarId
*
* @return array
*/
public function calendarQuery($calendarId, array $filters)
{
}
/**
* Searches through all of a users calendars and calendar objects to find
* an object with a specific UID.
*
* This method should return the path to this object, relative to the
* calendar home, so this path usually only contains two parts:
*
* calendarpath/objectpath.ics
*
* If the uid is not found, return null.
*
* This method should only consider * objects that the principal owns, so
* any calendars owned by other principals that also appear in this
* collection should be ignored.
*
* @param string $principalUri
* @param string $uid
*
* @return string|null
*/
public function getCalendarObjectByUID($principalUri, $uid)
{
}
}

View File

@ -136,11 +136,10 @@ class Principal implements PrincipalBackendInterface
*
* @param string $principal
*
* @return array<int, string>|null
* @return array
*/
public function getGroupMemberSet($principal)
{
return [];
}
/**
@ -148,7 +147,7 @@ class Principal implements PrincipalBackendInterface
*
* @param string $principal
*
* @return array<int, string>|null
* @return array
*/
public function getGroupMembership($principal)
{
@ -156,7 +155,7 @@ class Principal implements PrincipalBackendInterface
return null;
}
return ['addressbooks/' . $matches[1]];
return ['addressbooks/'.$matches[1]];
}
/**
@ -165,8 +164,6 @@ class Principal implements PrincipalBackendInterface
* The principals should be passed as a list of uri's.
*
* @param string $principal
* @param array<int, string> $members
* @return void
*/
public function setGroupMemberSet($principal, array $members)
{
@ -178,8 +175,8 @@ class Principal implements PrincipalBackendInterface
private function userToPrincipal(User $user): array
{
return [
'{DAV:}displayname' => $user->firstname . ' ' . $user->lastname,
'uri' => 'principals/' . $user->email,
'{DAV:}displayname' => $user->name,
'uri' => 'principals/'.$user->email,
'{http://sabredav.org/ns}email-address' => $user->email,
];
}

View File

@ -6,10 +6,11 @@ use Illuminate\Support\ServiceProvider as BaseServiceProvider;
use LaravelSabre\Http\Auth\AuthBackend;
use LaravelSabre\LaravelSabre;
use Sabre\CardDAV\AddressBookRoot;
use Sabre\CalDAV\CalendarRoot;
use Sabre\CardDAV\Plugin as CardDAVPlugin;
use Sabre\CalDAV\Plugin as CalDAVPlugin;
use Sabre\DAV\Auth\Plugin as AuthPlugin;
use Sabre\DAV\Browser\Plugin as BrowserPlugin;
use Sabre\DAV\ServerPlugin;
use Sabre\DAVACL\AbstractPrincipalCollection;
use Sabre\DAVACL\Plugin as AclPlugin;
use Sabre\DAVACL\PrincipalCollection;
@ -43,17 +44,15 @@ class ServiceProvider extends BaseServiceProvider
{
$principalBackend = new Principal();
$addressBookBackend = new AddressBookBackend();
$calendarBackend = new CalendarBackend();
// Directory tree
return [
new PrincipalCollection($principalBackend),
new AddressBookRoot($principalBackend, $addressBookBackend),
new CalendarRoot($principalBackend, $calendarBackend),
];
}
/**
* @return array<int, ServerPlugin>
*/
private function plugins(): array
{
$authBackend = new AuthBackend();
@ -62,6 +61,7 @@ class ServiceProvider extends BaseServiceProvider
new BrowserPlugin(),
new AuthPlugin($authBackend),
new CardDAVPlugin(),
new CalDAVPlugin(),
new AclPlugin(),
];
}

View File

@ -19,7 +19,7 @@ class EfzPendingBlock extends Block
})
->whereCurrentGroup()
->orderByRaw('lastname, firstname')
->whereHas('memberships', fn ($builder) => $builder->isLeader()->active());
->whereHas('memberships', fn ($builder) => $builder->isLeader());
}
/**

View File

@ -12,14 +12,15 @@ class Handler extends ExceptionHandler
/**
* A list of the exception types that are not reported.
*
* @var array<int, class-string<Throwable>>
* @var string[]
*/
protected $dontReport = [];
protected $dontReport = [
];
/**
* A list of the inputs that are never flashed for validation exceptions.
*
* @var array<int, string>
* @var string[]
*/
protected $dontFlash = [
'password',

View File

@ -4,14 +4,12 @@ namespace App;
use App\Nami\HasNamiField;
use App\Payment\Subscription;
use Database\Factories\FeeFactory;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;
class Fee extends Model
{
/** @use HasFactory<FeeFactory> */
use HasFactory;
use HasNamiField;

View File

@ -1,21 +0,0 @@
<?php
namespace App\Fileshare\Actions;
use App\Fileshare\Models\Fileshare;
use App\Fileshare\Resources\FileshareResource;
use Illuminate\Http\Resources\Json\AnonymousResourceCollection;
use Lorisleiva\Actions\Concerns\AsAction;
class FileshareApiIndexAction
{
use AsAction;
public function handle(): AnonymousResourceCollection
{
session()->put('menu', 'setting');
session()->put('title', 'Datei-Verbindungen');
return FileshareResource::collection(Fileshare::paginate(15));
}
}

View File

@ -1,42 +0,0 @@
<?php
namespace App\Fileshare\Actions;
use App\Fileshare\Models\Fileshare;
use App\Lib\Events\Succeeded;
use Illuminate\Validation\ValidationException;
use Lorisleiva\Actions\ActionRequest;
use Lorisleiva\Actions\Concerns\AsAction;
class FileshareStoreAction
{
use AsAction;
/**
* @return array<string, mixed>
*/
public function rules(): array
{
return [
'name' => 'required|string|max:255',
'type' => 'required|string|max:255|exclude',
'config' => 'array|exclude',
];
}
public function asController(ActionRequest $request): void
{
$type = $request->input('type')::from($request->input('config'));
if (!$type->check()) {
throw ValidationException::withMessages(['type' => 'Verbindung fehlgeschlagen']);
}
Fileshare::create([
...$request->validated(),
'type' => $type,
]);
Succeeded::message('Verbindung erstellt.')->dispatch();
}
}

View File

@ -1,42 +0,0 @@
<?php
namespace App\Fileshare\Actions;
use App\Fileshare\Models\Fileshare;
use App\Lib\Events\Succeeded;
use Illuminate\Validation\ValidationException;
use Lorisleiva\Actions\ActionRequest;
use Lorisleiva\Actions\Concerns\AsAction;
class FileshareUpdateAction
{
use AsAction;
/**
* @return array<string, mixed>
*/
public function rules(): array
{
return [
'name' => 'required|string|max:255',
'type' => 'required|string|max:255|exclude',
'config' => 'array|exclude',
];
}
public function handle(ActionRequest $request, Fileshare $fileshare): void
{
$type = $request->input('type')::from($request->input('config'));
if (!$type->check()) {
throw ValidationException::withMessages(['type' => 'Verbindung fehlgeschlagen']);
}
$fileshare->update([
...$request->validated(),
'type' => $type,
]);
Succeeded::message('Verbindung bearbeitet.')->dispatch();
}
}

View File

@ -1,22 +0,0 @@
<?php
namespace App\Fileshare\Actions;
use App\Fileshare\Data\ResourceData;
use App\Fileshare\Models\Fileshare;
use Lorisleiva\Actions\ActionRequest;
use Lorisleiva\Actions\Concerns\AsAction;
use Spatie\LaravelData\DataCollection;
class ListFilesAction
{
use AsAction;
/**
* @return DataCollection<int, ResourceData>
*/
public function handle(ActionRequest $request, Fileshare $fileshare): DataCollection
{
return ResourceData::collect($fileshare->type->getSubDirectories($request->input('parent')), DataCollection::class)->wrap('data');
}
}

View File

@ -1,57 +0,0 @@
<?php
namespace App\Fileshare\ConnectionTypes;
use Illuminate\Filesystem\FilesystemAdapter;
use Illuminate\Support\Collection;
use Spatie\LaravelData\Data;
abstract class ConnectionType extends Data
{
abstract public function check(): bool;
/**
* @return array<string, mixed>
*/
abstract public static function defaults(): array;
abstract public static function title(): string;
abstract public function getFilesystem(): FilesystemAdapter;
/**
* @return array<int, array{label: string, key: string, type: string}>
*/
abstract public static function fields(): array;
/**
* @return array<int, mixed>
*/
public static function forSelect(): array
{
return self::types()
->map(fn ($file) => ['id' => $file, 'name' => $file::title(), 'defaults' => $file::defaults(), 'fields' => $file::fields()])
->toArray();
}
/**
* @return array<int, string>
*/
public function getSubDirectories(?string $parent): array
{
$filesystem = $this->getFilesystem();
return $filesystem->directories($parent ?: '/');
}
/**
* @return Collection<int, class-string<ConnectionType>>
*/
private static function types(): Collection
{
return collect(glob(base_path('app/Fileshare/ConnectionTypes/*')))
->map(fn ($file) => 'App\\Fileshare\\ConnectionTypes\\' . pathinfo($file, PATHINFO_FILENAME))
->filter(fn ($file) => $file !== static::class)
->values();
}
}

View File

@ -1,44 +0,0 @@
<?php
namespace App\Fileshare\ConnectionTypes;
use Illuminate\Filesystem\FilesystemAdapter;
use Illuminate\Http\Client\ConnectionException;
use Illuminate\Support\Facades\Http;
use League\Flysystem\Filesystem;
use League\Flysystem\WebDAV\WebDAVAdapter;
use Sabre\DAV\Client;
class NextcloudConnection extends OwncloudConnection
{
public function check(): bool
{
try {
$response = Http::withoutVerifying()
->withBasicAuth($this->user, $this->password)
->withHeaders(['OCS-APIRequest' => 'true'])
->acceptJson()
->get($this->baseUrl . '/ocs/v2.php/cloud/capabilities');
return $response->ok();
} catch (ConnectionException $e) {
return false;
}
}
public static function title(): string
{
return 'Nextcloud';
}
public function getFilesystem(): FilesystemAdapter
{
$adapter = new WebDAVAdapter(new Client([
'baseUri' => $this->baseUrl . '/remote.php/dav/files/' . $this->user,
'userName' => $this->user,
'password' => $this->password,
]), '/remote.php/dav/files/' . $this->user);
return new FilesystemAdapter(new Filesystem($adapter), $adapter);
}
}

View File

@ -1,76 +0,0 @@
<?php
namespace App\Fileshare\ConnectionTypes;
use Illuminate\Filesystem\FilesystemAdapter;
use Illuminate\Http\Client\ConnectionException;
use Illuminate\Support\Facades\Http;
use League\Flysystem\Filesystem;
use League\Flysystem\WebDAV\WebDAVAdapter;
use Sabre\DAV\Client;
use Spatie\LaravelData\Attributes\MapInputName;
use Spatie\LaravelData\Attributes\MapOutputName;
use Spatie\LaravelData\Mappers\SnakeCaseMapper;
#[MapInputName(SnakeCaseMapper::class)]
#[MapOutputName(SnakeCaseMapper::class)]
class OwncloudConnection extends ConnectionType
{
public function __construct(
public string $user,
public string $password,
public string $baseUrl,
) {
}
public function check(): bool
{
try {
$response = Http::withoutVerifying()->withBasicAuth($this->user, $this->password)->acceptJson()->get($this->baseUrl . '/ocs/v1.php/cloud/capabilities?format=json');
return $response->ok();
} catch (ConnectionException $e) {
return false;
}
}
/**
* @inheritdoc
*/
public static function defaults(): array
{
return [
'user' => '',
'password' => '',
'base_url' => '',
];
}
public static function title(): string
{
return 'Owncloud';
}
/**
* @inheritdoc
*/
public static function fields(): array
{
return [
['label' => 'URL', 'key' => 'base_url', 'type' => 'text'],
['label' => 'Benutzer', 'key' => 'user', 'type' => 'text'],
['label' => 'Passwort', 'key' => 'password', 'type' => 'password'],
];
}
public function getFilesystem(): FilesystemAdapter
{
$adapter = new WebDAVAdapter(new Client([
'baseUri' => $this->baseUrl . '/remote.php/dav/files/' . $this->user,
'userName' => $this->user,
'password' => $this->password,
]), '/remote.php/dav/files/' . $this->user);
return new FilesystemAdapter(new Filesystem($adapter), $adapter);
}
}

View File

@ -1,30 +0,0 @@
<?php
namespace App\Fileshare\Data;
use App\Fileshare\Models\Fileshare;
use Illuminate\Filesystem\FilesystemAdapter;
use Spatie\LaravelData\Attributes\MapInputName;
use Spatie\LaravelData\Attributes\MapOutputName;
use Spatie\LaravelData\Data;
use Spatie\LaravelData\Mappers\SnakeCaseMapper;
#[MapInputName(SnakeCaseMapper::class)]
#[MapOutputName(SnakeCaseMapper::class)]
class FileshareResourceData extends Data
{
public function __construct(public int $connectionId, public string $resource)
{
}
public function getConnection(): Fileshare
{
return Fileshare::find($this->connectionId);
}
public function getStorage(): FilesystemAdapter
{
return $this->getConnection()->type->getFilesystem();
}
}

View File

@ -1,24 +0,0 @@
<?php
namespace App\Fileshare\Data;
use Spatie\LaravelData\Data;
class ResourceData extends Data
{
public function __construct(public string $name, public string $path, public string $parent)
{
}
public static function fromString(string $path): self
{
$dir = '/' . trim($path, '\\/');
return self::from([
'path' => $dir,
'name' => pathinfo($dir, PATHINFO_BASENAME),
'parent' => pathinfo($dir, PATHINFO_DIRNAME),
]);
}
}

View File

@ -1,30 +0,0 @@
<?php
namespace App\Fileshare;
use App\Fileshare\Models\Fileshare;
use App\Fileshare\Resources\FileshareResource;
use App\Setting\LocalSettings;
class FileshareSettings extends LocalSettings
{
public static function group(): string
{
return 'fileshare';
}
public static function title(): string
{
return 'Datei-Verbindungen';
}
/**
* @inheritdoc
*/
public function viewData(): array
{
return [
'data' => FileshareResource::collection(Fileshare::paginate(15))
];
}
}

View File

@ -1,20 +0,0 @@
<?php
namespace App\Fileshare\Models;
use App\Fileshare\ConnectionTypes\ConnectionType;
use Database\Factories\Fileshare\Models\FileshareFactory;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Fileshare extends Model
{
/** @use HasFactory<FileshareFactory> */
use HasFactory;
public $guarded = [];
public $casts = [
'type' => ConnectionType::class,
];
}

View File

@ -1,56 +0,0 @@
<?php
namespace App\Fileshare\Resources;
use App\Fileshare\ConnectionTypes\ConnectionType;
use App\Fileshare\Models\Fileshare;
use App\Lib\HasMeta;
use Illuminate\Http\Resources\Json\JsonResource;
/**
* @mixin Fileshare
*/
class FileshareResource extends JsonResource
{
use HasMeta;
/**
* Transform the resource into an array.
*
* @param \Illuminate\Http\Request $request
* @return array<string, mixed>
*/
public function toArray($request)
{
return [
'name' => $this->name,
'is_active' => $this->type->check(),
'type' => get_class($this->type),
'config' => $this->type->toArray(),
'id' => $this->id,
'type_human' => $this->type::title(),
'links' => [
'update' => route('fileshare.update', ['fileshare' => $this->getModel()]),
]
];
}
/**
* @return array<string, mixed>
*/
public static function meta(): array
{
return [
'default' => [
'name' => '',
'type' => null,
'config' => null,
],
'types' => ConnectionType::forSelect(),
'links' => [
'store' => route('fileshare.store'),
]
];
}
}

View File

@ -1,17 +0,0 @@
<?php
namespace App\Form\Actions;
use App\Form\FormSettings;
use Illuminate\Support\Facades\Http;
use Lorisleiva\Actions\Concerns\AsAction;
class ClearFrontendCacheAction
{
use AsAction;
public function handle(): void
{
Http::get(app(FormSettings::class)->clearCacheUrl);
}
}

View File

@ -1,71 +0,0 @@
<?php
namespace App\Form\Actions;
use App\Form\Models\Form;
use App\Form\Models\Participant;
use Illuminate\Database\Eloquent\Collection;
use Lorisleiva\Actions\Concerns\AsAction;
use Zoomyboy\TableDocument\SheetData;
use Zoomyboy\TableDocument\TableDocumentData;
class CreateExcelDocumentAction
{
use AsAction;
public Form $form;
/**
* @param Collection<int, Participant> $participants
*/
public function handle(Form $form, Collection $participants): string
{
$this->form = $form;
return file_get_contents($this->allSheet($participants)->compile($this->tempPath()));
}
/**
* @param Collection<int, Participant> $participants
*/
private function allSheet(Collection $participants): TableDocumentData
{
$document = TableDocumentData::from(['title' => 'Anmeldungen für ' . $this->form->name, 'sheets' => []]);
$headers = $this->form->getFields()->map(fn ($field) => $field->name)->toArray();
$document->addSheet(SheetData::from([
'header' => $headers,
'data' => $participants
->map(fn ($participant) => $this->form->getFields()->map(fn ($field) => $participant->getFields()->find($field)->presentRaw())->toArray())
->toArray(),
'name' => 'Alle',
]));
if ($this->form->export->groupBy) {
$groups = $participants->groupBy(fn ($participant) => $participant->getFields()->findByKey($this->form->export->groupBy)->presentRaw());
foreach ($groups as $name => $participants) {
$document->addSheet(SheetData::from([
'header' => $headers,
'data' => $participants
->map(fn ($participant) => $this->form->getFields()->map(fn ($field) => $participant->getFields()->find($field)->presentRaw())->toArray())
->toArray(),
'name' => $name,
]));
}
$document->addSheet(SheetData::from([
'header' => ['Wert', 'Anzahl'],
'data' => $groups->map(fn ($participants, $name) => [$name, (string) count($participants)])->toArray(),
'name' => 'Statistik',
]));
}
return $document;
}
private function tempPath(): string
{
return sys_get_temp_dir() . '/' . str()->uuid()->toString();
}
}

View File

@ -1,30 +0,0 @@
<?php
namespace App\Form\Actions;
use App\Form\Models\Form;
use Illuminate\Support\Facades\Storage;
use League\Csv\Writer;
use Lorisleiva\Actions\ActionRequest;
use Lorisleiva\Actions\Concerns\AsAction;
use Symfony\Component\HttpFoundation\StreamedResponse;
class ExportAction
{
use AsAction;
public function handle(Form $form): string
{
return CreateExcelDocumentAction::run($form, $form->participants);
}
public function asController(Form $form, ActionRequest $request): StreamedResponse
{
$contents = $this->handle($form);
$filename = 'tn-' . $form->slug . '.xlsx';
Storage::disk('temp')->put($filename, $contents);
return Storage::disk('temp')->download($filename);
}
}

View File

@ -1,41 +0,0 @@
<?php
namespace App\Form\Actions;
use App\Form\Models\Form;
use App\Group;
use Lorisleiva\Actions\Concerns\AsAction;
class ExportSyncAction
{
use AsAction;
public Form $form;
public function handle(Form $form): void
{
if (!$form->export->root) {
return;
}
$storage = $form->export->root->getStorage();
$storage->put($form->export->root->resource . '/Anmeldungen ' . $form->name . '.xlsx', CreateExcelDocumentAction::run($form, $form->participants));
if ($form->export->toGroupField) {
foreach ($form->participants->groupBy(fn ($participant) => $participant->data[$form->export->toGroupField]) as $groupId => $participants) {
$group = Group::find($groupId);
if (!$group?->fileshare) {
continue;
}
$group->fileshare->getStorage()->put($group->fileshare->resource . '/Anmeldungen ' . $form->name . '.xlsx', CreateExcelDocumentAction::run($form, $participants));
}
}
}
public function asJob(int $formId): void
{
$this->handle(Form::find($formId));
}
}

View File

@ -27,7 +27,7 @@ class FormApiListAction
{
return FormApiResource::collection($this->handle(
$request->input('filter', ''),
$request->input('perPage', 9999)
$request->input('perPage', 10)
));
}
}

View File

@ -14,8 +14,6 @@ class FormDestroyAction
{
$form->delete();
ClearFrontendCacheAction::run();
Succeeded::message('Veranstaltung gelöscht.')->dispatch();
}
}

View File

@ -28,14 +28,10 @@ class FormStoreAction
'to' => 'required|date',
'registration_from' => 'present|nullable|date',
'registration_until' => 'present|nullable|date',
'mail_top' => 'array',
'mail_bottom' => 'array',
'header_image' => 'required|exclude',
'mailattachments' => 'present|array|exclude',
'is_active' => 'boolean',
'is_private' => 'boolean',
'export' => 'nullable|array',
'needs_prevention' => 'present|boolean',
'prevention_text' => 'array',
'prevention_conditions' => 'array',
];
}
@ -47,7 +43,6 @@ class FormStoreAction
return tap(Form::create($attributes), function ($form) {
$form->setDeferredUploads(request()->input('header_image'));
$form->setDeferredUploads(request()->input('mailattachments'));
ClearFrontendCacheAction::run();
});
}

View File

@ -3,7 +3,6 @@
namespace App\Form\Actions;
use App\Form\Models\Form;
use App\Lib\Editor\Condition;
use App\Lib\Events\Succeeded;
use Illuminate\Http\JsonResponse;
use Lorisleiva\Actions\Concerns\AsAction;
@ -30,12 +29,8 @@ class FormUpdateAction
'to' => 'required|date',
'registration_from' => 'present|nullable|date',
'registration_until' => 'present|nullable|date',
'is_active' => 'boolean',
'is_private' => 'boolean',
'export' => 'nullable|array',
'needs_prevention' => 'present|boolean',
'prevention_text' => 'array',
'prevention_conditions' => 'array',
'mail_top' => 'array',
'mail_bottom' => 'array',
];
}
@ -45,9 +40,6 @@ class FormUpdateAction
public function handle(Form $form, array $attributes): Form
{
$form->update($attributes);
ClearFrontendCacheAction::run();
return $form;
}

View File

@ -22,10 +22,10 @@ class FormUpdateMetaAction
return [
'sorting' => 'array',
'sorting.by' => 'required|string',
'sorting.direction' => 'required|boolean',
'sorting.0' => 'required|string',
'sorting.1' => 'required|string|in:asc,desc',
'active_columns' => 'array',
'active_columns.*' => ['string', Rule::in([...$form->getFields()->pluck('key')->toArray(), 'created_at', 'prevention'])]
'active_columns.*' => ['string', Rule::in([...$form->getFields()->pluck('key')->toArray(), 'created_at'])]
];
}

View File

@ -18,7 +18,6 @@ trait HasValidation
'name' => 'required|string|max:255',
'config' => 'array',
'config.sections.*.name' => 'required',
'config.sections.*.intro' => 'nullable|string',
'config.sections.*.fields' => 'array',
'config.sections.*.fields.*.name' => 'required|string',
'config.sections.*.fields.*.type' => ['required', 'string', Rule::in(array_column(Field::asMeta(), 'id'))],
@ -28,8 +27,6 @@ trait HasValidation
'config.sections.*.fields.*.columns.mobile' => 'required|numeric|gt:0|lte:2',
'config.sections.*.fields.*.columns.tablet' => 'required|numeric|gt:0|lte:4',
'config.sections.*.fields.*.columns.desktop' => 'required|numeric|gt:0|lte:6',
'mail_top' => 'array',
'mail_bottom' => 'array',
];
}

View File

@ -1,27 +0,0 @@
<?php
namespace App\Form\Actions;
use App\Form\Models\Participant;
use Lorisleiva\Actions\ActionRequest;
use Lorisleiva\Actions\Concerns\AsAction;
class ParticipantAssignAction
{
use AsAction;
/**
* @return array<string, mixed>
*/
public function rules(): array
{
return [
'member_id' => 'required|exists:members,id',
];
}
public function handle(Participant $participant, ActionRequest $request): void
{
$participant->update(['member_id' => $request->input('member_id')]);
}
}

View File

@ -1,22 +0,0 @@
<?php
namespace App\Form\Actions;
use App\Form\Models\Participant;
use Illuminate\Http\JsonResponse;
use Lorisleiva\Actions\Concerns\AsAction;
class ParticipantFieldsAction
{
use AsAction;
public function handle(Participant $participant): JsonResponse
{
return response()->json([
'data' => [
'id' => $participant->id,
'config' => $participant->getConfig(),
]
]);
}
}

View File

@ -7,7 +7,7 @@ use App\Form\Models\Participant;
use App\Form\Resources\ParticipantResource;
use App\Form\Scopes\ParticipantFilterScope;
use Illuminate\Http\Resources\Json\AnonymousResourceCollection;
use Laravel\Scout\Builder;
use Illuminate\Pagination\LengthAwarePaginator;
use Lorisleiva\Actions\Concerns\AsAction;
class ParticipantIndexAction
@ -15,24 +15,17 @@ class ParticipantIndexAction
use AsAction;
/**
* @return Builder<Participant>
* @return LengthAwarePaginator<Participant>
*/
protected function getQuery(Form $form, ParticipantFilterScope $filter): Builder
public function handle(Form $form, ParticipantFilterScope $filter): LengthAwarePaginator
{
return $filter->setForm($form)->getQuery()
->query(fn ($q) => $q->withCount('children')->with('form'));
return $form->participants()->withFilter($filter)->with('form')->paginate(15);
}
public function asController(Form $form, ?int $parent = null): AnonymousResourceCollection
public function asController(Form $form): AnonymousResourceCollection
{
$filter = ParticipantFilterScope::fromRequest(request()->input('filter', ''))->parent($parent);
$data = match ($parent) {
null => $this->getQuery($form, $filter)->paginate(15), // initial all elements - paginate
-1 => $this->getQuery($form, $filter)->paginate(15), // initial root elements - parinate
default => $this->getQuery($form, $filter)->get(), // specific parent element - show all
};
return ParticipantResource::collection($data)->additional(['meta' => ParticipantResource::meta($form)]);
$filter = ParticipantFilterScope::fromRequest(request()->input('filter'));
return ParticipantResource::collection($this->handle($form, $filter))
->additional(['meta' => ParticipantResource::meta($form)]);
}
}

View File

@ -1,56 +0,0 @@
<?php
namespace App\Form\Actions;
use App\Form\Models\Form;
use App\Form\Models\Participant;
use App\Lib\Events\Succeeded;
use Illuminate\Http\JsonResponse;
use Lorisleiva\Actions\ActionRequest;
use Lorisleiva\Actions\Concerns\AsAction;
class ParticipantStoreAction
{
use AsAction;
/**
* @return array<string, mixed>
*/
public function rules(): array
{
/** @var Form */
$form = request()->route('form');
return $form->getRegistrationRules();
}
/**
* @return array<string, mixed>
*/
public function getValidationAttributes(): array
{
/** @var Form */
$form = request()->route('form');
return $form->getRegistrationAttributes();
}
/**
* @return array<string, mixed>
*/
public function getValidationMessages(): array
{
/** @var Form */
$form = request()->route('form');
return $form->getRegistrationMessages();
}
public function handle(Form $form, ActionRequest $request): JsonResponse
{
$form->participants()->create(['data' => $request->validated()]);
ExportSyncAction::dispatch($form->id);
Succeeded::message('Teilnehmer*in erstellt.')->dispatch();
return response()->json([]);
}
}

View File

@ -1,55 +0,0 @@
<?php
namespace App\Form\Actions;
use App\Form\Models\Participant;
use App\Lib\Events\Succeeded;
use Illuminate\Http\JsonResponse;
use Lorisleiva\Actions\ActionRequest;
use Lorisleiva\Actions\Concerns\AsAction;
class ParticipantUpdateAction
{
use AsAction;
/**
* @return array<string, mixed>
*/
public function rules(): array
{
/** @var Participant */
$participant = request()->route('participant');
return $participant->form->getRegistrationRules();
}
/**
* @return array<string, mixed>
*/
public function getValidationAttributes(): array
{
/** @var Participant */
$participant = request()->route('participant');
return $participant->form->getRegistrationAttributes();
}
/**
* @return array<string, mixed>
*/
public function getValidationMessages(): array
{
/** @var Participant */
$participant = request()->route('participant');
return $participant->form->getRegistrationMessages();
}
public function handle(Participant $participant, ActionRequest $request): JsonResponse
{
$participant->update(['data' => [...$participant->data, ...$request->validated()]]);
ExportSyncAction::dispatch($participant->form->id);
Succeeded::message('Teilnehmer*in bearbeitet.')->dispatch();
return response()->json([]);
}
}

View File

@ -1,49 +0,0 @@
<?php
namespace App\Form\Actions;
use App\Form\Editor\FormConditionResolver;
use App\Form\Models\Participant;
use App\Prevention\Mails\PreventionRememberMail;
use App\Prevention\PreventionSettings;
use Illuminate\Support\Facades\Mail;
use Lorisleiva\Actions\Concerns\AsAction;
class PreventionRememberAction
{
use AsAction;
public string $commandSignature = 'prevention:remember';
public function handle(): void
{
$query = Participant::whereHas(
'form',
fn ($form) => $form
->where('needs_prevention', true)
->where('from', '>=', now())
)
->where(
fn ($q) => $q
->where('last_remembered_at', '<=', now()->subWeeks(2))
->orWhereNull('last_remembered_at')
);
foreach ($query->get() as $participant) {
if (!app(FormConditionResolver::class)->forParticipant($participant)->filterCondition($participant->form->prevention_conditions)) {
continue;
}
if ($participant->getFields()->getMailRecipient() === null || count($participant->preventions()) === 0) {
continue;
}
$body = app(PreventionSettings::class)->refresh()->formmail
->placeholder('formname', $participant->form->name)
->append($participant->form->prevention_text);
Mail::send(new PreventionRememberMail($participant, $body));
$participant->update(['last_remembered_at' => now()]);
}
}
}

View File

@ -7,7 +7,6 @@ use App\Form\Models\Form;
use App\Form\Models\Participant;
use App\Member\Member;
use Illuminate\Http\JsonResponse;
use Illuminate\Validation\ValidationException;
use Lorisleiva\Actions\ActionRequest;
use Lorisleiva\Actions\Concerns\AsAction;
@ -20,24 +19,19 @@ class RegisterAction
*/
public function handle(Form $form, array $input): Participant
{
if (!$form->canRegister()) {
throw ValidationException::withMessages(['event' => 'Anmeldung zzt nicht möglich.']);
}
$memberQuery = FieldCollection::fromRequest($form, $input)
->withNamiType()
->reduce(fn ($query, $field) => $field->namiType->performQuery($query, $field->value), (new Member())->newQuery());
$member = $form->getFields()->withNamiType()->count() && $memberQuery->count() === 1 ? $memberQuery->first() : null;
$mglnr = $form->getFields()->withNamiType()->count() && $memberQuery->count() === 1 ? $memberQuery->first()->mitgliedsnr : null;
$participant = $form->participants()->create([
'data' => $input,
'member_id' => $member?->id,
'mitgliedsnr' => $mglnr,
]);
$form->getFields()->each(fn ($field) => $field->afterRegistration($form, $participant, $input));
$participant->sendConfirmationMail();
ExportSyncAction::dispatch($form->id);
return $participant;
}

View File

@ -1,31 +0,0 @@
<?php
namespace App\Form\Actions;
use App\Form\Models\Form;
use Lorisleiva\Actions\Concerns\AsAction;
class UpdateParticipantSearchIndexAction
{
use AsAction;
public function handle(Form $form): void
{
if (config('scout.driver') !== 'meilisearch') {
return;
}
$form->searchableUsing()->updateIndexSettings(
$form->participantsSearchableAs(),
[
'filterableAttributes' => [...$form->getFields()->filterables()->getKeys(), 'parent-id'],
'searchableAttributes' => $form->getFields()->searchables()->getKeys(),
'sortableAttributes' => [...$form->getFields()->sortables()->getKeys(), 'id', 'created_at'],
'displayedAttributes' => [...$form->getFields()->filterables()->getKeys(), ...$form->getFields()->searchables()->getKeys(), 'id'],
'pagination' => [
'maxTotalHits' => 1000000,
]
]
);
}
}

View File

@ -6,7 +6,6 @@ use App\Form\Fields\Field;
use Illuminate\Support\Collection;
use Spatie\LaravelData\Casts\Cast;
use Spatie\LaravelData\Data;
use Spatie\LaravelData\Support\Creation\CreationContext;
use Spatie\LaravelData\Support\DataProperty;
class CollectionCast implements Cast
@ -21,9 +20,10 @@ class CollectionCast implements Cast
/**
* @param array<int, array<string, mixed>> $value
* @param array<string, mixed> $context
* @return Collection<int, Data>
*/
public function cast(DataProperty $property, mixed $value, array $properties, CreationContext $context): mixed
public function cast(DataProperty $property, mixed $value, array $context): mixed
{
return collect($value)->map(fn ($item) => $this->target::from($item));
}

View File

@ -5,16 +5,16 @@ namespace App\Form\Casts;
use App\Form\Data\FieldCollection;
use App\Form\Fields\Field;
use Spatie\LaravelData\Casts\Cast;
use Spatie\LaravelData\Support\Creation\CreationContext;
use Spatie\LaravelData\Support\DataProperty;
class FieldCollectionCast implements Cast
{
/**
* @param array<int, array<string, string>> $value
* @param array<int, array<string, mixed>> $value
* @param array<string, mixed> $context
* @return FieldCollection
*/
public function cast(DataProperty $property, mixed $value, array $properties, CreationContext $context): mixed
public function cast(DataProperty $property, mixed $value, array $context): mixed
{
return new FieldCollection(collect($value)->map(fn ($value) => Field::classFromType($value['type'])::from($value))->all());
}

View File

@ -1,9 +0,0 @@
<?php
namespace App\Form\Contracts;
interface Filterable
{
/** @param mixed $value */
public function filter($value): string;
}

View File

@ -1,19 +0,0 @@
<?php
namespace App\Form\Data;
use App\Fileshare\Data\FileshareResourceData;
use App\Form\Fields\Field;
use Spatie\LaravelData\Attributes\MapInputName;
use Spatie\LaravelData\Attributes\MapOutputName;
use Spatie\LaravelData\Data;
use Spatie\LaravelData\Mappers\SnakeCaseMapper;
#[MapInputName(SnakeCaseMapper::class)]
#[MapOutputName(SnakeCaseMapper::class)]
class ExportData extends Data
{
public function __construct(public ?FileshareResourceData $root = null, public ?string $groupBy = null, public ?string $toGroupField = null)
{
}
}

View File

@ -2,7 +2,6 @@
namespace App\Form\Data;
use App\Form\Contracts\Filterable;
use App\Form\Enums\SpecialType;
use App\Form\Fields\Field;
use App\Form\Fields\NamiField;
@ -36,11 +35,6 @@ class FieldCollection extends Collection
return $this->filter(fn ($field) => !is_a($field, NamiField::class));
}
public function hasNamiField(): bool
{
return $this->first(fn ($field) => is_a($field, NamiField::class)) !== null;
}
/**
* @return stdClass
*/
@ -98,47 +92,8 @@ class FieldCollection extends Collection
return $attributes->toArray();
}
/**
* @return array<int, string>
*/
public function names(): array
{
return $this->map(fn ($field) => $field->name)->toArray();
}
/**
* @return array<int, string>
*/
public function presentValues(): array
{
return $this->map(fn ($field) => $field->presentRaw())->toArray();
}
private function findBySpecialType(SpecialType $specialType): ?Field
{
return $this->first(fn ($field) => $field->specialType === $specialType);
}
public function searchables(): self
{
return $this;
}
public function sortables(): self
{
return $this;
}
public function filterables(): self
{
return $this->filter(fn ($field) => $field instanceof Filterable);
}
/**
* @return array<int, string>
*/
public function getKeys(): array
{
return $this->map(fn ($field) => $field->key)->toArray();
}
}

View File

@ -15,8 +15,7 @@ class SectionData extends Data
public string $name,
#[WithCast(FieldCollectionCast::class)]
#[WithTransformer(FieldCollectionTransformer::class)]
public FieldCollection $fields,
public ?string $intro
public FieldCollection $fields
) {
}
}

View File

@ -3,7 +3,6 @@
namespace App\Form\Editor;
use App\Form\Models\Participant;
use App\Lib\Editor\Condition;
use App\Lib\Editor\ConditionResolver;
class FormConditionResolver extends ConditionResolver
@ -21,24 +20,24 @@ class FormConditionResolver extends ConditionResolver
/**
* @inheritdoc
*/
public function filterCondition(Condition $condition): bool
public function filterCondition(string $mode, array $ifs): bool
{
if (!$condition->hasStatements()) {
if (count($ifs) === 0) {
return true;
}
foreach ($condition->ifs as $if) {
$field = $this->participant->getFields()->findByKey($if->field);
$matches = $field->matches($if->comparator, $if->value);
if ($matches && $condition->isAny()) {
foreach ($ifs as $if) {
$field = $this->participant->getFields()->findByKey($if['field']);
$matches = $field->matches($if['comparator'], $if['value']);
if ($matches && $mode === 'any') {
return true;
}
if (!$matches && $condition->isAll()) {
if (!$matches && $mode === 'all') {
return false;
}
}
if ($condition->isAny()) {
if ($mode === 'any') {
return false;
}

View File

@ -2,7 +2,6 @@
namespace App\Form\Enums;
use App\Form\Models\Form;
use App\Group\Enums\Level;
use App\Member\Member;
use Illuminate\Database\Eloquent\Builder;
@ -11,7 +10,6 @@ enum NamiType: string
{
case FIRSTNAME = 'Vorname';
case LASTNAME = 'Nachname';
case NICKNAME = 'Spitzname';
case BIRTHDAY = 'Geburtstag';
case REGION = 'Bezirk';
case STAMM = 'Stamm';
@ -19,10 +17,6 @@ enum NamiType: string
case ADDRESS = 'Adresse';
case ZIP = 'PLZ';
case LOCATION = 'Ort';
case GENDER = 'Geschlecht';
case MOBILEPHONE = 'Handynummer';
case AGE = 'Alter (zum Zeitpunkt der Anmeldung)';
case AGEEVENT = 'Alter (zum Zeitpunkt der Veranstaltung)';
/**
* @return array<int, array{name: string, id: string}>
@ -34,7 +28,7 @@ enum NamiType: string
->toArray();
}
public function getMemberAttribute(Member $member, Form $form): ?string
public function getMemberAttribute(Member $member): ?string
{
return match ($this) {
static::FIRSTNAME => $member->firstname,
@ -46,11 +40,6 @@ enum NamiType: string
static::ADDRESS => $member->address,
static::ZIP => $member->zip,
static::LOCATION => $member->location,
static::NICKNAME => $member->nickname,
static::GENDER => $member->gender?->name,
static::AGE => intVal($member->birthday->diffInYears(now())),
static::AGEEVENT => $member->birthday->diffInYears($form->from),
static::MOBILEPHONE => $member->mobile_phone,
};
}
@ -64,6 +53,7 @@ enum NamiType: string
static::FIRSTNAME => $query->where('firstname', $value),
static::LASTNAME => $query->where('lastname', $value),
static::BIRTHDAY => $query->where('birthday', $value),
static::EMAIL => $query->where('email', $value),
default => $query,
};
}

View File

@ -2,7 +2,6 @@
namespace App\Form\Fields;
use App\Form\Contracts\Filterable;
use App\Form\Matchers\BooleanMatcher;
use App\Form\Matchers\Matcher;
use App\Form\Models\Form;
@ -10,8 +9,9 @@ use App\Form\Models\Participant;
use App\Form\Presenters\BooleanPresenter;
use App\Form\Presenters\Presenter;
use Faker\Generator;
use Illuminate\Validation\Rule;
class CheckboxField extends Field implements Filterable
class CheckboxField extends Field
{
public bool $required;
public string $description;
@ -86,11 +86,4 @@ class CheckboxField extends Field implements Filterable
{
return app(BooleanMatcher::class);
}
public function filter($value): string
{
$asString = $value ? 'true' : 'false';
return "{$this->key} = $asString";
}
}

View File

@ -13,8 +13,6 @@ class CheckboxesField extends Field
{
/** @var array<int, string> */
public array $options;
public ?int $min;
public ?int $max;
public static function name(): string
{
@ -25,8 +23,6 @@ class CheckboxesField extends Field
{
return [
['key' => 'options', 'default' => [], 'rules' => ['options' => 'array', 'options.*' => 'required|string'], 'label' => 'Optionen'],
['key' => 'min', 'default' => null, 'rules' => ['min' => 'present'], 'label' => 'minimale Anzahl'],
['key' => 'max', 'default' => null, 'rules' => ['max' => 'present'], 'label' => 'maximale Anzahl'],
];
}
@ -39,8 +35,6 @@ class CheckboxesField extends Field
{
return [
'options' => $faker->words(4),
'min' => null,
'max' => null,
];
}
@ -49,18 +43,8 @@ class CheckboxesField extends Field
*/
public function getRegistrationRules(Form $form): array
{
$globalRules = ['array'];
if ($this->min > 0) {
$globalRules[] = 'min:' . $this->min;
}
if ($this->max > 0) {
$globalRules[] = 'max:' . $this->max;
}
return [
$this->key => $globalRules,
$this->key => 'array',
$this->key . '.*' => ['string', Rule::in($this->options)],
];
}

View File

@ -2,7 +2,6 @@
namespace App\Form\Fields;
use App\Form\Contracts\Filterable;
use App\Form\Matchers\Matcher;
use App\Form\Matchers\SingleValueMatcher;
use App\Form\Models\Form;
@ -10,7 +9,7 @@ use App\Form\Models\Participant;
use Faker\Generator;
use Illuminate\Validation\Rule;
class DropdownField extends Field implements Filterable
class DropdownField extends Field
{
public bool $required;
/** @var array<int, string> */
@ -88,14 +87,4 @@ class DropdownField extends Field implements Filterable
{
return app(SingleValueMatcher::class);
}
/** @inheritdoc */
public function filter($value): string
{
if (is_null($value)) {
return "{$this->key} IS NULL";
}
return $this->key . ' = \'' . $value . '\'';
}
}

View File

@ -11,7 +11,6 @@ use App\Form\Models\Form;
use App\Form\Models\Participant;
use App\Form\Presenters\DefaultPresenter;
use App\Form\Presenters\Presenter;
use App\Lib\Editor\Comparator;
use Faker\Generator;
use Spatie\LaravelData\Data;
use Spatie\LaravelData\Attributes\MapInputName;
@ -30,7 +29,6 @@ abstract class Field extends Data
public bool $forMembers;
public ?SpecialType $specialType = null;
public ?string $hint;
public ?string $intro;
/** @var mixed */
public $value;
@ -80,9 +78,6 @@ abstract class Field extends Data
->toArray();
}
/**
* @return class-string<Field>
*/
public static function classFromType(string $type): ?string
{
/** @var class-string<Field> */
@ -105,7 +100,10 @@ abstract class Field extends Data
];
}
public function presentRaw(): string
/**
* @return mixed
*/
public function presentRaw()
{
return $this->getPresenter()->present($this->value);
}
@ -155,7 +153,6 @@ abstract class Field extends Data
'for_members' => true,
'special_type' => null,
'hint' => '',
'intro' => '',
...collect(static::meta())->mapWithKeys(fn ($meta) => [$meta['key'] => $meta['default']])->toArray(),
],
];
@ -171,7 +168,7 @@ abstract class Field extends Data
return $this->key . '_display';
}
public function matches(Comparator $comparator, mixed $value): bool
public function matches(string $comparator, mixed $value): bool
{
return $this->getMatcher()->setValue($this->value)->matches($comparator, $value);
}
@ -180,10 +177,4 @@ abstract class Field extends Data
{
return app(SingleValueMatcher::class);
}
/** @param mixed $value */
public function filter($value): string
{
return '';
}
}

View File

@ -65,7 +65,7 @@ class GroupField extends Field
$rules[] = Rule::in(Group::find($this->parentGroup)->children()->pluck('id')->push(-1));
}
if ($this->parentField && request()->input($this->parentField) && request()->input($this->parentField) !== -1) {
if ($this->parentField && request()->input($this->parentField)) {
$rules[] = Rule::in(Group::find(request()->input($this->parentField))->children()->pluck('id')->push(-1));
}

View File

@ -42,18 +42,19 @@ class NamiField extends Field
public function getRegistrationRules(Form $form): array
{
$rules = [$this->key => 'present|array'];
$inputMembers = request($this->key);
foreach ($form->getFields()->noNamiField()->forMembers() as $field) {
foreach ($field->getRegistrationRules($form) as $ruleKey => $rule) {
foreach ($inputMembers as $memberIndex => $inputMember) {
$rules[$this->key . '.' . $memberIndex . '.' . $ruleKey] = !$inputMember['id'] || $field->namiType === null ? $rule : '';
}
$c = $form->getFields()->forMembers()->noNamiType()->noNamiField()
->map(fn ($field) => $field->getRegistrationRules($form))
->toArray();
foreach ($c as $field) {
foreach ($field as $ruleKey => $rule) {
$rules[$this->key . '.*.' . $ruleKey] = $rule;
}
}
return [
$this->key . '.*.id' => ['nullable', 'numeric', 'exists:members,mitgliedsnr'],
$this->key . '.*.id' => ['required', 'numeric', 'exists:members,mitgliedsnr'],
...$rules,
];
}
@ -70,9 +71,12 @@ class NamiField extends Field
return [];
}
foreach ($form->getFields()->noNamiField()->forMembers() as $field) {
$c = $form->getFields()->noNamiField()->forMembers();
foreach ($c as $field) {
foreach ($field->getRegistrationRules($form) as $ruleKey => $rule) {
foreach ($inputMembers as $memberIndex => $inputMember) {
$message = $field->name . ' für ein Mitglied';
$rules = array_merge(
$rules,
@ -107,16 +111,16 @@ class NamiField extends Field
public function afterRegistration(Form $form, Participant $participant, array $input): void
{
foreach ($input[$this->key] as $memberData) {
$member = $memberData['id'] ? Member::firstWhere(['mitgliedsnr' => $memberData['id']]) : null;
$member = Member::firstWhere(['mitgliedsnr' => $memberData['id']]);
$data = [];
foreach (FieldCollection::fromRequest($form, $memberData) as $field) {
$data[$field->key] = $field->namiType === null || $member === null
$data[$field->key] = $field->namiType === null
? $field->value
: $field->namiType->getMemberAttribute($member, $form);
: $field->namiType->getMemberAttribute($member);
}
$data[$this->key] = [];
$form->participants()->create(['data' => $data, 'member_id' => $member?->id, 'parent_id' => $participant->id]);
$form->participants()->create(['data' => $data, 'mitgliedsnr' => $memberData['id'], 'parent_id' => $participant->id]);
}
}

View File

@ -2,7 +2,6 @@
namespace App\Form\Fields;
use App\Form\Contracts\Filterable;
use App\Form\Matchers\Matcher;
use App\Form\Matchers\SingleValueMatcher;
use App\Form\Models\Form;
@ -10,7 +9,7 @@ use App\Form\Models\Participant;
use Faker\Generator;
use Illuminate\Validation\Rule;
class RadioField extends Field implements Filterable
class RadioField extends Field
{
public bool $required;
/** @var array<int, string> */
@ -88,13 +87,4 @@ class RadioField extends Field implements Filterable
{
return app(SingleValueMatcher::class);
}
public function filter($value): string
{
if (is_null($value)) {
return "{$this->key} IS NULL";
}
return $this->key . ' = \'' . $value . '\'';
}
}

View File

@ -1,54 +0,0 @@
<?php
namespace App\Form;
use App\Form\Actions\SettingStoreAction;
use App\Setting\Contracts\Storeable;
use App\Setting\LocalSettings;
use Lorisleiva\Actions\ActionRequest;
class FormSettings extends LocalSettings implements Storeable
{
public string $registerUrl;
public string $clearCacheUrl;
public static function group(): string
{
return 'form';
}
public static function title(): string
{
return 'Formulare';
}
/**
* @inheritdoc
*/
public function rules(): array
{
return [
'registerUrl' => 'present|string',
'clearCacheUrl' => 'present|string',
];
}
public function beforeSave(ActionRequest $request): void
{
}
/**
* @inheritdoc
*/
public function viewData(): array
{
return [
'data' => [
'data' => [
'registerUrl' => $this->registerUrl,
'clearCacheUrl' => $this->clearCacheUrl,
]
]
];
}
}

View File

@ -5,7 +5,6 @@ namespace App\Form\Mails;
use App\Form\Data\FormConfigData;
use App\Form\Editor\FormConditionResolver;
use App\Form\Models\Participant;
use App\Lib\Editor\Condition;
use Illuminate\Bus\Queueable;
use Illuminate\Mail\Attachment;
use Illuminate\Mail\Mailable;
@ -19,9 +18,9 @@ class ConfirmRegistrationMail extends Mailable
public string $fullname;
public FormConfigData $config;
/** @var array<int, mixed> */
/** @var array<string, mixed> */
public array $topText;
/** @var array<int, mixed> */
/** @var array<string, mixed> */
public array $bottomText;
/**
@ -72,7 +71,10 @@ class ConfirmRegistrationMail extends Mailable
$conditionResolver = app(FormConditionResolver::class)->forParticipant($this->participant);
return $this->participant->form->getMedia('mailattachments')
->filter(fn ($media) => $conditionResolver->filterCondition(Condition::fromMedia($media)))
->filter(fn ($media) => $conditionResolver->filterCondition(
data_get($media->getCustomProperty('conditions'), 'mode', 'all'),
data_get($media->getCustomProperty('conditions'), 'ifs', []),
))
->map(fn ($media) => Attachment::fromStorageDisk($media->disk, $media->getPathRelativeToRoot()))
->all();
}

View File

@ -2,8 +2,6 @@
namespace App\Form\Matchers;
use App\Lib\Editor\Comparator;
abstract class Matcher
{
@ -16,5 +14,5 @@ abstract class Matcher
return $this;
}
abstract public function matches(Comparator $comparator, mixed $value): bool;
abstract public function matches(string $comparator, mixed $value): bool;
}

View File

@ -2,26 +2,24 @@
namespace App\Form\Matchers;
use App\Lib\Editor\Comparator;
class SingleValueMatcher extends Matcher
{
public function matches(Comparator $comparator, mixed $value): bool
public function matches(string $comparator, mixed $value): bool
{
if ($comparator === Comparator::EQUAL && $value === $this->value) {
if ($comparator === 'isEqual' && $value === $this->value) {
return true;
}
if ($comparator === Comparator::NOTEQUAL && $value !== $this->value) {
if ($comparator === 'isNotEqual' && $value !== $this->value) {
return true;
}
if ($comparator === Comparator::IN && in_array($this->value, $value)) {
if ($comparator === 'isIn' && in_array($this->value, $value)) {
return true;
}
if ($comparator === Comparator::NOTIN && !in_array($this->value, $value)) {
if ($comparator === 'isNotIn' && !in_array($this->value, $value)) {
return true;
}

View File

@ -2,29 +2,21 @@
namespace App\Form\Models;
use App\Form\Actions\UpdateParticipantSearchIndexAction;
use App\Form\Data\ExportData;
use App\Form\Data\FieldCollection;
use App\Form\Data\FormConfigData;
use App\Lib\Editor\Condition;
use App\Lib\Editor\EditorData;
use App\Lib\Sorting;
use Cviebrock\EloquentSluggable\Sluggable;
use Database\Factories\Form\Models\FormFactory;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Laravel\Scout\Searchable;
use Spatie\Image\Enums\Fit;
use Spatie\Image\Manipulations;
use Spatie\MediaLibrary\HasMedia;
use Spatie\MediaLibrary\InteractsWithMedia;
use Spatie\MediaLibrary\MediaCollections\Models\Media;
use Zoomyboy\MedialibraryHelper\DefersUploads;
/** @todo replace editor content with EditorData cast */
class Form extends Model implements HasMedia
{
/** @use HasFactory<FormFactory> */
use HasFactory;
use Sluggable;
use InteractsWithMedia;
@ -36,21 +28,14 @@ class Form extends Model implements HasMedia
public $casts = [
'config' => FormConfigData::class,
'meta' => 'json',
'description' => EditorData::class,
'mail_top' => EditorData::class,
'mail_bottom' => EditorData::class,
'is_active' => 'boolean',
'is_private' => 'boolean',
'export' => ExportData::class,
'needs_prevention' => 'boolean',
'prevention_text' => EditorData::class,
'prevention_conditions' => Condition::class,
'from' => 'datetime',
'to' => 'datetime',
'registration_from' => 'datetime',
'registration_until' => 'datetime',
'description' => 'json',
'mail_top' => 'json',
'mail_bottom' => 'json',
];
/** @var array<int, string> */
public $dates = ['from', 'to', 'registration_from', 'registration_until'];
/**
* @return SluggableConfig
*/
@ -76,9 +61,8 @@ class Form extends Model implements HasMedia
->singleFile()
->maxWidth(fn () => 500)
->forceFileName(fn (Form $model, string $name) => $model->slug)
->convert(fn () => 'jpg')
->registerMediaConversions(function (Media $media) {
$this->addMediaConversion('square')->fit(Fit::Crop, 400, 400);
$this->addMediaConversion('square')->fit(Manipulations::FIT_CROP, 400, 400);
});
$this->addMediaCollection('mailattachments')
->withDefaultProperties(fn () => [
@ -149,8 +133,6 @@ class Form extends Model implements HasMedia
'from' => $this->from->timestamp,
'to' => $this->to->timestamp,
'name' => $this->name,
'is_active' => $this->is_active,
'is_private' => $this->is_private,
];
}
@ -160,7 +142,7 @@ class Form extends Model implements HasMedia
if (is_null(data_get($model->meta, 'active_columns'))) {
$model->setAttribute('meta', [
'active_columns' => $model->getFields()->count() ? $model->getFields()->take(4)->pluck('key')->toArray() : null,
'sorting' => Sorting::by('id'),
'sorting' => $model->getFields()->count() ? [$model->getFields()->first()->key, 'asc'] : null,
]);
return;
}
@ -168,37 +150,10 @@ class Form extends Model implements HasMedia
if (is_array(data_get($model->meta, 'active_columns'))) {
$model->setAttribute('meta', [
...$model->meta,
'active_columns' => array_values(array_intersect([...$model->getFields()->pluck('key')->toArray(), 'created_at', 'prevention'], $model->meta['active_columns'])),
'active_columns' => array_values(array_intersect([...$model->getFields()->pluck('key')->toArray(), 'created_at'], $model->meta['active_columns'])),
]);
return;
}
});
static::saved(function ($model) {
UpdateParticipantSearchIndexAction::dispatch($model);
});
}
public function participantsSearchableAs(): string
{
return config('scout.prefix') . 'forms_' . $this->id . '_participants';
}
public function defaultSorting(): Sorting
{
return Sorting::from($this->meta['sorting']);
}
public function canRegister(): bool
{
if ($this->registration_from && $this->registration_from->gt(now())) {
return false;
}
if ($this->registration_until && $this->registration_until->lt(now())) {
return false;
}
return true;
}
}

View File

@ -3,8 +3,6 @@
namespace App\Form\Models;
use App\Form\Data\FormConfigData;
use App\Lib\Editor\EditorData;
use Database\Factories\Form\Models\FormtemplateFactory;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
@ -13,14 +11,11 @@ use Illuminate\Database\Eloquent\Model;
*/
class Formtemplate extends Model
{
/** @use HasFactory<FormtemplateFactory> */
use HasFactory;
public $guarded = [];
public $casts = [
'config' => FormConfigData::class,
'mail_top' => EditorData::class,
'mail_bottom' => EditorData::class,
];
}

View File

@ -6,30 +6,21 @@ use App\Form\Data\FieldCollection;
use App\Form\Data\FormConfigData;
use App\Form\Mails\ConfirmRegistrationMail;
use App\Form\Scopes\ParticipantFilterScope;
use App\Member\Member;
use App\Prevention\Contracts\Preventable;
use Database\Factories\Form\Models\ParticipantFactory;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Support\Facades\Mail;
use Laravel\Scout\Searchable;
use stdClass;
class Participant extends Model implements Preventable
class Participant extends Model
{
/** @use HasFactory<ParticipantFactory> */
use HasFactory;
use Searchable;
public $guarded = [];
public $casts = [
'data' => 'json',
'last_remembered_at' => 'datetime',
];
/**
@ -49,11 +40,12 @@ class Participant extends Model implements Preventable
}
/**
* @return BelongsTo<Member, self>
* @param Builder<self> $query
* @return Builder<self>
*/
public function member(): BelongsTo
public function scopeWithFilter(Builder $query, ParticipantFilterScope $filter): Builder
{
return $this->belongsTo(Member::class);
return $filter->apply($query);
}
public function getFields(): FieldCollection
@ -78,40 +70,6 @@ class Participant extends Model implements Preventable
return;
}
Mail::to($this->getMailRecipient())->queue(new ConfirmRegistrationMail($this));
}
public function preventableLayout(): string
{
return 'mail.prevention.prevention-remember-participant';
}
/**
* @inheritdoc
*/
public function preventions(): array
{
return $this->member?->preventions($this->form->from) ?: [];
}
public function getMailRecipient(): stdClass
{
return $this->getFields()->getMailRecipient();
}
public function preventableSubject(): string
{
return 'Nachweise erforderlich für deine Anmeldung zu ' . $this->form->name;
}
public function searchableAs(): string
{
return $this->form->participantsSearchableAs();
}
/** @return array<string, mixed> */
public function toSearchableArray(): array
{
return [...$this->data, 'parent-id' => $this->parent_id, 'created_at' => $this->created_at->timestamp];
Mail::to($this->getFields()->getMailRecipient())->queue(new ConfirmRegistrationMail($this));
}
}

View File

@ -33,9 +33,6 @@ class FormApiResource extends JsonResource
'slug' => $this->slug,
'dates' => $this->from->equalTo($this->to) ? $this->from->format('d.m.Y') : $this->from->format('d.m.Y') . ' - ' . $this->to->format('d.m.Y'),
'image' => $this->getMedia('headerImage')->first()->getFullUrl('square'),
'is_active' => $this->is_active,
'is_private' => $this->is_private,
'can_register' => $this->getModel()->canRegister(),
];
}

View File

@ -2,16 +2,13 @@
namespace App\Form\Resources;
use App\Form\Data\ExportData;
use App\Form\Enums\NamiType;
use App\Form\Enums\SpecialType;
use App\Form\Fields\Field;
use App\Form\FormSettings;
use App\Form\Scopes\FormFilterScope;
use App\Form\Models\Form;
use App\Form\Models\Formtemplate;
use App\Group;
use App\Lib\Editor\EditorData;
use App\Lib\HasMeta;
use Illuminate\Http\Resources\Json\JsonResource;
@ -46,21 +43,11 @@ class FormResource extends JsonResource
'registration_until' => $this->registration_until?->format('Y-m-d H:i:s'),
'config' => $this->config,
'participants_count' => $this->participants_count,
'is_active' => $this->is_active,
'is_private' => $this->is_private,
'has_nami_field' => $this->getFields()->hasNamiField(),
'export' => $this->export,
'needs_prevention' => $this->needs_prevention,
'prevention_text' => $this->prevention_text,
'prevention_conditions' => $this->prevention_conditions,
'links' => [
'participant_index' => route('form.participant.index', ['form' => $this->getModel(), 'parent' => null]),
'participant_root_index' => route('form.participant.index', ['form' => $this->getModel(), 'parent' => -1]),
'participant_index' => route('form.participant.index', ['form' => $this->getModel()]),
'update' => route('form.update', ['form' => $this->getModel()]),
'destroy' => route('form.destroy', ['form' => $this->getModel()]),
'is_dirty' => route('form.is-dirty', ['form' => $this->getModel()]),
'frontend' => str(app(FormSettings::class)->registerUrl)->replace('{slug}', $this->slug),
'export' => route('form.export', ['form' => $this->getModel()]),
]
];
}
@ -84,8 +71,6 @@ class FormResource extends JsonResource
'specialTypes' => SpecialType::forSelect(),
'default' => [
'description' => [],
'is_active' => true,
'is_private' => false,
'name' => '',
'excerpt' => '',
'from' => null,
@ -97,10 +82,7 @@ class FormResource extends JsonResource
'config' => null,
'header_image' => null,
'mailattachments' => [],
'prevention_text' => EditorData::default(),
'id' => null,
'export' => ExportData::from([]),
'prevention_conditions' => ['mode' => 'all', 'ifs' => []],
],
'section_default' => [
'name' => '',

View File

@ -7,7 +7,6 @@ use App\Form\Enums\SpecialType;
use App\Form\Fields\Field;
use App\Form\Models\Formtemplate;
use App\Group;
use App\Lib\Editor\EditorData;
use App\Lib\HasMeta;
use Illuminate\Http\Resources\Json\JsonResource;
@ -53,8 +52,6 @@ class FormtemplateResource extends JsonResource
],
'default' => [
'name' => '',
'mail_top' => EditorData::default(),
'mail_bottom' => EditorData::default(),
'config' => [
'sections' => [],
]

View File

@ -5,7 +5,6 @@ namespace App\Form\Resources;
use App\Form\Models\Form;
use App\Form\Models\Participant;
use App\Form\Scopes\ParticipantFilterScope;
use App\Prevention\Enums\Prevention;
use Illuminate\Http\Resources\Json\JsonResource;
use Illuminate\Support\Collection;
@ -24,18 +23,10 @@ class ParticipantResource extends JsonResource
{
return [
...$this->getModel()->getFields()->present(),
'id' => $this->id,
'created_at' => $this->created_at->format('Y-m-d H:i:s'),
'created_at_display' => $this->created_at->format('d.m.Y'),
'children_count' => $this->children_count,
'member_id' => $this->member_id,
'prevention_items' => $this->member ? Prevention::items($this->member->preventions()) : [],
'links' => [
'assign' => route('participant.assign', ['participant' => $this->getModel()]),
'destroy' => route('participant.destroy', ['participant' => $this->getModel()]),
'children' => route('form.participant.index', ['form' => $this->form, 'parent' => $this->id]),
'fields' => route('participant.fields', ['participant' => $this->getModel()]),
'update' => route('participant.update', ['participant' => $this->getModel()]),
]
];
}
@ -62,24 +53,17 @@ class ParticipantResource extends JsonResource
return [
'filter' => ParticipantFilterScope::fromRequest(request()->input('filter', ''))->setForm($form),
'form_config' => $form->config,
'default_filter_value' => ParticipantFilterScope::$nan,
'filters' => $filterData,
'form_meta' => $form->meta,
'has_nami_field' => $form->getFields()->hasNamiField(),
'links' => [
'update_form_meta' => route('form.update-meta', ['form' => $form]),
'store_participant' => route('form.participant.store', ['form' => $form]),
],
'columns' => $fieldData->push([
'name' => 'Registriert am',
'id' => 'created_at',
'display_attribute' => 'created_at_display'
])->push([
'name' => 'Prävention',
'id' => 'prevention',
'display_attribute' => 'prevention_display'
]),
])
];
}
}

View File

@ -19,7 +19,6 @@ class FormFilterScope extends ScoutFilter
public function __construct(
public ?string $search = '',
public bool $past = false,
public bool $inactive = false,
) {
}
@ -36,10 +35,6 @@ class FormFilterScope extends ScoutFilter
$filters->push('to > ' . now()->timestamp);
}
if ($this->inactive === false) {
$filters->push('is_active = true');
}
$options['filter'] = $filters->implode(' AND ');
return $engine->search($query, $options);

View File

@ -4,76 +4,33 @@ namespace App\Form\Scopes;
use App\Form\Models\Form;
use App\Form\Models\Participant;
use App\Lib\ScoutFilter;
use App\Lib\Sorting;
use App\Lib\Filter;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Support\Arr;
use Laravel\Scout\Builder;
use Spatie\LaravelData\Attributes\MapInputName;
use Spatie\LaravelData\Attributes\MapOutputName;
use Spatie\LaravelData\Mappers\SnakeCaseMapper;
/**
* @extends ScoutFilter<Participant>
* @extends Filter<Participant>
*/
#[MapInputName(SnakeCaseMapper::class)]
#[MapOutputName(SnakeCaseMapper::class)]
class ParticipantFilterScope extends ScoutFilter
class ParticipantFilterScope extends Filter
{
public static string $nan = 'deeb3ef4-d185-44b1-a4bc-0a4e7addebc3d8900c6f-a344-4afb-b54e-065ed483a7ba';
private Form $form;
/**
* @param array<string, mixed> $data
* @param array<string, mixed> $options
*/
public function __construct(
public array $data = [],
public string $search = '',
public array $options = [],
public ?int $parent = null,
public ?Sorting $sort = null
public array $data = [],
) {
}
public function getQuery(): Builder
{
$this->search = $this->search ?: '';
return Participant::search($this->search, function ($engine, string $query, array $options) {
$filter = collect([]);
foreach ($this->form->getFields()->filterables() as $field) {
if ($this->data[$field->key] === static::$nan) {
continue;
}
$filter->push($field->filter($this->data[$field->key]));
}
if ($this->parent === -1) {
$filter->push('parent-id IS NULL');
}
if ($this->parent !== null && $this->parent !== -1) {
$filter->push('parent-id = ' . $this->parent);
}
$options['filter'] = $filter->map(fn ($expression) => "($expression)")->implode(' AND ');
$options['sort'] = $this->sort->toMeilisearch();
return $engine->search($query, [...$this->options, ...$options]);
})->within($this->form->participantsSearchableAs());
}
public static string $nan = 'deeb3ef4-d185-44b1-a4bc-0a4e7addebc3d8900c6f-a344-4afb-b54e-065ed483a7ba';
public function setForm(Form $form): self
{
$this->form = $form;
if (is_null($this->sort)) {
$this->sort = $this->form->defaultSorting();
}
foreach ($form->getFields() as $field) {
if (!Arr::has($this->data, $field->key)) {
data_set($this->data, $field->key, static::$nan);
@ -83,10 +40,26 @@ class ParticipantFilterScope extends ScoutFilter
return $this;
}
public function parent(?int $parent): self
/**
* @inheritdoc
*/
public function apply(Builder $query): Builder
{
$this->parent = $parent;
if ($this->parent === -1) {
$query = $query->whereNull('parent_id');
}
return $this;
if (!is_null($this->parent) && $this->parent > 0) {
$query = $query->where('parent_id', $this->parent);
}
foreach ($this->data as $key => $value) {
if ($value === static::$nan) {
continue;
}
$query = $query->where('data->' . $key, $value);
}
return $query;
}
}

View File

@ -5,7 +5,6 @@ namespace App\Form\Transformers;
use App\Form\Fields\Field;
use Illuminate\Support\Collection;
use Spatie\LaravelData\Support\DataProperty;
use Spatie\LaravelData\Support\Transformation\TransformationContext;
use Spatie\LaravelData\Transformers\Transformer;
class CollectionTransformer implements Transformer
@ -19,7 +18,7 @@ class CollectionTransformer implements Transformer
* @param Collection<int, Field> $value
* @return array<string, mixed>
*/
public function transform(DataProperty $property, mixed $value, TransformationContext $context): mixed
public function transform(DataProperty $property, mixed $value): mixed
{
return $value->toArray();
}

View File

@ -5,7 +5,6 @@ namespace App\Form\Transformers;
use App\Form\Fields\Field;
use Illuminate\Support\Collection;
use Spatie\LaravelData\Support\DataProperty;
use Spatie\LaravelData\Support\Transformation\TransformationContext;
use Spatie\LaravelData\Transformers\Transformer;
class FieldCollectionTransformer implements Transformer
@ -15,7 +14,7 @@ class FieldCollectionTransformer implements Transformer
* @param Collection<int, Field> $value
* @return array<string, mixed>
*/
public function transform(DataProperty $property, mixed $value, TransformationContext $context): mixed
public function transform(DataProperty $property, mixed $value): mixed
{
return $value->map(fn ($field) => [
...$field->toArray(),

View File

@ -3,15 +3,12 @@
namespace App;
use App\Nami\HasNamiField;
use Database\Factories\GenderFactory;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Gender extends Model
{
use HasNamiField;
/** @use HasFactory<GenderFactory> */
use HasFactory;
public $fillable = ['name', 'nami_id'];
@ -25,15 +22,6 @@ class Gender extends Model
};
}
public function getShortAttribute(): string
{
return match ($this->name) {
'Männlich' => 'm',
'Weiblich' => 'w',
default => ''
};
}
public static function fromString(string $title): self
{
return self::firstWhere('name', $title);

View File

@ -2,10 +2,8 @@
namespace App;
use App\Fileshare\Data\FileshareResourceData;
use App\Group\Enums\Level;
use App\Nami\HasNamiField;
use Database\Factories\GroupFactory;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
@ -13,24 +11,22 @@ use Illuminate\Database\Eloquent\Relations\HasMany;
class Group extends Model
{
/** @use HasFactory<GroupFactory> */
use HasFactory;
use HasNamiField;
public $fillable = ['nami_id', 'name', 'inner_name', 'level', 'parent_id', 'fileshare'];
public $fillable = ['nami_id', 'name', 'inner_name', 'level', 'parent_id'];
public $timestamps = false;
public $casts = [
'level' => Level::class,
'fileshare' => FileshareResourceData::class,
'level' => Level::class
];
/**
* @return BelongsTo<self, self>
* @return BelongsTo<static, self>
*/
public function parent(): BelongsTo
{
return $this->belongsTo(self::class, 'parent_id');
return $this->belongsTo(static::class, 'parent_id');
}
/**
@ -38,7 +34,7 @@ class Group extends Model
*/
public function children(): HasMany
{
return $this->hasMany(self::class, 'parent_id');
return $this->hasMany(static::class, 'parent_id');
}
public static function booted(): void

View File

@ -6,7 +6,6 @@ use App\Group;
use App\Group\Resources\GroupResource;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Http\Resources\Json\AnonymousResourceCollection;
use Lorisleiva\Actions\ActionRequest;
use Lorisleiva\Actions\Concerns\AsAction;
class GroupApiIndexAction
@ -21,12 +20,8 @@ class GroupApiIndexAction
return Group::get();
}
public function asController(ActionRequest $request, ?Group $group = null): AnonymousResourceCollection
public function asController(?Group $group = null): AnonymousResourceCollection
{
return GroupResource::collection(
$request->has('all')
? Group::with('children')->get()
: ($group ? $group->children()->withCount('children')->get() : Group::where('parent_id', null)->withCount('children')->get())
);
return GroupResource::collection($group ? $group->children()->withCount('children')->get() : Group::where('parent_id', null)->withCount('children')->get());
}
}

Some files were not shown because too many files have changed in this diff Show More