当前位置: 首页>>代码示例>>PHP>>正文


PHP DB::getSchema方法代码示例

本文整理汇总了PHP中DB::getSchema方法的典型用法代码示例。如果您正苦于以下问题:PHP DB::getSchema方法的具体用法?PHP DB::getSchema怎么用?PHP DB::getSchema使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DB的用法示例。


在下文中一共展示了DB::getSchema方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: init

 public static function init()
 {
     self::$userDetails = CWebUser::$data;
     self::$profiles = array();
     $profilesTableSchema = DB::getSchema('profiles');
     self::$stringProfileMaxLength = $profilesTableSchema['fields']['value_str']['length'];
     $db_profiles = DBselect('SELECT p.*' . ' FROM profiles p' . ' WHERE p.userid=' . self::$userDetails['userid'] . andDbNode('p.profileid', false) . ' ORDER BY p.userid,p.profileid');
     while ($profile = DBfetch($db_profiles)) {
         $value_type = self::getFieldByType($profile['type']);
         if (!isset(self::$profiles[$profile['idx']])) {
             self::$profiles[$profile['idx']] = array();
         }
         self::$profiles[$profile['idx']][$profile['idx2']] = $profile[$value_type];
     }
 }
开发者ID:hujingguang,项目名称:work,代码行数:15,代码来源:profiles.inc.php

示例2: createBaseMigration

 private function createBaseMigration()
 {
     $sch = DB::getSchema();
     $tablename = "migrations";
     if (!$sch->hasTable($tablename)) {
         $sch->create($tablename, function ($table) {
             $table->increments('id');
             $table->string('class');
             $table->string('migration');
             $table->string('status');
             $table->integer('db_version')->default(0);
             $table->timestamps();
         });
     }
 }
开发者ID:kletellier,项目名称:mvc,代码行数:15,代码来源:Migrator.php

示例3: reserveIds

 /**
  * Reserve ids for primary key of passed table.
  * If record for table does not exist or value is out of range, ids record is created
  * using maximum id from table or minimum allowed value.
  *
  * @throw APIException
  *
  * @static
  *
  * @param string $table table name
  * @param int $count number of ids to reserve
  *
  * @return string
  */
 protected static function reserveIds($table, $count)
 {
     global $DB;
     $tableSchema = DB::getSchema($table);
     $id_name = $tableSchema['key'];
     $sql = 'SELECT nextid' . ' FROM ids' . ' WHERE table_name=' . zbx_dbstr($table) . ' AND field_name=' . zbx_dbstr($id_name);
     // SQLite3 does not support this syntax. Since we are in transaction, it can be ignored.
     if ($DB['TYPE'] != ZBX_DB_SQLITE3) {
         $sql = $sql . ' FOR UPDATE';
     }
     $res = DBfetch(DBselect($sql));
     if ($res) {
         $maxNextId = bcadd($res['nextid'], $count, 0);
         if (bccomp($maxNextId, ZBX_DB_MAX_ID) == 1) {
             $nextid = DB::refreshIds($table, $count);
         } else {
             $sql = 'UPDATE ids' . ' SET nextid=' . $maxNextId . ' WHERE table_name=' . zbx_dbstr($table) . ' AND field_name=' . zbx_dbstr($id_name);
             if (!DBexecute($sql)) {
                 self::exception(self::DBEXECUTE_ERROR, 'DBEXECUTE_ERROR');
             }
             $nextid = bcadd($res['nextid'], 1, 0);
         }
     } else {
         $nextid = DB::refreshIds($table, $count);
     }
     return $nextid;
 }
开发者ID:pida42,项目名称:Zabbix-Addons,代码行数:41,代码来源:DB.php

