diff --git a/Classes/Controller/LogController.php b/Classes/Controller/LogController.php index c3a2b7a..76fc5c5 100644 --- a/Classes/Controller/LogController.php +++ b/Classes/Controller/LogController.php @@ -345,6 +345,7 @@ public function editAction(): ResponseInterface $dbuid = 0; $table = $this->settings['table']; $groups = []; + $own_groups = []; $uid = intval($this->request->hasArgument('uid')) ? $this->request->getArgument('uid') : 0; $hash = ($this->request->hasArgument('hash')) ? $this->request->getArgument('hash') : ''; $languageAspect = GeneralUtility::makeInstance(Context::class)->getAspect('language'); @@ -391,13 +392,23 @@ public function editAction(): ResponseInterface elseif ($user['gender'] == 'm') $gender = 2; elseif ($user['gender'] == 'v') $gender = 3; $log->setGender($gender); + } elseif ($table == 'fe_users') { + $log->setPhone($user['telephone']); + if ($this->settings['newsletterExtension'] == 'mail') { + $gender = 0; + if ($user['mail_salutation'] == $this->settings['gender']['mrs']) $gender = 1; + elseif ($user['mail_salutation'] == $this->settings['gender']['mr']) $gender = 2; + elseif ($user['mail_salutation'] == $this->settings['gender']['divers']) $gender = 3; + $log->setGender($gender); + } + } + if ($table == 'tt_address' || $this->settings['newsletterExtension'] == 'mail') { $groups = $this->logRepository->getAllCats($catOrderBy); - $own_groups_tmp = $this->logRepository->getOwnCats($dbuidext); + $own_groups_tmp = $this->logRepository->getOwnCats($dbuidext, $table); foreach ($own_groups_tmp as $tmp) { $own_groups[] = $tmp['uid_local']; } } elseif ($table == 'fe_users') { - $log->setPhone($user['telephone']); $groups = $this->logRepository->getAllGroups($catOrderBy); $own_groups = explode(',', $user['usergroup']); } @@ -461,15 +472,12 @@ public function updateAction(Log $log): ResponseInterface $this->logRepository->update($log); $dbemail = $log->getEmail(); $dbuidext = $this->logRepository->getExternalUid($dbemail, $log->getPid(), $table, $this->settings['searchPidMode']); + $salutation = $this->helpersUtility->getSalutation(intval($log->getGender()), $this->settings['gender']); if ($dbuidext) { if ($table == 'tt_address') { - $salutation = ''; - if ($log->getGender() == 1) $salutation = $this->settings['gender']['mrs']; - elseif ($log->getGender() == 2) $salutation = $this->settings['gender']['mr']; - elseif ($log->getGender() == 3) $salutation = $this->settings['gender']['divers']; $this->logRepository->updateInTtAddress($log, intval($this->settings['html']), $dbuidext, $salutation); } elseif ($table == 'fe_users') { - $this->logRepository->updateInFeUsers($log, $dbuidext); + $this->logRepository->updateInFeUsers($log, $dbuidext, $this->settings['newsletterExtension']); } } else { $error = 1; @@ -1022,16 +1030,13 @@ public function verifyAction(): ResponseInterface $persistenceManager = GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\PersistenceManager'); $persistenceManager->persistAll(); $success = 0; + $salutation = $this->helpersUtility->getSalutation(intval($log->getGender()), $this->settings['gender']); + if ($dmCat) { + $dmCatArr = explode(',', $dmCat); + } else { + $dmCatArr = []; + } if ($this->settings['table'] == 'tt_address') { - if ($dmCat) { - $dmCatArr = explode(',', $dmCat); - } else { - $dmCatArr = []; - } - $salutation = ''; - if ($log->getGender() == 1) $salutation = $this->settings['gender']['mrs']; - elseif ($log->getGender() == 2) $salutation = $this->settings['gender']['mr']; - elseif ($log->getGender() == 3) $salutation = $this->settings['gender']['divers']; $success = $this->logRepository->insertInTtAddress($log, $html, $dmCatArr, $salutation); } else if ($this->settings['table'] == 'fe_users' && $this->settings['password']) { $frontendUser = new \Fixpunkt\FpNewsletter\Domain\Model\FrontendUser(); @@ -1057,12 +1062,29 @@ public function verifyAction(): ResponseInterface $frontendUser->setTelephone($log->getPhone()); $frontendUser->setFax($log->getFax()); $frontendUser->setCompany($log->getCompany()); - if ($dmCat) { - $frontendUser->setUsergroup($dmCat); - //$frontendUser->addUserGroup($this->frontendUserGroupRepository->findByUid($this->settings['frontendUserGroup'])); + if ($this->settings['newsletterExtension'] == 'mail') { + $frontendUser->setMailActive(1); + $frontendUser->setMailHtml(1); + $frontendUser->setMailSalutation($salutation); + $frontendUser->setCategories(count($dmCatArr)); + } else { + // default: Luxletter + if ($this->settings['newsletterExtension'] == 'luxletter') { + $frontendUser->setLuxletterLanguage($sys_language_uid); + } + if ($dmCat) { + $frontendUser->setUsergroup($dmCat); + //$frontendUser->addUserGroup($this->frontendUserGroupRepository->findByUid($this->settings['frontendUserGroup'])); + } } $this->frontendUserRepository->add($frontendUser); + $persistenceManager = GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\PersistenceManager'); + $persistenceManager->persistAll(); $success = 1; + $tableUid = $frontendUser->getUid(); + if ($tableUid) { + $this->logRepository->insertIntoMm($tableUid, $dmCatArr, $this->settings['table']); + } } if ($this->settings['table'] && $success < 1) { $error = 8; diff --git a/Classes/Domain/Model/FrontendUser.php b/Classes/Domain/Model/FrontendUser.php index fcd31b8..0b6d184 100644 --- a/Classes/Domain/Model/FrontendUser.php +++ b/Classes/Domain/Model/FrontendUser.php @@ -26,6 +26,12 @@ class FrontendUser extends AbstractEntity protected string $www = ''; protected string $company = ''; + protected int $luxletterLanguage = 0; + protected int $mailActive = 0; + protected int $mailHtml = 0; + protected string $mailSalutation = ''; + protected int $categories = 0; + public function __construct(string $username = '', string $password = '') { $this->username = $username; @@ -223,4 +229,59 @@ public function getUsergroup(): string { return $this->usergroup; } + + public function getLuxletterLanguage(): int + { + return $this->luxletterLanguage; + } + + public function setLuxletterLanguage(int $luxletterLanguage): self + { + $this->luxletterLanguage = $luxletterLanguage; + return $this; + } + + public function getMailActive(): int + { + return $this->mailActive; + } + + public function setMailActive(int $active): self + { + $this->mailActive = $active; + return $this; + } + + public function getMailHtml(): int + { + return $this->mailHtml; + } + + public function setMailHtml(int $html): self + { + $this->mailHtml = $html; + return $this; + } + + public function setMailSalutation(string $salutation): self + { + $this->mailSalutation = $salutation; + return $this; + } + + public function getMailSalutation(): string + { + return $this->mailSalutation; + } + + public function getCategories(): int + { + return $this->categories; + } + + public function setCategories(int $categories): self + { + $this->categories = $categories; + return $this; + } } diff --git a/Classes/Domain/Repository/LogRepository.php b/Classes/Domain/Repository/LogRepository.php index 25ce282..55a56a3 100644 --- a/Classes/Domain/Repository/LogRepository.php +++ b/Classes/Domain/Repository/LogRepository.php @@ -53,7 +53,7 @@ function getByEmailAndPid(string $email, array $pids, int $sys_language_uid, int /** * getUidFromExternal: find user ID - * @param string $email die Email-Adresse wurde schon vorher geprüft! + * @param string $email die E-Mail-Adresse wurde schon vorher geprüft! * @param mixed $pid PID oder Liste mit PIDs * @param string $table tt_address oder fe_users * @return integer @@ -143,9 +143,11 @@ function getAllCats($catOrderBy) /** * getOwnCats: find own mail categories + * @param integer $uid user-uid + * @param string $table tt_address or fe_users * @return array */ - function getOwnCats($uid) + function getOwnCats($uid, $table = 'tt_address') { $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('sys_category_record_mm'); $statement = $queryBuilder @@ -153,14 +155,14 @@ function getOwnCats($uid) ->from('sys_category_record_mm') ->where( $queryBuilder->expr()->eq('uid_foreign', $queryBuilder->createNamedParameter($uid, \PDO::PARAM_INT)), - $queryBuilder->expr()->eq('tablenames', $queryBuilder->createNamedParameter('tt_address')) + $queryBuilder->expr()->eq('tablenames', $queryBuilder->createNamedParameter($table)) ) ->executeQuery(); return $statement->fetchAllAssociative(); } /** - * getAllGroups: find all fe_groups + * getAllGroups: find all fe_groups for Luxletter * @param string $groupsOrderBy groups order by * @return array */ @@ -182,8 +184,9 @@ function getAllGroups($groupsOrderBy) * insertIntoMm: insert relations into sys_category_record_mm * @param integer $tableUid user-uid * @param array $dmCatArr sys_category UIDs + * @param string $table tt_content or fe_users */ - protected function insertIntoMm($tableUid, $dmCatArr = []) + function insertIntoMm($tableUid, $dmCatArr = [], $table = 'tt_address') { if (is_array($dmCatArr) && count($dmCatArr)>0) { $count = 0; @@ -197,7 +200,7 @@ protected function insertIntoMm($tableUid, $dmCatArr = []) ->values([ 'uid_foreign' => intval($tableUid), 'uid_local' => intval($uid), - 'tablenames' => 'tt_address', + 'tablenames' => $table, 'fieldname' => 'categories', 'sorting_foreign' => $count ]) @@ -210,8 +213,9 @@ protected function insertIntoMm($tableUid, $dmCatArr = []) /** * deleteInMm: delete relations into sys_category_record_mm * @param integer $tableUid user-uid + * @param string $table tt_content or fe_users */ - protected function deleteInMm($tableUid) + function deleteInMm($tableUid, $table = 'tt_address') { // alle Kategorie-Relationen löschen $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('sys_category_record_mm'); @@ -219,7 +223,7 @@ protected function deleteInMm($tableUid) ->delete('sys_category_record_mm') ->where( $queryBuilder->expr()->eq('uid_foreign', $queryBuilder->createNamedParameter($tableUid, \PDO::PARAM_INT)), - $queryBuilder->expr()->eq('tablenames', $queryBuilder->createNamedParameter('tt_address')) + $queryBuilder->expr()->eq('tablenames', $queryBuilder->createNamedParameter($table)) ) ->executeStatement(); } @@ -283,7 +287,7 @@ function insertInTtAddress($address, $mode, $dmCatArr = [], $salutation = '') ->executeStatement(); $tableUid = $queryBuilder->getConnection()->lastInsertId(); if ($tableUid) { - $this->insertIntoMm($tableUid, $dmCatArr); + $this->insertIntoMm($tableUid, $dmCatArr, 'tt_address'); } return $tableUid; } @@ -339,8 +343,8 @@ function updateInTtAddress($address, $mode, $tableUid, $salutation = '') ->set('mail_active', 1); } $queryBuilder->executeStatement(); - $this->deleteInMm($tableUid); - $this->insertIntoMm($tableUid, $dmCatArr); + $this->deleteInMm($tableUid, 'tt_address'); + $this->insertIntoMm($tableUid, $dmCatArr, 'tt_address'); return $tableUid; } @@ -348,8 +352,9 @@ function updateInTtAddress($address, $mode, $tableUid, $salutation = '') * updateInFeUsers: update fe_user * @param \Fixpunkt\FpNewsletter\Domain\Model\Log $address User * @param int $tableUid externe uid + * @param string $extension mail or luxletter */ - function updateInFeUsers($address, $tableUid) + function updateInFeUsers($address, $tableUid, $extension) { $timestamp = time(); $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('fe_users'); @@ -372,6 +377,34 @@ function updateInFeUsers($address, $tableUid) ->set('company', $address->getCompany()) ->set('usergroup', $address->getCategories()) ->executeStatement(); + if ($extension == 'mail') { + if ($address->getCategories()) { + // Priorität haben die Kategorien aus dem Formular/Log-Eintrag + $dmCatArr = explode(',', $address->getCategories()); + } else { + $dmCatArr = []; + } + $this->deleteInMm($tableUid, 'fe_users'); + $this->insertIntoMm($tableUid, $dmCatArr, 'fe_users'); + $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('fe_users'); + $queryBuilder + ->update('fe_users') + ->where( + $queryBuilder->expr()->eq('uid', $queryBuilder->createNamedParameter($tableUid, \PDO::PARAM_INT)) + ) + ->set('categories', count($dmCatArr)) + ->executeStatement(); + } else { + // Luxletter + $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('fe_users'); + $queryBuilder + ->update('fe_users') + ->where( + $queryBuilder->expr()->eq('uid', $queryBuilder->createNamedParameter($tableUid, \PDO::PARAM_INT)) + ) + ->set('usergroup', $address->getCategories()) + ->executeStatement(); + } return $tableUid; } @@ -403,7 +436,7 @@ function deleteExternalUser($uid, $mode, $dmCatArr = [], $table = 'tt_address') ->executeStatement(); } if (($table == 'tt_address') && is_array($dmCatArr) && count($dmCatArr)>0) { - $this->deleteInMm($uid); + $this->deleteInMm($uid, $table); } } diff --git a/Classes/Utility/HelpersUtility.php b/Classes/Utility/HelpersUtility.php index f2fa00a..4cd9bc5 100644 --- a/Classes/Utility/HelpersUtility.php +++ b/Classes/Utility/HelpersUtility.php @@ -125,6 +125,15 @@ public function checkIfValid( return 0; } + public function getSalutation(int $gender, array $settings): string + { + $salutation = ''; + if ($gender == 1) $salutation = $settings['mrs']; + elseif ($gender == 2) $salutation = $settings['mr']; + elseif ($gender == 3) $salutation = $settings['divers']; + return $salutation; + } + /** * Returns an array with genders * diff --git a/Configuration/TypoScript/setup.ts b/Configuration/TypoScript/setup.ts index b74fc2d..ba63ceb 100644 --- a/Configuration/TypoScript/setup.ts +++ b/Configuration/TypoScript/setup.ts @@ -16,6 +16,7 @@ plugin.tx_fpnewsletter { } settings { table = tt_address + newsletterExtension = optionalFields = gender,firstname,lastname optionalFieldsRequired = doubleOptOut = 1 diff --git a/Documentation/Administrator/Index.rst b/Documentation/Administrator/Index.rst index 7ef9657..bcefafb 100644 --- a/Documentation/Administrator/Index.rst +++ b/Documentation/Administrator/Index.rst @@ -103,6 +103,25 @@ a verification or delete plugin:: lib.nlsubscriptionContent.value = +.. _admin-note-mail: + +Note for the Mail-extension +--------------------------- + +If you are using the Mail-Extension, you can use tt_address or fe_users. +If you are using tt_address, this additional fields will be filled: mail_html, mail_salutation and mail_active. +If you use the table fe_users, this additional fields will be set: mail_html, mail_salutation, mail_active and +categories from categoryOrGroup. New users will not have a group set! + +.. _admin-note-luxletter: + +Note for the Luxletter-extension +-------------------------------- + +If you are using the Luxletter-Extension, you can use only the table fe_users. +This additional fields will be filled: user group with categoryOrGroup and if the setting newsletterExtension=luxletter +is set: luxletter_language. + .. _admin-mail: Unsubscription via Mail-extension diff --git a/Documentation/Configuration/Index.rst b/Documentation/Configuration/Index.rst index 4f74e4e..6cd07d3 100644 --- a/Documentation/Configuration/Index.rst +++ b/Documentation/Configuration/Index.rst @@ -27,6 +27,7 @@ Properties for settings Property Data type Description Default ================================= =========== ===================================================================== ================================= table string tt_address, fe_users or none (empty value) supported tt_address +newsletterExtension string luxletter (default for fe_users) or mail (default for tt_address) optionalFields string Optional fields: see below gender,firstname,lastname optionalFieldsRequired string Optional required* fields: see below doubleOptOut boolean Enable double out out unsubscription? 1 diff --git a/Documentation/Localization.de_DE/Administrator/Index.rst b/Documentation/Localization.de_DE/Administrator/Index.rst index d5173a5..1d5da25 100644 --- a/Documentation/Localization.de_DE/Administrator/Index.rst +++ b/Documentation/Localization.de_DE/Administrator/Index.rst @@ -99,6 +99,24 @@ Falls du das Anmelde-Plugin von fp_newsletter benutzt, solltest du das cachable In dem Fall muss noch eine Seite für die Anmeldung definiert werden, wohin das Formular umleiten soll. Ein mathematisches Captcha ist bei diesem cachable Anmelde-Formular nicht möglich! +.. _admin-note-mail: + +Anmerkung für die Mail-Extension +-------------------------------- + +Wenn man die Mail-Extension benutzt, kann man die Tabellen tt_address oder fe_users benutzen. +Wenn man tt_address benutzt, werden diese zusätzlichen Felder befüllt: mail_html, mail_salutation und mail_active. +Wenn man fe_users benutzt, werden diese zusätzlichen Felder befüllt: mail_html, mail_salutation, mail_active und +categories von categoryOrGroup. Es wird keine Gruppe zugewiesen! + +.. _admin-note-luxletter: + +Anmerkung für die Luxletter-Extension +------------------------------------- + +Wenn man die Luxletter-Extension benutzt, kann man nur die Tabelle fe_users verwenden. +Diese zusätzlichen Felder werden befüllt: Gruppe von categoryOrGroup und wenn die Setting newsletterExtension=luxletter +gesetzt ist: luxletter_language. .. _admin-mail: diff --git a/Documentation/Localization.de_DE/Configuration/Index.rst b/Documentation/Localization.de_DE/Configuration/Index.rst index a8734d5..46e1305 100644 --- a/Documentation/Localization.de_DE/Configuration/Index.rst +++ b/Documentation/Localization.de_DE/Configuration/Index.rst @@ -27,6 +27,7 @@ Settings-Einstellungen Feld Typ Beschreibung Standard-Wert ================================= =========== ===================================================================== ================================ table string tt_address, fe_users oder keine Tabelle (leerer Wert) möglich tt_address +newsletterExtension string luxletter (default für fe_users) oder mail (default für tt_address) optionalFields string Optionale Werte: siehe weiter unten gender,firstname,lastname optionalFieldsRequired string Optionale erforderliche* Werte: siehe weiter unten doubleOptOut boolean Double opt out Abmeldung einschalten? 1 diff --git a/README.md b/README.md index ce7f5a3..fe3a4db 100644 --- a/README.md +++ b/README.md @@ -38,4 +38,7 @@ Version 6.0: Version 6.1.0: - Compatibility to TYPO3 11.5 added again. -- Bugfix: language added to the links in the email. \ No newline at end of file +- Bugfix: language added to the links in the email. + +Version 6.2.0: +- fe_users can now be used with the extension luxletter or mail. \ No newline at end of file diff --git a/Resources/Private/Partials/Log/FormFieldsEdit.html b/Resources/Private/Partials/Log/FormFieldsEdit.html index 013c405..6b693bb 100644 --- a/Resources/Private/Partials/Log/FormFieldsEdit.html +++ b/Resources/Private/Partials/Log/FormFieldsEdit.html @@ -7,9 +7,9 @@