first commit

This commit is contained in:
salam committed 2026-10-06 19:40:28 +02:00
commit e81864e683
2984 files changed
+267797

No files matched your search

@@ -0,0 +1,138 @@
<?php
declare(strict_types=1);
namespace In2code\Femanager\Finisher;
use In2code\Femanager\Domain\Model\User;
use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;
/**
* Class AbstractFinisher
*/
abstract class AbstractFinisher implements FinisherInterface
{
/**
* @var User
*/
protected $user;
/**
* Extension settings
*
* @var array
*/
protected $settings;
/**
* Finisher service configuration
*
* @var array
*/
protected $configuration;
/**
* Controller actionName - usually "createAction" or "confirmationAction"
*
* @var null
*/
protected $actionMethodName;
/**
* @var ContentObjectRenderer
*/
protected $contentObject;
/**
* @return User
*/
public function getUser()
{
return $this->user;
}
/**
* @param User $user
* @return AbstractFinisher
*/
public function setUser($user)
{
$this->user = $user;
return $this;
}
/**
* @return array
*/
public function getSettings()
{
return $this->settings;
}
/**
* @param array $settings
* @return AbstractFinisher
*/
public function setSettings($settings)
{
$this->settings = $settings;
return $this;
}
/**
* @return array
*/
public function getConfiguration()
{
return $this->configuration;
}
/**
* @param array $configuration
* @return AbstractFinisher
*/
public function setConfiguration($configuration)
{
$this->configuration = $configuration;
return $this;
}
public function getActionMethodName()
{
return $this->actionMethodName;
}
/**
* @param null $actionMethodName
* @return AbstractFinisher
*/
public function setActionMethodName($actionMethodName)
{
$this->actionMethodName = $actionMethodName;
return $this;
}
public function initializeFinisher()
{
}
/**
* @param User $user
* @param array $configuration
* @param array $settings
* @param ContentObjectRenderer $contentObject
* @param string $actionMethodName
*/
public function __construct(
User $user,
array $configuration,
array $settings,
$actionMethodName,
ContentObjectRenderer $contentObject
) {
$this->setUser($user);
$this->setConfiguration($configuration);
$this->setSettings($settings);
$this->setActionMethodName($actionMethodName);
$this->contentObject = $contentObject;
}
}
@@ -0,0 +1,48 @@
<?php
declare(strict_types=1);
namespace In2code\Femanager\Finisher;
use In2code\Femanager\Domain\Model\User;
/**
* Interface FinisherInterface
*/
interface FinisherInterface
{
/**
* @return User
*/
public function getUser();
/**
* @param User $user
* @return AbstractFinisher
*/
public function setUser($user);
/**
* Get settings
*
* @return array
*/
public function getSettings();
/**
* Set settings
*
* @param array $settings
* @return AbstractFinisher
*/
public function setSettings($settings);
public function getActionMethodName();
/**
* @param null $actionMethodName
* @return AbstractFinisher
*/
public function setActionMethodName($actionMethodName);
public function initializeFinisher();
}
@@ -0,0 +1,90 @@
<?php
declare(strict_types=1);
namespace In2code\Femanager\Finisher;
use In2code\Femanager\Domain\Model\User;
use In2code\Femanager\Domain\Service\FinisherService;
use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface;
use TYPO3\CMS\Extbase\Object\ObjectManagerInterface;
use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;
/**
* Class FinisherRunner
*/
class FinisherRunner
{
/**
* @var ObjectManagerInterface
*/
protected $objectManager;
/**
* @var ConfigurationManagerInterface
*/
protected $configurationManager;
/**
* @var ContentObjectRenderer
*/
protected $contentObject;
/**
* TypoScript settings
*
* @var array
*/
protected $settings = [];
/**
* FinisherRunner constructor.
* @param ObjectManagerInterface $objectManager
* @param ConfigurationManagerInterface $configurationManager
*/
public function __construct(
ObjectManagerInterface $objectManager,
ConfigurationManagerInterface $configurationManager
) {
$this->objectManager = $objectManager;
$this->configurationManager = $configurationManager;
}
/**
* Call finisher classes after submit
*
* @param User $user
* @param string $actionMethodName
* @param array $settings
* @param ContentObjectRenderer $contentObject
*/
public function callFinishers(
User $user,
$actionMethodName,
$settings,
ContentObjectRenderer $contentObject
) {
foreach ($this->getFinisherClasses($settings) as $finisherSettings) {
/** @var FinisherService $finisherService */
$finisherService = $this->objectManager->get(FinisherService::class, $user, $settings, $contentObject);
$finisherService->setClass($finisherSettings['class']);
$finisherService->setRequirePath($finisherSettings['require'] ?? '');
$finisherService->setConfiguration($finisherSettings['config'] ?? []);
$finisherService->setActionMethodName($actionMethodName);
$finisherService->start();
}
}
/**
* Get all finisher classes from typoscript and sort them
*
* @param array $settings
* @return array
*/
protected function getFinisherClasses($settings)
{
$finishers = (array)$settings['finishers'];
ksort($finishers);
return $finishers;
}
}
@@ -0,0 +1,192 @@
<?php
declare(strict_types=1);
namespace In2code\Femanager\Finisher;
use In2code\Femanager\Domain\Service\StoreInDatabaseService;
use In2code\Femanager\Utility\StringUtility;
use TYPO3\CMS\Core\TypoScript\TypoScriptService;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Object\ObjectManager;
use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;
/**
* Class SaveToAnyTableFinisher
*/
class SaveToAnyTableFinisher extends AbstractFinisher implements FinisherInterface
{
/**
* Inject a complete new content object
*
* @var ContentObjectRenderer
*/
protected $contentObject;
/**
* @var ObjectManager
*/
protected $objectManager;
/**
* @var TypoScriptService
*/
protected $typoScriptService;
/**
* @var array
*/
protected $configuration = [];
/**
* @var int
*/
protected $lastGeneratedUid = 0;
/**
* @var array
*/
protected $dataArray = [];
/**
* @param ContentObjectRenderer $contentObject
*/
public function injectContentObjectRenderer(ContentObjectRenderer $contentObject)
{
$this->contentObject = $contentObject;
}
/**
* @param ObjectManager $objectManager
*/
public function injectObjectManager(ObjectManager $objectManager)
{
$this->objectManager = $objectManager;
}
/**
* @param TypoScriptService $typoScriptService
*/
public function injectTypoScriptService(TypoScriptService $typoScriptService)
{
$this->typoScriptService = $typoScriptService;
}
/**
* Overwrite configuration with
* plugin.tx_femanager.settings.new.storeInDatabase
*/
public function initializeFinisher()
{
if ($this->typoScriptService == null) {
$this->typoScriptService = GeneralUtility::makeInstance(TypoScriptService::class);
}
$configuration = $this->typoScriptService->convertPlainArrayToTypoScriptArray($this->settings);
if (!empty($configuration['new.']['storeInDatabase.'])) {
$this->configuration = $configuration['new.']['storeInDatabase.'];
}
}
/**
* Store to any table
*/
public function storeFinisher()
{
if (!empty($this->configuration)) {
$this->addArrayToDataArray($this->user->_getProperties());
foreach ((array)array_keys($this->configuration) as $table) {
$this->storeForTable($table);
}
}
}
/**
* Store for a given table
*
* @param string $table
*/
protected function storeForTable($table)
{
if ($this->isTableEnabled($table)) {
$this->contentObject->start($this->getDataArray());
/** @var StoreInDatabaseService $storeInDatabase */
$storeInDatabase = $this->objectManager->get(StoreInDatabaseService::class);
$storeInDatabase->setTable($table);
$this->setPropertiesForTable($table, $storeInDatabase);
$this->addArrayToDataArray(['uid_' . $table => $storeInDatabase->execute()]);
}
}
/**
* Store properties for a table
*
* @param string $table
* @param StoreInDatabaseService $storeInDatabase
*/
protected function setPropertiesForTable($table, StoreInDatabaseService $storeInDatabase)
{
foreach ($this->configuration[$table] as $field => $value) {
if (!$this->isSkippedKey($field)) {
$value = $this->contentObject->cObjGetSingle(
(string)$this->configuration[$table][$field],
(array)$this->configuration[$table][$field . '.']
);
$storeInDatabase->addProperty($field, $value);
}
}
}
/**
* Check if this table is enabled in TypoScript
*
* @param string $table
* @return bool
*/
protected function isTableEnabled($table)
{
return $this->contentObject->cObjGetSingle(
(string)$this->configuration[$table]['_enable'],
(array)$this->configuration[$table]['_enable.']
) === '1';
}
/**
* Should this key skipped because it starts with _ or ends with .
*
* @param string $key
* @return bool
*/
protected function isSkippedKey($key)
{
return StringUtility::startsWith($key, '_') || StringUtility::endsWith($key, '.');
}
/**
* Add array to dataArray
*
* @param array $array
*/
protected function addArrayToDataArray(array $array)
{
$dataArray = $this->getDataArray();
$dataArray = array_merge($dataArray, $array);
$this->setDataArray($dataArray);
}
/**
* @return array
*/
public function getDataArray()
{
return $this->dataArray;
}
/**
* @param array $dataArray
* @return SaveToAnyTableFinisher
*/
public function setDataArray($dataArray)
{
$this->dataArray = $dataArray;
return $this;
}
}
@@ -0,0 +1,124 @@
<?php
declare(strict_types=1);
namespace In2code\Femanager\Finisher;
use TYPO3\CMS\Core\Http\RequestFactory;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface;
use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;
/**
* Class SendParametersFinisher
*/
class SendParametersFinisher extends AbstractFinisher implements FinisherInterface
{
/**
* Inject a complete new content object
*
* @var ContentObjectRenderer
*/
protected $contentObject;
/**
* @var ConfigurationManagerInterface
*/
protected $configurationManager;
/**
* TypoScript configuration part sendPost
*
* @var array
*/
protected $configuration;
/**
* @param ConfigurationManagerInterface $configurationManager
*/
public function injectConfigurationManagerInterface(ConfigurationManagerInterface $configurationManager)
{
$this->configurationManager = $configurationManager;
}
/**
* @param ContentObjectRenderer $contentObject
*/
public function injectContentObjectRenderer(ContentObjectRenderer $contentObject)
{
$this->contentObject = $contentObject;
}
/**
* Initialize
*/
public function initializeFinisher()
{
$this->contentObject->start($this->user->_getProperties());
$typoScript = $this->configurationManager->getConfiguration(
ConfigurationManagerInterface::CONFIGURATION_TYPE_FULL_TYPOSCRIPT
);
$this->configuration = $typoScript['plugin.']['tx_femanager.']['settings.']['new.']['sendPost.'];
}
/**
* Send values via curl to a third party software
*/
public function sendFinisher()
{
if ($this->isEnabled()) {
$curlSettings = $this->getCurlSettings();
/** @var RequestFactory $requestFactory */
$requestFactory = GeneralUtility::makeInstance(RequestFactory::class);
$params = $curlSettings['params'];
$parsedParams = [];
parse_str($params, $parsedParams);
$requestFactory->request($curlSettings['url'], 'POST', ['form_params' => $parsedParams]);
}
}
/**
* CURL settings
*
* @return array
*/
protected function getCurlSettings()
{
return [
'url' => $this->getTargetUrl(),
'params' => $this->getData()
];
}
/**
* Get parameters
*
* @return string
*/
protected function getData()
{
return $this->contentObject->cObjGetSingle((string)$this->configuration['data'], (array)$this->configuration['data.']);
}
protected function getTargetUrl()
{
$linkConfiguration = [
'parameter' => $this->configuration['targetUrl'],
'forceAbsoluteUrl' => '1',
'returnLast' => 'url'
];
return $this->contentObject->typoLink('dummy', $linkConfiguration);
}
/**
* Check if sendPost is activated
*
* @return bool
*/
protected function isEnabled()
{
return $this->contentObject->cObjGetSingle($this->configuration['_enable'] ?? 'TEXT', $this->configuration['_enable.'] ?? '0')
=== '1';
}
}