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

[TASK] Fixed record location, backend view

parent 209cf43d
No related branches found
No related tags found
No related merge requests found
......@@ -30,11 +30,13 @@ use SGalinski\SgJobs\Domain\Model\Company;
use SGalinski\SgJobs\Service\BackendService;
use TYPO3\CMS\Backend\Template\Components\DocHeaderComponent;
use TYPO3\CMS\Backend\Utility\BackendUtility;
use TYPO3\CMS\Core\Messaging\FlashMessage;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Utility\VersionNumberUtility;
use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
use TYPO3\CMS\Extbase\Persistence\ObjectStorage;
use TYPO3\CMS\Extbase\Persistence\QueryResultInterface;
use TYPO3\CMS\Extbase\Utility\LocalizationUtility;
/**
* The backend module controller
......@@ -87,19 +89,20 @@ class BackendController extends ActionController {
BackendService::makeButtons($this->docHeaderComponent, $this->request);
$this->view->assign('docHeader', $this->docHeaderComponent->docHeaderContent());
list($totalJobCount, $jobs) = BackendService::getJobsByPid($pageUid, $filters);
debug($totalJobCount);
// when we are on a siteroot page then display the normal view
// get all jobs
/** @var ObjectStorage $jobs */
$jobs = $this->jobRepository->findJobs($pageUid, $filters);
$totalJobCount = $jobs->count();
$this->view->assign('pages', BackendService::getPagesWithJobRecords());
$this->view->assign('pageUid', $pageUid);
if ($totalJobCount) {
// get all jobs
/** @var ObjectStorage $jobs */
$jobs = $this->jobRepository->findJobs($this->rootPageUid, $filters);
$this->view->assign('jobs', $jobs);
// get all Locations
/** @noinspection PhpUndefinedMethodInspection */
/** @var QueryResultInterface $categories */
$companies = $this->companyRepository->findByPid($this->rootPageUid);
$companies = $this->companyRepository->findByPid($pageUid);
$locationOptions = [];
/** @var Company $companies */
......@@ -113,13 +116,15 @@ class BackendController extends ActionController {
$this->view->assign('rootPageUid', $this->rootPageUid);
$this->view->assign('typo3Version', VersionNumberUtility::convertVersionNumberToInteger(TYPO3_version));
} else {
$this->view->assign('pages', BackendService::getPagesWithJobRecords());
$this->view->assign('noRecords', 1);
$this->addFlashMessage(
LocalizationUtility::translate('backend.notice.noRecords', 'SgJobs'), '', FlashMessage::INFO
);
}
} catch (\Exception $exception) {
// check for NULL value in view and render an error message
$this->view->assign('docHeader', NULL);
}
}
}
......@@ -29,14 +29,12 @@ namespace SGalinski\SgJobs\Service;
use TYPO3\CMS\Backend\Template\Components\ButtonBar;
use TYPO3\CMS\Backend\Template\Components\DocHeaderComponent;
use TYPO3\CMS\Backend\Utility\BackendUtility;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Database\DatabaseConnection;
use TYPO3\CMS\Core\Imaging\Icon;
use TYPO3\CMS\Core\Imaging\IconFactory;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Mvc\Request;
use TYPO3\CMS\Extbase\Utility\LocalizationUtility;
use TYPO3\CMS\Recordlist\RecordList\DatabaseRecordList;
/**
* Backend Service class
......@@ -207,50 +205,4 @@ class BackendService {
}
return $out;
}
/**
* Counts the job records on the specified page and returns users records based on the filter options
*
* @param int $pid
* @param array $filters
* @return array
* @throws \InvalidArgumentException
*/
public static function getJobsByPid($pid, array $filters = []): array {
$pid = (int) $pid;
$tableName = 'fe_users';
/** @var $databaseConnection DatabaseConnection */
$databaseConnection = $GLOBALS['TYPO3_DB'];
/** @var DatabaseRecordList $databaseRecordList */
$databaseRecordList = GeneralUtility::makeInstance(DatabaseRecordList::class);
$databaseRecordList->start($pid, $tableName, 0);
$databaseRecordList->setTotalItems($tableName, $pid, []);
$totalUserCount = (int) $databaseRecordList->totalItems;
if (trim($filters['search'])) {
$databaseRecordList->start($pid, $tableName, 0, trim($filters['search']));
}
$queryBuilder = $databaseRecordList->getQueryBuilder($tableName, $pid);
if ($filters['usergroups'] && count($filters['usergroups'])) {
$expressionBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
->getConnectionForTable($tableName)
->getExpressionBuilder();
$groupConstraints = [];
/** @var array $usergroups */
$usergroups = $filters['usergroups'];
foreach ($usergroups as $groupUid) {
$groupUid = (int) $groupUid;
if ($groupUid) {
$groupConstraints[] = $expressionBuilder->inSet($tableName . '.usergroup', $groupUid);
}
}
if (count($groupConstraints)) {
$groupConstraint = call_user_func_array([$expressionBuilder, 'orX'], $groupConstraints);
$queryBuilder = $databaseRecordList->getQueryBuilder($tableName, $pid, [$groupConstraint]);
}
}
$users = $queryBuilder->execute()->fetchAll();
return [$totalUserCount, $users];
}
}
......@@ -110,6 +110,10 @@
<source>There are no jobs that match your criteria</source>
<target>Es gibt keine Stellenangebote für Ihre Suchkriterien</target>
</trans-unit>
<trans-unit id="backend.notice.noRecords" approved="yes">
<source>There are no records on this page</source>
<target>Es gibt keine Datensätze auf dieser Seite</target>
</trans-unit>
<trans-unit id="backend.selectRootPage" approved="yes">
<source>Please select one of the following website roots:</source>
<target>Bitte wählen Sie eine der folgenden Seiten aus:</target>
......
......@@ -84,6 +84,9 @@
<trans-unit id="backend.noJobsMessage">
<source>There are no jobs that match your criteria</source>
</trans-unit>
<trans-unit id="backend.notice.noRecords">
<source>There are no records on this page</source>
</trans-unit>
<trans-unit id="backend.selectRootPage">
<source>Please select one of the following website roots:</source>
</trans-unit>
......
......@@ -9,30 +9,42 @@
<f:translate key="backend.jobs.header" />
</f:section>
<f:section name="content">
<f:if condition="{docHeader}">
<f:flashMessages />
<f:if condition="{pageUid}">
<f:then>
<f:if condition="{pages}">
<f:if condition="{docHeader}">
<f:then>
<f:render partial="SelectRoot" arguments="{pages: pages}" />
</f:then>
<f:else>
<f:render partial="Filter" arguments="{filters: filters, locationOptions: locationOptions}" />
<f:render partial="CreateJob" arguments="{rootPageUid:rootPageUid}" />
<f:if condition="{jobs}">
<f:if condition="{noRecords}">
<f:then>
<f:render partial="JobList" arguments="{jobs: jobs}" />
</f:then>
<f:else>
<p>
<f:translate key="backend.noJobsMessage" />
</p>
<f:render partial="CreateJob" arguments="{rootPageUid:rootPageUid}" />
</f:then>
<f:else>
<f:render partial="Filter" arguments="{filters: filters, locationOptions: locationOptions}" />
<f:render partial="CreateJob" arguments="{rootPageUid:rootPageUid}" />
<f:if condition="{jobs}">
<f:then>
<f:render partial="JobList" arguments="{jobs: jobs}" />
</f:then>
<f:else>
<p>
<f:translate key="backend.noJobsMessage" />
</p>
</f:else>
</f:if>
</f:else>
</f:if>
</f:then>
<f:else>
<f:render partial="Error" />
</f:else>
</f:if>
</f:then>
<f:else>
<f:render partial="Error" />
<f:render partial="SelectRoot" arguments="{pages: pages}" />
</f:else>
</f:if>
</f:section>
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