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 22require_once dirname(__FILE__).'/../../include/blocks.inc.php'; 23 24class CControllerWidgetFavScreensView extends CControllerWidget { 25 26 public function __construct() { 27 parent::__construct(); 28 29 $this->setType(WIDGET_FAV_SCREENS); 30 $this->setValidationRules([ 31 'name' => 'string', 32 'fields' => 'json' 33 ]); 34 } 35 36 protected function doAction() { 37 $screens = []; 38 $ids = ['screenid' => [], 'slideshowid' => []]; 39 40 foreach (CFavorite::get('web.favorite.screenids') as $favourite) { 41 $ids[$favourite['source']][$favourite['value']] = true; 42 } 43 44 if ($ids['screenid']) { 45 $db_screens = API::Screen()->get([ 46 'output' => ['screenid', 'name'], 47 'screenids' => array_keys($ids['screenid']) 48 ]); 49 50 foreach ($db_screens as $db_screen) { 51 $screens[] = [ 52 'screenid' => $db_screen['screenid'], 53 'label' => $db_screen['name'], 54 'slideshow' => false 55 ]; 56 } 57 } 58 59 if ($ids['slideshowid']) { 60 foreach ($ids['slideshowid'] as $slideshowid) { 61 if (slideshow_accessible($slideshowid, PERM_READ)) { 62 $db_slideshow = get_slideshow_by_slideshowid($slideshowid, PERM_READ); 63 64 if ($db_slideshow) { 65 $screens[] = [ 66 'slideshowid' => $db_slideshow['slideshowid'], 67 'label' => $db_slideshow['name'], 68 'slideshow' => true 69 ]; 70 } 71 } 72 } 73 } 74 75 CArrayHelper::sort($screens, ['label']); 76 77 $this->setResponse(new CControllerResponseData([ 78 'name' => $this->getInput('name', CWidgetConfig::getKnownWidgetTypes()[WIDGET_FAV_SCREENS]), 79 'screens' => $screens, 80 'user' => [ 81 'debug_mode' => $this->getDebugMode() 82 ] 83 ])); 84 } 85} 86