summaryrefslogtreecommitdiffstats
path: root/library/Toplevelview/Monitoring/IgnoredNotificationPeriods.php
blob: 4b9e94c3d6b6c074bbf3531a5ef82190efb2a7ff (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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<?php
/* Copyright (C) 2019 Icinga Development Team <info@icinga.com> */

namespace Icinga\Module\Toplevelview\Monitoring;

trait IgnoredNotificationPeriods
{
    protected $ignoredNotificationPeriods = [];

    public function ignoreNotificationPeriod($name)
    {
        $this->ignoredNotificationPeriods[$name] = true;
        return $this;
    }

    /**
     * @param string|array|iterable $list
     *
     * @return $this
     */
    public function ignoreNotificationPeriods($list)
    {
        if (is_string($list)) {
            /** @var string $list */
            $this->ignoredNotificationPeriods[$list] = true;
        } else {
            foreach ($list as $i) {
                $this->ignoredNotificationPeriods[$i] = true;
            }
        }

        return $this;
    }

    public function getIgnoredNotificationPeriods()
    {
        return array_keys($this->ignoredNotificationPeriods);
    }

    public function resetIgnoredNotificationPeriods()
    {
        $this->ignoredNotificationPeriods = [];
    }

    public function hasIgnoredNotifications()
    {
        return ! empty($this->ignoredNotificationPeriods);
    }
}