Completed
Push — master ( ad2e84...81aee3 )
by Tim
06:21
created

ExternalTimeTable::getEventsFixedEndDate()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 14
rs 9.7998
c 0
b 0
f 0
cc 3
nc 3
nop 1
1
<?php
2
3
/**
4
 * External service.
5
 */
6
declare(strict_types=1);
7
8
namespace HDNET\Calendarize\Service\TimeTable;
9
10
use HDNET\Calendarize\Domain\Model\Configuration;
11
use HDNET\Calendarize\Service\IcsReaderService;
12
use HDNET\Calendarize\Utility\HelperUtility;
13
use TYPO3\CMS\Core\Messaging\FlashMessage;
14
use TYPO3\CMS\Core\Utility\GeneralUtility;
15
16
/**
17
 * External service.
18
 */
19
class ExternalTimeTable extends AbstractTimeTable
20
{
21
    /**
22
     * ICS reader service.
23
     *
24
     * @var \HDNET\Calendarize\Service\IcsReaderService
25
     */
26
    protected $icsReaderService;
27
28
    /**
29
     * Inject ICS reader service.
30
     *
31
     * @param IcsReaderService $icsReaderService
32
     */
33
    public function injectIcsReaderService(IcsReaderService $icsReaderService)
34
    {
35
        $this->icsReaderService = $icsReaderService;
36
    }
37
38
    /**
39
     * Modify the given times via the configuration.
40
     *
41
     * @param array         $times
42
     * @param Configuration $configuration
43
     *
44
     * @throws \TYPO3\CMS\Core\Exception
45
     */
46
    public function handleConfiguration(array &$times, Configuration $configuration)
47
    {
48
        $url = $configuration->getExternalIcsUrl();
49
        if (!GeneralUtility::isValidUrl($url)) {
50
            HelperUtility::createFlashMessage(
51
                'Configuration with invalid ICS URL: ' . $url,
52
                'Index ICS URL',
53
                FlashMessage::ERROR
54
            );
55
56
            return;
57
        }
58
59
        $externalTimes = $this->icsReaderService->getTimes($url);
60
        foreach ($externalTimes as $time) {
61
            $time['pid'] = $configuration->getPid();
62
            $time['state'] = $configuration->getState();
63
            $times[$this->calculateEntryKey($time)] = $time;
64
        }
65
    }
66
}
67