From 9f2b5f173ca49c3552484d2c58c288f8ae69115f Mon Sep 17 00:00:00 2001 From: Kevin Ditscheid <kevin.ditscheid@sgalinski.de> Date: Thu, 13 Aug 2020 14:48:26 +0200 Subject: [PATCH] [TASK] Remove BS code from the backend module --- Classes/Domain/Repository/JobRepository.php | 82 ++++++----------- .../Backend/EditLinkViewHelper.php | 66 -------------- .../Backend/EditOnClickViewHelper.php | 58 ------------ .../ViewHelpers/Backend/IconViewHelper.php | 75 ---------------- .../Widget/Controller/PaginateController.php | 90 ------------------- .../Backend/Widget/PaginateViewHelper.php | 81 ----------------- .../Private/Backend/Partials/CreateJob.html | 17 ++-- .../Private/Backend/Partials/Filter.html | 6 +- .../Private/Backend/Partials/JobList.html | 22 ++--- 9 files changed, 48 insertions(+), 449 deletions(-) delete mode 100644 Classes/ViewHelpers/Backend/EditLinkViewHelper.php delete mode 100644 Classes/ViewHelpers/Backend/EditOnClickViewHelper.php delete mode 100644 Classes/ViewHelpers/Backend/IconViewHelper.php delete mode 100644 Classes/ViewHelpers/Backend/Widget/Controller/PaginateController.php delete mode 100644 Classes/ViewHelpers/Backend/Widget/PaginateViewHelper.php diff --git a/Classes/Domain/Repository/JobRepository.php b/Classes/Domain/Repository/JobRepository.php index a6ccc660..dd60eafc 100644 --- a/Classes/Domain/Repository/JobRepository.php +++ b/Classes/Domain/Repository/JobRepository.php @@ -26,10 +26,9 @@ namespace SGalinski\SgJobs\Domain\Repository; * This copyright notice MUST APPEAR in all copies of the script! ***************************************************************/ -use Doctrine\DBAL\Connection; -use TYPO3\CMS\Core\Database\ConnectionPool; -use TYPO3\CMS\Core\Database\Query\Restriction\DeletedRestriction; use TYPO3\CMS\Core\Utility\GeneralUtility; +use TYPO3\CMS\Extbase\Object\ObjectManagerInterface; +use TYPO3\CMS\Extbase\Persistence\Generic\Typo3QuerySettings; use TYPO3\CMS\Extbase\Persistence\QueryInterface; use TYPO3\CMS\Extbase\Persistence\QueryResultInterface; use TYPO3\CMS\Extbase\Persistence\QueryResultInterface as ExtbaseQueryResultInterface; @@ -48,11 +47,9 @@ class JobRepository extends Repository { */ protected $allowManualSorting = FALSE; - /** - * initializes the object - */ - public function initializeObject(): void { - $querySettings = $this->createQuery()->getQuerySettings(); + public function __construct(ObjectManagerInterface $objectManager) { + parent::__construct($objectManager); + $querySettings = GeneralUtility::makeInstance(Typo3QuerySettings::class); $querySettings->setRespectStoragePage(TRUE); $querySettings->setLanguageUid($GLOBALS['TSFE']->sys_language_uid); $this->setDefaultQuerySettings($querySettings); @@ -83,67 +80,42 @@ class JobRepository extends Repository { * @throws \InvalidArgumentException */ public function findBackendJobs($recordPageId, array $filters = [], $limit = 0, $offset = 0) { - // get all company ids - $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable( - 'tx_sgjobs_domain_model_company' + $query = $this->createQuery(); + $query->setOrderings( + [ + 'sorting' => QueryInterface::ORDER_ASCENDING, + ] ); - - /** @var DeletedRestriction $type */ - $deletedRestrictionObject = GeneralUtility::makeInstance(DeletedRestriction::class); - $queryBuilder - ->getRestrictions() - ->removeAll() - ->add($deletedRestrictionObject); - - $statement = $queryBuilder->select('a.uid') - ->from('tx_sgjobs_domain_model_job', 'a') - ->join( - 'a', 'tx_sgjobs_domain_model_company', 'b' - , $queryBuilder->expr()->eq('a.company', 'b.uid') - ); - + $query->getQuerySettings()->setStoragePageIds([$recordPageId]); + $query->getQuerySettings()->setIgnoreEnableFields(TRUE); + $constraints = []; if (\is_array($filters['locations'])) { - $quotedLocationNames = $queryBuilder->createNamedParameter( - $filters['locations'], Connection::PARAM_STR_ARRAY - ); - $statement->andWhere($queryBuilder->expr()->in('b.city', $quotedLocationNames)); + $constraints[] = $query->in('company.city', $filters['locations']); } elseif ($filters['locations'] !== '' && $filters['locations'] !== NULL) { - $statement->andWhere( - $queryBuilder->expr()->eq( - 'b.city', $queryBuilder->createNamedParameter($filters['locations']) - ) - ); + $constraints[] = $query->equals('company.city', $filters['locations']); } if ($filters['search'] !== '' && $filters['search'] !== NULL) { - $statement->andWhere( - $queryBuilder->expr()->like( - 'a.title', $queryBuilder->createNamedParameter('%' . $filters['search'] . '%') - ) - ); + $constraints[] = $query->like('title', '%' . $filters['search'] . '%'); } - $statement->andWhere( - $queryBuilder->expr()->eq( - 'b.pid', $queryBuilder->createNamedParameter($recordPageId) - ) - ); + if ($limit > 0) { + $query->setLimit($limit); + } - $companies = $statement->execute()->fetchAll(); + if ($offset > 0) { + $query->setOffset($offset); + } - $result = []; - $result[0] = ''; - foreach ($companies as $company) { - $result[$company['uid']] = $company['uid']; + if (\count($constraints) > 1) { + return $query->matching($query->logicalAnd($constraints))->execute(); } - // when filters are set, but there are no companies found, return an empty result - if (empty(!$filters) && empty($companies)) { - return $companies; + if(\count($constraints) > 0) { + return $query->matching($constraints[0])->execute(); } - // return the filtered jobs - return $this->findByJobIds($result, $limit, $offset); + return $query->execute(); } /** diff --git a/Classes/ViewHelpers/Backend/EditLinkViewHelper.php b/Classes/ViewHelpers/Backend/EditLinkViewHelper.php deleted file mode 100644 index d7af5c7e..00000000 --- a/Classes/ViewHelpers/Backend/EditLinkViewHelper.php +++ /dev/null @@ -1,66 +0,0 @@ -<?php - -namespace SGalinski\SgJobs\ViewHelpers\Backend; - -/*************************************************************** - * Copyright notice - * - * (c) sgalinski Internet Services (https://www.sgalinski.de) - * - * All rights reserved - * - * This script is part of the TYPO3 project. The TYPO3 project is - * free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * The GNU General Public License can be found at - * http://www.gnu.org/copyleft/gpl.html. - * - * This script is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * This copyright notice MUST APPEAR in all copies of the script! - ***************************************************************/ - -use TYPO3\CMS\Backend\Routing\UriBuilder; -use TYPO3\CMS\Core\Utility\GeneralUtility; -use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper; - -/** - * Class EditOnClickViewHelper - **/ -class EditLinkViewHelper extends AbstractViewHelper { - - /** - * Register the ViewHelpers arguments - */ - public function initializeArguments() { - parent::initializeArguments(); - $this->registerArgument('table', 'string', 'The table of the edit link', TRUE); - $this->registerArgument('uid', 'int', 'The uid of the record', TRUE); - $this->registerArgument('new', 'bool', 'Wether the record is new or not', FALSE, FALSE); - } - - /** - * Renders the onclick script for editing a record - * - * @return string - * @throws \TYPO3\CMS\Backend\Routing\Exception\RouteNotFoundException - */ - public function render(): string { - $uriBuilder = GeneralUtility::makeInstance(UriBuilder::class); - return $uriBuilder->buildUriFromRoute( - 'record_edit', [ - 'edit' => [ - $this->arguments['table'] => [ - $this->arguments['uid'] => $this->arguments['new'] ? 'new' : 'edit' - ] - ] - ] - ); - } -} diff --git a/Classes/ViewHelpers/Backend/EditOnClickViewHelper.php b/Classes/ViewHelpers/Backend/EditOnClickViewHelper.php deleted file mode 100644 index 564bd421..00000000 --- a/Classes/ViewHelpers/Backend/EditOnClickViewHelper.php +++ /dev/null @@ -1,58 +0,0 @@ -<?php - -namespace SGalinski\SgJobs\ViewHelpers\Backend; - -/*************************************************************** - * Copyright notice - * - * (c) sgalinski Internet Services (https://www.sgalinski.de) - * - * All rights reserved - * - * This script is part of the TYPO3 project. The TYPO3 project is - * free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * The GNU General Public License can be found at - * http://www.gnu.org/copyleft/gpl.html. - * - * This script is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * This copyright notice MUST APPEAR in all copies of the script! - ***************************************************************/ - -use TYPO3\CMS\Backend\Utility\BackendUtility; -use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper; - -/** - * Class EditLink - **/ -class EditOnClickViewHelper extends AbstractViewHelper { - - /** - * Register the ViewHelper arguments - */ - public function initializeArguments() { - parent::initializeArguments(); - $this->registerArgument('table', 'string', 'The table for the clickenlarge link', TRUE); - $this->registerArgument('uid', 'int', 'The uid of the record to clickenlarge', TRUE); - $this->registerArgument('new', 'bool', 'Open a new record in the popup', FALSE, FALSE); - } - - /** - * Renders the onclick script for editing a record - * - * @return string - */ - public function render(): string { - return BackendUtility::editOnClick( - '&edit[' . $this->arguments['table'] . '][' . $this->arguments['uid'] . ']=' . ($this->arguments['new'] ? 'new' : 'edit'), - '', -1 - ); - } -} diff --git a/Classes/ViewHelpers/Backend/IconViewHelper.php b/Classes/ViewHelpers/Backend/IconViewHelper.php deleted file mode 100644 index 7345ae2b..00000000 --- a/Classes/ViewHelpers/Backend/IconViewHelper.php +++ /dev/null @@ -1,75 +0,0 @@ -<?php - -namespace SGalinski\SgJobs\ViewHelpers\Backend; - -/*************************************************************** - * Copyright notice - * - * (c) sgalinski Internet Services (https://www.sgalinski.de) - * - * All rights reserved - * - * This script is part of the TYPO3 project. The TYPO3 project is - * free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * The GNU General Public License can be found at - * http://www.gnu.org/copyleft/gpl.html. - * - * This script is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * This copyright notice MUST APPEAR in all copies of the script! - ***************************************************************/ - -use TYPO3\CMS\Backend\Utility\BackendUtility; -use TYPO3\CMS\Core\Imaging\Icon; -use TYPO3\CMS\Core\Imaging\IconFactory; -use TYPO3\CMS\Core\Utility\GeneralUtility; -use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper; - -/** - * Class EditLink - **/ -class IconViewHelper extends AbstractViewHelper { - - /** - * Register the ViewHelper arguments - */ - public function initializeArguments() { - parent::initializeArguments(); - $this->registerArgument('table', 'string', 'The table for the icon', TRUE); - $this->registerArgument('row', 'mixed', 'The row of the record', TRUE); - $this->registerArgument('clickMenu', 'bool', 'Render a clickMenu around the icon', FALSE, TRUE); - } - - /** - * Renders the icon for the specified record - * - * @return string - * @throws \InvalidArgumentException - */ - public function render(): string { - $row = $this->arguments['row']; - $table = $this->arguments['table']; - $clickMenu = $this->arguments['clickMenu']; - if (!\is_array($row)) { - $row = BackendUtility::getRecord($table, $row->getUid()); - } - /** @var IconFactory $iconFactory */ - $iconFactory = GeneralUtility::makeInstance(IconFactory::class); - $toolTip = BackendUtility::getRecordToolTip($row, $table); - $iconImg = '<span ' . $toolTip . '>' - . $iconFactory->getIconForRecord($table, $row, Icon::SIZE_SMALL)->render() - . '</span>'; - if ($clickMenu) { - return BackendUtility::wrapClickMenuOnIcon($iconImg, $table, $row['uid']); - } - return $iconImg; - } - -} diff --git a/Classes/ViewHelpers/Backend/Widget/Controller/PaginateController.php b/Classes/ViewHelpers/Backend/Widget/Controller/PaginateController.php deleted file mode 100644 index 58aaaf5c..00000000 --- a/Classes/ViewHelpers/Backend/Widget/Controller/PaginateController.php +++ /dev/null @@ -1,90 +0,0 @@ -<?php - -namespace SGalinski\SgJobs\ViewHelpers\Backend\Widget\Controller; - -/*************************************************************** - * Copyright notice - * - * (c) sgalinski Internet Services (https://www.sgalinski.de) - * - * All rights reserved - * - * This script is part of the TYPO3 project. The TYPO3 project is - * free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * The GNU General Public License can be found at - * http://www.gnu.org/copyleft/gpl.html. - * - * This script is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * This copyright notice MUST APPEAR in all copies of the script! - ***************************************************************/ - -/** - * Class PaginateController - */ -class PaginateController extends \TYPO3\CMS\Fluid\ViewHelpers\Be\Widget\Controller\PaginateController { - /** - * Renders the paginator - * - * @param int $currentPage - * @return void - */ - public function indexAction($currentPage = 1) { - // set current page - $this->currentPage = (int) $currentPage; - if ($this->currentPage < 1) { - $this->currentPage = 1; - } - if ($this->currentPage > $this->numberOfPages) { - // set $modifiedObjects to NULL if the page does not exist - $modifiedObjects = NULL; - } else { - // modify query - $this->itemsPerPage = (int) $this->configuration['itemsPerPage']; - $this->offset = $this->itemsPerPage * ($this->currentPage - 1); - if (\is_array($this->objects)) { - $modifiedObjects = []; - for ($index = $this->offset; $index < $this->offset + $this->itemsPerPage; $index++) { - if (isset($this->objects[$index])) { - $modifiedObjects[] = $this->objects[$index]; - } else { - break; - } - } - } else { - $query = $this->objects->getQuery(); - $query->setLimit($this->itemsPerPage); - if ($this->currentPage > 1) { - $query->setOffset($this->offset); - } - $modifiedObjects = $query->execute(); - } - } - $this->view->assign( - 'contentArguments', [ - $this->widgetConfiguration['as'] => $modifiedObjects - ] - ); - $this->view->assign('configuration', $this->configuration); - $this->view->assign('pagination', $this->buildPagination()); - } - - /** - * Returns an array with the keys "pages", "current", "numberOfPages", - * "nextPage" & "previousPage" - * - * @return array - */ - protected function buildPagination(): array { - $pagination = parent::buildPagination(); - $pagination['totalObjects'] = \count($this->objects); - return $pagination; - } -} diff --git a/Classes/ViewHelpers/Backend/Widget/PaginateViewHelper.php b/Classes/ViewHelpers/Backend/Widget/PaginateViewHelper.php deleted file mode 100644 index e278489f..00000000 --- a/Classes/ViewHelpers/Backend/Widget/PaginateViewHelper.php +++ /dev/null @@ -1,81 +0,0 @@ -<?php - -namespace SGalinski\SgJobs\ViewHelpers\Backend\Widget; - -/*************************************************************** - * Copyright notice - * - * (c) sgalinski Internet Services (https://www.sgalinski.de) - * - * All rights reserved - * - * This script is part of the TYPO3 project. The TYPO3 project is - * free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * The GNU General Public License can be found at - * http://www.gnu.org/copyleft/gpl.html. - * - * This script is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * This copyright notice MUST APPEAR in all copies of the script! - ***************************************************************/ - -use SGalinski\SgJobs\ViewHelpers\Backend\Widget\Controller\PaginateController; -use TYPO3\CMS\Fluid\Core\Widget\AbstractWidgetViewHelper; -use TYPO3\CMS\Fluid\Core\Widget\Exception\MissingControllerException; - -/** - * Class PaginateViewHelper - */ -class PaginateViewHelper extends AbstractWidgetViewHelper { - /** - * @var PaginateController - */ - protected $controller; - - /** - * Initializes the controller - * - * @param PaginateController $controller - */ - public function injectPaginateController(PaginateController $controller) { - $this->controller = $controller; - } - - /** - * Register the ViewHelper arguments - */ - public function initializeArguments() { - parent::initializeArguments(); - $this->registerArgument('objects', 'mixed', 'The objects to paginate', TRUE); - $this->registerArgument('as', 'string', 'The name of the variable inside the pagination', TRUE); - $this->registerArgument( - 'configuration', - 'array', - 'The configuration of the pagination', - FALSE, - [ - 'itemsPerPage' => 10, - 'insertAbove' => FALSE, - 'insertBelow' => TRUE, - 'recordsLabel' => '' - ] - ); - } - - /** - * Renders the paginator - * - * @return string - * @throws MissingControllerException - */ - public function render(): string { - return $this->initiateSubRequest(); - } -} diff --git a/Resources/Private/Backend/Partials/CreateJob.html b/Resources/Private/Backend/Partials/CreateJob.html index df676991..ef8d08c3 100644 --- a/Resources/Private/Backend/Partials/CreateJob.html +++ b/Resources/Private/Backend/Partials/CreateJob.html @@ -1,12 +1,13 @@ {namespace sg=SGalinski\SgJobs\ViewHelpers} +{namespace be=TYPO3\CMS\Backend\ViewHelpers} <div class="form-group"> - <a href="#" class="btn btn-default" onclick="{sg:backend.editOnClick(table: 'tx_sgjobs_domain_model_job', uid: pageUid, new: 1)}"> - <span class="t3js-icon icon icon-size-small icon-state-default icon-actions-document-new"> - <span class="icon-markup"> - <img src="/typo3/sysext/core/Resources/Public/Icons/T3Icons/actions/actions-document-new.svg" width="16" height="16"> - </span> - </span> + <be:link.newRecord class="btn btn-default" table="tx_sgjobs_domain_model_job" pid="{pageUid}"> + <span class="t3js-icon icon icon-size-small icon-state-default icon-actions-document-new"> + <span class="icon-markup"> + <img src="/typo3/sysext/core/Resources/Public/Icons/T3Icons/actions/actions-document-new.svg" width="16" height="16"> + </span> + </span> <f:translate key="backend.button_create_job" /> - </a> -</div> \ No newline at end of file + </be:link.newRecord> +</div> diff --git a/Resources/Private/Backend/Partials/Filter.html b/Resources/Private/Backend/Partials/Filter.html index b3f674d3..b54e0eeb 100644 --- a/Resources/Private/Backend/Partials/Filter.html +++ b/Resources/Private/Backend/Partials/Filter.html @@ -1,3 +1,4 @@ +{namespace be=TYPO3\CMS\Backend\ViewHelpers} <f:form action="index" controller="Backend" method="post" objectName="filters" object="{filters}"> <div class="row"> <div class="col-xs-6"> @@ -7,15 +8,14 @@ </label> <f:form.select class="form-control" multiple="1" size="4" property="locations" optionLabelField="name" optionValueField="city" options="{locationOptions}" id="filter-locations" /> <small> - <f:format.raw><f:translate key="backend.filters.locations.description" /> - </f:format.raw> + <f:format.raw><f:translate key="backend.filters.locations.description" /></f:format.raw> </small> <script> var LocationEditLinks = {}; </script> <f:for each="{locationOptions}" key="uid" as="location"> <script> - LocationEditLinks["{uid}"] = "{sg:backend.editLink(table: 'tx_sgjobs_domain_model_company', uid: uid) -> f:format.raw()}"; + LocationEditLinks["{uid}"] = "{be:uri.editRecord(uid: location.uid, table: 'tx_sgjobs_domain_model_company')}"; </script> </f:for> </div> diff --git a/Resources/Private/Backend/Partials/JobList.html b/Resources/Private/Backend/Partials/JobList.html index 9b1e1013..ccaf4f27 100644 --- a/Resources/Private/Backend/Partials/JobList.html +++ b/Resources/Private/Backend/Partials/JobList.html @@ -1,4 +1,5 @@ {namespace sg=SGalinski\SgJobs\ViewHelpers} +{namespace be=TYPO3\CMS\Backend\ViewHelpers} <p> <f:translate key="backend.message.sorting" /> @@ -10,31 +11,26 @@ <div class="panel panel-default recordlist"> <div class="table-fit"> - <table data-table="tx_sgjobs_domain_model_job" class="table table-striped table-hover"> - <sg:backend.widget.paginate objects="{jobs}" as="paginatedJobs" configuration="{insertAbove: 1, itemsPerPage: 20}"> + <f:be.widget.paginate objects="{jobs}" as="paginatedJobs" configuration="{insertAbove: 1, itemsPerPage: 20}"> + <table data-table="tx_sgjobs_domain_model_job" class="table table-striped table-hover"> <tbody> <f:for each="{paginatedJobs}" as="job"> - {sg:backend.editOnClick(table: 'tx_sgjobs_domain_model_job', uid: job.uid) -> sg:set(name: 'editOnClick')} <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> + <core:icon identifier="tcarecords-tx_sgjobs_domain_model_job-default"></core:icon> </td> <td style="white-space: normal;"> - <a href="#" onclick="{editOnClick}"> + <be:link.editRecord uid="{job.uid}" table="tx_sgjobs_domain_model_job"> <span>{job.title} - {job.company.name}, {job.company.city}</span> - </a> + </be:link.editRecord> </td> <td nowrap="nowrap" class="col-control"> - <f:format.raw> - <sg:backend.control table="tx_sgjobs_domain_model_job" row="{job}" sortingData="{sortingData}"/> - </f:format.raw> + <f:format.raw><sg:backend.control table="tx_sgjobs_domain_model_job" row="{job}" sortingData="{sortingData}"/></f:format.raw> </td> </tr> </f:for> </tbody> - </sg:backend.widget.paginate> - </table> + </table> + </f:be.widget.paginate> </div> </div> -- GitLab