Skip to content
Snippets Groups Projects
Commit 26cd6420 authored by Stefan Galinski's avatar Stefan Galinski :video_game:
Browse files

Merge branch 'task_RemovePagebrowser' into 'master'

[TASK] Remove the pagebrowser controller and let the view helper handle stuff

See merge request !30
parents 39b41956 d24ac685
No related branches found
No related tags found
1 merge request!30[TASK] Remove the pagebrowser controller and let the view helper handle stuff
......@@ -123,15 +123,28 @@ class JoblistController extends ActionController {
$this->jobRepository = $jobRepository;
}
/**
* Initialize the indexAction to set the currentPageBrowserPage parameter
*
* @throws \TYPO3\CMS\Extbase\Mvc\Exception\InvalidArgumentNameException
*/
public function initializeIndexAction() {
$currentPageBrowserPage = (int) GeneralUtility::_GP('tx_sgjobs_pagebrowser')['currentPage'];
if ($currentPageBrowserPage > 0) {
$this->request->setArgument('currentPageBrowserPage', $currentPageBrowserPage);
}
}
/**
* Show all job offers and options to manage them
*
* @param array $filters
* @param int $jobId
* @param int $currentPageBrowserPage
* @return void
* @throws \InvalidArgumentException
* @throws \TYPO3\CMS\Core\Context\Exception\AspectNotFoundException
*/
public function indexAction(array $filters = [], $jobId = NULL): void {
public function indexAction(array $filters = [], int $jobId = NULL, int $currentPageBrowserPage = 0): void {
if ($filters) {
$this->view->assign('selectedCountry', $filters['filterCountry']);
$this->view->assign('selectedCompany', $filters['filterCompany']);
......@@ -167,7 +180,6 @@ class JoblistController extends ActionController {
} else {
// pagination logic
$offset = 0;
$currentPageBrowserPage = (int) GeneralUtility::_GP('tx_sgjobs_pagebrowser')['currentPage'];
if ($currentPageBrowserPage && $jobLimit) {
$offset = $currentPageBrowserPage * $jobLimit;
}
......@@ -203,16 +215,15 @@ class JoblistController extends ActionController {
/**
* Renders the application form with an optional job
*
* @param JobApplication $applyData
* @param JobApplication|null $applyData
* @param string $error
* @param int $jobId
* @throws \TYPO3\CMS\Core\Context\Exception\AspectNotFoundException
* @throws \TYPO3\CMS\Extbase\Mvc\Exception\InvalidArgumentNameException
* @throws \TYPO3\CMS\Extbase\Mvc\Exception\StopActionException
* @throws \TYPO3\CMS\Extbase\Mvc\Exception\UnsupportedRequestTypeException
* @throws \TYPO3\CMS\Core\Context\Exception\AspectNotFoundException
*/
public function applyFormAction(JobApplication $applyData = NULL, $error = NULL, $jobId = NULL): void {
if ($error !== NULL && $error !== '') {
public function applyFormAction(JobApplication $applyData = NULL, string $error = '', int $jobId = NULL): void {
if ($error !== '') {
$this->view->assign('internalError', $error);
$this->request->setArgument('error', NULL);
}
......@@ -302,7 +313,6 @@ class JoblistController extends ActionController {
* @return void
* @throws NoSuchArgumentException
* @throws \TYPO3\CMS\Extbase\Mvc\Exception\StopActionException
* @throws \TYPO3\CMS\Extbase\Mvc\Exception\UnsupportedRequestTypeException
*/
protected function initializeApplyAction(): void {
try {
......@@ -333,17 +343,14 @@ class JoblistController extends ActionController {
* @param string $folderName
* @return void
* @throws \TYPO3\CMS\Extbase\Mvc\Exception\StopActionException
* @throws \RuntimeException
* @throws \InvalidArgumentException
* @throws \TYPO3\CMS\Extbase\Mvc\Exception\UnsupportedRequestTypeException
* @throws \TYPO3\CMS\Core\Resource\Exception\ResourceDoesNotExistException
*/
protected function submitApplicationFiles(JobApplication $applicationData, $folderName): void {
$resourceFactory = $this->objectManager->get(ResourceFactory::class);
$newName = \date('Ymd-His') . '_' . $applicationData->getJobId() . '-' . $applicationData->getFirstName()
. '-' . $applicationData->getLastName();
$storage = $resourceFactory->getStorageObject(1);
$applicationFilePath = Environment::getPublicPath() . '/' . $storage->getConfiguration()['basePath'] . 'JobApplication/' . $folderName .
$applicationFilePath = Environment::getPublicPath() . '/' . $storage->getConfiguration(
)['basePath'] . 'JobApplication/' . $folderName .
'/' . $newName . '.csv';
$this->writeApplicationFile($applicationData, $applicationFilePath);
}
......@@ -363,9 +370,7 @@ class JoblistController extends ActionController {
$applyData->setPid($GLOBALS['TSFE']->id);
$job = $applyData->getJob();
// look for a configured default job, in case of unsolicited application
if (($job === '' || $job === NULL || $applyData->getJobId() === NULL)
&& $applyData->getCompany() !== NULL
) {
if ((!$job || $applyData->getJobId() === NULL) && $applyData->getCompany() !== NULL) {
$applyData->setJobId($applyData->getCompany()->getJobId());
}
......@@ -378,7 +383,6 @@ class JoblistController extends ActionController {
$this->moveTmpFolder($folderName);
$this->submitApplicationFiles($applyData, $folderName);
/** @noinspection PhpMethodParametersCountMismatchInspection */
$mailService = $this->objectManager->get(
MailTemplateService::class, 'application_mail', 'sg_jobs',
$this->getApplicationMailMarkers($applyData)
......@@ -426,8 +430,11 @@ class JoblistController extends ActionController {
$redirectPageUid = (int) $this->settings['redirectPage'];
if ($redirectPageUid) {
$url = $this->configurationManager->getContentObject()->getTypoLink_URL($redirectPageUid);
$this->redirectToUri($url);
$contentObject = $this->configurationManager->getContentObject();
if ($contentObject) {
$url = $contentObject->getTypoLink_URL($redirectPageUid);
$this->redirectToUri($url);
}
}
$this->redirect('applyForm');
......@@ -448,7 +455,7 @@ class JoblistController extends ActionController {
* Assign filter values
*
* @param int $rootPageId
* @throws \InvalidArgumentException
* @throws \TYPO3\CMS\Core\Context\Exception\AspectNotFoundException
*/
protected function assignFilterValues($rootPageId): void {
$countries = $this->companyRepository->getAllCountries($rootPageId);
......@@ -473,7 +480,7 @@ class JoblistController extends ActionController {
* @param JobApplication $applyData
* @return array
*/
protected function getApplicationMailMarkers($applyData): array {
protected function getApplicationMailMarkers(JobApplication $applyData): array {
$location = '';
if ($applyData->getCompany() !== NULL) {
$location = $applyData->getCompany()->getCity();
......@@ -499,13 +506,36 @@ class JoblistController extends ActionController {
*
* @param JobApplication $data
* @param string $filePath
* @throws \TYPO3\CMS\Extbase\Mvc\Exception\UnsupportedRequestTypeException
* @throws \TYPO3\CMS\Extbase\Mvc\Exception\StopActionException
* @throws \InvalidArgumentException
* @throws \RuntimeException
* @throws \TYPO3\CMS\Core\Resource\Exception\ResourceDoesNotExistException
*/
protected function writeApplicationFile(JobApplication $data, $filePath): void {
$coverLetter = '';
$coverLetterObject = $data->getCoverLetter();
if ($coverLetterObject) {
$coverLetterObject = $coverLetterObject->getOriginalResource();
if ($coverLetterObject) {
$coverLetter = $coverLetterObject->getPublicUrl();
}
}
$cv = '';
$cvObject = $data->getCv();
if ($cvObject) {
$cvObject = $cvObject->getOriginalResource();
if ($cvObject) {
$cv = $cvObject->getPublicUrl();
}
}
$certificate = '';
$certificateObject = $data->getCertificate();
if ($certificateObject) {
$certificateObject = $certificateObject->getOriginalResource();
if ($certificateObject) {
$certificate = $certificateObject->getPublicUrl();
}
}
$dataToInsertArr = [
$data->getJobId(),
$data->getFirstName(),
......@@ -520,9 +550,9 @@ class JoblistController extends ActionController {
$data->getNationality(),
$data->getPhone(),
$data->getEmail(),
$data->getCoverLetter() === NULL ? '' : $data->getCoverLetter()->getOriginalResource()->getPublicUrl(),
$data->getCv() === NULL ? '' : $data->getCv()->getOriginalResource()->getPublicUrl(),
$data->getCertificate() === NULL ? '' : $data->getCertificate()->getOriginalResource()->getPublicUrl(),
$coverLetter,
$cv,
$certificate,
$data->getMessage()
];
......@@ -583,7 +613,7 @@ class JoblistController extends ActionController {
/**
* If for any reason something goes wrong, delete the tmp upload folder
*
* @return string|void
* @return void
* @throws NoSuchArgumentException
*/
public function errorAction() {
......
<?php
namespace SGalinski\SgJobs\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!
***************************************************************/
use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
/**
* Controller that handles the page browser.
*/
class PageBrowserController extends ActionController {
/**
* @var string
*/
protected $pageParameterName = '';
/**
* @var int
*/
protected $numberOfPages = 0;
/**
* @var int
*/
protected $currentPage = 0;
/**
* @var int
*/
protected $pagesBefore = 0;
/**
* @var int
*/
protected $pagesAfter = 0;
/**
* @var bool
*/
protected $enableMorePages = FALSE;
/**
* @var bool
*/
protected $enableLessPages = FALSE;
/**
* Renders the index view.
*
* @param int $currentPage
* @return void
*/
public function indexAction($currentPage = 0): void {
$this->currentPage = (int) $currentPage;
$this->initializeConfiguration();
$this->addDataToView();
}
/**
* Initializes the configuration.
*
* @return void
*/
protected function initializeConfiguration(): void {
$this->pageParameterName = 'tx_sgjobs_pagebrowser[currentPage]';
$this->numberOfPages = (int) $this->settings['numberOfPages'];
$this->pagesBefore = (int) $this->settings['pagesBefore'];
$this->pagesAfter = (int) $this->settings['pagesAfter'];
$this->enableMorePages = (bool) $this->settings['enableMorePages'];
$this->enableLessPages = (bool) $this->settings['enableLessPages'];
}
/**
* Adds the necessary data to the view.
*
* @return void
*/
protected function addDataToView(): void {
if ($this->numberOfPages <= 1) {
$this->view = NULL;
return;
}
$pageLinks = [];
$start = max($this->currentPage - $this->pagesBefore, 0);
$end = min($this->numberOfPages, $this->currentPage + $this->pagesAfter + 1);
for ($i = $start; $i < $end; $i++) {
$pageLinks[] = [
'number' => $i + 1,
'link' => $this->getPageLink($i),
'isCurrentPage' => $i === $this->currentPage,
];
}
$this->view->assignMultiple(
[
'enableLessPages' => $this->enableLessPages,
'enableMorePages' => $this->enableMorePages,
'previousLink' => $this->getPageLink($this->currentPage - 1),
'nextLink' => $this->getPageLink($this->currentPage + 1),
'enableLessPagesLink' => $this->getPageLink($this->currentPage - $this->pagesBefore - 1),
'enableMorePagesLink' => $this->getPageLink($this->currentPage + $this->pagesAfter + 1),
'pageLinks' => $pageLinks,
'prevPageExist' => $this->currentPage > 0,
'showLessPages' => ($this->currentPage - $this->pagesBefore) > 0,
'showNextPages' => ($this->currentPage + $this->pagesAfter + 1) < $this->numberOfPages,
'nextPageExist' => $this->currentPage < ($this->numberOfPages - 1),
]
);
}
/**
* Generates page link. Keeps all current URL parameters except for cHash and tx_pagebrowse_pi1[page].
*
* @param int $page Page number starting from 1
* @return string
*/
protected function getPageLink($page): string {
return $this->uriBuilder->reset()->setAddQueryString(TRUE)
->uriFor('index', ['currentPage' => $page,]);
}
}
......@@ -26,26 +26,34 @@ namespace SGalinski\SgJobs\ViewHelpers;
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
use TYPO3\CMS\Core\TypoScript\TypoScriptService;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Object\ObjectManager;
use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;
use TYPO3\CMS\Fluid\View\StandaloneView;
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
/**
* View helper that renders a page browser based upon the pagebrowse extension.
*
* Example:
* {namespace sg=SGalinski\SgJobs\ViewHelpers}
* {namespace sg=SGalinski\SgNews\ViewHelpers}
* <sg:pageBrowser numberOfPages="" />
*/
class PageBrowserViewHelper extends AbstractViewHelper {
/**
* Specifies whether the escaping interceptors should be disabled or enabled for the render-result of this ViewHelper
*
* @see isOutputEscapingEnabled()
*
* @var boolean
*/
protected $escapeOutput = FALSE;
/**
* Register the ViewHelper arguments
* Initialize the ViewHelpers arguments
*/
public function initializeArguments() {
parent::initializeArguments();
$this->registerArgument('numberOfPages', 'int', 'The number of pages', TRUE);
$this->registerArgument('numberOfPages', 'int', 'The number of pages to browse', TRUE);
}
/**
......@@ -55,13 +63,48 @@ class PageBrowserViewHelper extends AbstractViewHelper {
* @throws \UnexpectedValueException
*/
public function render(): string {
$configuration = $GLOBALS['TSFE']->tmpl->setup['plugin.']['tx_sgjobs.']['pagebrowser.'];
$configuration['settings.']['numberOfPages'] = (int) $this->arguments['numberOfPages'];
/** @var TypoScriptService $typoScriptService */
$typoScriptService = GeneralUtility::makeInstance(TypoScriptService::class);
$configuration = $typoScriptService->convertTypoScriptArrayToPlainArray(
$GLOBALS['TSFE']->tmpl->setup['plugin.']['tx_sgjobs.']
);
$view = GeneralUtility::makeInstance(StandaloneView::class);
$view->setRenderingContext($this->renderingContext);
$view->setTemplateRootPaths($configuration['view']['templateRootPaths']);
$view->setPartialRootPaths($configuration['view']['partialRootPaths']);
$view->setLayoutRootPaths($configuration['view']['layoutRootPaths']);
$view->setTemplate('PageBrowser/Index');
$currentPage = 0;
$pageBrowserVars = GeneralUtility::_GP('tx_sgjobs_pagebrowser');
if (isset($pageBrowserVars['currentPage']) && (int) $pageBrowserVars['currentPage'] > 0) {
$currentPage = (int) $pageBrowserVars['currentPage'];
}
$pageLinks = [];
$start = \max($currentPage - 2, 0);
$end = \min($this->arguments['numberOfPages'], $currentPage + 2);
for ($i = $start; $i < $end; $i++) {
$pageLinks[] = [
'number' => $i + 1,
'page' => $i,
'isCurrentPage' => $i === $currentPage,
];
}
/** @var ContentObjectRenderer $contentObject */
$objectManager = GeneralUtility::makeInstance(ObjectManager::class);
$contentObject = $objectManager->get(ContentObjectRenderer::class);
$contentObject->start([]);
return $contentObject->cObjGetSingle('USER', $configuration);
$view->assignMultiple(
[
'enableLessPages' => 1,
'enableMorePages' => 1,
'pageLinks' => $pageLinks,
'currentPage' => $currentPage,
'prevPageExist' => $currentPage >= 1,
'showLessPages' => ($currentPage - 1) > 1,
'showNextPages' => ($currentPage + 2) < $this->arguments['numberOfPages'],
'nextPageExist' => $currentPage < $this->arguments['numberOfPages'] - 1,
'numberOfPages' => $this->arguments['numberOfPages']
]
);
return $view->render();
}
}
plugin.tx_sgjobs {
view {
# cat=plugin.tx_tx_extensionskeleton/file; type=string; label=Path to template root (FE)
templateRootPath = EXT:tx_sgjobs/Resources/Private/Templates/
templateRootPath = EXT:sg_jobs/Resources/Private/Templates/
# cat=plugin.tx_tx_extensionskeleton/file; type=string; label=Path to template partials (FE)
partialRootPath = EXT:tx_sgjobs/Resources/Private/Partials/
partialRootPath = EXT:sg_jobs/Resources/Private/Partials/
# cat=plugin.tx_tx_extensionskeleton/file; type=string; label=Path to template layouts (FE)
layoutRootPath = EXT:tx_sgjobs/Resources/Private/Layouts/
layoutRootPath = EXT:sg_jobs/Resources/Private/Layouts/
}
settings {
......@@ -26,18 +26,4 @@ plugin.tx_sgjobs {
# cat=plugin.tx_sgjobs/other; type=int+; If set to 1, the application-form page will redirect to the overview if no jobId is passed
disallowUnsolicitedApplication = 0
}
pagebrowser.settings {
# Number of page links to show before the current page
pagesBefore = 1
# Number of page links to show before the current page
pagesAfter = 1
# Enables section for "more" pages. This section is shown after links to next pages, normally like three dots (1 2 3 ...). Notice that you can also hide it by emptying corresponding template section.
enableMorePages = 1
# Enables section for "less" pages. This section is shown after links to next pages, normally like three dots (... 1 2 3) Notice that you can also hide it by emptying corresponding template section.
enableLessPages = 1
}
}
......@@ -2,17 +2,14 @@ plugin.tx_sgjobs {
view {
templateRootPaths {
0 = {$plugin.tx_sgjobs.view.templateRootPath}
1 =
}
partialRootPaths {
0 = {$plugin.tx_sgjobs.view.partialRootPath}
1 =
}
layoutRootPaths {
0 = {$plugin.tx_sgjobs.view.layoutRootPath}
1 =
}
}
......@@ -37,41 +34,6 @@ plugin.tx_sgjobs {
legacy {
enableLegacyFlashMessageHandling = 0
}
pagebrowser = USER
pagebrowser {
userFunc = TYPO3\CMS\Extbase\Core\Bootstrap->run
extensionName = SgJobs
pluginName = PageBrowser
vendorName = SGalinski
controller = PageBrowser
action = index
view < plugin.tx_sgjobs.view
persistence < plugin.tx_sgjobs.persistence
features < plugin.tx_sgjobs.features
# cHash can't be generated for pageBrowser call; will cause a 404 error if not set to 0
features.requireCHashArgumentForActionArguments = 0
legacy < plugin.tx_sgjobs.legacy
settings {
# Number of page links to show before the current page
pagesBefore = {$plugin.tx_sgjobs.pagebrowser.settings.pagesBefore}
# Number of page links to show before the current page
pagesAfter = {$plugin.tx_sgjobs.pagebrowser.settings.pagesAfter}
# Enables section for "more" pages. This section is shown after links to next pages, normally like three dots (1 2 3 ...). Notice that you can also hide it by emptying corresponding template section.
enableMorePages = {$plugin.tx_sgjobs.pagebrowser.settings.enableMorePages}
# Enables section for "less" pages. This section is shown after links to next pages, normally like three dots (... 1 2 3) Notice that you can also hide it by emptying corresponding template section.
enableLessPages = {$plugin.tx_sgjobs.pagebrowser.settings.enableLessPages}
# The number of the pages
numberOfPages = 0
# The current page
currentPage = 0
}
}
}
config.recordLinks {
......
{namespace sg=SGalinski\SgJobs\ViewHelpers}
<f:layout name="PageBrowser" />
<f:layout name="PageBrowser"/>
<f:section name="main">
<nav>
......@@ -8,9 +8,11 @@
<f:if condition="{prevPageExist}">
<f:then>
<li class="tx-pagebrowse-prev">
<a href="{previousLink}" aria-label="Previous">
<f:variable name="prevPage" value="{currentPage - 1}"/>
<f:link.action addQueryString="1" additionalParams="{tx_sgjobs_pagebrowser: {currentPage: prevPage}}"
additionalAttributes="{aria-label: 'Previous'}">
&laquo;
</a>
</f:link.action>
</li>
</f:then>
<f:else>
......@@ -26,9 +28,10 @@
<f:if condition="{enableLessPages} && {showLessPages}">
<li>
<a href="{enableLessPagesLink}">
<f:variable name="lessPage" value="{currentPage - 2}"/>
<f:link.action addQueryString="1" additionalParams="{tx_sgjobs_pagebrowser: {currentPage: lessPage}}">
...
</a>
</f:link.action>
</li>
</f:if>
......@@ -46,9 +49,9 @@
</f:then>
<f:else>
<li class="tx-pagebrowse-page">
<a href="{pageLink.link}">
<f:link.action addQueryString="1" additionalParams="{tx_sgjobs_pagebrowser: {currentPage: pageLink.page}}">
{pageLink.number}
</a>
</f:link.action>
</li>
</f:else>
</f:if>
......@@ -56,18 +59,21 @@
<f:if condition="{enableMorePages} && {showNextPages}">
<li>
<a href="{enableMorePagesLink}">
<f:variable name="morePage" value="{currentPage + 2}"/>
<f:link.action addQueryString="1" additionalParams="{tx_sgjobs_pagebrowser: {currentPage: morePage}}">
...
</a>
</f:link.action>
</li>
</f:if>
<f:if condition="{nextPageExist}">
<f:then>
<li class="tx-pagebrowse-next">
<a href="{nextLink}" aria-label="Next">
<f:variable name="nextPage" value="{currentPage + 1}"/>
<f:link.action addQueryString="1" additionalParams="{tx_sgjobs_pagebrowser: {currentPage: nextPage}}"
additionalAttributes="{aria-label: 'Next'}">
&raquo;
</a>
</f:link.action>
</li>
</f:then>
<f:else>
......
......@@ -65,12 +65,6 @@ call_user_func(
'JobTeaser' => ''
]
);
\TYPO3\CMS\Extbase\Utility\ExtensionUtility::configurePlugin(
'SGalinski.sg_jobs',
'PageBrowser',
['PageBrowser' => 'index',],
['PageBrowser' => '',]
);
// Backend preview for plugins
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['cms/layout/class.tx_cms_layout.php']['tt_content_drawItem']['sg_jobs']
= \SGalinski\SgJobs\Hooks\PageLayoutView\PluginRenderer::class;
......
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