Skip to content

Commit

Permalink
Version 6.1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
bihor committed Nov 27, 2023
1 parent 4346665 commit 1b5a21e
Show file tree
Hide file tree
Showing 11 changed files with 203 additions and 35 deletions.
60 changes: 41 additions & 19 deletions Classes/Controller/LogController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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']);
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand All @@ -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;
Expand Down
61 changes: 61 additions & 0 deletions Classes/Domain/Model/FrontendUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
}
59 changes: 46 additions & 13 deletions Classes/Domain/Repository/LogRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -143,24 +143,26 @@ 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
->select('uid_local')
->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
*/
Expand All @@ -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;
Expand All @@ -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
])
Expand All @@ -210,16 +213,17 @@ 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');
$queryBuilder
->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();
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -339,17 +343,18 @@ 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;
}

/**
* 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');
Expand All @@ -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;
}

Expand Down Expand Up @@ -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);
}
}

Expand Down
9 changes: 9 additions & 0 deletions Classes/Utility/HelpersUtility.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down
1 change: 1 addition & 0 deletions Configuration/TypoScript/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ plugin.tx_fpnewsletter {
}
settings {
table = tt_address
newsletterExtension =
optionalFields = gender,firstname,lastname
optionalFieldsRequired =
doubleOptOut = 1
Expand Down
19 changes: 19 additions & 0 deletions Documentation/Administrator/Index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions Documentation/Configuration/Index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading

0 comments on commit 1b5a21e

Please sign in to comment.