Completed
Push — master ( a9a357...5d1efe )
by Tim
02:14
created

getCalendarizeDatabaseString()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.9332
c 0
b 0
f 0
cc 3
nc 3
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace HDNET\Calendarize\EventListener;
6
7
use HDNET\Calendarize\Register;
8
use TYPO3\CMS\Core\Database\Event\AlterTableDefinitionStatementsEvent;
9
10
class CalendarizeFieldListener
11
{
12
    public function __invoke(AlterTableDefinitionStatementsEvent $event): void
13
    {
14
        $event->addSqlData($this->getCalendarizeDatabaseString());
15
    }
16
17
    /**
18
     * Get the calendarize string for the registered tables.
19
     *
20
     * @return string
21
     */
22
    protected function getCalendarizeDatabaseString()
23
    {
24
        $sql = [];
25
        foreach (Register::getRegister() as $configuration) {
26
            $fieldName = isset($configuration['fieldName']) ? $configuration['fieldName'] : 'calendarize';
27
            $sql[] = 'CREATE TABLE ' . $configuration['tableName'] . ' (' . $fieldName . ' tinytext, calendarize_info tinytext);';
28
        }
29
30
        return implode(LF, $sql);
31
    }
32
}
33