1<?php 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 CScreenBuilder { 23 24 /** 25 * Get particular screen object. 26 * 27 * @static 28 * 29 * @param array $options 30 * @param int $options['resourcetype'] 31 * @param int $options['screenitemid'] 32 * @param int $options['hostid'] 33 * @param array $options['screen'] 34 * @param int $options['screenid'] 35 * 36 * @return CScreenBase 37 */ 38 public static function getScreen(array $options = []) { 39 if (!array_key_exists('resourcetype', $options)) { 40 $options['resourcetype'] = null; 41 42 if (is_array($options['screenitem']) && array_key_exists('screenitem', $options) 43 && array_key_exists('resourcetype', $options['screenitem'])) { 44 $options['resourcetype'] = $options['screenitem']['resourcetype']; 45 } 46 else { 47 return null; 48 } 49 } 50 51 if ($options['resourcetype'] === null) { 52 return null; 53 } 54 55 // get screen 56 switch ($options['resourcetype']) { 57 case SCREEN_RESOURCE_MAP: 58 return new CScreenMap($options); 59 60 case SCREEN_RESOURCE_HISTORY: 61 return new CScreenHistory($options); 62 63 case SCREEN_RESOURCE_HTTPTEST_DETAILS: 64 return new CScreenHttpTestDetails($options); 65 66 case SCREEN_RESOURCE_DISCOVERY: 67 return new CScreenDiscovery($options); 68 69 case SCREEN_RESOURCE_HTTPTEST: 70 return new CScreenHttpTest($options); 71 72 case SCREEN_RESOURCE_PROBLEM: 73 return new CScreenProblem($options); 74 75 default: 76 return null; 77 } 78 } 79 80 /** 81 * Insert javascript to start time control rendering. 82 * 83 * @static 84 */ 85 public static function insertProcessObjectsJs() { 86 zbx_add_post_js('timeControl.processObjects();'); 87 } 88 89 /** 90 * Insert javascript for standard screens. 91 * 92 * @param array $timeline 93 * 94 * @static 95 */ 96 public static function insertScreenStandardJs(array $timeline) { 97 CScreenBuilder::insertProcessObjectsJs(); 98 } 99 100 /** 101 * Creates a string for screen table ID attribute. 102 * 103 * @param string $screenId 104 * 105 * @return string 106 */ 107 protected static function makeScreenTableId($screenId) { 108 return 'screentable_'.$screenId; 109 } 110} 111