Bluz\Crud\Table::readSet PHP Method

readSet() public method

Get set of records
public readSet ( integer $offset, integer $limit = 10, array $params = [], integer &$total = null ) : array | integer | mixed
$offset integer
$limit integer
$params array
$total integer
return array | integer | mixed
    public function readSet($offset = 0, $limit = 10, $params = [], &$total = null)
    {
        $select = $this->getTable()->select();
        // switch statement for DB type
        $type = Proxy\Db::getOption('connect', 'type');
        switch ($type) {
            case 'mysql':
                $selectPart = $select->getQueryPart('select');
                $selectPart = 'SQL_CALC_FOUND_ROWS ' . current($selectPart);
                $select->select($selectPart);
                $totalSQL = 'SELECT FOUND_ROWS()';
                break;
            case 'pgsql':
            default:
                $selectTotal = clone $select;
                $selectTotal->select('COUNT(*)');
                $totalSQL = $selectTotal->getSql();
                break;
        }
        $select->setLimit($limit);
        $select->setOffset($offset);
        // run queries
        // use transaction to avoid errors
        Proxy\Db::transaction(function () use(&$result, &$total, $select, $totalSQL) {
            $result = $select->execute();
            if (!is_null($total)) {
                $total = Proxy\Db::fetchOne($totalSQL);
            }
        });
        return $result;
    }