Files
wk-sync-bundle/src/Command/SeedCategoriesCommand.php
T
admin.juergenandClaude Fable 5.1 142afa6e52 Initial version of the W&K sync bundle for Contao 5.7
Import of W&K seminar exports with preview, booking form via form generator
with event-dependent field rules, notification routing, inbox with folders
and CSV export for W&K.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-09-24 17:42:34 +02:00

73 lines
3.9 KiB
PHP

<?php
declare(strict_types=1);
namespace Mummert\ContaoWkSyncBundle\Command;
use Doctrine\DBAL\Connection;
use Mummert\ContaoWkSyncBundle\Category\CategoryKind;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
#[AsCommand(name: 'wk-sync:categories:seed', description: 'Legt die Standard-Kategorien (TPI Moritzburg) an, sofern sie noch nicht existieren.')]
class SeedCategoriesCommand extends Command
{
/**
* @var list<array{title: string, alias: string, kind: CategoryKind, names: list<string>}>
*/
public const array DEFAULTS = [
['title' => 'Elementarbereich', 'alias' => 'elementarbereich', 'kind' => CategoryKind::Elementary, 'names' => ['Elementarbereich']],
['title' => 'Grundschule/Förderschule', 'alias' => 'grundschule-foerderschule', 'kind' => CategoryKind::School, 'names' => ['Grundschule', 'Förderschule', 'Grund- und Förderschule', 'Alle Schularten']],
['title' => 'Weiterführende Schule', 'alias' => 'weiterfuehrende-schule', 'kind' => CategoryKind::School, 'names' => ['Weiterführende Schule', 'Weiterführende', 'Oberschule', 'Gymnasium', 'Berufsbildende', 'Alle Schularten']],
['title' => 'Evang. Schulen', 'alias' => 'evang-schulen', 'kind' => CategoryKind::EvangelicalSchool, 'names' => ['Evang. Schulen', 'Evangelische Schulen', 'evang']],
['title' => 'Gemeinde', 'alias' => 'gemeinde', 'kind' => CategoryKind::Community, 'names' => ['Gemeinde', 'Gemeindepädagogische Arbeit', 'Gemeindepädagogik']],
['title' => 'Gottesdienst mit Kindern', 'alias' => 'gottesdienst-mit-kindern', 'kind' => CategoryKind::ChildrenService, 'names' => ['Gottesdienst mit Kindern']],
['title' => 'Ausbildung', 'alias' => 'ausbildung', 'kind' => CategoryKind::Training, 'names' => ['Ausbildung']],
['title' => 'Mentoring', 'alias' => 'mentoring', 'kind' => CategoryKind::Mentoring, 'names' => ['Mentoring', 'Mentoren', 'Mentor']],
['title' => 'Tagungen', 'alias' => 'tagungen', 'kind' => CategoryKind::Conference, 'names' => ['Tagungen', 'Tagung']],
['title' => 'AusZEIT', 'alias' => 'auszeit', 'kind' => CategoryKind::Other, 'names' => ['AusZEIT']],
['title' => 'Angebote anderer Träger', 'alias' => 'angebote-anderer-traeger', 'kind' => CategoryKind::Other, 'names' => ['Angebote anderer Träger']],
['title' => 'Schule', 'alias' => 'schule', 'kind' => CategoryKind::School, 'names' => ['Schule']],
];
public function __construct(private readonly Connection $connection)
{
parent::__construct();
}
protected function execute(InputInterface $input, OutputInterface $output): int
{
$io = new SymfonyStyle($input, $output);
$existing = $this->connection->fetchFirstColumn('SELECT alias FROM tl_wk_category');
$sorting = (int) $this->connection->fetchOne('SELECT COALESCE(MAX(sorting), 0) FROM tl_wk_category');
$created = 0;
foreach (self::DEFAULTS as $category) {
if (\in_array($category['alias'], $existing, true)) {
continue;
}
$sorting += 16;
$this->connection->insert('tl_wk_category', [
'tstamp' => time(),
'sorting' => $sorting,
'title' => $category['title'],
'alias' => $category['alias'],
'kind' => $category['kind']->value,
'wkNames' => implode("\n", $category['names']),
]);
++$created;
$io->writeln(\sprintf(' + %s (%s)', $category['title'], $category['kind']->value));
}
$io->success(\sprintf('%d Kategorien angelegt, %d bereits vorhanden.', $created, \count(self::DEFAULTS) - $created));
return Command::SUCCESS;
}
}