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

[BUGFIX] Code Cleanup, Improve code stability, Fix completely broken pagebrowser integration

parent dff5bf18
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() {
......
......@@ -28,26 +28,32 @@ namespace SGalinski\SgJobs\ViewHelpers;
use TYPO3\CMS\Core\TypoScript\TypoScriptService;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Object\ObjectManager;
use TYPO3\CMS\Fluid\View\StandaloneView;
use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;
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);
}
/**
......@@ -57,27 +63,31 @@ class PageBrowserViewHelper extends AbstractViewHelper {
* @throws \UnexpectedValueException
*/
public function render(): string {
/** @var TypoScriptService $typoScriptService */
$typoScriptService = GeneralUtility::makeInstance(TypoScriptService::class);
$configuration = $typoScriptService->convertTypoScriptArrayToPlainArray($GLOBALS['TSFE']->tmpl->setup['plugin.']['tx_sgjobs.']);
$configuration = $typoScriptService->convertTypoScriptArrayToPlainArray(
$GLOBALS['TSFE']->tmpl->setup['plugin.']['tx_sgjobs.']
);
$view = GeneralUtility::makeInstance(StandaloneView::class);
$view->setRenderingContext($this->renderingContext);
$view->setTemplate('PageBrowser/Index');
$view->setTemplateRootPaths($configuration['view']['templateRootPaths']);
$view->setPartialRootPaths($configuration['view']['partialRootPaths']);
$view->setLayoutRootPaths($configuration['view']['layoutRootPaths']);
$pageBrowserVars = GeneralUtility::_GP('tx_sgnews_pagebrowser');
$view->setTemplate('PageBrowser/Index');
$currentPage = 0;
$pageBrowserVars = GeneralUtility::_GP('tx_sgjobs_pagebrowser');
if (isset($pageBrowserVars['currentPage']) && (int) $pageBrowserVars['currentPage'] > 0) {
$currentPage = (int) $pageBrowserVars['currentPage'];
} else {
$currentPage = 1;
}
$pageLinks = [];
$start = \max($currentPage - 1, 1);
$start = \max($currentPage - 2, 0);
$end = \min($this->arguments['numberOfPages'], $currentPage + 2);
for ($i = $start; $i < $end; $i++) {
$pageLinks[] = [
'number' => $i,
'number' => $i + 1,
'page' => $i,
'isCurrentPage' => $i === $currentPage,
];
}
......@@ -88,7 +98,7 @@ class PageBrowserViewHelper extends AbstractViewHelper {
'enableMorePages' => 1,
'pageLinks' => $pageLinks,
'currentPage' => $currentPage,
'prevPageExist' => $currentPage > 1,
'prevPageExist' => $currentPage >= 1,
'showLessPages' => ($currentPage - 1) > 1,
'showNextPages' => ($currentPage + 2) < $this->arguments['numberOfPages'],
'nextPageExist' => $currentPage < $this->arguments['numberOfPages'] - 1,
......
{namespace sg=SGalinski\SgJobs\ViewHelpers}
<f:layout name="PageBrowser" />
<f:layout name="PageBrowser"/>
<f:section name="main">
<nav>
......@@ -8,8 +8,8 @@
<f:if condition="{prevPageExist}">
<f:then>
<li class="tx-pagebrowse-prev">
<f:variable name="prevPage" value="{currentPage - 1}" />
<f:link.action additionalParams="{tx_sgnews_pagebrowser: {currentPage: prevPage}}"
<f:variable name="prevPage" value="{currentPage - 1}"/>
<f:link.action addQueryString="1" additionalParams="{tx_sgjobs_pagebrowser: {currentPage: prevPage}}"
additionalAttributes="{aria-label: 'Previous'}">
&laquo;
</f:link.action>
......@@ -28,8 +28,8 @@
<f:if condition="{enableLessPages} && {showLessPages}">
<li>
<f:variable name="lessPage" value="{currentPage - 2}" />
<f:link.action additionalParams="{tx_sgnews_pagebrowser: {currentPage: lessPage}}">
<f:variable name="lessPage" value="{currentPage - 2}"/>
<f:link.action addQueryString="1" additionalParams="{tx_sgjobs_pagebrowser: {currentPage: lessPage}}">
...
</f:link.action>
</li>
......@@ -49,7 +49,7 @@
</f:then>
<f:else>
<li class="tx-pagebrowse-page">
<f:link.action additionalParams="{tx_sgnews_pagebrowser: {currentPage: pageLink.number}}">
<f:link.action addQueryString="1" additionalParams="{tx_sgjobs_pagebrowser: {currentPage: pageLink.page}}">
{pageLink.number}
</f:link.action>
</li>
......@@ -59,8 +59,8 @@
<f:if condition="{enableMorePages} && {showNextPages}">
<li>
<f:variable name="morePage" value="{currentPage + 2}" />
<f:link.action additionalParams="{tx_sgnews_pagebrowser: {currentPage: morePage}}">
<f:variable name="morePage" value="{currentPage + 2}"/>
<f:link.action addQueryString="1" additionalParams="{tx_sgjobs_pagebrowser: {currentPage: morePage}}">
...
</f:link.action>
</li>
......@@ -69,8 +69,8 @@
<f:if condition="{nextPageExist}">
<f:then>
<li class="tx-pagebrowse-next">
<f:variable name="nextPage" value="{currentPage + 1}" />
<f:link.action additionalParams="{tx_sgnews_pagebrowser: {currentPage: nextPage}}"
<f:variable name="nextPage" value="{currentPage + 1}"/>
<f:link.action addQueryString="1" additionalParams="{tx_sgjobs_pagebrowser: {currentPage: nextPage}}"
additionalAttributes="{aria-label: 'Next'}">
&raquo;
</f:link.action>
......
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