Skip to content
Snippets Groups Projects
Commit 9f2b5f17 authored by Kevin Ditscheid's avatar Kevin Ditscheid
Browse files

[TASK] Remove BS code from the backend module

parent fff356d3
No related branches found
No related tags found
No related merge requests found
......@@ -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();
}
/**
......
<?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'
]
]
]
);
}
}
<?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
);
}
}
<?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;
}
}
<?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;
}
}
<?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();
}
}
{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>
{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>
......
{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>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment