Skip to content
Snippets Groups Projects
Commit df3b3581 authored by Torsten Oppermann's avatar Torsten Oppermann
Browse files

[TASK] Removed unncessary ajax code

parent ed57b2bd
No related branches found
No related tags found
No related merge requests found
<?php
namespace SGalinski\SgJobs\Controller\Ajax;
/***************************************************************
* 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\SgAjax\Controller\Ajax\AbstractAjaxController;
use SGalinski\SgJobs\Service\FrontendFilterService;
use TYPO3\CMS\Core\Resource\ResourceFactory;
use TYPO3\CMS\Core\Utility\GeneralUtility;
/**
* Ajax Controller
*/
class JoblistController extends AbstractAjaxController {
/**
* @var \SGalinski\SgJobs\Domain\Repository\CompanyRepository
* @inject
*/
private $companyRepository;
/**
* @var \SGalinski\SgJobs\Domain\Repository\JobRepository
* @inject
*/
private $jobRepository;
/**
* Show all job offers and options to manage them
*
* @return void
* @throws \InvalidArgumentException
*/
public function filterAction() {
$recordPageId = (int) $_POST['recordPageId'];
$filters = [
'country' => $_POST['parameters']['country'],
'location' => $_POST['parameters']['location'],
'company' => $_POST['parameters']['company'],
'area' => $_POST['parameters']['area'],
'function' => $_POST['parameters']['function'],
];
$this->assignFilterValues($recordPageId);
// pagination logic
$jobLimit = (int) $_POST['parameters']['limit'];
$offset = 0;
$currentPageBrowserPage = (int) GeneralUtility::_GP('tx_sgjobs_pagebrowser')['currentPage'];
if ($currentPageBrowserPage && $jobLimit) {
$offset = $currentPageBrowserPage * $jobLimit;
}
// get all jobs for the current page
$jobs = FrontendFilterService::getJobs($filters, $recordPageId, $jobLimit, $offset);
// get the amount of all filtered jobs
$jobsCount = \count(FrontendFilterService::getJobs($filters, $recordPageId));
$numberOfPages = ($jobLimit <= 0 ? 0 : ceil($jobsCount / $jobLimit));
$this->view->assign('jobs', $jobs);
$this->view->assign('numberOfPages', $numberOfPages);
// set default selected values
$this->view->assign('selectedCountry', $filters['country']);
$this->view->assign('selectedCompany', $filters['company']);
$this->view->assign('selectedLocation', $filters['location']);
$this->view->assign('selectedArea', $filters['area']);
$this->view->assign('selectedFunction', $filters['function']);
$this->view->assign('limit', $jobLimit);
$this->view->assign('recordPageId', $recordPageId);
}
/**
* Delete an uploaded file from temp storage
*
* @return void
* @throws \TYPO3\CMS\Core\Resource\Exception\InsufficientFileAccessPermissionsException
* @throws \TYPO3\CMS\Core\Resource\Exception\FileOperationErrorException
* @throws \InvalidArgumentException
*/
public function deleteTempFileAction() {
$file = $_POST['file'];
$type = $_POST['type'];
$resourceFactory = GeneralUtility::makeInstance(ResourceFactory::class);
$storage = $resourceFactory->getStorageObject(1);
$fileObject = $storage->getFile('/Extension/temp/' . $GLOBALS['TSFE']->fe_user->id . '/' . $type . '/' . $file);
$storage->deleteFile($fileObject);
}
/**
* Assign filter values
*
* @param int $rootPageId
*/
private function assignFilterValues($rootPageId) {
$countries = $this->companyRepository->getAllCountries($rootPageId);
$this->view->assign('countries', $countries);
$cities = $this->companyRepository->getAllCities($rootPageId);
$this->view->assign('cities', $cities);
$companies = $this->companyRepository->getAllCompanyNames($rootPageId);
$this->view->assign('companies', $companies);
$areas = $this->jobRepository->getAllAreas($rootPageId);
$this->view->assign('areas', $areas);
$functions = $this->jobRepository->getAllFunctions($rootPageId);
$this->view->assign('functions', $functions);
}
}
{namespace sg=SGalinski\SgJobs\ViewHelpers}
<f:render
partial="Filter"
arguments="{recordPageId: recordPageId, filters: filters, countries: countries, cities: cities, companies: companies, areas: areas,
functions: functions, selectedCountry: selectedCountry, selectedCompany: selectedCompany,
selectedLocation: selectedLocation, selectedArea: selectedArea, selectedFunction: selectedFunction, limit: limit}"
/>
<f:for each="{jobs}" as="job">
<f:render partial="Job" arguments="{job: job}" />
</f:for>
<div id="sgjobs-pagination">
<f:format.raw>
<sg:pageBrowser numberOfPages="{numberOfPages}" />
</f:format.raw>
</div>
......@@ -33,14 +33,6 @@
['PageBrowser' => '',]
);
// Configure ajax controller
\SGalinski\SgAjax\Service\AjaxRegistration::configureAjaxFrontendPlugin(
'sg_jobs', [
'Ajax\Joblist' => 'filter',
'Ajax\JobApplication' => 'deleteTempFile',
]
);
if (TYPO3_MODE === 'BE') {
$extPath = \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath('sg_jobs');
$tsPath = $extPath . 'Configuration/TypoScript/Backend/';
......
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