src/Select.php
public function find($category, $attribute, $value) {
        $cmdbObjects = new CMDBObjects($this->api);

        $limit = 100;
        $offset = 0;

        $objectIDs = [];

        while (true) {
            $objects = $cmdbObjects->read([], $limit, $offset);

            $count = count($objects);

            if ($count === 0) {
                break;
            }

            foreach ($objects as $object) {
                $objectIDs[] = (int)$object['id'];
            }

            unset($objects);

            $cmdbCategory = new CMDBCategory($this->api);

            $result = $cmdbCategory->batchRead(
                $objectIDs,
                [$category]
            );

            $objectIDs = [];

            foreach ($result as $categoryEntries) {
                foreach ($categoryEntries as $categoryEntry) {
                    if (!array_key_exists($attribute, $categoryEntry)) {
                        continue;
                    }

                    $found = false;

                    if (is_array($categoryEntry[$attribute]) &&
                        array_key_exists('ref_title', $categoryEntry[$attribute]) &&
                        $categoryEntry[$attribute]['ref_title'] === $value
                    ) {
                        $found = true;
                    } elseif (is_array($categoryEntry[$attribute]) &&
                        array_key_exists('title', $categoryEntry[$attribute]) &&
                        $categoryEntry[$attribute]['title'] === $value
                    ) {
                        $found = true;
                    } elseif (is_numeric($categoryEntry[$attribute]) &&
                        is_int($value) &&
                        (int)$categoryEntry[$attribute] === $value
                    ) {
                        $found = true;
                    } elseif (is_string($categoryEntry[$attribute]) &&
                        is_string($value) &&
                        $categoryEntry[$attribute] === $value
                    ) {
                        $found = true;
                    }

                    if ($found === false) {
                        continue;
                    }

                    if (!array_key_exists('objID', $categoryEntry)) {
                        throw new RuntimeException('Found attribute for unknown object');
                    }

                    $objectIDs[] = (int)$categoryEntry['objID'];
                }
            }

            if ($count < $limit) {
                break;
            }

            $offset += $limit;
        }

        return $objectIDs;
    }
public function find($category, $attribute, $value) {
        $cmdbObjects = new CMDBObjects($this->api);

        $limit = 100;
        $offset = 0;

        $objectIDs = [];

        while (true) {
            $objects = $cmdbObjects->read([], $limit, $offset);

            $count = count($objects);

            if ($count === 0) {
                break;
            }

            foreach ($objects as $object) {
                $objectIDs[] = (int)$object['id'];
            }

            unset($objects);

            $cmdbCategory = new CMDBCategory($this->api);

            $result = $cmdbCategory->batchRead(
                $objectIDs,
                [$category]
            );

            $objectIDs = [];

            foreach ($result as $categoryEntries) {
                foreach ($categoryEntries as $categoryEntry) {
                    if (!array_key_exists($attribute, $categoryEntry)) {
                        continue;
                    }

                    $found = false;

                    if (is_array($categoryEntry[$attribute]) &&
                        array_key_exists('ref_title', $categoryEntry[$attribute]) &&
                        $categoryEntry[$attribute]['ref_title'] === $value
                    ) {
                        $found = true;
                    } elseif (is_array($categoryEntry[$attribute]) &&
                        array_key_exists('title', $categoryEntry[$attribute]) &&
                        $categoryEntry[$attribute]['title'] === $value
                    ) {
                        $found = true;
                    } elseif (is_numeric($categoryEntry[$attribute]) &&
                        is_int($value) &&
                        (int)$categoryEntry[$attribute] === $value
                    ) {
                        $found = true;
                    } elseif (is_string($categoryEntry[$attribute]) &&
                        is_string($value) &&
                        $categoryEntry[$attribute] === $value
                    ) {
                        $found = true;
                    }

                    if ($found === false) {
                        continue;
                    }

                    if (!array_key_exists('objID', $categoryEntry)) {
                        throw new RuntimeException('Found attribute for unknown object');
                    }

                    $objectIDs[] = (int)$categoryEntry['objID'];
                }
            }

            if ($count < $limit) {
                break;
            }

            $offset += $limit;
        }

        return $objectIDs;
    }
public function find ( $ category , $ attribute , $ value ) { $ cmdbObjects = new CMDBObjects ( $ this -> api ) ; $ limit = 100 ; $ offset = 0 ; $ objectIDs = [ ] ; while ( true ) { $ objects = $ cmdbObjects -> read ( [ ] , $ limit , $ offset ) ; $ count = count ( $ objects ) ; if ( $ count === 0 ) { break ; } foreach ( $ objects as $ object ) { $ objectIDs [ ] = ( int ) $ object [ 'id' ] ; } unset ( $ objects ) ; $ cmdbCategory = new CMDBCategory ( $ this -> api ) ; $ result = $ cmdbCategory -> batchRead ( $ objectIDs , [ $ category ] ) ; $ objectIDs = [ ] ; foreach ( $ result as $ categoryEntries ) { foreach ( $ categoryEntries as $ categoryEntry ) { if ( ! array_key_exists ( $ attribute , $ categoryEntry ) ) { continue ; } $ found = false ; if ( is_array ( $ categoryEntry [ $ attribute ] ) && array_key_exists ( 'ref_title' , $ categoryEntry [ $ attribute ] ) && $ categoryEntry [ $ attribute ] [ 'ref_title' ] === $ value ) { $ found = true ; } elseif ( is_array ( $ categoryEntry [ $ attribute ] ) && array_key_exists ( 'title' , $ categoryEntry [ $ attribute ] ) && $ categoryEntry [ $ attribute ] [ 'title' ] === $ value ) { $ found = true ; } elseif ( is_numeric ( $ categoryEntry [ $ attribute ] ) && is_int ( $ value ) && ( int ) $ categoryEntry [ $ attribute ] === $ value ) { $ found = true ; } elseif ( is_string ( $ categoryEntry [ $ attribute ] ) && is_string ( $ value ) && $ categoryEntry [ $ attribute ] === $ value ) { $ found = true ; } if ( $ found === false ) { continue ; } if ( ! array_key_exists ( 'objID' , $ categoryEntry ) ) { throw new RuntimeException ( 'Found attribute for unknown object' ) ; } $ objectIDs [ ] = ( int ) $ categoryEntry [ 'objID' ] ; } } if ( $ count < $ limit ) { break ; } $ offset += $ limit ; } return $ objectIDs ; }
Find objects by attribute

@param string $category
@param string $attribute
@param mixed $value

@return array List of object identifiers as integers

@throws Exception on error
Find objects by attribute