PartKeepr\DoctrineReflectionBundle\Filter\AdvancedSearchFilter::extractJSONSorters PHP Method

extractJSONSorters() private method

Extracts the sorters from the JSON object.
private extractJSONSorters ( $data ) : Sorter
$data
return Sorter A Sorter object
    private function extractJSONSorters($data)
    {
        $sorter = new Sorter();
        if ($data->property) {
            if (strpos($data->property, '.') !== false) {
                $associations = explode('.', $data->property);
                $property = array_pop($associations);
                $sorter->setAssociation(implode('.', $associations));
                $sorter->setProperty($property);
            } else {
                $sorter->setAssociation(null);
                $sorter->setProperty($data->property);
            }
        } else {
            throw new \Exception('You need to set the filter property');
        }
        if ($data->direction) {
            switch (strtoupper($data->direction)) {
                case 'DESC':
                    $sorter->setDirection("DESC");
                    break;
                case 'ASC':
                default:
                    $sorter->setDirection("ASC");
                    break;
            }
        } else {
            $sorter->setDirection("ASC");
        }
        return $sorter;
    }