<?php

namespace Internetgalerie\IgDatapoolFe\Utility;

use TYPO3\CMS\Extbase\Persistence\QueryInterface;
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' ? QueryInterface::ORDER_ASCENDING : QueryInterface::ORDER_DESCENDING;
                }
            }
        }
        return $orderings;
    }
}
