From c0edefb182e588d328238b1020d6b047f44ab51d Mon Sep 17 00:00:00 2001
From: Torsten Oppermann <torsten@sgalinski.de>
Date: Fri, 28 Jul 2017 10:58:40 +0200
Subject: [PATCH] [TASK] Rendering the news

---
 Classes/Domain/Repository/NewsRepository.php  |  7 ++--
 Classes/Service/Backend/Utility.php           |  2 +-
 .../Private/Templates/Backend/Index.html      | 39 +++++++++++++++++++
 3 files changed, 44 insertions(+), 4 deletions(-)

diff --git a/Classes/Domain/Repository/NewsRepository.php b/Classes/Domain/Repository/NewsRepository.php
index 393250b..a8119d9 100644
--- a/Classes/Domain/Repository/NewsRepository.php
+++ b/Classes/Domain/Repository/NewsRepository.php
@@ -43,11 +43,12 @@ class NewsRepository extends AbstractRepository {
 	 * @param int $offset
 	 * @param string $sortBy date or positionInTree
 	 * @param array $tagIds NULL, if the tag filter isn't applied, otherwise an array with the tag uids.
-	 * @return QueryResultInterface
+	 * @param boolean $raw execute raw parameter
+	 * @return QueryResultInterface | array
 	 * @throws \TYPO3\CMS\Extbase\Persistence\Exception\InvalidQueryException
 	 */
 	public function findAllSortedNewsByCategories(
-		array $categoryIds = NULL, $limit = 0, $offset = 0, $sortBy = 'date', array $tagIds = NULL
+		array $categoryIds = NULL, $limit = 0, $offset = 0, $sortBy = 'date', array $tagIds = NULL, $raw = FALSE
 	) {
 		$query = $this->createQuery();
 
@@ -99,7 +100,7 @@ class NewsRepository extends AbstractRepository {
 			);
 		}
 
-		return $query->execute();
+		return $query->execute($raw);
 	}
 
 	/**
diff --git a/Classes/Service/Backend/Utility.php b/Classes/Service/Backend/Utility.php
index 9dc8b6a..c5adcef 100644
--- a/Classes/Service/Backend/Utility.php
+++ b/Classes/Service/Backend/Utility.php
@@ -140,6 +140,6 @@ class Utility {
 		$objectManager = GeneralUtility::makeInstance(ObjectManager::class);
 		/** @var NewsRepository $newsRepository */
 		$newsRepository = $objectManager->get(NewsRepository::class);
-		return $newsRepository->findAllSortedNewsByCategories($categories)->toArray();
+		return $newsRepository->findAllSortedNewsByCategories($categories, 0, 0, 'date', NULL, $raw = TRUE);
 	}
 }
diff --git a/Resources/Private/Templates/Backend/Index.html b/Resources/Private/Templates/Backend/Index.html
index 208d379..00f2f02 100644
--- a/Resources/Private/Templates/Backend/Index.html
+++ b/Resources/Private/Templates/Backend/Index.html
@@ -12,4 +12,43 @@
 		<f:translate key="backend.message" />
 	</p>
 
+	<f:if condition="{news}">
+		<div class="panel panel-default recordlist">
+			<div class="table-fit">
+				<table data-table="pages" class="table table-striped table-hover">
+					<sg:backend.widget.paginate objects="{news}" as="paginatedNews" configuration="{insertAbove: 1, itemsPerPage: 20}">
+						<tbody>
+							<f:for each="{paginatedNews}" as="singleNews">
+								{sg:backend.editOnClick(table: 'pages', uid: singleNews.uid) -> sg:set(name: 'editOnClick')}
+								<tr data-uid="{singleNews.uid}">
+									<td nowrap="nowrap" class="col-icon">
+										<f:format.raw>
+											<sg:backend.icon table="pages" row="{singleNews}" />
+										</f:format.raw>
+									</td>
+									<td nowrap="nowrap">
+										<a href="#" onclick="{editOnClick}">
+												<span>
+													<f:if condition="{singleNews.title}">
+														<f:then>
+															{singleNews.title}
+														</f:then>
+													</f:if>
+												</span>
+										</a>
+									</td>
+									<td nowrap="nowrap" class="col-control">
+										<f:format.raw>
+											<sg:backend.control table="tx_sgroutes_domain_model_page" row="{singleNews}" />
+										</f:format.raw>
+									</td>
+								</tr>
+							</f:for>
+						</tbody>
+					</sg:backend.widget.paginate>
+				</table>
+			</div>
+		</div>
+	</f:if>
+
 </f:section>
-- 
GitLab