1<?php declare(strict_types = 1);
2/*
3** Zabbix
4** Copyright (C) 2001-2021 Zabbix SIA
5**
6** This program is free software; you can redistribute it and/or modify
7** it under the terms of the GNU General Public License as published by
8** the Free Software Foundation; either version 2 of the License, or
9** (at your option) any later version.
10**
11** This program is distributed in the hope that it will be useful,
12** but WITHOUT ANY WARRANTY; without even the implied warranty of
13** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14** GNU General Public License for more details.
15**
16** You should have received a copy of the GNU General Public License
17** along with this program; if not, write to the Free Software
18** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
19**/
20
21
22class CHintBoxHelper {
23
24	/**
25	 * Prepare data for a hint with trigger events and, if defined, trigger description and a clickable URL.
26	 *
27	 * @param string $triggerid                  Trigger ID to select events.
28	 * @param string $eventid_till
29	 * @param bool   $show_timeline              (optional) Show time line flag.
30	 * @param int    $show_tags                  (optional) Show tags flag. Possible values:
31	 *                                             - PROBLEMS_SHOW_TAGS_NONE;
32	 *                                             - PROBLEMS_SHOW_TAGS_1;
33	 *                                             - PROBLEMS_SHOW_TAGS_2;
34	 *                                             - PROBLEMS_SHOW_TAGS_3 (default).
35	 * @param array  $filter_tags                (optional) An array of tag filtering data.
36	 * @param string $filter_tags[]['tag']       Tag name.
37	 * @param int    $filter_tags[]['operator']  Tag operator.
38	 * @param string $filter_tags[]['value']     Tag value.
39	 * @param int    $tag_name_format            (optional) Tag name format. Possible values:
40	 *                                             - PROBLEMS_TAG_NAME_FULL (default);
41	 *                                             - PROBLEMS_TAG_NAME_SHORTENED;
42	 *                                             - PROBLEMS_TAG_NAME_NONE.
43	 * @param string $tag_priority               (optional) A list of comma-separated tag names.
44	 *
45	 * @return array
46	 */
47	public static function getEventList(string $triggerid, string $eventid_till, bool $show_timeline = true,
48			int $show_tags = PROBLEMS_SHOW_TAGS_3, array $filter_tags = [],
49			int $tag_name_format = PROBLEMS_TAG_NAME_FULL, string $tag_priority = ''): array {
50		$data = [
51			'type' => 'eventlist',
52			'data' => [
53				'triggerid' => $triggerid,
54				'eventid_till' => $eventid_till,
55				'show_timeline' => (int) $show_timeline,
56				'show_tags' => $show_tags,
57				'tag_name_format' => $tag_name_format,
58				'tag_priority' => $tag_priority
59			]
60		];
61
62		if ($filter_tags) {
63			$data['data']['filter_tags'] = $filter_tags;
64		}
65
66		return $data;
67	}
68}
69