summaryrefslogtreecommitdiffstats
path: root/library/Director/Objects/IcingaTimePeriodRanges.php
blob: b18437d53bef36b9e93422f33ec95936ef8737fc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
<?php

namespace Icinga\Module\Director\Objects;

use Countable;
use Iterator;
use Icinga\Module\Director\IcingaConfig\IcingaConfigRenderer;
use Icinga\Module\Director\IcingaConfig\IcingaLegacyConfigHelper as c1;

class IcingaTimePeriodRanges extends IcingaRanges implements Iterator, Countable, IcingaConfigRenderer
{
    protected $rangeClass = IcingaTimePeriodRange::class;
    protected $objectIdColumn = 'timeperiod_id';

    public function toLegacyConfigString()
    {
        if (empty($this->ranges) && $this->object->isTemplate()) {
            return '';
        }

        $out = '';

        foreach ($this->ranges as $range) {
            $out .= c1::renderKeyValue(
                $range->get('range_key'),
                $range->get('range_value')
            );
        }
        if ($out !== '') {
            $out = "\n".$out;
        }

        return $out;
    }
}