protected function _fieldSetsParameter($fieldSets, Subject $subject, $options)
    {
        // could be null for e.g. using integration tests
        if ($fieldSets === null) {
             return;
        }

        // format $fieldSets to array acceptable by listener config()
        $fieldSets = array_map(function ($val) {
            return explode(',', $val);
        }, $fieldSets);

        $repository = $subject->query->getRepository();
        $associations = $repository->associations();

        $nodeName = Inflector::tableize($repository->getAlias());
        if (empty($fieldSets[$nodeName])) {
            $selectFields = [];
        } else {
            $selectFields = [$repository->aliasField($repository->getPrimaryKey())];
        }
        $columns = $repository->getSchema()->columns();
        $contains = [];
        foreach ($fieldSets as $include => $fields) {
            if ($include === $nodeName) {
                $aliasFields = array_map(function ($val) use ($repository, $columns) {
                    if (!in_array($val, $columns)) {
                        return null;
                    }

                    return $repository->aliasField($val);
                }, $fields);
                $selectFields = array_merge($selectFields, array_filter($aliasFields));
            }

            $association = $associations->get($include);
            if (!empty($association)) {
                $contains[$association->getAlias()] = [
                    'fields' => $fields,
                ];
            }
        }

        $subject->query->select($selectFields);
        if (!empty($contains)) {
            $subject->query->contain($contains);
        }

        $this->setConfig('fieldSets', $fieldSets);
    }
protected function _fieldSetsParameter($fieldSets, Subject $subject, $options)
    {
        // could be null for e.g. using integration tests
        if ($fieldSets === null) {
             return;
        }

        // format $fieldSets to array acceptable by listener config()
        $fieldSets = array_map(function ($val) {
            return explode(',', $val);
        }, $fieldSets);

        $repository = $subject->query->getRepository();
        $associations = $repository->associations();

        $nodeName = Inflector::tableize($repository->getAlias());
        if (empty($fieldSets[$nodeName])) {
            $selectFields = [];
        } else {
            $selectFields = [$repository->aliasField($repository->getPrimaryKey())];
        }
        $columns = $repository->getSchema()->columns();
        $contains = [];
        foreach ($fieldSets as $include => $fields) {
            if ($include === $nodeName) {
                $aliasFields = array_map(function ($val) use ($repository, $columns) {
                    if (!in_array($val, $columns)) {
                        return null;
                    }

                    return $repository->aliasField($val);
                }, $fields);
                $selectFields = array_merge($selectFields, array_filter($aliasFields));
            }

            $association = $associations->get($include);
            if (!empty($association)) {
                $contains[$association->getAlias()] = [
                    'fields' => $fields,
                ];
            }
        }

        $subject->query->select($selectFields);
        if (!empty($contains)) {
            $subject->query->contain($contains);
        }

        $this->setConfig('fieldSets', $fieldSets);
    }
protected function _fieldSetsParameter ( $ fieldSets , Subject $ subject , $ options ) { // could be null for e.g. using integration tests if ( $ fieldSets === null ) { return ; } // format $fieldSets to array acceptable by listener config() $ fieldSets = array_map ( function ( $ val ) { return explode ( ',' , $ val ) ; } , $ fieldSets ) ; $ repository = $ subject -> query -> getRepository ( ) ; $ associations = $ repository -> associations ( ) ; $ nodeName = Inflector :: tableize ( $ repository -> getAlias ( ) ) ; if ( empty ( $ fieldSets [ $ nodeName ] ) ) { $ selectFields = [ ] ; } else { $ selectFields = [ $ repository -> aliasField ( $ repository -> getPrimaryKey ( ) ) ] ; } $ columns = $ repository -> getSchema ( ) -> columns ( ) ; $ contains = [ ] ; foreach ( $ fieldSets as $ include => $ fields ) { if ( $ include === $ nodeName ) { $ aliasFields = array_map ( function ( $ val ) use ( $ repository , $ columns ) { if ( ! in_array ( $ val , $ columns ) ) { return null ; } return $ repository -> aliasField ( $ val ) ; } , $ fields ) ; $ selectFields = array_merge ( $ selectFields , array_filter ( $ aliasFields ) ) ; } $ association = $ associations -> get ( $ include ) ; if ( ! empty ( $ association ) ) { $ contains [ $ association -> getAlias ( ) ] = [ 'fields' => $ fields , ] ; } } $ subject -> query -> select ( $ selectFields ) ; if ( ! empty ( $ contains ) ) { $ subject -> query -> contain ( $ contains ) ; } $ this -> setConfig ( 'fieldSets' , $ fieldSets ) ; }
Parses out fields query parameter and apply it to the query

@param string|array|null $fieldSets The query data
@param \Crud\Event\Subject $subject The subject
@param array $options Array of options for includes.
@return void
Parses out fields query parameter and apply it to the query