diff --git a/Classes/Controller/BackendController.php b/Classes/Controller/BackendController.php index dc11a05f5bc9b50dbed032ea20670d4e7ee2a560..8d714ecfe0607822388b68d57e7cb38da14adf08 100644 --- a/Classes/Controller/BackendController.php +++ b/Classes/Controller/BackendController.php @@ -49,19 +49,19 @@ class BackendController extends ActionController { * * @var DocHeaderComponent */ - protected $docHeaderComponent; + protected DocHeaderComponent $docHeaderComponent; /** * @var CompanyRepository * */ - protected $companyRepository; + protected CompanyRepository $companyRepository; /** * @var JobRepository * */ - protected $jobRepository; + protected JobRepository $jobRepository; /** * Inject the CompanyRepository @@ -86,7 +86,7 @@ class BackendController extends ActionController { * * @param array $filters * @return \Psr\Http\Message\ResponseInterface|null - * @throws \TYPO3\CMS\Extbase\Persistence\Exception\InvalidQueryException + * @throws \TYPO3\CMS\Extbase\Persistence\Exception\InvalidQueryException|\TYPO3\CMS\Extbase\Mvc\Exception\NoSuchArgumentException */ public function indexAction(array $filters = []): ?\Psr\Http\Message\ResponseInterface { $pageUid = (int) GeneralUtility::_GP('id'); @@ -145,10 +145,10 @@ class BackendController extends ActionController { if (version_compare(\TYPO3\CMS\Core\Utility\VersionNumberUtility::getCurrentTypo3Version(), '11.0.0', '<')) { $this->view->assign('V11', FALSE); return NULL; - } else { - $this->view->assign('V11', TRUE); - return $this->createBackendResponse(); } + + $this->view->assign('V11', TRUE); + return $this->createBackendResponse(); } /** diff --git a/Classes/Controller/JobTeaserController.php b/Classes/Controller/JobTeaserController.php index f32858a6d04ac7f749c5c46210c19f1dd3304d34..071513536d1154cc666a5c569ec3419a53212ecb 100644 --- a/Classes/Controller/JobTeaserController.php +++ b/Classes/Controller/JobTeaserController.php @@ -37,7 +37,7 @@ class JobTeaserController extends ActionController { /** * @var JobRepository */ - protected $jobRepository; + protected JobRepository $jobRepository; /** * @param JobRepository $jobRepository @@ -69,13 +69,14 @@ class JobTeaserController extends ActionController { if (version_compare(\TYPO3\CMS\Core\Utility\VersionNumberUtility::getCurrentTypo3Version(), '11.0.0', '<')) { return NULL; - } else { - return $this->htmlResponse(); } + + return $this->htmlResponse(); } /** * Build Typo3 11 Response + * * @param string|NULL $html * @return \Psr\Http\Message\ResponseInterface */ diff --git a/Classes/Controller/JoblistController.php b/Classes/Controller/JoblistController.php index d174a1b6aed4e82c17592a6a8eeb8602cf96a7d9..8907f8f4a4734e744b91029ef6a6aa39736d93ee 100644 --- a/Classes/Controller/JoblistController.php +++ b/Classes/Controller/JoblistController.php @@ -26,6 +26,7 @@ namespace SGalinski\SgJobs\Controller; * This copyright notice MUST APPEAR in all copies of the script! ***************************************************************/ +use Psr\Http\Message\ResponseInterface; use SGalinski\ProjectBase\Domain\Repository\CountryRepository; use SGalinski\SgJobs\Domain\Model\Company; use SGalinski\SgJobs\Domain\Model\Job; @@ -39,8 +40,16 @@ use SGalinski\SgJobs\Service\FileAndFolderService; use SGalinski\SgMail\Service\MailTemplateService; use SGalinski\SgSeo\Service\HeadTagService; use TYPO3\CMS\Core\Context\Context; +use TYPO3\CMS\Core\Context\Exception\AspectNotFoundException; use TYPO3\CMS\Core\Core\Environment; +use TYPO3\CMS\Core\Error\Http\PageNotFoundException; +use TYPO3\CMS\Core\Exception\SiteNotFoundException; use TYPO3\CMS\Core\Http\ImmediateResponseException; +use TYPO3\CMS\Core\Resource\Exception\ExistingTargetFileNameException; +use TYPO3\CMS\Core\Resource\Exception\ExistingTargetFolderException; +use TYPO3\CMS\Core\Resource\Exception\InsufficientFolderAccessPermissionsException; +use TYPO3\CMS\Core\Resource\Exception\InsufficientFolderReadPermissionsException; +use TYPO3\CMS\Core\Resource\Exception\InsufficientFolderWritePermissionsException; use TYPO3\CMS\Core\Resource\ResourceFactory; use TYPO3\CMS\Core\Site\SiteFinder; use TYPO3\CMS\Core\Utility\ExtensionManagementUtility; @@ -73,32 +82,32 @@ class JoblistController extends ActionController { /** * @var CompanyRepository */ - protected $companyRepository; + protected CompanyRepository $companyRepository; /** * @var JobRepository */ - protected $jobRepository; + protected JobRepository $jobRepository; /** * @var JobApplicationRepository */ - protected $jobApplicationRepository; + protected JobApplicationRepository $jobApplicationRepository; /** * @var DepartmentRepository */ - protected $departmentRepository; + protected DepartmentRepository $departmentRepository; /** * @var ExperienceLevelRepository */ - protected $experienceLevelRepository; + protected ExperienceLevelRepository $experienceLevelRepository; /** * @var FileAndFolderService */ - protected $fileAndFolderService; + protected FileAndFolderService $fileAndFolderService; /** * Inject the CompanyRepository @@ -112,7 +121,7 @@ class JoblistController extends ActionController { /** * Inject the CompanyRepository * - * @param CompanyRepository $companyRepository + * @param FileAndFolderService $fileAndFolderService */ public function injectFileAndFolderService(FileAndFolderService $fileAndFolderService): void { $this->fileAndFolderService = $fileAndFolderService; @@ -156,13 +165,10 @@ class JoblistController extends ActionController { /** * Initialize the indexAction to set the currentPageBrowserPage parameter - * - * @throws \TYPO3\CMS\Extbase\Mvc\Exception\InvalidArgumentNameException */ - public function initializeIndexAction() { - $currentPageBrowserPage = GeneralUtility::_GP('tx_sgjobs_pagebrowser') ? (int) GeneralUtility::_GP( - 'tx_sgjobs_pagebrowser' - )['currentPage'] : 0; + public function initializeIndexAction(): void { + $currentPageBrowserPage = GeneralUtility::_GP('tx_sgjobs_pagebrowser') ? + (int) GeneralUtility::_GP('tx_sgjobs_pagebrowser')['currentPage'] : 0; if ($currentPageBrowserPage > 0) { $this->request->setArgument('currentPageBrowserPage', $currentPageBrowserPage); } @@ -172,18 +178,18 @@ class JoblistController extends ActionController { * Show all job offers and options to manage them * * @param array $filters - * @param int $jobId + * @param int|null $jobId * @param int $currentPageBrowserPage - * @throws \TYPO3\CMS\Core\Context\Exception\AspectNotFoundException - * @throws \TYPO3\CMS\Core\Error\Http\PageNotFoundException + * @return ResponseInterface|null * @throws ImmediateResponseException - * @throws \TYPO3\CMS\Core\Package\Exception + * @throws AspectNotFoundException + * @throws PageNotFoundException */ public function indexAction( array $filters = [], int $jobId = NULL, int $currentPageBrowserPage = 0 - ): ?\Psr\Http\Message\ResponseInterface { + ): ?ResponseInterface { if ($filters) { $this->view->assign('selectedCountry', $filters['filterCountry'] ?? ''); $this->view->assign('selectedCompany', $filters['filterCompany'] ?? ''); @@ -264,9 +270,9 @@ class JoblistController extends ActionController { if (version_compare(\TYPO3\CMS\Core\Utility\VersionNumberUtility::getCurrentTypo3Version(), '11.0.0', '<')) { return NULL; - } else { - return $this->htmlResponse(); } + + return $this->htmlResponse(); } /** @@ -274,16 +280,17 @@ class JoblistController extends ActionController { * * @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 + * @param int|null $jobId + * @return ResponseInterface|null + * @throws AspectNotFoundException + * @throws StopActionException + * @throws SiteNotFoundException */ public function applyFormAction( JobApplication $applyData = NULL, string $error = '', int $jobId = NULL - ): ?\Psr\Http\Message\ResponseInterface { + ): ?ResponseInterface { if ($error !== '') { $this->view->assign('internalError', $error); $this->request->setArgument('error', NULL); @@ -383,9 +390,9 @@ class JoblistController extends ActionController { if (version_compare(\TYPO3\CMS\Core\Utility\VersionNumberUtility::getCurrentTypo3Version(), '11.0.0', '<')) { return NULL; - } else { - return $this->htmlResponse(); } + + return $this->htmlResponse(); } /** @@ -394,9 +401,9 @@ class JoblistController extends ActionController { * @param JobApplication $applicationData * @param string $folderName * @return void - * @throws \TYPO3\CMS\Extbase\Mvc\Exception\StopActionException + * @throws StopActionException */ - protected function submitApplicationFiles(JobApplication $applicationData, $folderName): void { + protected function submitApplicationFiles(JobApplication $applicationData, string $folderName): void { $resourceFactory = $this->objectManager->get(ResourceFactory::class); $newName = \date('Ymd-His') . '_' . $applicationData->getJobId() . '-' . $applicationData->getFirstName() . '-' . $applicationData->getLastName(); @@ -411,28 +418,9 @@ class JoblistController extends ActionController { * Pre-apply action setup, configures model-property mapping and handles file upload * * @throws NoSuchArgumentException - * @throws \TYPO3\CMS\Extbase\Mvc\Exception\StopActionException + * @throws StopActionException */ - protected function initializeApplyAction() { - $arguments = ($this->request->getArguments()); - $parsedBody = $this->request->getParsedBody(); - $uniqueFolderName = $arguments['folderName'] ?? ''; - try { - $uniqueFolderName = $this->request->getArgument('folderName'); - } catch (NoSuchArgumentException $exception) { - $exceptionMessage = LocalizationUtility::translate('error.NoSuchArgumentException', 'sg_jobs'); - - if (version_compare( - \TYPO3\CMS\Core\Utility\VersionNumberUtility::getCurrentTypo3Version(), - '11.0.0', - '<' - )) { - $this->redirect('applyForm', NULL, NULL, ['error' => $exceptionMessage]); - return NULL; - } else { - return $this->redirect('applyForm', NULL, NULL, ['error' => $exceptionMessage]); - } - } + protected function initializeApplyAction(): void { $propertyMappingConfiguration = $this->arguments->getArgument('applyData')->getPropertyMappingConfiguration(); $propertyMappingConfiguration->forProperty('job')->allowAllProperties(); @@ -453,11 +441,11 @@ class JoblistController extends ActionController { * Saves the application send by the applyFormAction * * @param JobApplication $applyData + * @return ResponseInterface|null * @throws NoSuchArgumentException - * @throws \TYPO3\CMS\Extbase\Mvc\Exception\InvalidArgumentNameException - * @throws \TYPO3\CMS\Extbase\Mvc\Exception\StopActionException + * @throws StopActionException */ - public function applyAction(JobApplication $applyData): ?\Psr\Http\Message\ResponseInterface { + public function applyAction(JobApplication $applyData): ?ResponseInterface { $folderName = $this->request->getArgument('folderName'); try { @@ -560,18 +548,18 @@ class JoblistController extends ActionController { if (version_compare(\TYPO3\CMS\Core\Utility\VersionNumberUtility::getCurrentTypo3Version(), '11.0.0', '<')) { return NULL; - } else { - return $this->htmlResponse(); } + + return $this->htmlResponse(); } /** * Assign filter values * * @param int $rootPageId - * @throws \TYPO3\CMS\Core\Context\Exception\AspectNotFoundException + * @throws AspectNotFoundException */ - protected function assignFilterValues($rootPageId): void { + protected function assignFilterValues(int $rootPageId): void { $countries = $this->companyRepository->getAllCountries($rootPageId); $this->view->assign('countries', $countries); @@ -620,9 +608,9 @@ class JoblistController extends ActionController { * * @param JobApplication $data * @param string $filePath - * @throws \TYPO3\CMS\Extbase\Mvc\Exception\StopActionException + * @throws StopActionException */ - protected function writeApplicationFile(JobApplication $data, $filePath): void { + protected function writeApplicationFile(JobApplication $data, string $filePath): void { $coverLetter = ''; $coverLetterObject = $data->getCoverLetter(); if ($coverLetterObject) { @@ -684,14 +672,15 @@ class JoblistController extends ActionController { * Move the temp folder to its proper location * * @param string $folderName - * @throws \TYPO3\CMS\Core\Resource\Exception\ExistingTargetFileNameException - * @throws \TYPO3\CMS\Core\Resource\Exception\ExistingTargetFolderException - * @throws \TYPO3\CMS\Core\Resource\Exception\InsufficientFolderAccessPermissionsException - * @throws \TYPO3\CMS\Core\Resource\Exception\InsufficientFolderWritePermissionsException + * @param JobApplication $applicationData + * @throws TypeConverterException + * @throws ExistingTargetFileNameException + * @throws ExistingTargetFolderException + * @throws InsufficientFolderAccessPermissionsException + * @throws InsufficientFolderReadPermissionsException + * @throws InsufficientFolderWritePermissionsException */ protected function moveTmpFolder(string $folderName, JobApplication $applicationData): void { - $filePathInfo = []; - $namesToMove = []; $allowedFileExtensions = $this->getAllowedFileExtensions(); /** @var ResourceFactory $resourceFactory */ @@ -712,35 +701,39 @@ class JoblistController extends ActionController { if (array_key_exists($singleFilePostKey, $_POST)) { foreach ($_POST[$singleFilePostKey] as $singleUploadedArr) { $filePathInfo = PathUtility::pathinfo($singleUploadedArr['path']); - $namesToMove[] = $filePathInfo['basename']; if (!GeneralUtility::inList($allowedFileExtensions, strtolower($filePathInfo['extension']))) { - throw new TypeConverterException(LocalizationUtility::translate('error.TypeConverterException.type', 'sg_jobs'), 1399312430); + throw new TypeConverterException( + LocalizationUtility::translate('error.TypeConverterException.type', 'sg_jobs'), 1399312430 + ); } if (!$newFolder->hasFile($filePathInfo['basename'])) { + /** @noinspection PhpUnreachableStatementInspection */ $singleFileToMove = $storage->getFileInFolder($filePathInfo['basename'], $tempFolder); - // when we reload etc this image might already be moved. + // when we reload etc. this image might already be moved. $usableFile = $storage->moveFile($singleFileToMove, $newFolder); } else { + /** @noinspection PhpUnreachableStatementInspection */ $usableFile = $newFolder->getFile($filePathInfo['basename']); } $fileReference = $this->fileAndFolderService->createFileReferenceFromFalFileObject($usableFile); - if ($fileReference) { - if ($singleFilePostKey === 'coverLetter') { - $applicationData->setCoverLetter($fileReference); - } - if ($singleFilePostKey === 'cv') { - $applicationData->setCV($fileReference); - } - if ($singleFilePostKey === 'certificate') { - $applicationData->setCertificate($fileReference); - } + if ($singleFilePostKey === 'coverLetter') { + $applicationData->setCoverLetter($fileReference); + } + if ($singleFilePostKey === 'cv') { + $applicationData->setCV($fileReference); + } + if ($singleFilePostKey === 'certificate') { + $applicationData->setCertificate($fileReference); } - continue; } } else { - throw new TypeConverterException(LocalizationUtility::translate('error.TypeConverterException.missing.' . $singleFilePostKey, 'sg_jobs'), 1399312430); + throw new TypeConverterException( + LocalizationUtility::translate( + 'error.TypeConverterException.missing.' . $singleFilePostKey, 'sg_jobs' + ), 1399312430 + ); } } } @@ -759,7 +752,7 @@ class JoblistController extends ActionController { * * @param string $folderName */ - protected function deleteTmpFolder($folderName): void { + protected function deleteTmpFolder(string $folderName): void { /** @var ResourceFactory $resourceFactory */ $resourceFactory = $this->objectManager->get(ResourceFactory::class); $storage = $resourceFactory->getStorageObject(1); @@ -774,7 +767,7 @@ class JoblistController extends ActionController { /** * If for any reason something goes wrong, delete the tmp upload folder * - * @return mixed + * @return ResponseInterface * @throws NoSuchArgumentException */ public function errorAction() { @@ -787,12 +780,12 @@ class JoblistController extends ActionController { } /** - * Build Typo3 11 Response + * Build TYPO3 11 Response * * @param string|NULL $html - * @return \Psr\Http\Message\ResponseInterface + * @return ResponseInterface */ - protected function htmlResponse(string $html = NULL): \Psr\Http\Message\ResponseInterface { + protected function htmlResponse(string $html = NULL): ResponseInterface { return $this->responseFactory->createResponse() ->withHeader('Content-Type', 'text/html; charset=utf-8') ->withBody($this->streamFactory->createStream($html ?? $this->view->render())); diff --git a/Classes/Domain/Repository/JobRepository.php b/Classes/Domain/Repository/JobRepository.php index d64ae6d15fa2d92ca25a7344456e6c45f756e74f..4955e0e9e9f5dc1043e4b818d6a0f818b6ff56f9 100644 --- a/Classes/Domain/Repository/JobRepository.php +++ b/Classes/Domain/Repository/JobRepository.php @@ -56,10 +56,10 @@ class JobRepository extends Repository { * @param array $filters * @param int $limit * @param int $offset - * @return mixed + * @return ExtbaseQueryResultInterface|object[] * @throws \TYPO3\CMS\Extbase\Persistence\Exception\InvalidQueryException */ - public function findBackendJobs($recordPageId, array $filters = [], $limit = 0, $offset = 0) { + public function findBackendJobs(int $recordPageId, array $filters = [], int $limit = 0, int $offset = 0) { $query = $this->createQuery(); $query->setOrderings( [ @@ -166,13 +166,18 @@ class JobRepository extends Repository { */ public function findJobsByFilter( array $filters = [], - $limit = 0, - $offset = 0, - $ordering = 0 + int $limit = 0, + int $offset = 0, + int $ordering = 0 ): ExtbaseQueryResultInterface { $query = $this->createQuery(); - $storagePageIds = $query->getQuerySettings()->getStoragePageIds(); + + // we always show all jobs (translated or only created in the specific language) + $querySettings = $query->getQuerySettings(); + $querySettings->setLanguageOverlayMode(FALSE); + $query->setQuerySettings($querySettings); + if (empty($storagePageIds)) { // if no record storage page has been selected in the plugin, ignore it $query->getQuerySettings()->setRespectStoragePage(FALSE);