blob: 858c7269ffc760239874663a10fbab6ad12b2f0c (
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
|
<?php
/* Icinga Web 2 | (c) 2013 Icinga Development Team | GPLv2+ */
class Zend_View_Helper_ContactFlags extends Zend_View_Helper_Abstract
{
/**
* Get the human readable flag name for the given contact notification option
*
* @param string $tableName The name of the option table
*
* @return string
*/
public function getNotificationOptionName($tableName)
{
$exploded = explode('_', $tableName);
$name = end($exploded);
return ucfirst($name);
}
/**
* Build all active notification options to a readable string
*
* @param object $contact The contact retrieved from a backend
* @param string $type Whether to display the flags for 'host' or 'service'
* @param string $glue The symbol to use to concatenate the flag names
*
* @return string A string that contains a human readable list of active options
*/
public function contactFlags($contact, $type, $glue = ', ')
{
$optionName = 'contact_' . $type . '_notification_options';
if (isset($contact->$optionName)) {
return $contact->$optionName;
}
$out = array();
foreach ($contact as $key => $value) {
if (preg_match('/^contact_notify_' . $type . '_.*/', $key) && $value == true) {
$option = $this->getNotificationOptionName($key);
if (strtolower($option) != 'timeperiod') {
array_push($out, $option);
}
}
}
return implode($glue, $out);
}
}
|