public static function getOrderByString($orderBy, $tablename)
    {
        if (isset($orderBy) && !empty($orderBy)) {
            $cleanOrderByParts = [];
            $tableColumns = $GLOBALS['TCA'][$tablename]['columns'];
            $orderByParts = GeneralUtility::trimExplode(',', $orderBy);
            foreach ($orderByParts as $part) {
                $subparts = GeneralUtility::trimExplode(' ', $part);
                if (count($subparts) === 1) {
                    if (is_array($tableColumns[$subparts[0]])) {
                        $cleanOrderByParts[] = $subparts[0];
                    }
                } elseif (count($subparts) === 2) {
                    if (is_array($tableColumns[$subparts[0]]) && ($subparts[1] === 'ASC' || $subparts[1] === 'DESC')) {
                        $cleanOrderByParts[] = $subparts[0] . ' ' . $subparts[1];
                    }
                }
            }

            return implode(',', $cleanOrderByParts);
        }

        return '';
    }