<?php

namespace Internetgalerie\IgDatapoolFe\Utility;

use TYPO3\CMS\Core\SingletonInterface;
use TYPO3\CMS\Core\Utility\GeneralUtility;

class SearchUtility implements SingletonInterface
{
    public function getOrderings($sortingsFormField)
    {
        $orderings=[];
        //if( $sortingsFormField===null)         $search['sorting']
        if ($sortingsFormField) {
            $sortings=GeneralUtility::trimExplode(',', $sortingsFormField, true);
            foreach ($sortings as $sorting) {
                $ordering=explode(' ', $sorting); // @todo  Komma für mehrerre Attribute erlauben und jeweils nur bei letztem Punkt fuer subattribute (organisation.name asc)
                if (count($ordering)==2) {
                    $orderings[$ordering[0]]=$ordering[1]=='asc' ? \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_ASCENDING : \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_DESCENDING;
                }
            }
        }
        return $orderings;
    }
}
