parameters = [ 'isFlickerfree' => true, 'mode' => SCREEN_MODE_SLIDESHOW, 'timestamp' => time(), 'resourcetype' => null, 'screenid' => null, 'action' => null, 'groupid' => null, 'hostid' => 0, 'pageFile' => null, 'profileIdx' => '', 'profileIdx2' => null, 'timeline' => null, 'dataId' => null, 'page' => 1 ]; $this->resourcetype = array_key_exists('resourcetype', $options) ? $options['resourcetype'] : null; $this->required_parameters = [ 'isFlickerfree' => true, 'mode' => true, 'timestamp' => true, 'resourcetype' => true, 'dataId' => true ]; switch ($this->resourcetype) { case SCREEN_RESOURCE_HTTPTEST_DETAILS: $this->required_parameters += [ 'screenid' => false, 'action' => false, 'groupid' => false, 'hostid' => false, 'pageFile' => false, 'profileIdx' => false, 'profileIdx2' => true, 'timeline' => false, 'page' => false ]; break; case SCREEN_RESOURCE_DISCOVERY: $this->required_parameters += [ 'screenid' => false, 'action' => false, 'groupid' => false, 'hostid' => false, 'pageFile' => false, 'profileIdx' => false, 'profileIdx2' => false, 'timeline' => false, 'page' => false ]; break; case SCREEN_RESOURCE_HTTPTEST: $this->required_parameters += [ 'screenid' => false, 'action' => false, 'groupid' => true, 'hostid' => true, 'pageFile' => false, 'profileIdx' => false, 'profileIdx2' => false, 'timeline' => false, 'page' => true ]; break; case SCREEN_RESOURCE_PROBLEM: $this->required_parameters += [ 'screenid' => false, 'action' => false, 'groupid' => false, 'hostid' => false, 'pageFile' => false, 'profileIdx' => true, 'profileIdx2' => true, 'timeline' => true, 'page' => true ]; break; case SCREEN_RESOURCE_HISTORY: $this->required_parameters += [ 'screenid' => true, 'action' => true, 'groupid' => false, 'hostid' => false, 'pageFile' => true, 'profileIdx' => true, 'profileIdx2' => true, 'timeline' => true, 'page' => true ]; break; default: $this->required_parameters += [ 'screenid' => true, 'action' => true, 'groupid' => true, 'hostid' => true, 'pageFile' => true, 'profileIdx' => true, 'profileIdx2' => true, 'timeline' => true, 'page' => false ]; } // Get screenitem if its required or resource type is null. $this->screenitem = []; if (array_key_exists('screenitem', $options) && is_array($options['screenitem'])) { $this->screenitem = $options['screenitem']; } // Get resourcetype. if ($this->resourcetype === null && array_key_exists('resourcetype',$this->screenitem)) { $this->resourcetype = $this->screenitem['resourcetype']; } foreach ($this->parameters as $pname => $default_value) { if ($this->required_parameters[$pname]) { $this->$pname = array_key_exists($pname, $options) ? $options[$pname] : $default_value; } } // Get page file. if ($this->required_parameters['pageFile'] && $this->pageFile === null) { global $page; $this->pageFile = ($page === null) ? null : $page['file']; } // Calculate timeline. if ($this->required_parameters['timeline'] && $this->timeline === null) { $this->timeline = getTimeSelectorPeriod([ 'profileIdx' => $this->profileIdx, 'profileIdx2' => $this->profileIdx2, 'from' => array_key_exists('from', $options) ? $options['from'] : null, 'to' => array_key_exists('to', $options) ? $options['to'] : null ]); } // Get screenid. if ($this->required_parameters['screenid'] && $this->screenid === null && $this->screenitem) { $this->screenid = $this->screenitem['screenid']; } } /** * Create and get unique screen id for time control. * * @return string */ public function getDataId() { if ($this->dataId === null) { $this->dataId = $this->screenitem ? $this->screenitem['screenitemid'].'_'.$this->screenitem['screenid'] : 1; } return $this->dataId; } /** * Get unique screen container id. * * @return string */ public function getScreenId() { return 'flickerfreescreen_'.$this->getDataId(); } /** * Get enveloped screen inside container. * * @param object $item * @param boolean $insertFlickerfreeJs * @param array $flickerfreeData * * @return CDiv */ public function getOutput($item = null, $insertFlickerfreeJs = true, $flickerfreeData = []) { if ($insertFlickerfreeJs) { $this->insertFlickerfreeJs($flickerfreeData); } $div = (new CDiv($item)) ->addClass('flickerfreescreen') ->setAttribute('data-timestamp', $this->timestamp) ->setId($this->getScreenId()); if ($this->mode == SCREEN_MODE_EDIT) { $div->addItem( (new CDiv([ new CLink(_x('Change', 'verb'), $this->action) ]))->addClass(ZBX_STYLE_CENTER) ); } return $div; } /** * Insert javascript flicker-free screen data. * * @param array $data */ public function insertFlickerfreeJs(array $data = []) { $jsData = [ 'id' => $this->getDataId(), 'interval' => CWebUser::getRefresh() ]; $parameters = $this->parameters; // unset redundant parameters unset($parameters['action'], $parameters['dataId']); foreach ($parameters as $pname => $default_value) { if ($this->required_parameters[$pname]) { $jsData[$pname] = $this->$pname; } } if ($this->screenitem) { $jsData['screenitemid'] = array_key_exists('screenitemid', $this->screenitem) ? $this->screenitem['screenitemid'] : null; } if ($this->required_parameters['screenid']) { $jsData['screenid'] = array_key_exists('screenid', $this->screenitem) ? $this->screenitem['screenid'] : $this->screenid; } if ($data) { $jsData['data'] = $data; } zbx_add_post_js('window.flickerfreeScreen.add('.zbx_jsvalue($jsData).');'); } }