FluidTYPO3\Flux\Service\ContentService::getPreviousLocalizedRecordUid PHP Method

getPreviousLocalizedRecordUid() protected method

This is a port from DataHandler::getPreviousLocalizedRecordUid that respects tx_flux_parent and tx_flux_column!
protected getPreviousLocalizedRecordUid ( integer $uid, integer $language, TYPO3\CMS\Core\DataHandling\DataHandler $reference ) : integer
$uid integer Uid of default language record
$language integer Language of localization
$reference TYPO3\CMS\Core\DataHandling\DataHandler
return integer uid of record after which the localized record should be inserted
    protected function getPreviousLocalizedRecordUid($uid, $language, DataHandler $reference)
    {
        $table = 'tt_content';
        $previousLocalizedRecordUid = $uid;
        $sortRow = $GLOBALS['TCA'][$table]['ctrl']['sortby'];
        $select = $sortRow . ',pid,uid,colPos,tx_flux_parent,tx_flux_column';
        // Get the sort value of the default language record
        $row = BackendUtility::getRecord($table, $uid, $select);
        if (is_array($row)) {
            // Find the previous record in default language on the same page
            $where = sprintf('pid=%d AND sys_language_uid=0 AND %s < %d', (int) $row['pid'], $sortRow, (int) $row[$sortRow]);
            // Respect the colPos for content elements
            if ($table === 'tt_content') {
                $where .= sprintf(' AND colPos=%d AND tx_flux_column=\'%s\' AND tx_flux_parent=%d', (int) $row['colPos'], $row['tx_flux_column'], (int) $row['tx_flux_parent']);
            }
            $where .= $reference->deleteClause($table);
            $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery($select, $table, $where, '', $sortRow . ' DESC', '1');
            // If there is an element, find its localized record in specified localization language
            if ($previousRow = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
                $previousLocalizedRecord = BackendUtility::getRecordLocalization($table, $previousRow['uid'], $language);
                if (is_array($previousLocalizedRecord[0])) {
                    $previousLocalizedRecordUid = $previousLocalizedRecord[0]['uid'];
                }
            }
            $GLOBALS['TYPO3_DB']->sql_free_result($res);
        }
        return $previousLocalizedRecordUid;
    }