From 36fa7ed932fcd864577f85af3d781374c586ba08 Mon Sep 17 00:00:00 2001
From: Matthias Adrowski <matthias.adrowski@sgalinski.de>
Date: Wed, 13 Jul 2022 12:07:11 +0200
Subject: [PATCH] [TASK] Add sorting to BE module

---
 .../ViewHelpers/Backend/ControlViewHelper.php | 40 +++++++++++++++++++
 .../TCA/tx_sgjobs_domain_model_company.php    |  8 ----
 .../TCA/tx_sgjobs_domain_model_contact.php    |  8 ----
 .../TCA/tx_sgjobs_domain_model_department.php |  8 ----
 ...x_sgjobs_domain_model_experience_level.php |  8 ----
 .../TCA/tx_sgjobs_domain_model_job.php        |  8 ----
 ...tx_sgjobs_domain_model_job_application.php |  8 ----
 .../Private/Backend/Templates/Index.html      |  4 +-
 8 files changed, 42 insertions(+), 50 deletions(-)

diff --git a/Classes/ViewHelpers/Backend/ControlViewHelper.php b/Classes/ViewHelpers/Backend/ControlViewHelper.php
index 4c3a3ebb..048fd39a 100644
--- a/Classes/ViewHelpers/Backend/ControlViewHelper.php
+++ b/Classes/ViewHelpers/Backend/ControlViewHelper.php
@@ -77,6 +77,46 @@ class ControlViewHelper extends AbstractViewHelper {
 		$languageService = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Localization\LanguageService::class);
 		$languageService->includeLLFile('EXT:backend/Resources/Private/Language/locallang_alt_doc.xlf');
 
+		// DatabaseRecordList has a $prevPrevUid, which might track back a page. We wont do that, 1st+last record are always
+		// not sortable in one direction
+		$uidPrev = false;
+		$uidNext = false;
+		$iterator = $this->arguments['iter'];
+		if (!$iterator['isFirst'] && $iterator['index'] !== 1){
+			$uidPrev = '-'.$this->arguments['allItems'][$iterator['index'] - 2]['uid'];
+		}
+		if ($iterator['index'] === 1){
+			$uidPrev = $row['pid'];
+		}
+		if (!$iterator['isLast']){
+			$uidNext = '-'.$this->arguments['allItems'][$iterator['index'] + 1]['uid'];
+		}
+
+		$newCurrentTableArr = [
+			'prev' => [
+				$row['uid'] => $uidPrev
+			],
+			'next' => [
+				$row['uid'] => $uidNext
+			]
+		];
+		if (!$uidPrev) {
+			$newCurrentTableArr = [
+				'next' => [
+					$row['uid'] => $uidNext
+				]
+			];
+		}
+		if (!$uidNext) {
+			$newCurrentTableArr = [
+				'prev' => [
+					$row['uid'] => $uidPrev
+				]
+			];
+		}
+		$databaseRecordList->id = $row['pid'];
+		$databaseRecordList->currentTable = $newCurrentTableArr;
+
 		return $databaseRecordList->makeControl($table, $row);
 	}
 }
diff --git a/Configuration/TCA/tx_sgjobs_domain_model_company.php b/Configuration/TCA/tx_sgjobs_domain_model_company.php
index 66dc4db0..8c076303 100644
--- a/Configuration/TCA/tx_sgjobs_domain_model_company.php
+++ b/Configuration/TCA/tx_sgjobs_domain_model_company.php
@@ -95,14 +95,6 @@ $columns = [
 				'type' => 'passthrough',
 			],
 		],
-		't3ver_label' => [
-			'label' => 'LLL:EXT:core/Resources/Private/Language/locallang_general.xlf:LGL.versionLabel',
-			'config' => [
-				'type' => 'input',
-				'size' => 30,
-				'max' => 255,
-			]
-		],
 		'pid' => [
 			'exclude' => 0,
 			'label' => 'PID',
diff --git a/Configuration/TCA/tx_sgjobs_domain_model_contact.php b/Configuration/TCA/tx_sgjobs_domain_model_contact.php
index 77067bd9..35c15a11 100644
--- a/Configuration/TCA/tx_sgjobs_domain_model_contact.php
+++ b/Configuration/TCA/tx_sgjobs_domain_model_contact.php
@@ -97,14 +97,6 @@ $columns = [
 				'type' => 'passthrough',
 			],
 		],
