first commit
This commit is contained in:
commit
e81864e683
2984 files changed
+267797
No files matched your search
@@ -0,0 +1,77 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace In2code\Femanager\UserFunc;
|
||||
|
||||
use In2code\Femanager\DataProvider\CountryDataProvider;
|
||||
use In2code\Femanager\DataProvider\CountryZonesDataProvider;
|
||||
use In2code\Femanager\DataProvider\FallbackCountryDataProvider;
|
||||
use TYPO3\CMS\Backend\Form\FormDataProvider\TcaSelectItems;
|
||||
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
|
||||
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
||||
|
||||
class StaticInfoTables
|
||||
{
|
||||
public function isStaticInfoTablesInstalled(): bool
|
||||
{
|
||||
return ExtensionManagementUtility::isLoaded('static_info_tables');
|
||||
}
|
||||
|
||||
public function getStatesOptions(array $data, TcaSelectItems $tcaSelectItems)
|
||||
{
|
||||
if (ExtensionManagementUtility::isLoaded('static_info_tables')) {
|
||||
$countryZonesDataProvider = GeneralUtility::makeInstance(CountryZonesDataProvider::class);
|
||||
$country = $data['row']['country'] ?? null;
|
||||
if (is_array($country)) {
|
||||
if (count($country) > 0) {
|
||||
$country = array_values($country)[0];
|
||||
} else {
|
||||
$country = null;
|
||||
}
|
||||
}
|
||||
if (empty($country)) {
|
||||
$data['items'] = [
|
||||
[
|
||||
'LLL:EXT:femanager/Resources/Private/Language/locallang_db.xlf:pleaseChooseCountry',
|
||||
''
|
||||
]
|
||||
];
|
||||
} else {
|
||||
$countryZones = $countryZonesDataProvider->getCountryZonesForCountryIso3($country);
|
||||
|
||||
if (empty($countryZones)) {
|
||||
$data['items'] = [
|
||||
[
|
||||
'LLL:EXT:femanager/Resources/Private/Language/locallang_db.xlf:noZonesForThisCountry',
|
||||
''
|
||||
]
|
||||
];
|
||||
} else {
|
||||
foreach ($countryZones as $countryZone) {
|
||||
$data['items'][] = [$countryZone->getLocalName(), $countryZone->getIsoCode()];
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$data['items'][] = ['Error: static_info_tables is not installed', ''];
|
||||
}
|
||||
}
|
||||
|
||||
public function getCountryOptions(array $data, TcaSelectItems $tcaSelectItems)
|
||||
{
|
||||
if (ExtensionManagementUtility::isLoaded('static_info_tables')) {
|
||||
$countryDataProvider = GeneralUtility::makeInstance(CountryDataProvider::class);
|
||||
$countries = $countryDataProvider->getCountries();
|
||||
foreach ($countries as $country) {
|
||||
$data['items'][] = [$country->getShortNameEn(), $country->getIsoCodeA3()];
|
||||
}
|
||||
} else {
|
||||
$fallbackCountryDataProvider = GeneralUtility::makeInstance(FallbackCountryDataProvider::class);
|
||||
$countries = $fallbackCountryDataProvider->getCountries();
|
||||
foreach ($countries as $key => $name) {
|
||||
$data['items'][] = [$name, $key];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,113 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
namespace In2code\Femanager\UserFunc;
|
||||
|
||||
use In2code\Femanager\Utility\StringUtility;
|
||||
use TYPO3\CMS\Backend\Utility\BackendUtility;
|
||||
use TYPO3\CMS\Core\Localization\LanguageService;
|
||||
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
|
||||
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
||||
|
||||
/**
|
||||
* Class UserFieldsOptions
|
||||
*/
|
||||
class UserFieldsOptions
|
||||
{
|
||||
/**
|
||||
* @var LanguageService
|
||||
*/
|
||||
protected $languageService;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $localLangPrefix = 'LLL:EXT:femanager/Resources/Private/Language/locallang_db.xlf:';
|
||||
|
||||
/**
|
||||
* Add options to FlexForm Selection - Options can be defined in TSConfig
|
||||
*
|
||||
* @param array $params
|
||||
*/
|
||||
public function addOptions(&$params)
|
||||
{
|
||||
$this->initialize();
|
||||
$tSconfig = BackendUtility::getPagesTSconfig($this->getPid());
|
||||
$this->addCaptchaOption($params);
|
||||
$this->addStateOption($params);
|
||||
$tab = $params['config']['itemsProcFuncTab'] . '.';
|
||||
if (!empty($tSconfig['tx_femanager.']['flexForm.'][$tab]['addFieldOptions.'])) {
|
||||
$options = $tSconfig['tx_femanager.']['flexForm.'][$tab]['addFieldOptions.'];
|
||||
foreach ((array)$options as $value => $label) {
|
||||
$params['items'][] = [
|
||||
StringUtility::startsWith($label, 'LLL:') ? $this->languageService->sL($label) : $label,
|
||||
$value
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add captcha option
|
||||
*
|
||||
* @param array $params
|
||||
*/
|
||||
protected function addCaptchaOption(&$params)
|
||||
{
|
||||
if (ExtensionManagementUtility::isLoaded('sr_freecap')) {
|
||||
$params['items'][] = [
|
||||
$this->languageService->sL($this->localLangPrefix . 'tx_femanager_domain_model_user.captcha'),
|
||||
'captcha'
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add captcha option
|
||||
*
|
||||
* @param array $params
|
||||
*/
|
||||
protected function addStateOption(&$params)
|
||||
{
|
||||
if (ExtensionManagementUtility::isLoaded('static_info_tables')) {
|
||||
$params['items'][] = [
|
||||
$this->languageService->sL($this->localLangPrefix . 'tx_femanager_domain_model_user.state'),
|
||||
'state'
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Read pid from current URL
|
||||
* URL example:
|
||||
* http://femanager.localhost.de/typo3/alt_doc.php?&returnUrl=
|
||||
* %2Ftypo3%2Fsysext%2Fcms%2Flayout%2Fdb_layout.php
|
||||
* %3Fid%3D17%23element-tt_content-14
|
||||
* &edit[tt_content][14]=edit
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
protected function getPid()
|
||||
{
|
||||
$pid = 0;
|
||||
$backUrl = str_replace('?', '&', GeneralUtility::_GP('returnUrl'));
|
||||
$urlParts = GeneralUtility::trimExplode('&', $backUrl, true);
|
||||
foreach ($urlParts as $part) {
|
||||
if (stristr($part, 'id=')) {
|
||||
$pid = str_replace('id=', '', $part);
|
||||
}
|
||||
}
|
||||
|
||||
return (int)$pid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize
|
||||
*
|
||||
* @SuppressWarnings(PHPMD.Superglobals)
|
||||
*/
|
||||
protected function initialize()
|
||||
{
|
||||
$this->languageService = $GLOBALS['LANG'];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
namespace In2code\Femanager\UserFunc;
|
||||
|
||||
use In2code\Femanager\Domain\Model\User;
|
||||
use In2code\Femanager\Utility\ObjectUtility;
|
||||
use TYPO3\CMS\Core\Database\QueryGenerator;
|
||||
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
||||
|
||||
/**
|
||||
* Class UserOptions
|
||||
*/
|
||||
class UserOptions
|
||||
{
|
||||
/**
|
||||
* Just add users from start point to selection
|
||||
*
|
||||
* @param array $params
|
||||
*/
|
||||
public function addOptions(&$params)
|
||||
{
|
||||
if ($this->getPages($params) !== []) {
|
||||
$params['items'] = [
|
||||
$params['items'][0], // please choose
|
||||
$params['items'][1] // currently logged in user
|
||||
];
|
||||
|
||||
foreach ($this->getUsers($params) as $user) {
|
||||
$params['items'][] = [$user['username'], $user['uid']];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $params
|
||||
* @return array
|
||||
*/
|
||||
protected function getUsers(array $params): array
|
||||
{
|
||||
$queryBuilder = ObjectUtility::getQueryBuilder(User::TABLE_NAME);
|
||||
$result = $queryBuilder
|
||||
->select('uid', 'username')
|
||||
->from(User::TABLE_NAME)
|
||||
->where('pid in (' . $this->getPageUidList($params) . ')')
|
||||
->setMaxResults(10000)
|
||||
->orderBy('username', 'ASC')
|
||||
->execute();
|
||||
return $result->fetchAll();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get lists of page uids where the users are stored with recursive setting
|
||||
*
|
||||
* @param array $params
|
||||
* @return string
|
||||
*/
|
||||
protected function getPageUidList(array $params): string
|
||||
{
|
||||
$list = '';
|
||||
$queryGenerator = GeneralUtility::makeInstance(QueryGenerator::class);
|
||||
$depth = $params['flexParentDatabaseRow']['recursive'];
|
||||
foreach ($this->getPages($params) as $pageIdentifier) {
|
||||
$list .= $queryGenerator->getTreeList($pageIdentifier, $depth, 0, 1);
|
||||
$list .= ',';
|
||||
}
|
||||
return rtrim($list, ',');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $params
|
||||
* @return array
|
||||
*/
|
||||
protected function getPages(array $params): array
|
||||
{
|
||||
$pages = [];
|
||||
if (!empty($params['flexParentDatabaseRow']['pages'][0]['uid'])) {
|
||||
foreach ($params['flexParentDatabaseRow']['pages'] as $page) {
|
||||
$pages[] = $page['uid'];
|
||||
}
|
||||
}
|
||||
return $pages;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user