protected function _sortParameter($sortFields, Subject $subject, $options)
    {
        if (is_string($sortFields)) {
            $sortFields = explode(',', $sortFields);
        }
        $sortFields = array_filter((array)$sortFields);

        $order = [];
        $includes = $this->getConfig('include');
        $repository = $subject->query->getRepository();
        foreach ($sortFields as $sortField) {
            $direction = 'ASC';
            if ($sortField[0] == '-') {
                $direction = 'DESC';
                $sortField = substr($sortField, 1);
            }

            if (strpos($sortField, '.') !== false) {
                list ($include, $field) = explode('.', $sortField);

                if ($include === Inflector::tableize($repository->getAlias())) {
                    $order[$repository->aliasField($field)] = $direction;
                    continue;
                }

                if (!in_array($include, $includes)) {
                    continue;
                }

                $associations = $repository->associations();
                foreach ($associations as $association) {
                    if ($association->getProperty() !== $include) {
                        continue;
                    }
                    $subject->query->contain([
                        $association->getAlias() => [
                            'sort' => [
                                $association->aliasField($field) => $direction,
                            ],
                            'strategy' => 'select',
                        ]
                    ]);
                    $subject->query->leftJoinWith($association->getAlias());

                    $order[$association->aliasField($field)] = $direction;
                }
                continue;
            } else {
                $order[$repository->aliasField($sortField)] = $direction;
            }
        }
        $subject->query->order($order);
    }
protected function _sortParameter($sortFields, Subject $subject, $options)
    {
        if (is_string($sortFields)) {
            $sortFields = explode(',', $sortFields);
        }
        $sortFields = array_filter((array)$sortFields);

        $order = [];
        $includes = $this->getConfig('include');
        $repository = $subject->query->getRepository();
        foreach ($sortFields as $sortField) {
            $direction = 'ASC';
            if ($sortField[0] == '-') {
                $direction = 'DESC';
                $sortField = substr($sortField, 1);
            }

            if (strpos($sortField, '.') !== false) {
                list ($include, $field) = explode('.', $sortField);

                if ($include === Inflector::tableize($repository->getAlias())) {
                    $order[$repository->aliasField($field)] = $direction;
                    continue;
                }

                if (!in_array($include, $includes)) {
                    continue;
                }

                $associations = $repository->associations();
                foreach ($associations as $association) {
                    if ($association->getProperty() !== $include) {
                        continue;
                    }
                    $subject->query->contain([
                        $association->getAlias() => [
                            'sort' => [
                                $association->aliasField($field) => $direction,
                            ],
                            'strategy' => 'select',
                        ]
                    ]);
                    $subject->query->leftJoinWith($association->getAlias());

                    $order[$association->aliasField($field)] = $direction;
                }
                continue;
            } else {
                $order[$repository->aliasField($sortField)] = $direction;
            }
        }
        $subject->query->order($order);
    }
protected function _sortParameter ( $ sortFields , Subject $ subject , $ options ) { if ( is_string ( $ sortFields ) ) { $ sortFields = explode ( ',' , $ sortFields ) ; } $ sortFields = array_filter ( ( array ) $ sortFields ) ; $ order = [ ] ; $ includes = $ this -> getConfig ( 'include' ) ; $ repository = $ subject -> query -> getRepository ( ) ; foreach ( $ sortFields as $ sortField ) { $ direction = 'ASC' ; if ( $ sortField [ 0 ] == '-' ) { $ direction = 'DESC' ; $ sortField = substr ( $ sortField , 1 ) ; } if ( strpos ( $ sortField , '.' ) !== false ) { list ( $ include , $ field ) = explode ( '.' , $ sortField ) ; if ( $ include === Inflector :: tableize ( $ repository -> getAlias ( ) ) ) { $ order [ $ repository -> aliasField ( $ field ) ] = $ direction ; continue ; } if ( ! in_array ( $ include , $ includes ) ) { continue ; } $ associations = $ repository -> associations ( ) ; foreach ( $ associations as $ association ) { if ( $ association -> getProperty ( ) !== $ include ) { continue ; } $ subject -> query -> contain ( [ $ association -> getAlias ( ) => [ 'sort' => [ $ association -> aliasField ( $ field ) => $ direction , ] , 'strategy' => 'select' , ] ] ) ; $ subject -> query -> leftJoinWith ( $ association -> getAlias ( ) ) ; $ order [ $ association -> aliasField ( $ field ) ] = $ direction ; } continue ; } else { $ order [ $ repository -> aliasField ( $ sortField ) ] = $ direction ; } } $ subject -> query -> order ( $ order ) ; }
Add 'sort' capability

@see http://jsonapi.org/format/#fetching-sorting
@param string|array $sortFields Field sort request
@param \Crud\Event\Subject $subject The subject
@param array $options Array of options for includes.
@return void
Add sort capability