You are browsing the documentation for iTop 2.7 which is not the current version.

Consider browsing to iTop 3.1 documentation

๐Ÿ”™ Back

DBObjectSet

api

A set of persistent objects

Created against a DBObjectSearch with additional information not relevant for the DBObjectSearch (ie: order, limit, ...) This set could be heterogeneous as long as the objects in the set have a common ancestor class.

Implements

\iDBObjectSetIterator

API synthesis

List of the public API methods. When manipulating DBObjectSet, You can call those methods:

  • __construct() โ€” Create a new set based on a Search definition.
  • Count() โ€” The total number of rows in this set. Independently of the SetLimit used for loading the set and taking intoaccount the rows added in-memory.
  • Fetch() โ€” Fetch an object (with the given class alias) at the current position in the set and move the cursor to the next position.
  • FetchAssoc() โ€” Fetch the whole row of objects (if several classes have been specified in the query) and move the cursor to the next position
  • OptimizeColumnLoad() โ€” Specify the subset of attributes to loadthis subset is specified for each class of objects,this has to be done before the actual fetch.
  • Rewind() โ€” Position the cursor (for iterating in the set) to the first position (equivalent to Seek(0))
  • ToArray() โ€” Fetch all as array of DBObject
  • ToArrayOfValues() โ€” Fetch all as a structured array

Public methods

__construct

api public

Create a new set based on a Search definition.
public __construct($oFilter, $aOrderBy = array(), $aArgs = array(), $aExtendedDataSpec = null, $iLimitCount, $iLimitStart, $bSort = true)

Parameters

types name default description
\DBSearch $oFilter The search filter defining the objects which are part of the set (multiple columns/objects per row are supported)
array $aOrderBy array() Array of '[<classalias>.]attcode' โ‡’ bAscending (true for ASC, false, for DESC) Example : array('name' โ‡’ true, 'id' โ‡’ false)
array $aArgs array() Values to substitute for the search/query parameters (if any). Format: param_name โ‡’ value
array $aExtendedDataSpec null
integer $iLimitCount 0 Maximum number of rows to load (i.e. equivalent to MySQL's LIMIT start, count)
integer $iLimitStart 0 Index of the first row to load (i.e. equivalent to MySQL's LIMIT start, count)
boolean $bSort true if false no order by is done

Count

api public

The total number of rows in this set. Independently of the SetLimit used for loading the set and taking intoaccount the rows added in-memory.

May actually perform the SQL query SELECT COUNT... if the set was not previously loaded, or loaded with a SetLimit

public Count()

Parameters

none

Returns

integer The total number of rows for this set.

Throws

  • \CoreException
  • \MissingQueryArgument
  • \MySQLException
  • \MySQLHasGoneAwayException

Fetch

api public

Fetch an object (with the given class alias) at the current position in the set and move the cursor to the next position.
public Fetch($sRequestedClassAlias = '')

Parameters

types name default description
string $sRequestedClassAlias '' The class alias to fetch (defaults to the first selected class)

Returns

\DBObject The fetched object or null when at the end

Throws

  • \CoreException
  • \CoreUnexpectedValue
  • \MySQLException

FetchAssoc

api public

Fetch the whole row of objects (if several classes have been specified in the query) and move the cursor to the next position
public FetchAssoc()

Parameters

none

Returns

array An associative with the format 'classAlias' => $oObj representing the current row of the set. Returns null when at the end.

Throws

  • \CoreException
  • \CoreUnexpectedValue
  • \MySQLException

OptimizeColumnLoad

api public

Specify the subset of attributes to loadthis subset is specified for each class of objects,this has to be done before the actual fetch.
public OptimizeColumnLoad($aAttToLoad)

Parameters

types name default description
array $aAttToLoad Format: alias โ‡’ array of attribute_codes

Throws

  • \Exception
  • \CoreException

Rewind

api public

Position the cursor (for iterating in the set) to the first position (equivalent to Seek(0))
public Rewind()

Parameters

none

Throws

\Exception

ToArray

api public

Fetch all as array of DBObject

Note: After calling this method, the set cursor will be at the end of the set. You might want to rewind it.

public ToArray($bWithId = true)

Parameters

types name default description
boolean $bWithId true

Returns

array<mixed,\DBObject>

Throws

  • \Exception
  • \CoreException
  • \CoreUnexpectedValue
  • \MySQLException

ToArrayOfValues

api public

Fetch all as a structured array

Unlike ToArray, ToArrayOfValues return the objects as an array. Only the scalar values will be presents (see AttributeDefinition::IsScalar())

public ToArrayOfValues()

Parameters

none

Returns

array<mixed,array>

Throws

  • \Exception
  • \CoreException
  • \CoreUnexpectedValue
  • \MySQLException

๐Ÿ”™ Back

2_7_0/customization/api/objects-manipulation/dbobjectset.txt ยท Last modified: 2020/04/15 15:23 (external edit)
Back to top
Contact us