-		't3ver_label' => [
-			'label' => 'LLL:EXT:core/Resources/Private/Language/locallang_general.xlf:LGL.versionLabel',
-			'config' => [
-				'type' => 'input',
-				'size' => 30,
-				'max' => 255,
-			]
-		],
 		'pid' => [
 			'exclude' => FALSE,
 			'label' => 'PID',
diff --git a/Configuration/TCA/tx_sgjobs_domain_model_department.php b/Configuration/TCA/tx_sgjobs_domain_model_department.php
index 7590e661..37dec179 100644
--- a/Configuration/TCA/tx_sgjobs_domain_model_department.php
+++ b/Configuration/TCA/tx_sgjobs_domain_model_department.php
@@ -95,14 +95,6 @@ $columns = [
 				'type' => 'passthrough',
 			],
 		],
-		't3ver_label' => [
-			'label' => 'LLL:EXT:core/Resources/Private/Language/locallang_general.xlf:LGL.versionLabel',
-			'config' => [
-				'type' => 'input',
-				'size' => 30,
-				'max' => 255,
-			]
-		],
 		'pid' => [
 			'exclude' => FALSE,
 			'label' => 'PID',
diff --git a/Configuration/TCA/tx_sgjobs_domain_model_experience_level.php b/Configuration/TCA/tx_sgjobs_domain_model_experience_level.php
index 1d03860c..45b7a5dc 100644
--- a/Configuration/TCA/tx_sgjobs_domain_model_experience_level.php
+++ b/Configuration/TCA/tx_sgjobs_domain_model_experience_level.php
@@ -95,14 +95,6 @@ $columns = [
 				'type' => 'passthrough',
 			],
 		],
-		't3ver_label' => [
-			'label' => 'LLL:EXT:core/Resources/Private/Language/locallang_general.xlf:LGL.versionLabel',
-			'config' => [
-				'type' => 'input',
-				'size' => 30,
-				'max' => 255,
-			]
-		],
 		'pid' => [
 			'exclude' => FALSE,
 			'label' => 'PID',
diff --git a/Configuration/TCA/tx_sgjobs_domain_model_job.php b/Configuration/TCA/tx_sgjobs_domain_model_job.php
index 1bc54225..59ee86ed 100644
--- a/Configuration/TCA/tx_sgjobs_domain_model_job.php
+++ b/Configuration/TCA/tx_sgjobs_domain_model_job.php
@@ -127,14 +127,6 @@ $columns = [
 				'renderType' => 'languageVisibility'
 			]
 		],
-		't3ver_label' => [
-			'label' => 'LLL:EXT:core/Resources/Private/Language/locallang_general.xlf:LGL.versionLabel',
-			'config' => [
-				'type' => 'input',
-				'size' => 30,
-				'max' => 255,
-			]
-		],
 		'pid' => [
 			'exclude' => FALSE,
 			'label' => 'PID',
diff --git a/Configuration/TCA/tx_sgjobs_domain_model_job_application.php b/Configuration/TCA/tx_sgjobs_domain_model_job_application.php
index 618b4744..1e70873a 100644
--- a/Configuration/TCA/tx_sgjobs_domain_model_job_application.php
+++ b/Configuration/TCA/tx_sgjobs_domain_model_job_application.php
@@ -97,14 +97,6 @@ $columns = [
 				'type' => 'passthrough',
 			],
 		],
-		't3ver_label' => [
-			'label' => 'LLL:EXT:core/Resources/Private/Language/locallang_general.xlf:LGL.versionLabel',
-			'config' => [
-				'type' => 'input',
-				'size' => 30,
-				'max' => 255,
-			]
-		],
 		'pid' => [
 			'exclude' => FALSE,
 			'label' => 'PID',
diff --git a/Resources/Private/Backend/Templates/Index.html b/Resources/Private/Backend/Templates/Index.html
index 7e54c758..5de8e287 100644
--- a/Resources/Private/Backend/Templates/Index.html
+++ b/Resources/Private/Backend/Templates/Index.html
@@ -39,7 +39,7 @@
 									</tr>
 								</thead>
 								<tbody>
-									<f:for each="{paginator.paginatedItems}" as="job">
+									<f:for each="{paginator.paginatedItems}" as="job" iteration="iter">
 										<tr data-uid="{job.uid}">
 											<td nowrap="nowrap" class="col-icon">
 												<f:format.raw><sg:backend.icon table="tx_sgjobs_domain_model_job" row="{job}" /></f:format.raw>
@@ -50,7 +50,7 @@
 												</be:link.editRecord>
 											</td>
 											<td nowrap="nowrap" class="col-control">
-												<f:format.raw><sg:backend.control table="tx_sgjobs_domain_model_job" row="{job}" /></f:format.raw>
+												<f:format.raw><sg:backend.control table="tx_sgjobs_domain_model_job" row="{job}" allItems="{paginator.paginatedItems}" iter="{iter}" /></f:format.raw>
 											</td>
 										</tr>
 									</f:for>
-- 
GitLab