Fire/Sql/Collection.php
private function _getObjectsByFilter(Filter $filterQuery)
    {
        $records = [];
        $props = [];
        $filters = [];
        foreach ($filterQuery->getComparisons() as $comparison) {
            $props[] = $comparison->prop;
            if ($comparison->expression && $comparison->comparison && $comparison->prop) {
                $expression = ($comparison->expression !== 'WHERE') ? $comparison->expression . ' ' : '';
                $prop = is_int($comparison->val) ? 'CAST(' . $comparison->prop . ' AS INT)' : $comparison->prop;
                $compare = $comparison->comparison;
                $value = (!isset($comparison->val) || is_null($comparison->val)) ? 'NULL' : $comparison->val;
                $filters[] = $expression . $prop . ' ' . $compare . ' \'' . $value . '\'';
            }
        }

        $props = array_unique($props);
        $joins = [];
        foreach ($props as $prop)
        {
            $standardFields = [
                '__id',
                '__type',
                '__collection',
                '__origin'
            ];
            if (!in_array($prop, $standardFields)) {
                $asTbl = $this->_generateAlphaToken();
                $joins[] =
                    'JOIN(' .
                        'SELECT id, val AS ' . $prop . ' ' .
                        'FROM ' . $this->_name . '__index ' .
                        'WHERE prop = \'' . $prop . '\'' .
                    ') AS ' . $asTbl . ' ' .
                    'ON A.id = ' . $asTbl . '.id';
            }
        }

        $select = Statement::get(
            'GET_OBJECTS_BY_FILTER',
            [
                '@collection' => $this->_name,
                '@columns' => (count($props) > 0) ? ', ' . implode($props, ', ') : '',
                '@joinColumns' => (count($joins) > 0) ? implode($joins, ' ') . ' ' : '',
                '@type' => $this->_connector->quote($filterQuery->getIndexType()),
                '@filters' => ($filters) ? 'AND (' . implode($filters, ' ') . ') ' : '',
                '@order' => $filterQuery->getOrderBy(),
                '@reverse' => ($filterQuery->getReverse()) ? 'DESC' : 'ASC',
                '@limit' => $filterQuery->getLength(),
                '@offset' => $filterQuery->getOffset()
            ]
        );

        $result = $this->_connector->query($select);
        if ($result) {
            $records = $result->fetchAll();
        }
        return ($records) ? array_map([$this, '_mapObjectIds'], $records) : [];
    }
private function _getObjectsByFilter(Filter $filterQuery)
    {
        $records = [];
        $props = [];
        $filters = [];
        foreach ($filterQuery->getComparisons() as $comparison) {
            $props[] = $comparison->prop;
            if ($comparison->expression && $comparison->comparison && $comparison->prop) {
                $expression = ($comparison->expression !== 'WHERE') ? $comparison->expression . ' ' : '';
                $prop = is_int($comparison->val) ? 'CAST(' . $comparison->prop . ' AS INT)' : $comparison->prop;
                $compare = $comparison->comparison;
                $value = (!isset($comparison->val) || is_null($comparison->val)) ? 'NULL' : $comparison->val;
                $filters[] = $expression . $prop . ' ' . $compare . ' \'' . $value . '\'';
            }
        }

        $props = array_unique($props);
        $joins = [];
        foreach ($props as $prop)
        {
            $standardFields = [
                '__id',
                '__type',
                '__collection',
                '__origin'
            ];
            if (!in_array($prop, $standardFields)) {
                $asTbl = $this->_generateAlphaToken();
                $joins[] =
                    'JOIN(' .
                        'SELECT id, val AS ' . $prop . ' ' .
                        'FROM ' . $this->_name . '__index ' .
                        'WHERE prop = \'' . $prop . '\'' .
                    ') AS ' . $asTbl . ' ' .
                    'ON A.id = ' . $asTbl . '.id';
            }
        }

        $select = Statement::get(
            'GET_OBJECTS_BY_FILTER',
            [
                '@collection' => $this->_name,
                '@columns' => (count($props) > 0) ? ', ' . implode($props, ', ') : '',
                '@joinColumns' => (count($joins) > 0) ? implode($joins, ' ') . ' ' : '',
                '@type' => $this->_connector->quote($filterQuery->getIndexType()),
                '@filters' => ($filters) ? 'AND (' . implode($filters, ' ') . ') ' : '',
                '@order' => $filterQuery->getOrderBy(),
                '@reverse' => ($filterQuery->getReverse()) ? 'DESC' : 'ASC',
                '@limit' => $filterQuery->getLength(),
                '@offset' => $filterQuery->getOffset()
            ]
        );

        $result = $this->_connector->query($select);
        if ($result) {
            $records = $result->fetchAll();
        }
        return ($records) ? array_map([$this, '_mapObjectIds'], $records) : [];
    }
private function _getObjectsByFilter ( Filter $ filterQuery ) { $ records = [ ] ; $ props = [ ] ; $ filters = [ ] ; foreach ( $ filterQuery -> getComparisons ( ) as $ comparison ) { $ props [ ] = $ comparison -> prop ; if ( $ comparison -> expression && $ comparison -> comparison && $ comparison -> prop ) { $ expression = ( $ comparison -> expression !== 'WHERE' ) ? $ comparison -> expression . ' ' : '' ; $ prop = is_int ( $ comparison -> val ) ? 'CAST(' . $ comparison -> prop . ' AS INT)' : $ comparison -> prop ; $ compare = $ comparison -> comparison ; $ value = ( ! isset ( $ comparison -> val ) || is_null ( $ comparison -> val ) ) ? 'NULL' : $ comparison -> val ; $ filters [ ] = $ expression . $ prop . ' ' . $ compare . ' \'' . $ value . '\'' ; } } $ props = array_unique ( $ props ) ; $ joins = [ ] ; foreach ( $ props as $ prop ) { $ standardFields = [ '__id' , '__type' , '__collection' , '__origin' ] ; if ( ! in_array ( $ prop , $ standardFields ) ) { $ asTbl = $ this -> _generateAlphaToken ( ) ; $ joins [ ] = 'JOIN(' . 'SELECT id, val AS ' . $ prop . ' ' . 'FROM ' . $ this -> _name . '__index ' . 'WHERE prop = \'' . $ prop . '\'' . ') AS ' . $ asTbl . ' ' . 'ON A.id = ' . $ asTbl . '.id' ; } } $ select = Statement :: get ( 'GET_OBJECTS_BY_FILTER' , [ '@collection' => $ this -> _name , '@columns' => ( count ( $ props ) > 0 ) ? ', ' . implode ( $ props , ', ' ) : '' , '@joinColumns' => ( count ( $ joins ) > 0 ) ? implode ( $ joins , ' ' ) . ' ' : '' , '@type' => $ this -> _connector -> quote ( $ filterQuery -> getIndexType ( ) ) , '@filters' => ( $ filters ) ? 'AND (' . implode ( $ filters , ' ' ) . ') ' : '' , '@order' => $ filterQuery -> getOrderBy ( ) , '@reverse' => ( $ filterQuery -> getReverse ( ) ) ? 'DESC' : 'ASC' , '@limit' => $ filterQuery -> getLength ( ) , '@offset' => $ filterQuery -> getOffset ( ) ] ) ; $ result = $ this -> _connector -> query ( $ select ) ; if ( $ result ) { $ records = $ result -> fetchAll ( ) ; } return ( $ records ) ? array_map ( [ $ this , '_mapObjectIds' ] , $ records ) : [ ] ; }
Returns a collection of objects that matches a filter.
@param Filter $filterQuery
@return array
Returns a collection of objects that matches a filter .