Initial commit - Typo3 11.5.41
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
namespace SJBR\StaticInfoTables\Hook\Backend\Form\FormDataProvider;
|
||||
|
||||
/*
|
||||
* Copyright notice
|
||||
*
|
||||
* (c) 2017 Stanislas Rolland <typo3(arobas)sjbr.ca>
|
||||
* 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 2 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 SJBR\StaticInfoTables\Utility\LocalizationUtility;
|
||||
use TYPO3\CMS\Backend\Form\Wizard\SuggestWizardDefaultReceiver;
|
||||
|
||||
/**
|
||||
* Processor for suggest items
|
||||
*/
|
||||
class SuggestLabelProcessor
|
||||
{
|
||||
/**
|
||||
* Translate label of entity in suggest selector
|
||||
*
|
||||
* @param array $params: table, uid, row, entry
|
||||
* @param SuggestWizardDefaultReceiver $parentObj
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function translateLabel(array &$params, SuggestWizardDefaultReceiver $parentObj)
|
||||
{
|
||||
$path = $params['entry']['path'];
|
||||
if (mb_strlen($path, 'utf-8') > 30) {
|
||||
$croppedPath = '<abbr title="' . htmlspecialchars($path) . '">' .
|
||||
htmlspecialchars(
|
||||
mb_substr($path, 0, 10, 'utf-8')
|
||||
. '...'
|
||||
. mb_substr($path, -20, null, 'utf-8')
|
||||
) .
|
||||
'</abbr>';
|
||||
} else {
|
||||
$croppedPath = htmlspecialchars($path);
|
||||
}
|
||||
$label = LocalizationUtility::translate(['uid' => $params['uid']], $params['table']);
|
||||
$params['entry']['text'] = '<span class="suggest-label">' . $label . '</span><span class="suggest-uid">[' . $params['uid'] . ']</span><br />
|
||||
<span class="suggest-path">' . $croppedPath . '</span>';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,136 @@
|
||||
<?php
|
||||
namespace SJBR\StaticInfoTables\Hook\Backend\Form\FormDataProvider;
|
||||
|
||||
/*
|
||||
* Copyright notice
|
||||
*
|
||||
* (c) 2013-2022 Stanislas Rolland <typo3AAAA(arobas)sjbr.ca>
|
||||
* 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 2 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 Psr\Http\Message\ServerRequestInterface;
|
||||
use SJBR\StaticInfoTables\Domain\Model\Country;
|
||||
use SJBR\StaticInfoTables\Domain\Model\Currency;
|
||||
use SJBR\StaticInfoTables\Domain\Model\Language;
|
||||
use SJBR\StaticInfoTables\Domain\Model\Territory;
|
||||
use SJBR\StaticInfoTables\Domain\Repository\CountryRepository;
|
||||
use SJBR\StaticInfoTables\Domain\Repository\CurrencyRepository;
|
||||
use SJBR\StaticInfoTables\Domain\Repository\LanguageRepository;
|
||||
use SJBR\StaticInfoTables\Domain\Repository\TerritoryRepository;
|
||||
use SJBR\StaticInfoTables\Utility\LocalizationUtility;
|
||||
use TYPO3\CMS\Core\Http\ApplicationType;
|
||||
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
||||
|
||||
/**
|
||||
* Processor for TCA select items
|
||||
*/
|
||||
class TcaLabelProcessor
|
||||
{
|
||||
/**
|
||||
* @var TerritoryRepository
|
||||
*/
|
||||
protected $territoryRepository;
|
||||
|
||||
/**
|
||||
* @param TerritoryRepository $territoryRepository
|
||||
*/
|
||||
public function injectTerritoryRepository(TerritoryRepository $territoryRepository)
|
||||
{
|
||||
$this->territoryRepository = $territoryRepository;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add ISO codes to the label of entities
|
||||
*
|
||||
* @param array $PA: parameters: items, config, TSconfig, table, row, field
|
||||
* @return void
|
||||
*/
|
||||
public function addIsoCodeToLabel(&$PA)
|
||||
{
|
||||
if (!isset($PA['row']['uid'])) {
|
||||
return;
|
||||
}
|
||||
$PA['title'] = LocalizationUtility::translate(['uid' => $PA['row']['uid']], $PA['table']);
|
||||
if (($GLOBALS['TYPO3_REQUEST'] ?? null) instanceof ServerRequestInterface
|
||||
&& ApplicationType::fromRequest($GLOBALS['TYPO3_REQUEST'])->isBackend()) {
|
||||
switch ($PA['table']) {
|
||||
case 'static_territories':
|
||||
$isoCode = $PA['row']['tr_iso_nr'] ?? 0;
|
||||
if (!$isoCode) {
|
||||
$territory = $this->territoryRepository->findByUid($PA['row']['uid']);
|
||||
if ($territory instanceof Territory) {
|
||||
$isoCode = $territory->getUnCodeNumber();
|
||||
}
|
||||
}
|
||||
if ($isoCode) {
|
||||
$PA['title'] .= ' (' . $isoCode . ')';
|
||||
}
|
||||
break;
|
||||
case 'static_countries':
|
||||
$isoCode = $PA['row']['cn_iso_2'] ?? '';
|
||||
if (!$isoCode) {
|
||||
$countryRepository = GeneralUtility::makeInstance(CountryRepository::class);
|
||||
$country = $countryRepository->findByUid($PA['row']['uid']);
|
||||
if ($country instanceof Country) {
|
||||
$isoCode = $country->getIsoCodeA2();
|
||||
}
|
||||
}
|
||||
if ($isoCode) {
|
||||
$PA['title'] .= ' (' . $isoCode . ')';
|
||||
}
|
||||
break;
|
||||
case 'static_languages':
|
||||
$isoCodes = [$PA['row']['lg_iso_2'] ?? ''];
|
||||
if ($PA['row']['lg_country_iso_2'] ?? '') {
|
||||
$isoCodes[] = $PA['row']['lg_country_iso_2'];
|
||||
}
|
||||
$isoCode = implode('_', $isoCodes);
|
||||
if (!$isoCode || !($PA['row']['lg_country_iso_2'] ?? '')) {
|
||||
$languageRepository = GeneralUtility::makeInstance(LanguageRepository::class);
|
||||
$language = $languageRepository->findByUid($PA['row']['uid']);
|
||||
if ($language instanceof Language) {
|
||||
$isoCodes = [$language->getIsoCodeA2()];
|
||||
if ($language->getCountryIsoCodeA2()) {
|
||||
$isoCodes[] = $language->getCountryIsoCodeA2();
|
||||
}
|
||||
$isoCode = implode('_', $isoCodes);
|
||||
}
|
||||
}
|
||||
if ($isoCode) {
|
||||
$PA['title'] .= ' (' . $isoCode . ')';
|
||||
}
|
||||
break;
|
||||
case 'static_currencies':
|
||||
$isoCode = $PA['row']['cu_iso_3'] ?? '';
|
||||
if (!$isoCode) {
|
||||
$currencyRepository = GeneralUtility::makeInstance(CurrencyRepository::class);
|
||||
$currency = $currencyRepository->findByUid($PA['row']['uid']);
|
||||
if ($currency instanceof Currency) {
|
||||
$isoCode = $currency->getIsoCodeA3();
|
||||
}
|
||||
}
|
||||
if ($isoCode) {
|
||||
$PA['title'] .= ' (' . $isoCode . ')';
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,280 @@
|
||||
<?php
|
||||
namespace SJBR\StaticInfoTables\Hook\Backend\Form\FormDataProvider;
|
||||
|
||||
/*
|
||||
* Copyright notice
|
||||
*
|
||||
* (c) 2013-2022 Stanislas Rolland <typo3AAAA(arobas)sjbr.ca>
|
||||
* 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 2 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 SJBR\StaticInfoTables\Domain\Model\Country;
|
||||
use SJBR\StaticInfoTables\Domain\Model\CountryZone;
|
||||
use SJBR\StaticInfoTables\Domain\Model\Currency;
|
||||
use SJBR\StaticInfoTables\Domain\Model\Language;
|
||||
use SJBR\StaticInfoTables\Domain\Model\Territory;
|
||||
use SJBR\StaticInfoTables\Domain\Repository\CountryRepository;
|
||||
use SJBR\StaticInfoTables\Domain\Repository\CountryZoneRepository;
|
||||
use SJBR\StaticInfoTables\Domain\Repository\CurrencyRepository;
|
||||
use SJBR\StaticInfoTables\Domain\Repository\LanguageRepository;
|
||||
use SJBR\StaticInfoTables\Domain\Repository\TerritoryRepository;
|
||||
use SJBR\StaticInfoTables\Utility\LocalizationUtility;
|
||||
use TYPO3\CMS\Backend\Form\FormDataProvider\TcaSelectItems;
|
||||
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
||||
use TYPO3\CMS\Extbase\Persistence\Generic\Mapper\DataMapper;
|
||||
|
||||
/**
|
||||
* Processor for TCA select items
|
||||
*/
|
||||
class TcaSelectItemsProcessor
|
||||
{
|
||||
/**
|
||||
* Translate and sort the territories selector using the current locale
|
||||
*
|
||||
* @param array $PA: parameters: items, config, TSconfig, table, row, field
|
||||
* @param DataPreprocessor $fObj
|
||||
* @return void
|
||||
*/
|
||||
public function translateTerritoriesSelector($PA, TcaSelectItems $fObj)
|
||||
{
|
||||
switch ($PA['table'] ?? '') {
|
||||
case 'static_territories':
|
||||
// Avoid circular relation
|
||||
$row = $PA['row'] ?? [];
|
||||
foreach (($PA['items'] ?? []) as $index => $item) {
|
||||
if ($item[1] == $row['uid']) {
|
||||
unset($PA['items'][$index]);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
$PA['items'] = $this->translateSelectorItems($PA['items'], 'static_territories');
|
||||
$PA['items'] = $this->replaceSelectorIndexField($PA);
|
||||
}
|
||||
|
||||
/**
|
||||
* Translate and sort the countries selector using the current locale
|
||||
*
|
||||
* @param array $PA: parameters: items, config, TSconfig, table, row, field
|
||||
* @param DataPreprocessor $fObj
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function translateCountriesSelector($PA, TcaSelectItems $fObj)
|
||||
{
|
||||
$PA['items'] = $this->translateSelectorItems($PA['items'], 'static_countries');
|
||||
$PA['items'] = $this->replaceSelectorIndexField($PA);
|
||||
}
|
||||
|
||||
/**
|
||||
* Translate and sort the country zones selector using the current locale
|
||||
*
|
||||
* @param array $PA: parameters: items, config, TSconfig, table, row, field
|
||||
* @param DataPreprocessor $fObj
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function translateCountryZonesSelector($PA, TcaSelectItems $fObj)
|
||||
{
|
||||
$PA['items'] = $this->translateSelectorItems($PA['items'], 'static_country_zones');
|
||||
$PA['items'] = $this->replaceSelectorIndexField($PA);
|
||||
}
|
||||
|
||||
/**
|
||||
* Translate and sort the currencies selector using the current locale
|
||||
*
|
||||
* @param array $PA: parameters: items, config, TSconfig, table, row, field
|
||||
* @param DataPreprocessor $fObj
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function translateCurrenciesSelector($PA, TcaSelectItems $fObj)
|
||||
{
|
||||
$PA['items'] = $this->translateSelectorItems($PA['items'], 'static_currencies');
|
||||
$PA['items'] = $this->replaceSelectorIndexField($PA);
|
||||
}
|
||||
|
||||
/**
|
||||
* Translate and sort the languages selector using the current locale
|
||||
*
|
||||
* @param array $PA: parameters: items, config, TSconfig, table, row, field
|
||||
* @param DataPreprocessor $fObj
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function translateLanguagesSelector($PA, TcaSelectItems $fObj)
|
||||
{
|
||||
$PA['items'] = $this->translateSelectorItems($PA['items'], 'static_languages');
|
||||
$PA['items'] = $this->replaceSelectorIndexField($PA);
|
||||
}
|
||||
|
||||
/**
|
||||
* Translate selector items array
|
||||
*
|
||||
* @param array $items: array of value/label pairs
|
||||
* @param string $tableName: name of static info tables
|
||||
*
|
||||
* @return array array of value/translated label pairs
|
||||
*/
|
||||
protected function translateSelectorItems($items, $tableName)
|
||||
{
|
||||
$translatedItems = $items;
|
||||
if (isset($translatedItems) && is_array($translatedItems)) {
|
||||
foreach ($translatedItems as $key => $item) {
|
||||
if (is_array($translatedItems[$key]) && array_key_exists(1, $translatedItems[$key]) && ($translatedItems[$key][1] ?? '')) {
|
||||
//Get isocode if present
|
||||
$code = strstr($item[0], '(');
|
||||
$code2 = strstr(substr($code, 1), '(');
|
||||
$code = $code2 ? $code2 : $code;
|
||||
// Translate
|
||||
$translatedItems[$key][0] = LocalizationUtility::translate(['uid' => $item[1]], $tableName);
|
||||
// Re-append isocode, if present
|
||||
$translatedItems[$key][0] = $translatedItems[$key][0] . ($code ? ' ' . $code : '');
|
||||
}
|
||||
}
|
||||
$currentLocale = setlocale(LC_COLLATE, '0');
|
||||
$locale = LocalizationUtility::setCollatingLocale();
|
||||
if ($locale !== false) {
|
||||
uasort($translatedItems, [$this, 'strcollOnLabels']);
|
||||
}
|
||||
setlocale(LC_COLLATE, $currentLocale);
|
||||
}
|
||||
$items = $translatedItems;
|
||||
return $items;
|
||||
}
|
||||
|
||||
/**
|
||||
* Using strcoll comparison on labels
|
||||
*
|
||||
* @return int see strcoll
|
||||
*
|
||||
* @param mixed $itemA
|
||||
* @param mixed $itemB
|
||||
*/
|
||||
protected function strcollOnLabels($itemA, $itemB)
|
||||
{
|
||||
return strcoll($itemA[0], $itemB[0]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Replace the selector's uid index with configured indexField
|
||||
*
|
||||
* @param array $PA: TCA select field parameters array
|
||||
* @return array The new $items array
|
||||
*/
|
||||
protected function replaceSelectorIndexField($PA)
|
||||
{
|
||||
$items = $PA['items'] ?? [];
|
||||
$indexFields = GeneralUtility::trimExplode(',', $PA['config']['itemsProcFunc_config']['indexField'] ?? '', true);
|
||||
if (!empty($indexFields)) {
|
||||
$rows = [];
|
||||
// Collect items uid's
|
||||
$uids = [];
|
||||
foreach ($items as $key => $item) {
|
||||
if (is_array($items[$key]) && array_key_exists(1, $items[$key]) && ($items[$key][1] ?? 0)) {
|
||||
$uids[] = $item[1];
|
||||
}
|
||||
}
|
||||
$uidList = implode(',', $uids);
|
||||
if (!empty($uidList)) {
|
||||
switch ($PA['config']['foreign_table'] ?? '') {
|
||||
case 'static_territories':
|
||||
/** @var $territoryRepository TerritoryRepository */
|
||||
$territoryRepository = GeneralUtility::makeInstance(TerritoryRepository::class);
|
||||
$objects = $territoryRepository->findAllByUidInList($uidList)->toArray();
|
||||
break;
|
||||
case 'static_countries':
|
||||
/** @var $countryRepository CountryRepository */
|
||||
$countryRepository = GeneralUtility::makeInstance(CountryRepository::class);
|
||||
$objects = $countryRepository->findAllByUidInList($uidList)->toArray();
|
||||
break;
|
||||
case 'static_country_zones':
|
||||
/** @var $countryZoneRepository CountryZoneRepository */
|
||||
$countryZoneRepository = GeneralUtility::makeInstance(CountryZoneRepository::class);
|
||||
$objects = $countryZoneRepository->findAllByUidInList($uidList)->toArray();
|
||||
break;
|
||||
case 'static_languages':
|
||||
/** @var $languageRepository LanguageRepository */
|
||||
$languageRepository = GeneralUtility::makeInstance(LanguageRepository::class);
|
||||
$objects = $languageRepository->findAllByUidInList($uidList)->toArray();
|
||||
break;
|
||||
case 'static_currencies':
|
||||
/** @var $currencyRepository CurrencyRepository */
|
||||
$currencyRepository = GeneralUtility::makeInstance(CurrencyRepository::class);
|
||||
$objects = $currencyRepository->findAllByUidInList($uidList)->toArray();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
if (!empty($objects)) {
|
||||
$columnsMapping = $this->getColumnsMapping($objects[0]);
|
||||
// Map table column to object property
|
||||
$indexProperties = [];
|
||||
foreach ($indexFields as $indexField) {
|
||||
if ($columnsMapping[$indexField]['mapOnProperty'] ?? '') {
|
||||
$indexProperties[] = $columnsMapping[$indexField]['mapOnProperty'];
|
||||
} else {
|
||||
$indexProperties[] = GeneralUtility::underscoredToLowerCamelCase($indexField);
|
||||
}
|
||||
}
|
||||
// Index rows by uid
|
||||
$uidIndexedRows = [];
|
||||
foreach ($objects as $object) {
|
||||
$uidIndexedObjects[$object->getUid()] = $object;
|
||||
}
|
||||
// Replace the items index field
|
||||
foreach ($items as $key => $item) {
|
||||
if (is_array($items[$key]) && array_key_exists(1, $items[$key]) && ($items[$key][1] ?? 0)) {
|
||||
$object = $uidIndexedObjects[$items[$key][1]];
|
||||
$items[$key][1] = $object->_getProperty($indexProperties[0]);
|
||||
if (($indexFields[1] ?? false) && $object->_getProperty($indexProperties[1] ?? '')) {
|
||||
$items[$key][1] .= '_' . $object->_getProperty($indexProperties[1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return $items;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the columns mapping for the object
|
||||
*
|
||||
* @param object $object
|
||||
* @return array
|
||||
*/
|
||||
protected function getColumnsMapping($object)
|
||||
{
|
||||
$columnsMapping = [];
|
||||
$dataMapper = GeneralUtility::makeInstance(DataMapper::class);
|
||||
$className = get_class($object);
|
||||
$dataMap = $dataMapper->getDataMap($className);
|
||||
$properties = $object->_getProperties();
|
||||
foreach ($properties as $propertyName => $propertyValue) {
|
||||
if (!$dataMap->isPersistableProperty($propertyName)) {
|
||||
continue;
|
||||
}
|
||||
$columnMap = $dataMap->getColumnMap($propertyName);
|
||||
$columnName = $columnMap->getColumnName();
|
||||
$columnsMapping[$columnName] = ['mapOnProperty' => $propertyName];
|
||||
}
|
||||
return $columnsMapping;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,121 @@
|
||||
<?php
|
||||
namespace SJBR\StaticInfoTables\Hook\Backend\Form\Wizard;
|
||||
|
||||
/*
|
||||
* Copyright notice
|
||||
*
|
||||
* (c) 2007-2011 Andreas Wolf <andreas.wolf@ikt-werk.de>
|
||||
* (c) 2013-2021 Stanislas Rolland <typo3AAAA(arobas)sjbr.ca>
|
||||
* 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 2 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.
|
||||
* A copy is found in the textfile GPL.txt and important notices to the license
|
||||
* from the author is found in LICENSE.txt distributed with these scripts.
|
||||
*
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
use SJBR\StaticInfoTables\Utility\LocalizationUtility;
|
||||
use TYPO3\CMS\Backend\Form\Wizard\SuggestWizardDefaultReceiver;
|
||||
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
||||
|
||||
/**
|
||||
* Default implementation of a handler class for an ajax record selector.
|
||||
*
|
||||
* Normally other implementations should be inherited from this one.
|
||||
* queryTable() should not be overwritten under normal circumstances.
|
||||
*
|
||||
* @author Andreas Wolf <andreas.wolf@ikt-werk.de>
|
||||
* @author Benjamin Mack <benni@typo3.org>
|
||||
* @author Stanislas Rolland <typo3(arobas)sjbr.ca>
|
||||
*/
|
||||
class SuggestReceiver extends SuggestWizardDefaultReceiver
|
||||
{
|
||||
/**
|
||||
* Prepare the statement for selecting the records which will be returned to the selector. May also return some
|
||||
* other records (e.g. from a mm-table) which will be used later on to select the real records
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function prepareSelectStatement()
|
||||
{
|
||||
$expressionBuilder = $this->queryBuilder->expr();
|
||||
$searchWholePhrase = !isset($this->config['searchWholePhrase']) || $this->config['searchWholePhrase'];
|
||||
$searchString = $this->params['value'];
|
||||
$searchUid = (int)$searchString;
|
||||
if ($searchString !== '') {
|
||||
$likeCondition = ($searchWholePhrase ? '%' : '') . $this->queryBuilder->escapeLikeWildcards($searchString) . '%';
|
||||
// Get the label field for the current language, if any is available
|
||||
$lang = LocalizationUtility::getCurrentLanguage();
|
||||
$lang = LocalizationUtility::getIsoLanguageKey($lang);
|
||||
$labelFields = LocalizationUtility::getLabelFields($this->table, $lang);
|
||||
$selectFieldsList = $labelFields[0] . ',' . $this->config['additionalSearchFields'];
|
||||
$selectFields = GeneralUtility::trimExplode(',', $selectFieldsList, true);
|
||||
$selectFields = array_unique($selectFields);
|
||||
$selectParts = $expressionBuilder->orX();
|
||||
foreach ($selectFields as $field) {
|
||||
$selectParts->add($expressionBuilder->like($field, $this->queryBuilder->createPositionalParameter($likeCondition)));
|
||||
}
|
||||
$searchClause = $expressionBuilder->orX($selectParts);
|
||||
if ($searchUid > 0 && $searchUid == $searchString) {
|
||||
$searchClause->add($expressionBuilder->eq('uid', $searchUid));
|
||||
}
|
||||
$this->queryBuilder->andWhere($expressionBuilder->orX($searchClause));
|
||||
}
|
||||
if (!empty($this->allowedPages)) {
|
||||
$pidList = array_map('intval', $this->allowedPages);
|
||||
if (!empty($pidList)) {
|
||||
$this->queryBuilder->andWhere(
|
||||
$expressionBuilder->in('pid', $pidList)
|
||||
);
|
||||
}
|
||||
}
|
||||
// add an additional search condition comment
|
||||
if (isset($this->config['searchCondition']) && $this->config['searchCondition'] !== '') {
|
||||
$this->queryBuilder->andWhere(QueryHelper::stripLogicalOperatorPrefix($this->config['searchCondition']));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepares the clause by which the result elements are sorted. See description of ORDER BY in
|
||||
* SQL standard for reference.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function prepareOrderByStatement()
|
||||
{
|
||||
// Get the label field for the current language, if any is available
|
||||
$lang = LocalizationUtility::getCurrentLanguage();
|
||||
$lang = LocalizationUtility::getIsoLanguageKey($lang);
|
||||
$labelFields = LocalizationUtility::getLabelFields($this->table, $lang);
|
||||
if (!empty($labelFields)) {
|
||||
foreach ($labelFields as $labelField) {
|
||||
$this->queryBuilder->addOrderBy($labelField);
|
||||
}
|
||||
} elseif ($GLOBALS['TCA'][$this->table]['ctrl']['label']) {
|
||||
$this->queryBuilder->addOrderBy($GLOBALS['TCA'][$this->table]['ctrl']['label']);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Manipulate a record before using it to render the selector; may be used to replace a MM-relation etc.
|
||||
*
|
||||
* @param array $row
|
||||
*/
|
||||
protected function manipulateRecord(&$row)
|
||||
{
|
||||
// Localize the record
|
||||
$row[$GLOBALS['TCA'][$this->table]['ctrl']['label']] = LocalizationUtility::translate(['uid' => $row['uid']], $this->table);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
<?php
|
||||
namespace SJBR\StaticInfoTables\Hook\Backend\Recordlist;
|
||||
|
||||
/*
|
||||
* Copyright notice
|
||||
*
|
||||
* (c) 2018-2022 Stanislas Rolland <typo3AAAA(arobas)sjbr.ca>
|
||||
* 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 2 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\Core\Database\Query\QueryBuilder;
|
||||
use TYPO3\CMS\Core\Database\Query\QueryHelper;
|
||||
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
|
||||
|
||||
/**
|
||||
* Order records according to language field of current language
|
||||
*/
|
||||
class ModifyQuery
|
||||
{
|
||||
/**
|
||||
* Specify records order
|
||||
*
|
||||
* @param array $parameters
|
||||
* @param string $table
|
||||
* @param int $pageId
|
||||
* @param string $additionalConstraints
|
||||
* @param string $fieldList
|
||||
* @param QueryBuilder $queryBuilder
|
||||
* @return void
|
||||
*/
|
||||
public function modifyQuery(&$parameters, $table, $pageId, $additionalConstraints, $fieldList, QueryBuilder $queryBuilder)
|
||||
{
|
||||
if (in_array($table, array_keys($GLOBALS['TYPO3_CONF_VARS']['EXTENSIONS']['static_info_tables']['tables'] ?? []))) {
|
||||
$lang = substr(strtolower($this->getLanguageService()->lang), 0, 2);
|
||||
if (ExtensionManagementUtility::isLoaded('static_info_tables_' . $lang) &&
|
||||
isset($GLOBALS['TYPO3_CONF_VARS']['EXTENSIONS']['static_info_tables']['tables'][$table]['label_fields']) &&
|
||||
is_array($GLOBALS['TYPO3_CONF_VARS']['EXTENSIONS']['static_info_tables']['tables'][$table]['label_fields'])) {
|
||||
$label = array_key_first($GLOBALS['TYPO3_CONF_VARS']['EXTENSIONS']['static_info_tables']['tables'][$table]['label_fields']);
|
||||
if ($label) {
|
||||
$orderBy = str_replace('##', $lang, $label);
|
||||
$orderByFields = QueryHelper::parseOrderBy((string)$orderBy);
|
||||
foreach ($orderByFields as $fieldNameAndSorting) {
|
||||
list($fieldName, $sorting) = $fieldNameAndSorting;
|
||||
$queryBuilder->orderBy($fieldName, $sorting);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected function getLanguageService()
|
||||
{
|
||||
return $GLOBALS['LANG'];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,145 @@
|
||||
<?php
|
||||
namespace SJBR\StaticInfoTables\Hook\Core\DataHandling;
|
||||
|
||||
/*
|
||||
* Copyright notice
|
||||
*
|
||||
* (c) 2013-2022 Stanislas Rolland <typo3AAAA(arobas)sjbr.ca>
|
||||
* 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 2 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 SJBR\StaticInfoTables\Domain\Repository\CountryRepository;
|
||||
use SJBR\StaticInfoTables\Domain\Repository\CurrencyRepository;
|
||||
use SJBR\StaticInfoTables\Domain\Repository\TerritoryRepository;
|
||||
use TYPO3\CMS\Core\Database\ConnectionPool;
|
||||
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
||||
|
||||
/**
|
||||
* Hook on Core/DataHandling/DataHandler to manage redundancy of ISO codes in static info tables
|
||||
*/
|
||||
class ProcessDataMap
|
||||
{
|
||||
protected $countryRepository;
|
||||
|
||||
public function injectCountryRepository(CountryRepository $countryRepository)
|
||||
{
|
||||
$this->countryRepository = $countryRepository;
|
||||
}
|
||||
protected $currencyRepository;
|
||||
|
||||
public function injectCurrencyRepository(CurrencyRepository $currencyRepository)
|
||||
{
|
||||
$this->currencyRepository = $currencyRepository;
|
||||
}
|
||||
|
||||
protected $territoryRepository;
|
||||
|
||||
public function injectTerritoryRepository(TerritoryRepository $territoryRepository)
|
||||
{
|
||||
$this->territoryRepository = $territoryRepository;
|
||||
}
|
||||
|
||||
/**
|
||||
* Post-process redundant ISO codes fields
|
||||
*
|
||||
* @param object $fobj TCEmain object reference
|
||||
* @param mixed $status
|
||||
* @param mixed $table
|
||||
* @param mixed $id
|
||||
* @return void
|
||||
*/
|
||||
public function processDatamap_postProcessFieldArray($status, $table, $id, &$incomingFieldArray, &$fObj)
|
||||
{
|
||||
switch ($table) {
|
||||
case 'static_territories':
|
||||
//Post-process containing territory ISO numeric code
|
||||
if ($incomingFieldArray['tr_parent_territory_uid'] ?? 0) {
|
||||
$territory = $this->territoryRepository->findOneByUid((int)$incomingFieldArray['tr_parent_territory_uid']);
|
||||
if (is_object($territory)) {
|
||||
$incomingFieldArray['tr_parent_iso_nr'] = $territory->getUnCodeNumber();
|
||||
}
|
||||
} elseif (isset($incomingFieldArray['tr_parent_territory_uid'])) {
|
||||
$incomingFieldArray['tr_parent_iso_nr'] = 0;
|
||||
}
|
||||
break;
|
||||
case 'static_countries':
|
||||
//Post-process containing territory ISO numeric code
|
||||
if ($incomingFieldArray['cn_parent_territory_uid'] ?? 0) {
|
||||
$territory = $this->territoryRepository->findOneByUid((int)$incomingFieldArray['cn_parent_territory_uid']);
|
||||
if (is_object($territory)) {
|
||||
$incomingFieldArray['cn_parent_tr_iso_nr'] = $territory->getUnCodeNumber();
|
||||
}
|
||||
} elseif (isset($incomingFieldArray['cn_parent_territory_uid'])) {
|
||||
$incomingFieldArray['cn_parent_tr_iso_nr'] = 0;
|
||||
}
|
||||
//Post-process currency ISO numeric and A3 codes
|
||||
if ($incomingFieldArray['cn_currency_uid'] ?? 0) {
|
||||
$currency = $this->currencyRepository->findOneByUid((int)$incomingFieldArray['cn_currency_uid']);
|
||||
if (is_object($currency)) {
|
||||
$incomingFieldArray['cn_currency_iso_nr'] = $currency->getIsoCodeNumber();
|
||||
$incomingFieldArray['cn_currency_iso_3'] = $currency->getIsoCodeA3();
|
||||
}
|
||||
} elseif (isset($incomingFieldArray['cn_currency_uid'])) {
|
||||
$incomingFieldArray['cn_currency_iso_nr'] = 0;
|
||||
$incomingFieldArray['cn_currency_iso_3'] = '';
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Post-process redundant ISO codes fields of IRRE child
|
||||
*
|
||||
* @param object $fobj TCEmain object reference
|
||||
* @param mixed $status
|
||||
* @param mixed $table
|
||||
* @param mixed $id
|
||||
* @return void
|
||||
*/
|
||||
public function processDatamap_afterDatabaseOperations($status, $table, $id, &$fieldArray, &$fObj)
|
||||
{
|
||||
switch ($table) {
|
||||
case 'static_countries':
|
||||
//Post-process country ISO numeric, A2 and A3 codes on country zones
|
||||
// Get the country record uid
|
||||
if ($status === 'new') {
|
||||
$id = $fObj->substNEWwithIDs[$id];
|
||||
}
|
||||
// Get the country
|
||||
$country = $this->countryRepository->findOneByUid((int)$id);
|
||||
// Get the country zones
|
||||
$countryZones = $country->getCountryZones()->toArray();
|
||||
if (count($countryZones)) {
|
||||
$connection = GeneralUtility::makeInstance(ConnectionPool::class)->getConnectionForTable('static_country_zones');
|
||||
foreach ($countryZones as $countryZone) {
|
||||
$connection->update(
|
||||
'static_country_zones',
|
||||
[
|
||||
'zn_country_iso_nr' => (int)$country->getIsoCodeNumber(),
|
||||
'zn_country_iso_2' => $country->getIsoCodeA2(),
|
||||
'zn_country_iso_3' => $country->getIsoCodeA3(),
|
||||
],
|
||||
['uid' => (int)$countryZone->getUid()]
|
||||
);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user