コード例 #1
0
ファイル: CMap.php プロジェクト: TonywalkerCN/Zabbix
 protected function addRelatedObjects(array $options, array $result)
 {
     $result = parent::addRelatedObjects($options, $result);
     $sysmapIds = array_keys($result);
     // adding elements
     if ($options['selectSelements'] !== null && $options['selectSelements'] != API_OUTPUT_COUNT) {
         $selements = API::getApiService()->select('sysmaps_elements', array('output' => $this->outputExtend($options['selectSelements'], array('selementid', 'sysmapid')), 'filter' => array('sysmapid' => $sysmapIds), 'preservekeys' => true));
         $relationMap = $this->createRelationMap($selements, 'sysmapid', 'selementid');
         // add selement URLs
         if ($this->outputIsRequested('urls', $options['selectSelements'])) {
             foreach ($selements as &$selement) {
                 $selement['urls'] = array();
             }
             unset($selement);
             if (!is_null($options['expandUrls'])) {
                 $dbMapUrls = DBselect('SELECT su.sysmapurlid,su.sysmapid,su.name,su.url,su.elementtype' . ' FROM sysmap_url su' . ' WHERE ' . dbConditionInt('su.sysmapid', $sysmapIds));
                 while ($mapUrl = DBfetch($dbMapUrls)) {
                     foreach ($selements as $snum => $selement) {
                         if (bccomp($selement['sysmapid'], $mapUrl['sysmapid']) == 0 && ($selement['elementtype'] == $mapUrl['elementtype'] && $selement['elementsubtype'] == SYSMAP_ELEMENT_SUBTYPE_HOST_GROUP || $selement['elementsubtype'] == SYSMAP_ELEMENT_SUBTYPE_HOST_GROUP_ELEMENTS && $mapUrl['elementtype'] == SYSMAP_ELEMENT_TYPE_HOST)) {
                             $selements[$snum]['urls'][] = $this->expandUrlMacro($mapUrl, $selement);
                         }
                     }
                 }
             }
             $dbSelementUrls = DBselect('SELECT seu.sysmapelementurlid,seu.selementid,seu.name,seu.url' . ' FROM sysmap_element_url seu' . ' WHERE ' . dbConditionInt('seu.selementid', array_keys($selements)));
             while ($selementUrl = DBfetch($dbSelementUrls)) {
                 $selements[$selementUrl['selementid']]['urls'][] = is_null($options['expandUrls']) ? $selementUrl : $this->expandUrlMacro($selementUrl, $selements[$selementUrl['selementid']]);
             }
         }
         $selements = $this->unsetExtraFields($selements, array('sysmapid', 'selementid'), $options['selectSelements']);
         $result = $relationMap->mapMany($result, $selements, 'selements');
     }
     // adding icon maps
     if ($options['selectIconMap'] !== null && $options['selectIconMap'] != API_OUTPUT_COUNT) {
         $iconMaps = API::IconMap()->get(array('output' => $this->outputExtend($options['selectIconMap'], array('sysmapid', 'iconmapid')), 'sysmapids' => $sysmapIds, 'preservekeys' => true, 'nopermissions' => true));
         $relationMap = $this->createRelationMap($iconMaps, 'sysmapid', 'iconmapid');
         $iconMaps = $this->unsetExtraFields($iconMaps, array('sysmapid', 'iconmapid'), $options['selectIconMap']);
         $result = $relationMap->mapOne($result, $iconMaps, 'iconmap');
     }
     // adding links
     if ($options['selectLinks'] !== null && $options['selectLinks'] != API_OUTPUT_COUNT) {
         $links = API::getApiService()->select('sysmaps_links', array('output' => $this->outputExtend($options['selectLinks'], array('sysmapid', 'linkid')), 'filter' => array('sysmapid' => $sysmapIds), 'preservekeys' => true));
         $relationMap = $this->createRelationMap($links, 'sysmapid', 'linkid');
         // add link triggers
         if ($this->outputIsRequested('linktriggers', $options['selectLinks'])) {
             $linkTriggers = DBFetchArrayAssoc(DBselect('SELECT DISTINCT slt.*' . ' FROM sysmaps_link_triggers slt' . ' WHERE ' . dbConditionInt('slt.linkid', $relationMap->getRelatedIds())), 'linktriggerid');
             $linkTriggerRelationMap = $this->createRelationMap($linkTriggers, 'linkid', 'linktriggerid');
             $links = $linkTriggerRelationMap->mapMany($links, $linkTriggers, 'linktriggers');
         }
         $links = $this->unsetExtraFields($links, array('sysmapid', 'linkid'), $options['selectLinks']);
         $result = $relationMap->mapMany($result, $links, 'links');
     }
     // adding urls
     if ($options['selectUrls'] !== null && $options['selectUrls'] != API_OUTPUT_COUNT) {
         $links = API::getApiService()->select('sysmap_url', array('output' => $this->outputExtend($options['selectUrls'], array('sysmapid', 'sysmapurlid')), 'filter' => array('sysmapid' => $sysmapIds), 'preservekeys' => true));
         $relationMap = $this->createRelationMap($links, 'sysmapid', 'sysmapurlid');
         $links = $this->unsetExtraFields($links, array('sysmapid', 'sysmapurlid'), $options['selectUrls']);
         $result = $relationMap->mapMany($result, $links, 'urls');
     }
     return $result;
 }
コード例 #2
0
 protected function applyQueryNodeOptions($tableName, $tableAlias, array $options, array $sqlParts)
 {
     // only apply the node option if no specific ids are given
     if ($options['sysmapids'] === null) {
         $sqlParts = parent::applyQueryNodeOptions($tableName, $tableAlias, $options, $sqlParts);
     }
     return $sqlParts;
 }