示例4: get

 /**
  * Get UserGroups
  *
  * @param array $options
  * @param array $options['nodeids'] Node IDs
  * @param array $options['usrgrpids'] UserGroup IDs
  * @param array $options['userids'] User IDs
  * @param boolean $options['status']
  * @param boolean $options['with_gui_access']
  * @param boolean $options['selectUsers']
  * @param int $options['count']
  * @param string $options['pattern']
  * @param int $options['limit'] limit selection
  * @param string $options['order']
  * @return array
  */
 public function get($options = array())
 {
     $result = array();
     $userType = self::$userData['type'];
     $userid = self::$userData['userid'];
     // allowed columns for sorting
     $sortColumns = array('usrgrpid', 'name');
     // allowed output options for [ select_* ] params
     $subselectsAllowedOutputs = array(API_OUTPUT_REFER, API_OUTPUT_EXTEND);
     $sqlParts = array('select' => array('usrgrp' => 'g.usrgrpid'), 'from' => array('usrgrp' => 'usrgrp g'), 'where' => array(), 'order' => array(), 'limit' => null);
     $defOptions = array('nodeids' => null, 'usrgrpids' => null, 'userids' => null, 'status' => null, 'with_gui_access' => null, 'filter' => null, 'search' => null, 'searchByAny' => null, 'startSearch' => null, 'excludeSearch' => null, 'searchWildcardsEnabled' => null, 'editable' => null, 'output' => API_OUTPUT_REFER, 'selectUsers' => null, 'countOutput' => null, 'preservekeys' => null, 'sortfield' => '', 'sortorder' => '', 'limit' => null);
     $options = zbx_array_merge($defOptions, $options);
     if (is_array($options['output'])) {
         unset($sqlParts['select']['usrgrp']);
         $dbTable = DB::getSchema('usrgrp');
         $sqlParts['select']['usrgrpid'] = 'g.usrgrpid';
         foreach ($options['output'] as $field) {
             if (isset($dbTable['fields'][$field])) {
                 $sqlParts['select'][$field] = 'g.' . $field;
             }
         }
         $options['output'] = API_OUTPUT_CUSTOM;
     }
     // permission check
     if (USER_TYPE_SUPER_ADMIN == $userType) {
     } elseif (is_null($options['editable']) && self::$userData['type'] == USER_TYPE_ZABBIX_ADMIN) {
         $sqlParts['where'][] = 'g.usrgrpid IN (' . 'SELECT uug.usrgrpid' . ' FROM users_groups uug' . ' WHERE uug.userid=' . self::$userData['userid'] . ')';
     } elseif (!is_null($options['editable']) && self::$userData['type'] != USER_TYPE_SUPER_ADMIN) {
         return array();
     }
     // nodeids
     $nodeids = !is_null($options['nodeids']) ? $options['nodeids'] : get_current_nodeid();
     // usrgrpids
     if (!is_null($options['usrgrpids'])) {
         zbx_value2array($options['usrgrpids']);
         $sqlParts['where'][] = dbConditionInt('g.usrgrpid', $options['usrgrpids']);
     }
     // userids
     if (!is_null($options['userids'])) {
         zbx_value2array($options['userids']);
         if ($options['output'] != API_OUTPUT_SHORTEN) {
             $sqlParts['select']['userid'] = 'ug.userid';
         }
         $sqlParts['from']['users_groups'] = 'users_groups ug';
         $sqlParts['where'][] = dbConditionInt('ug.userid', $options['userids']);
         $sqlParts['where']['gug'] = 'g.usrgrpid=ug.usrgrpid';
     }
     // status
     if (!is_null($options['status'])) {
         $sqlParts['where'][] = 'g.users_status=' . zbx_dbstr($options['status']);
     }
     // with_gui_access
     if (!is_null($options['with_gui_access'])) {
         $sqlParts['where'][] = 'g.gui_access=' . GROUP_GUI_ACCESS_ENABLED;
     }
     // output
     if ($options['output'] == API_OUTPUT_EXTEND) {
         $sqlParts['select']['usrgrp'] = 'g.*';
     }
     // countOutput
     if (!is_null($options['countOutput'])) {
         $options['sortfield'] = '';
         $sqlParts['select'] = array('count(g.usrgrpid) as rowscount');
     }
     // filter
     if (is_array($options['filter'])) {
         $this->dbFilter('usrgrp g', $options, $sqlParts);
     }
     // search
     if (is_array($options['search'])) {
         zbx_db_search('usrgrp g', $options, $sqlParts);
     }
     // sorting
     zbx_db_sorting($sqlParts, $options, $sortColumns, 'g');
     // limit
     if (zbx_ctype_digit($options['limit']) && $options['limit']) {
         $sqlParts['limit'] = $options['limit'];
     }
     $usrgrpids = array();
     $sqlParts['select'] = array_unique($sqlParts['select']);
     $sqlParts['from'] = array_unique($sqlParts['from']);
     $sqlParts['where'] = array_unique($sqlParts['where']);
     $sqlParts['order'] = array_unique($sqlParts['order']);
     $sqlSelect = '';
//.........这里部分代码省略.........
开发者ID:quanta-computing,项目名称:debian-packages,代码行数:101,代码来源:CUserGroup.php

示例5: get

 /**
  * Get Map data
  *
  * @param array $options
  * @param array $options['nodeids'] Node IDs
  * @param array $options['groupids'] HostGroup IDs
  * @param array $options['hostids'] Host IDs
  * @param boolean $options['monitored_hosts'] only monitored Hosts
  * @param boolean $options['templated_hosts'] include templates in result
  * @param boolean $options['with_items'] only with items
  * @param boolean $options['with_historical_items'] only with historical items
  * @param boolean $options['with_triggers'] only with triggers
  * @param boolean $options['with_httptests'] only with http tests
  * @param boolean $options['with_graphs'] only with graphs
  * @param boolean $options['editable'] only with read-write permission. Ignored for SuperAdmins
  * @param int $options['count'] count Hosts, returned column name is rowscount
  * @param string $options['pattern'] search hosts by pattern in host names
  * @param int $options['limit'] limit selection
  * @param string $options['sortorder']
  * @param string $options['sortfield']
  * @return array|boolean Host data as array or false if error
  */
 public function get($options = array())
 {
     $result = array();
     $userType = self::$userData['type'];
     // allowed columns for sorting
     $sortColumns = array('name', 'width', 'height');
     // allowed output options for [ select_* ] params
     $subselectsAllowedOutputs = array(API_OUTPUT_REFER, API_OUTPUT_EXTEND);
     $sqlParts = array('select' => array('sysmaps' => 's.sysmapid'), 'from' => array('sysmaps' => 'sysmaps s'), 'where' => array(), 'order' => array(), 'limit' => null);
     $defOptions = array('nodeids' => null, 'sysmapids' => null, 'editable' => null, 'nopermissions' => null, 'filter' => null, 'search' => null, 'searchByAny' => null, 'startSearch' => null, 'excludeSearch' => null, 'searchWildcardsEnabled' => null, 'output' => API_OUTPUT_REFER, 'selectSelements' => null, 'selectLinks' => null, 'selectIconMap' => null, 'countOutput' => null, 'expandUrls' => null, 'preservekeys' => null, 'sortfield' => '', 'sortorder' => '', 'limit' => null);
     $options = zbx_array_merge($defOptions, $options);
     if (is_array($options['output'])) {
         unset($sqlParts['select']['sysmaps']);
         $dbTable = DB::getSchema('sysmaps');
         $sqlParts['select']['sysmapid'] = 's.sysmapid';
         foreach ($options['output'] as $field) {
             if (isset($dbTable['fields'][$field])) {
                 $sqlParts['select'][$field] = 's.' . $field;
             }
         }
         $options['output'] = API_OUTPUT_CUSTOM;
     }
     // sysmapids
     if (!is_null($options['sysmapids'])) {
         zbx_value2array($options['sysmapids']);
         $sqlParts['where']['sysmapid'] = dbConditionInt('s.sysmapid', $options['sysmapids']);
     }
     // search
     if (!is_null($options['search'])) {
         zbx_db_search('sysmaps s', $options, $sqlParts);
     }
     // filter
     if (!is_null($options['filter'])) {
         $this->dbFilter('sysmaps s', $options, $sqlParts);
     }
     // output
     if ($options['output'] == API_OUTPUT_EXTEND) {
         $sqlParts['select']['sysmaps'] = 's.*';
     }
     // countOutput
     if (!is_null($options['countOutput'])) {
         $options['sortfield'] = '';
         $sqlParts['select'] = array('count(DISTINCT s.sysmapid) as rowscount');
     }
     // sorting
     zbx_db_sorting($sqlParts, $options, $sortColumns, 's');
     // limit
     if (zbx_ctype_digit($options['limit']) && $options['limit']) {
         $sqlParts['limit'] = $options['limit'];
     }
     $sysmapids = array();
     $sqlParts = $this->applyQueryNodeOptions($this->tableName(), $this->tableAlias(), $options, $sqlParts);
     $res = DBselect($this->createSelectQueryFromParts($sqlParts), $sqlParts['limit']);
     while ($sysmap = DBfetch($res)) {
         if ($options['countOutput']) {
             $result = $sysmap['rowscount'];
         } else {
             $sysmapids[$sysmap['sysmapid']] = $sysmap['sysmapid'];
             if ($options['output'] == API_OUTPUT_SHORTEN) {
                 $result[$sysmap['sysmapid']] = array('sysmapid' => $sysmap['sysmapid']);
             } else {
                 if (!isset($result[$sysmap['sysmapid']])) {
                     $result[$sysmap['sysmapid']] = array();
                 }
                 // originally we intended not to pass those parameters if advanced labels are off, but they might be useful
                 // leaving this block commented
                 // if (isset($sysmap['label_format']) && ($sysmap['label_format'] == SYSMAP_LABEL_ADVANCED_OFF)) {
                 // 	unset($sysmap['label_string_hostgroup'], $sysmap['label_string_host'], $sysmap['label_string_trigger'], $sysmap['label_string_map'], $sysmap['label_string_image']);
                 // }
                 if (!is_null($options['selectSelements']) && !isset($result[$sysmap['sysmapid']]['selements'])) {
                     $result[$sysmap['sysmapid']]['selements'] = array();
                 }
                 if (!is_null($options['selectLinks']) && !isset($result[$sysmap['sysmapid']]['links'])) {
                     $result[$sysmap['sysmapid']]['links'] = array();
                 }
                 if (!is_null($options['selectIconMap']) && !isset($result[$sysmap['sysmapid']]['iconmap'])) {
                     $result[$sysmap['sysmapid']]['iconmap'] = array();
                 }
//.........这里部分代码省略.........
开发者ID:quanta-computing,项目名称:debian-packages,代码行数:101,代码来源:CMap.php

示例6: get

 /**
  * Get GraphPrototype data
  *
  * @param array $options
  * @return array
  */
 public function get($options = array())
 {
     $result = array();
     $userType = self::$userData['type'];
     $userid = self::$userData['userid'];
     // allowed columns for sorting
     $sortColumns = array('graphid', 'name', 'graphtype');
     // allowed output options for [ select_* ] params
     $subselectsAllowedOutputs = array(API_OUTPUT_REFER, API_OUTPUT_EXTEND, API_OUTPUT_CUSTOM);
     $sqlParts = array('select' => array('graphs' => 'g.graphid'), 'from' => array('graphs' => 'graphs g'), 'where' => array('g.flags=' . ZBX_FLAG_DISCOVERY_CHILD), 'group' => array(), 'order' => array(), 'limit' => null);
     $defOptions = array('nodeids' => null, 'groupids' => null, 'templateids' => null, 'hostids' => null, 'graphids' => null, 'itemids' => null, 'discoveryids' => null, 'type' => null, 'templated' => null, 'inherited' => null, 'editable' => null, 'nopermissions' => null, 'filter' => null, 'search' => null, 'searchByAny' => null, 'startSearch' => null, 'excludeSearch' => null, 'searchWildcardsEnabled' => null, 'output' => API_OUTPUT_REFER, 'selectGroups' => null, 'selectTemplates' => null, 'selectHosts' => null, 'selectItems' => null, 'selectGraphItems' => null, 'selectDiscoveryRule' => null, 'countOutput' => null, 'groupCount' => null, 'preservekeys' => null, 'sortfield' => '', 'sortorder' => '', 'limit' => null);
     $options = zbx_array_merge($defOptions, $options);
     if (is_array($options['output'])) {
         unset($sqlParts['select']['graphs']);
         $dbTable = DB::getSchema('graphs');
         foreach ($options['output'] as $field) {
             if (isset($dbTable['fields'][$field])) {
                 $sqlParts['select'][$field] = 'g.' . $field;
             }
         }
         $options['output'] = API_OUTPUT_CUSTOM;
     }
     // editable + PERMISSION CHECK
     if ($userType != USER_TYPE_SUPER_ADMIN && !$options['nopermissions']) {
         $permission = $options['editable'] ? PERM_READ_WRITE : PERM_READ_ONLY;
         $userGroups = getUserGroupsByUserId($userid);
         $sqlParts['where'][] = 'EXISTS (' . 'SELECT NULL' . ' FROM graphs_items gi,items i,hosts_groups hgg' . ' JOIN rights r' . ' ON r.id=hgg.groupid' . ' AND ' . dbConditionInt('r.groupid', $userGroups) . ' WHERE g.graphid=gi.graphid' . ' AND gi.itemid=i.itemid' . ' AND i.hostid=hgg.hostid' . ' GROUP BY gi.graphid' . ' HAVING MIN(r.permission)>=' . $permission . ')';
     }
     // nodeids
     $nodeids = !is_null($options['nodeids']) ? $options['nodeids'] : get_current_nodeid();
     // groupids
     if (!is_null($options['groupids'])) {
         zbx_value2array($options['groupids']);
         if ($options['output'] != API_OUTPUT_SHORTEN) {
             $sqlParts['select']['groupid'] = 'hg.groupid';
         }
         $sqlParts['from']['graphs_items'] = 'graphs_items gi';
         $sqlParts['from']['items'] = 'items i';
         $sqlParts['from']['hosts_groups'] = 'hosts_groups hg';
         $sqlParts['where'][] = dbConditionInt('hg.groupid', $options['groupids']);
         $sqlParts['where'][] = 'hg.hostid=i.hostid';
         $sqlParts['where']['gig'] = 'gi.graphid=g.graphid';
         $sqlParts['where']['igi'] = 'i.itemid=gi.itemid';
         $sqlParts['where']['hgi'] = 'hg.hostid=i.hostid';
         if (!is_null($options['groupCount'])) {
             $sqlParts['group']['hg'] = 'hg.groupid';
         }
     }
     // templateids
     if (!is_null($options['templateids'])) {
         zbx_value2array($options['templateids']);
         if (!is_null($options['hostids'])) {
             zbx_value2array($options['hostids']);
             $options['hostids'] = array_merge($options['hostids'], $options['templateids']);
         } else {
             $options['hostids'] = $options['templateids'];
         }
     }
     // hostids
     if (!is_null($options['hostids'])) {
         zbx_value2array($options['hostids']);
         if ($options['output'] != API_OUTPUT_SHORTEN) {
             $sqlParts['select']['hostid'] = 'i.hostid';
         }
         $sqlParts['from']['graphs_items'] = 'graphs_items gi';
         $sqlParts['from']['items'] = 'items i';
         $sqlParts['where'][] = dbConditionInt('i.hostid', $options['hostids']);
         $sqlParts['where']['gig'] = 'gi.graphid=g.graphid';
         $sqlParts['where']['igi'] = 'i.itemid=gi.itemid';
         if (!is_null($options['groupCount'])) {
             $sqlParts['group']['i'] = 'i.hostid';
         }
     }
     // graphids
     if (!is_null($options['graphids'])) {
         zbx_value2array($options['graphids']);
         $sqlParts['where'][] = dbConditionInt('g.graphid', $options['graphids']);
     }
     // itemids
     if (!is_null($options['itemids'])) {
         zbx_value2array($options['itemids']);
         if ($options['output'] != API_OUTPUT_SHORTEN) {
             $sqlParts['select']['itemid'] = 'gi.itemid';
         }
         $sqlParts['from']['graphs_items'] = 'graphs_items gi';
         $sqlParts['where']['gig'] = 'gi.graphid=g.graphid';
         $sqlParts['where'][] = dbConditionInt('gi.itemid', $options['itemids']);
         if (!is_null($options['groupCount'])) {
             $sqlParts['group']['gi'] = 'gi.itemid';
         }
     }
     // discoveryids
     if (!is_null($options['discoveryids'])) {
         zbx_value2array($options['discoveryids']);
//.........这里部分代码省略.........
开发者ID:quanta-computing,项目名称:debian-packages,代码行数:101,代码来源:CGraphPrototype.php

示例7: jQuery

<?php

$schema = DB::getSchema('config');
?>
<div id="dialog" style="display:none; white-space: normal;"></div>

<script type="text/javascript">

	jQuery(document).ready(function(){

		jQuery("#resetDefaults").click(function(){

			jQuery('#dialog').text(<?php 
echo CJs::encodeJson(_('Reset all fields to default values?'));
?>
);
			var w = jQuery('#dialog').outerWidth()+20;

			jQuery('#dialog').dialog({
				buttons: [
					{text: <?php 
echo CJs::encodeJson(_('Reset defaults'));
?>
, click: function(){
						// Unacknowledged problem events
						jQuery('#problem_unack_color').val("<?php 
echo $schema['fields']['problem_unack_color']['default'];
?>
");
						jQuery('#problem_unack_color').change();
						jQuery('#problem_unack_style').prop(
开发者ID:davidmr001,项目名称:zatree-2.2,代码行数:31,代码来源:administration.general.triggerDisplayOptions.js.php

示例8: get

 /**
  * Get IconMap data.
  * @param array $options
  * @param array $options['nodeids']
  * @param array $options['iconmapids']
  * @param array $options['sysmapids']
  * @param array $options['editable']
  * @param array $options['count']
  * @param array $options['limit']
  * @param array $options['order']
  * @return array
  */
 public function get(array $options = array())
 {
     $result = array();
     // allowed columns for sorting
     $sortColumns = array('iconmapid', 'name');
     // allowed output options for [ select_* ] params
     $subselectsAllowedOutputs = array(API_OUTPUT_REFER, API_OUTPUT_EXTEND);
     $sqlParts = array('select' => array('icon_map' => 'im.iconmapid'), 'from' => array('icon_map' => 'icon_map im'), 'where' => array(), 'order' => array(), 'limit' => null);
     $defOptions = array('nodeids' => null, 'iconmapids' => null, 'sysmapids' => null, 'nopermissions' => null, 'editable' => null, 'filter' => null, 'search' => null, 'searchByAny' => null, 'startSearch' => null, 'excludeSearch' => null, 'searchWildcardsEnabled' => null, 'output' => API_OUTPUT_REFER, 'selectMappings' => null, 'countOutput' => null, 'preservekeys' => null, 'sortfield' => '', 'sortorder' => '', 'limit' => null);
     $options = zbx_array_merge($defOptions, $options);
     if (is_array($options['output'])) {
         $dbTable = DB::getSchema('icon_map');
         foreach ($options['output'] as $field) {
             if (isset($dbTable['fields'][$field])) {
                 $sqlParts['select'][$field] = 'im.' . $field;
             }
         }
         $options['output'] = API_OUTPUT_CUSTOM;
     }
     // editable + PERMISSION CHECK
     if ($options['editable'] && self::$userData['type'] != USER_TYPE_SUPER_ADMIN) {
         return array();
     }
     // nodeids
     $nodeids = !is_null($options['nodeids']) ? $options['nodeids'] : get_current_nodeid();
     // iconmapids
     if (!is_null($options['iconmapids'])) {
         zbx_value2array($options['iconmapids']);
         $sqlParts['where'][] = dbConditionInt('im.iconmapid', $options['iconmapids']);
     }
     // sysmapids
     if (!is_null($options['sysmapids'])) {
         zbx_value2array($options['sysmapids']);
         if ($options['output'] != API_OUTPUT_SHORTEN) {
             $sqlParts['select']['sysmapids'] = 's.sysmapid';
         }
         $sqlParts['from']['sysmaps'] = 'sysmaps s';
         $sqlParts['where'][] = dbConditionInt('s.sysmapid', $options['sysmapids']);
         $sqlParts['where']['ims'] = 'im.iconmapid=s.iconmapid';
     }
     // filter
     if (is_array($options['filter'])) {
         $this->dbFilter('icon_map im', $options, $sqlParts);
     }
     // search
     if (is_array($options['search'])) {
         zbx_db_search('icon_map im', $options, $sqlParts);
     }
     // output
     if ($options['output'] == API_OUTPUT_EXTEND) {
         $sqlParts['select']['icon_map'] = 'im.*';
     }
     // countOutput
     if (!is_null($options['countOutput'])) {
         $options['sortfield'] = '';
         $sqlParts['select'] = array('COUNT(DISTINCT im.iconmapid) AS rowscount');
     }
     // sorting
     zbx_db_sorting($sqlParts, $options, $sortColumns, 'im');
     // limit
     if (zbx_ctype_digit($options['limit']) && $options['limit']) {
         $sqlParts['limit'] = $options['limit'];
     }
     $iconMapids = array();
     $sqlParts['select'] = array_unique($sqlParts['select']);
     $sqlParts['from'] = array_unique($sqlParts['from']);
     $sqlParts['where'] = array_unique($sqlParts['where']);
     $sqlParts['order'] = array_unique($sqlParts['order']);
     $sqlSelect = '';
     $sqlFrom = '';
     $sqlWhere = '';
     $sqlOrder = '';
     if (!empty($sqlParts['select'])) {
         $sqlSelect .= implode(',', $sqlParts['select']);
     }
     if (!empty($sqlParts['from'])) {
         $sqlFrom .= implode(',', $sqlParts['from']);
     }
     if (!empty($sqlParts['where'])) {
         $sqlWhere .= ' AND ' . implode(' AND ', $sqlParts['where']);
     }
     if (!empty($sqlParts['order'])) {
         $sqlOrder .= ' ORDER BY ' . implode(',', $sqlParts['order']);
     }
     $sqlLimit = $sqlParts['limit'];
     $sql = 'SELECT ' . $sqlSelect . ' FROM ' . $sqlFrom . ' WHERE ' . DBin_node('im.iconmapid', $nodeids) . $sqlWhere . $sqlOrder;
     $dbRes = DBselect($sql, $sqlLimit);
     while ($iconMap = DBfetch($dbRes)) {
//.........这里部分代码省略.........
开发者ID:quanta-computing,项目名称:debian-packages,代码行数:101,代码来源:CIconMap.php

示例9: zbx_db_search

function zbx_db_search($table, $options, &$sql_parts)
{
    list($table, $tableShort) = explode(' ', $table);
    $tableSchema = DB::getSchema($table);
    if (!$tableSchema) {
        info(_s('Error in search request for table "%1$s".', $table));
    }
    $start = is_null($options['startSearch']) ? '%' : '';
    $exclude = is_null($options['excludeSearch']) ? '' : ' NOT ';
    $glue = !$options['searchByAny'] ? ' AND ' : ' OR ';
    $search = array();
    foreach ($options['search'] as $field => $patterns) {
        if (!isset($tableSchema['fields'][$field]) || zbx_empty($patterns)) {
            continue;
        }
        if ($tableSchema['fields'][$field]['type'] != DB::FIELD_TYPE_CHAR && $tableSchema['fields'][$field]['type'] != DB::FIELD_TYPE_TEXT) {
            continue;
        }
        $fieldSearch = array();
        foreach ((array) $patterns as $pattern) {
            if (zbx_empty($pattern)) {
                continue;
            }
            // escaping parameter that is about to be used in LIKE statement
            $pattern = str_replace("!", "!!", $pattern);
            $pattern = str_replace("%", "!%", $pattern);
            $pattern = str_replace("_", "!_", $pattern);
            if (!$options['searchWildcardsEnabled']) {
                $fieldSearch[] = ' UPPER(' . $tableShort . '.' . $field . ') ' . $exclude . ' LIKE ' . zbx_dbstr($start . mb_strtoupper($pattern) . '%') . " ESCAPE '!'";
            } else {
                $pattern = str_replace("*", "%", $pattern);
                $fieldSearch[] = ' UPPER(' . $tableShort . '.' . $field . ') ' . $exclude . ' LIKE ' . zbx_dbstr(mb_strtoupper($pattern)) . " ESCAPE '!'";
            }
        }
        $search[$field] = '( ' . implode($glue, $fieldSearch) . ' )';
    }
    if (!empty($search)) {
        if (isset($sql_parts['where']['search'])) {
            $search[] = $sql_parts['where']['search'];
        }
        $sql_parts['where']['search'] = '( ' . implode($glue, $search) . ' )';
        return true;
    }
    return false;
}
开发者ID:TonywalkerCN,项目名称:Zabbix,代码行数:45,代码来源:db.inc.php

示例10: get

 /**
  * Get Screen data
  *
  * @param array $options
  * @param array $options['nodeids'] Node IDs
  * @param boolean $options['with_items'] only with items
  * @param boolean $options['editable'] only with read-write permission. Ignored for SuperAdmins
  * @param int $options['count'] count Hosts, returned column name is rowscount
  * @param string $options['pattern'] search hosts by pattern in host names
  * @param int $options['limit'] limit selection
  * @param string $options['order'] deprecated parameter (for now)
  * @return array|boolean Host data as array or false if error
  */
 public function get($options = array())
 {
     $result = array();
     $userType = self::$userData['type'];
     $userid = self::$userData['userid'];
     // allowed columns for sorting
     $sortColumns = array('screenid', 'name');
     // allowed output options for [ select_* ] params
     $subselectsAllowedOutputs = array(API_OUTPUT_REFER, API_OUTPUT_EXTEND);
     $sqlParts = array('select' => array('screens' => 's.screenid,s.templateid'), 'from' => array('screens' => 'screens s'), 'where' => array('template' => 's.templateid IS NOT NULL'), 'order' => array(), 'group' => array(), 'limit' => null);
     $defOptions = array('nodeids' => null, 'screenids' => null, 'screenitemids' => null, 'templateids' => null, 'hostids' => null, 'editable' => null, 'noInheritance' => null, 'nopermissions' => null, 'filter' => null, 'search' => null, 'searchByAny' => null, 'startSearch' => null, 'excludeSearch' => null, 'searchWildcardsEnabled' => null, 'output' => API_OUTPUT_REFER, 'selectScreenItems' => null, 'countOutput' => null, 'groupCount' => null, 'preservekeys' => null, 'sortfield' => '', 'sortorder' => '', 'limit' => null);
     $options = zbx_array_merge($defOptions, $options);
     if (is_array($options['output'])) {
         unset($sqlParts['select']['screens']);
         $dbTable = DB::getSchema('screens');
         foreach ($options['output'] as $field) {
             if (isset($dbTable['fields'][$field])) {
                 $sqlParts['select'][$field] = 's.' . $field;
             }
         }
         $options['output'] = API_OUTPUT_CUSTOM;
     }
     if (!is_null($options['editable']) || is_null($options['hostids']) && is_null($options['templateids'])) {
         $options['noInheritance'] = 1;
     }
     // editable + PERMISSION CHECK
     if ($userType != USER_TYPE_SUPER_ADMIN && !$options['nopermissions']) {
         // TODO: think how we could combine templateids && hostids options
         if (!is_null($options['templateids'])) {
             unset($options['hostids']);
             $options['templateids'] = API::Template()->get(array('templateids' => $options['templateids'], 'editable' => $options['editable'], 'preservekeys' => true));
             $options['templateids'] = array_keys($options['templateids']);
         } elseif (!is_null($options['hostids'])) {
             $options['templateids'] = API::Host()->get(array('hostids' => $options['hostids'], 'editable' => $options['editable'], 'preservekeys' => true));
             $options['templateids'] = array_keys($options['templateids']);
         } else {
             // TODO: get screen
             $permission = $options['editable'] ? PERM_READ_WRITE : PERM_READ_ONLY;
             $userGroups = getUserGroupsByUserId($userid);
             $sqlParts['where'][] = 'EXISTS (' . 'SELECT NULL' . ' FROM hosts_groups hgg' . ' JOIN rights r' . ' ON r.id=hgg.groupid' . ' AND ' . dbConditionInt('r.groupid', $userGroups) . ' WHERE s.templateid=hgg.hostid' . ' GROUP BY hgg.hostid' . ' HAVING MIN(r.permission)>=' . $permission . ')';
         }
     }
     // nodeids
     $nodeids = !is_null($options['nodeids']) ? $options['nodeids'] : get_current_nodeid();
     // screenids
     if (!is_null($options['screenids'])) {
         zbx_value2array($options['screenids']);
         $sqlParts['where'][] = dbConditionInt('s.screenid', $options['screenids']);
     }
     // screenitemids
     if (!is_null($options['screenitemids'])) {
         zbx_value2array($options['screenitemids']);
         if ($options['output'] != API_OUTPUT_EXTEND) {
             $sqlParts['select']['screenitemid'] = 'si.screenitemid';
         }
         $sqlParts['from']['screens_items'] = 'screens_items si';
         $sqlParts['where']['ssi'] = 'si.screenid=s.screenid';
         $sqlParts['where'][] = dbConditionInt('si.screenitemid', $options['screenitemids']);
     }
     // templateids
     if (!is_null($options['templateids'])) {
         zbx_value2array($options['templateids']);
         if (isset($options['hostids']) && !is_null($options['hostids'])) {
             zbx_value2array($options['hostids']);
             $options['hostids'] = array_merge($options['hostids'], $options['templateids']);
         } else {
             $options['hostids'] = $options['templateids'];
         }
     }
     // hostids
     if (!is_null($options['hostids'])) {
         zbx_value2array($options['hostids']);
         // collecting template chain
         $templatesChain = array();
         $linkedTemplateids = $options['hostids'];
         $childTemplateids = $options['hostids'];
         while (is_null($options['noInheritance']) && !empty($childTemplateids)) {
             $sql = 'SELECT ht.*' . ' FROM hosts_templates ht' . ' WHERE ' . dbConditionInt('hostid', $childTemplateids);
             $dbTemplates = DBselect($sql);
             $childTemplateids = array();
             while ($link = DBfetch($dbTemplates)) {
                 $childTemplateids[$link['templateid']] = $link['templateid'];
                 $linkedTemplateids[$link['templateid']] = $link['templateid'];
                 createParentToChildRelation($templatesChain, $link, 'templateid', 'hostid');
             }
         }
         if ($options['output'] != API_OUTPUT_EXTEND) {
//.........这里部分代码省略.........
开发者ID:quanta-computing,项目名称:debian-packages,代码行数:101,代码来源:CTemplateScreen.php

示例11: get

 /**
  * Get Template data
  *
  * @param array $options
  * @return array|boolean Template data as array or false if error
  */
 public function get($options = array())
 {
     $result = array();
     $nodeCheck = false;
     $userType = self::$userData['type'];
     $userid = self::$userData['userid'];
     // allowed columns for sorting
     $sortColumns = array('hostid', 'host', 'name');
     // allowed output options for [ select_* ] params
     $subselectsAllowedOutputs = array(API_OUTPUT_REFER, API_OUTPUT_EXTEND);
     $sqlParts = array('select' => array('templates' => 'h.hostid'), 'from' => array('hosts' => 'hosts h'), 'where' => array('h.status=' . HOST_STATUS_TEMPLATE), 'group' => array(), 'order' => array(), 'limit' => null);
     $defOptions = array('nodeids' => null, 'groupids' => null, 'templateids' => null, 'parentTemplateids' => null, 'hostids' => null, 'graphids' => null, 'itemids' => null, 'triggerids' => null, 'with_items' => null, 'with_triggers' => null, 'with_graphs' => null, 'editable' => null, 'nopermissions' => null, 'filter' => null, 'search' => '', 'searchByAny' => null, 'startSearch' => null, 'excludeSearch' => null, 'searchWildcardsEnabled' => null, 'output' => API_OUTPUT_REFER, 'selectGroups' => null, 'selectHosts' => null, 'selectTemplates' => null, 'selectParentTemplates' => null, 'selectItems' => null, 'selectDiscoveries' => null, 'selectTriggers' => null, 'selectGraphs' => null, 'selectApplications' => null, 'selectMacros' => null, 'selectScreens' => null, 'countOutput' => null, 'groupCount' => null, 'preservekeys' => null, 'sortfield' => '', 'sortorder' => '', 'limit' => null, 'limitSelects' => null);
     $options = zbx_array_merge($defOptions, $options);
     if (is_array($options['output'])) {
         unset($sqlParts['select']['templates']);
         $dbTable = DB::getSchema('hosts');
         $sqlParts['select']['hostid'] = 'h.hostid';
         foreach ($options['output'] as $field) {
             if ($field == 'templateid') {
                 continue;
             }
             if (isset($dbTable['fields'][$field])) {
                 $sqlParts['select'][$field] = 'h.' . $field;
             }
         }
         $options['output'] = API_OUTPUT_CUSTOM;
     }
     // editable + PERMISSION CHECK
     if ($userType != USER_TYPE_SUPER_ADMIN && !$options['nopermissions']) {
         $permission = $options['editable'] ? PERM_READ_WRITE : PERM_READ_ONLY;
         $userGroups = getUserGroupsByUserId($userid);
         $sqlParts['where'][] = 'EXISTS (' . 'SELECT NULL' . ' FROM hosts_groups hgg' . ' JOIN rights r' . ' ON r.id=hgg.groupid' . ' AND ' . dbConditionInt('r.groupid', $userGroups) . ' WHERE h.hostid=hgg.hostid' . ' GROUP BY hgg.hostid' . ' HAVING MIN(r.permission)>=' . $permission . ')';
     }
     // nodeids
     $nodeids = !is_null($options['nodeids']) ? $options['nodeids'] : get_current_nodeid();
     // groupids
     if (!is_null($options['groupids'])) {
         zbx_value2array($options['groupids']);
         if ($options['output'] != API_OUTPUT_SHORTEN) {
             $sqlParts['select']['groupid'] = 'hg.groupid';
         }
         $sqlParts['from']['hosts_groups'] = 'hosts_groups hg';
         $sqlParts['where'][] = dbConditionInt('hg.groupid', $options['groupids']);
         $sqlParts['where']['hgh'] = 'hg.hostid=h.hostid';
         if (!is_null($options['groupCount'])) {
             $sqlParts['group']['hg'] = 'hg.groupid';
         }
         if (!$nodeCheck) {
             $nodeCheck = true;
             $sqlParts['where'][] = DBin_node('hg.groupid', $nodeids);
         }
     }
     // templateids
     if (!is_null($options['templateids'])) {
         zbx_value2array($options['templateids']);
         $sqlParts['where']['templateid'] = dbConditionInt('h.hostid', $options['templateids']);
         if (!$nodeCheck) {
             $nodeCheck = true;
             $sqlParts['where'][] = DBin_node('h.hostid', $nodeids);
         }
     }
     // parentTemplateids
     if (!is_null($options['parentTemplateids'])) {
         zbx_value2array($options['parentTemplateids']);
         if ($options['output'] != API_OUTPUT_SHORTEN) {
             $sqlParts['select']['parentTemplateid'] = 'ht.templateid as parentTemplateid';
         }
         $sqlParts['from']['hosts_templates'] = 'hosts_templates ht';
         $sqlParts['where'][] = dbConditionInt('ht.templateid', $options['parentTemplateids']);
         $sqlParts['where']['hht'] = 'h.hostid=ht.hostid';
         if (!is_null($options['groupCount'])) {
             $sqlParts['group']['templateid'] = 'ht.templateid';
         }
         if (!$nodeCheck) {
             $nodeCheck = true;
             $sqlParts['where'][] = DBin_node('ht.templateid', $nodeids);
         }
     }
     // hostids
     if (!is_null($options['hostids'])) {
         zbx_value2array($options['hostids']);
         if ($options['output'] != API_OUTPUT_SHORTEN) {
             $sqlParts['select']['linked_hostid'] = 'ht.hostid as linked_hostid';
         }
         $sqlParts['from']['hosts_templates'] = 'hosts_templates ht';
         $sqlParts['where'][] = dbConditionInt('ht.hostid', $options['hostids']);
         $sqlParts['where']['hht'] = 'h.hostid=ht.templateid';
         if (!is_null($options['groupCount'])) {
             $sqlParts['group']['ht'] = 'ht.hostid';
         }
         if (!$nodeCheck) {
             $nodeCheck = true;
             $sqlParts['where'][] = DBin_node('ht.hostid', $nodeids);
         }
//.........这里部分代码省略.........
开发者ID:quanta-computing,项目名称:debian-packages,代码行数:101,代码来源:CTemplate.php

示例12: is_db

 private function is_db($value, $table, $field)
 {
     $table_schema = DB::getSchema($table);
     return is_string($value) && $this->check_db_value($table_schema['fields'][$field], $value);
 }
开发者ID:jbfavre,项目名称:debian-zabbix,代码行数:5,代码来源:CNewValidator.php

示例13: get

 /**
  * Get items data.
  *
  * @param array $options
  * @param array $options['itemids']
  * @param array $options['hostids']
  * @param array $options['groupids']
  * @param array $options['triggerids']
  * @param array $options['applicationids']
  * @param boolean $options['status']
  * @param boolean $options['templated_items']
  * @param boolean $options['editable']
  * @param boolean $options['count']
  * @param string $options['pattern']
  * @param int $options['limit']
  * @param string $options['order']
  *
  * @return array|int item data as array or false if error
  */
 public function get($options = array())
 {
     $result = array();
     $userType = self::$userData['type'];
     $userid = self::$userData['userid'];
     // allowed columns for sorting
     $sortColumns = array('itemid', 'name', 'key_', 'delay', 'history', 'trends', 'type', 'status');
     // allowed output options for [ select_* ] params
     $subselectsAllowedOutputs = array(API_OUTPUT_REFER, API_OUTPUT_EXTEND, API_OUTPUT_CUSTOM);
     $sqlParts = array('select' => array('items' => 'i.itemid'), 'from' => array('items' => 'items i'), 'where' => array('webtype' => 'i.type<>' . ITEM_TYPE_HTTPTEST, 'flags' => 'i.flags IN (' . ZBX_FLAG_DISCOVERY_NORMAL . ',' . ZBX_FLAG_DISCOVERY_CREATED . ')'), 'group' => array(), 'order' => array(), 'limit' => null);
     $defOptions = array('nodeids' => null, 'groupids' => null, 'templateids' => null, 'hostids' => null, 'proxyids' => null, 'itemids' => null, 'interfaceids' => null, 'graphids' => null, 'triggerids' => null, 'applicationids' => null, 'webitems' => null, 'inherited' => null, 'templated' => null, 'monitored' => null, 'editable' => null, 'nopermissions' => null, 'group' => null, 'host' => null, 'application' => null, 'with_triggers' => null, 'filter' => null, 'search' => null, 'searchByAny' => null, 'startSearch' => null, 'excludeSearch' => null, 'searchWildcardsEnabled' => null, 'output' => API_OUTPUT_REFER, 'selectHosts' => null, 'selectInterfaces' => null, 'selectTriggers' => null, 'selectGraphs' => null, 'selectApplications' => null, 'selectDiscoveryRule' => null, 'selectItemDiscovery' => null, 'countOutput' => null, 'groupCount' => null, 'preservekeys' => null, 'sortfield' => '', 'sortorder' => '', 'limit' => null, 'limitSelects' => null);
     $options = zbx_array_merge($defOptions, $options);
     if (is_array($options['output'])) {
         unset($sqlParts['select']['items']);
         $dbTable = DB::getSchema('items');
         $sqlParts['select']['itemid'] = 'i.itemid';
         foreach ($options['output'] as $field) {
             if (isset($dbTable['fields'][$field])) {
                 $sqlParts['select'][$field] = 'i.' . $field;
             }
         }
         $options['output'] = API_OUTPUT_CUSTOM;
     }
     // editable + permission check
     if ($userType != USER_TYPE_SUPER_ADMIN && !$options['nopermissions']) {
         $permission = $options['editable'] ? PERM_READ_WRITE : PERM_READ_ONLY;
         $userGroups = getUserGroupsByUserId($userid);
         $sqlParts['where'][] = 'EXISTS (' . 'SELECT NULL' . ' FROM hosts_groups hgg' . ' JOIN rights r' . ' ON r.id=hgg.groupid' . ' AND ' . dbConditionInt('r.groupid', $userGroups) . ' WHERE i.hostid=hgg.hostid' . ' GROUP BY hgg.hostid' . ' HAVING MIN(r.permission)>=' . $permission . ')';
     }
     // itemids
     if (!is_null($options['itemids'])) {
         zbx_value2array($options['itemids']);
         $sqlParts['where']['itemid'] = dbConditionInt('i.itemid', $options['itemids']);
     }
     // templateids
     if (!is_null($options['templateids'])) {
         zbx_value2array($options['templateids']);
         if (!is_null($options['hostids'])) {
             zbx_value2array($options['hostids']);
             $options['hostids'] = array_merge($options['hostids'], $options['templateids']);
         } else {
             $options['hostids'] = $options['templateids'];
         }
     }
     // hostids
     if (!is_null($options['hostids'])) {
         zbx_value2array($options['hostids']);
         if ($options['output'] != API_OUTPUT_EXTEND) {
             $sqlParts['select']['hostid'] = 'i.hostid';
         }
         $sqlParts['where']['hostid'] = dbConditionInt('i.hostid', $options['hostids']);
         if (!is_null($options['groupCount'])) {
             $sqlParts['group']['i'] = 'i.hostid';
         }
     }
     // interfaceids
     if (!is_null($options['interfaceids'])) {
         zbx_value2array($options['interfaceids']);
         if ($options['output'] != API_OUTPUT_EXTEND) {
             $sqlParts['select']['interfaceid'] = 'i.interfaceid';
         }
         $sqlParts['where']['interfaceid'] = dbConditionInt('i.interfaceid', $options['interfaceids']);
         if (!is_null($options['groupCount'])) {
             $sqlParts['group']['i'] = 'i.interfaceid';
         }
     }
     // groupids
     if (!is_null($options['groupids'])) {
         zbx_value2array($options['groupids']);
         if ($options['output'] != API_OUTPUT_SHORTEN) {
             $sqlParts['select']['groupid'] = 'hg.groupid';
         }
         $sqlParts['from']['hosts_groups'] = 'hosts_groups hg';
         $sqlParts['where'][] = dbConditionInt('hg.groupid', $options['groupids']);
         $sqlParts['where'][] = 'hg.hostid=i.hostid';
         if (!is_null($options['groupCount'])) {
             $sqlParts['group']['hg'] = 'hg.groupid';
         }
     }
     // proxyids
     if (!is_null($options['proxyids'])) {
//.........这里部分代码省略.........
开发者ID:quanta-computing,项目名称:debian-packages,代码行数:101,代码来源:CItem.php

示例14: getLinks

 protected function getLinks($options = array())
 {
     $result = array();
     $nodeCheck = false;
     $userType = self::$userData['type'];
     $sortColumns = array('linkid');
     // allowed columns for sorting
     $subselectsAllowedOutputs = array(API_OUTPUT_REFER, API_OUTPUT_EXTEND);
     // allowed output options for [ select_* ] params
     $sqlParts = array('select' => array('sysmaps_links' => 'sl.linkid'), 'from' => array('sysmaps_links' => 'sysmaps_links sl'), 'where' => array(), 'order' => array(), 'limit' => null);
     $defOptions = array('nodeids' => null, 'sysmapids' => null, 'editable' => null, 'nopermissions' => null, 'filter' => null, 'search' => null, 'searchByAny' => null, 'startSearch' => null, 'excludeSearch' => null, 'output' => API_OUTPUT_REFER, 'countOutput' => null, 'preservekeys' => null, 'sortfield' => '', 'sortorder' => '', 'limit' => null);
     $options = zbx_array_merge($defOptions, $options);
     if (is_array($options['output'])) {
         unset($sqlParts['select']['sysmaps_links']);
         $dbTable = DB::getSchema('sysmaps_links');
         $sqlParts['select']['linkid'] = 'sl.linkid';
         foreach ($options['output'] as $key => $field) {
             if (isset($dbTable['fields'][$field])) {
                 $sqlParts['select'][$field] = 'sl.' . $field;
             }
         }
         $options['output'] = API_OUTPUT_CUSTOM;
     }
     // editable + PERMISSION CHECK
     // nodeids
     $nodeids = !is_null($options['nodeids']) ? $options['nodeids'] : get_current_nodeid();
     // linkids
     if (!is_null($options['linkids'])) {
         zbx_value2array($options['linkids']);
         $sqlParts['where']['linkid'] = dbConditionInt('sl.linkid', $options['linkids']);
         if (!$nodeCheck) {
             $nodeCheck = true;
             $sqlParts['where'][] = DBin_node('sl.linkid', $nodeids);
         }
     }
     // sysmapids
     if (!is_null($options['sysmapids'])) {
         zbx_value2array($options['sysmapids']);
         if ($options['output'] != API_OUTPUT_SHORTEN) {
             $sqlParts['select']['sysmapid'] = 'sl.sysmapid';
         }
         $sqlParts['where']['sysmapid'] = dbConditionInt('sl.sysmapid', $options['sysmapids']);
         if (!is_null($options['groupCount'])) {
             $sqlParts['group']['sysmapid'] = 'sl.sysmapid';
         }
         if (!$nodeCheck) {
             $nodeCheck = true;
             $sqlParts['where'][] = DBin_node('sl.sysmapid', $nodeids);
         }
     }
     // node check !!!!!
     // should last, after all ****IDS checks
     if (!$nodeCheck) {
         $nodeCheck = true;
         $sqlParts['where'][] = DBin_node('sl.linkid', $nodeids);
     }
     // search
     if (!is_null($options['search'])) {
         zbx_db_search('sysmaps_links sl', $options, $sqlParts);
     }
     // filter
     if (!is_null($options['filter'])) {
         $this->dbFilter('sysmaps_links sl', $options, $sqlParts);
     }
     // output
     if ($options['output'] == API_OUTPUT_EXTEND) {
         $sqlParts['select']['sysmaps'] = 'sl.*';
     }
     // countOutput
     if (!is_null($options['countOutput'])) {
         $options['sortfield'] = '';
         $sqlParts['select'] = array('count(DISTINCT s.sysmapid) as rowscount');
     }
     // sorting
     zbx_db_sorting($sqlParts, $options, $sortColumns, 'sl');
     // limit
     if (zbx_ctype_digit($options['limit']) && $options['limit']) {
         $sqlParts['limit'] = $options['limit'];
     }
     //-------
     $linkids = array();
     $sqlParts['select'] = array_unique($sqlParts['select']);
     $sqlParts['from'] = array_unique($sqlParts['from']);
     $sqlParts['where'] = array_unique($sqlParts['where']);
     $sqlParts['group'] = array_unique($sqlParts['group']);
     $sqlParts['order'] = array_unique($sqlParts['order']);
     $sqlSelect = '';
     $sqlFrom = '';
     $sqlWhere = '';
     $sqlGroup = '';
     $sqlOrder = '';
     if (!empty($sqlParts['select'])) {
         $sqlSelect .= implode(',', $sqlParts['select']);
     }
     if (!empty($sqlParts['from'])) {
         $sqlFrom .= implode(',', $sqlParts['from']);
     }
     if (!empty($sqlParts['where'])) {
         $sqlWhere .= implode(' AND ', $sqlParts['where']);
     }
//.........这里部分代码省略.........
开发者ID:quanta-computing,项目名称:debian-packages,代码行数:101,代码来源:CMapElement.php

示例15: get

 /**
  * Get Screen data
  *
  * @param array $options
  * @param array $options['nodeids'] Node IDs
  * @param boolean $options['with_items'] only with items
  * @param boolean $options['editable'] only with read-write permission. Ignored for SuperAdmins
  * @param int $options['count'] count Hosts, returned column name is rowscount
  * @param string $options['pattern'] search hosts by pattern in host names
  * @param int $options['limit'] limit selection
  * @param string $options['order'] deprecated parameter (for now)
  * @return array|boolean Host data as array or false if error
  */
 public function get($options = array())
 {
     $result = array();
     $userType = self::$userData['type'];
     // allowed columns for sorting
     $sortColumns = array('screenid', 'name');
     // allowed output options for [ select_* ] params
     $subselectsAllowedOutputs = array(API_OUTPUT_REFER, API_OUTPUT_EXTEND);
     $sqlParts = array('select' => array('screens' => 's.screenid'), 'from' => array('screens' => 'screens s'), 'where' => array('template' => 's.templateid IS NULL'), 'order' => array(), 'group' => array(), 'limit' => null);
     $defOptions = array('nodeids' => null, 'screenids' => null, 'screenitemids' => null, 'editable' => null, 'nopermissions' => null, 'filter' => null, 'search' => null, 'searchByAny' => null, 'startSearch' => null, 'excludeSearch' => null, 'searchWildcardsEnabled' => null, 'output' => API_OUTPUT_REFER, 'selectScreenItems' => null, 'countOutput' => null, 'groupCount' => null, 'preservekeys' => null, 'sortfield' => '', 'sortorder' => '', 'limit' => null);
     $options = zbx_array_merge($defOptions, $options);
     if (is_array($options['output'])) {
         unset($sqlParts['select']['screens']);
         $dbTable = DB::getSchema('screens');
         foreach ($options['output'] as $field) {
             if (isset($dbTable['fields'][$field])) {
                 $sqlParts['select'][$field] = 's.' . $field;
             }
         }
         $options['output'] = API_OUTPUT_CUSTOM;
     }
     // screenids
     if (!is_null($options['screenids'])) {
         zbx_value2array($options['screenids']);
         $sqlParts['where'][] = dbConditionInt('s.screenid', $options['screenids']);
     }
     // screenitemids
     if (!is_null($options['screenitemids'])) {
         zbx_value2array($options['screenitemids']);
         if ($options['output'] != API_OUTPUT_EXTEND) {
             $sqlParts['select']['screenitemid'] = 'si.screenitemid';
         }
         $sqlParts['from']['screens_items'] = 'screens_items si';
         $sqlParts['where']['ssi'] = 'si.screenid=s.screenid';
         $sqlParts['where'][] = dbConditionInt('si.screenitemid', $options['screenitemids']);
     }
     // filter
     if (is_array($options['filter'])) {
         $this->dbFilter('screens s', $options, $sqlParts);
     }
     // search
     if (is_array($options['search'])) {
         zbx_db_search('screens s', $options, $sqlParts);
     }
     // output
     if ($options['output'] == API_OUTPUT_EXTEND) {
         $sqlParts['select']['screens'] = 's.*';
     }
     // countOutput
     if (!is_null($options['countOutput'])) {
         $options['sortfield'] = '';
         $sqlParts['select'] = array('COUNT(DISTINCT s.screenid) AS rowscount');
         // groupCount
         if (!is_null($options['groupCount'])) {
             foreach ($sqlParts['group'] as $key => $fields) {
                 $sqlParts['select'][$key] = $fields;
             }
         }
     }
     // sorting
     zbx_db_sorting($sqlParts, $options, $sortColumns, 's');
     // limit
     if (zbx_ctype_digit($options['limit']) && $options['limit']) {
         $sqlParts['limit'] = $options['limit'];
     }
     $screenids = array();
     $sqlParts = $this->applyQueryNodeOptions($this->tableName(), $this->tableAlias(), $options, $sqlParts);
     $res = DBselect($this->createSelectQueryFromParts($sqlParts), $sqlParts['limit']);
     while ($screen = DBfetch($res)) {
         if (!is_null($options['countOutput'])) {
             if (!is_null($options['groupCount'])) {
                 $result[] = $screen;
             } else {
                 $result = $screen['rowscount'];
             }
         } else {
             $screenids[$screen['screenid']] = $screen['screenid'];
             if ($options['output'] == API_OUTPUT_SHORTEN) {
                 $result[$screen['screenid']] = array('screenid' => $screen['screenid']);
             } else {
                 if (!isset($result[$screen['screenid']])) {
                     $result[$screen['screenid']] = array();
                 }
                 if (!is_null($options['selectScreenItems']) && !isset($result[$screen['screenid']]['screenitems'])) {
                     $result[$screen['screenid']]['screenitems'] = array();
                 }
                 if (isset($screen['screenitemid']) && is_null($options['selectScreenItems'])) {
//.........这里部分代码省略.........
开发者ID:quanta-computing,项目名称:debian-packages,代码行数:101,代码来源:CScreen.php


注:本文中的DB::getSchema方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。