Commit 0fb427fb authored by ErikHommel's avatar ErikHommel
Browse files

alternative way for email preferences

parent d7813e7d
......@@ -69,10 +69,7 @@ class GetEmailPrefs extends AbstractAction {
new Specification("display_name", "String", E::ts("Contact Display Name"), FALSE),
new Specification("sort_name", "String", E::ts("Contact Sort Name"), FALSE),
new Specification("contact_id", "Integer", E::ts("Contact ID"), TRUE),
new Specification("newsletter_and_actions", "Boolean", E::ts("Maandelijkse nieuwsbrief en actie berichten"), TRUE),
new Specification("newsletter_only", "Boolean", E::ts("Alleen maandelijkse nieuwsbrief"), TRUE),
new Specification("yearly_report", "Boolean", E::ts("Alleen jaar rapport"), TRUE),
new Specification("no_general_info", "Boolean", E::ts("Geen algemene berichten"), TRUE),
new Specification("general_info", "Integer", E::ts("Algemene berichten"), TRUE),
new Specification("flex1", "Boolean", E::ts("Flexibel 1"), TRUE),
new Specification("flex2", "Boolean", E::ts("Flexibel 2"), TRUE),
new Specification("flex3", "Boolean", E::ts("Flexibel 3"), TRUE),
......@@ -126,23 +123,6 @@ class GetEmailPrefs extends AbstractAction {
return $result;
}
/**
* Method to generate the webform field name from the group title
*
* @param $groupTitle
* @return mixed|string
*/
private function generateWebformName($groupTitle) {
$webformName = strtolower($groupTitle);
$webformName = str_replace(' ', '_', $webformName);
$webformName = str_replace(',', '_', $webformName);
$webformName = str_replace('.', '_', $webformName);
$webformName = str_replace(';', '_', $webformName);
$webformName = str_replace(':', '_', $webformName);
$webformName = str_replace('__', '_', $webformName);
return $webformName;
}
/**
* Method to get the contact data
*
......@@ -185,42 +165,32 @@ class GetEmailPrefs extends AbstractAction {
$flex1GroupId = $this->configuration->getParameter("flex1_group_id");
$flex2GroupId = $this->configuration->getParameter("flex2_group_id");
$flex3GroupId = $this->configuration->getParameter("flex3_group_id");
// default no general info
$result['general_info'] = 4;
foreach ($groups as $groupId) {
switch ($groupId) {
// if monthly newsletter: monthly newsletter on and no general, yearly report and monthly actions off
// if monthly newsletter: monthly newsletter on (only if no monthly action)
case $newsGroupId:
if (!$result['newsletter_and_actions']) {
$result['newsletter_only'] = "1";
$result['newsletter_and_actions'] = "0";
$result['yearly_report'] = "0";
$result['no_general_info'] = "0";
if ($result['general_info'] != 1) {
$result['general_info'] = 2;
}
break;
// if monthy actions: monthly newsletter and monthly actions on, general and yearly report off
// if monthy actions: monthly newsletter and monthly actions on
case $actionGroupId:
$result['newsletter_only'] = "0";
$result['newsletter_and_actions'] = "1";
$result['yearly_report'] = "0";
$result['no_general_info'] = "0";
$result['general_info'] = 1;
break;
// if yearly report: yearly report on and monthly newsletter, monthly actions and general off
// if yearly report: yearly report on
case $yearlyGroupId:
$result['newsletter_only'] = "0";
$result['newsletter_and_actions'] = "0";
$result['yearly_report'] = "1";
$result['no_general_info'] = "0";
$result['general_info'] = 3;
break;
// check if any of the specifics need setting
case $flex1GroupId:
$result['no_general_info'] = "0";
$result['flex1'] = "1";
break;
case $flex2GroupId:
$result['no_general_info'] = "0";
$result['flex2'] = "1";
break;
case $flex3GroupId:
$result['no_general_info'] = "0";
$result['flex3'] = "1";
break;
}
......@@ -233,10 +203,7 @@ class GetEmailPrefs extends AbstractAction {
*/
private function defaultPreferencesForGet() {
return [
"no_general_info" => "1",
"newsletter_only" => "0",
"newsletter_and_actions" => "0",
"yearly_report" => "0",
"general_info" => 4,
"flex1" => "0",
"flex2" => "0",
"flex3" => "0",
......
......@@ -27,10 +27,7 @@ class SetEmailPrefs extends AbstractAction {
public function getParameterSpecification() {
$specs = new SpecificationBag();
$specs->addSpecification(new Specification("contact_id", "Integer", E::ts("Contact ID"), TRUE, NULL));
$specs->addSpecification(new Specification("newsletter_and_actions", "Boolean", E::ts("Maandelijkse nieuwsbrief en actie berichten"), TRUE, FALSE));
$specs->addSpecification(new Specification("newsletter_only", "Boolean", E::ts("Alleen maandelijkse nieuwsbrief"), TRUE, FALSE));
$specs->addSpecification(new Specification("yearly_report", "Boolean", E::ts("Alleen jaar rapport"), TRUE, FALSE));
$specs->addSpecification(new Specification("no_general_info", "Boolean", E::ts("Geen algemene berichten"), TRUE, FALSE));
$specs->addSpecification(new Specification("general_info", "Integer", E::ts("Algemene berichten"), TRUE, 4));
$specs->addSpecification(new Specification("flex1", "Boolean", E::ts("Flexibel 1"), FALSE, FALSE));
$specs->addSpecification(new Specification("flex2", "Boolean", E::ts("Flexibel 2"), FALSE, FALSE));
$specs->addSpecification(new Specification("flex3", "Boolean", E::ts("Flexibel 3"), FALSE, FALSE));
......@@ -88,43 +85,45 @@ class SetEmailPrefs extends AbstractAction {
private function setGroupMemberships($contactId, ParameterBagInterface $parameters) {
$adds = [];
$removes = [];
$action = $parameters->getParameter('newsletter_and_actions');
$news = $parameters->getParameter('newsletter_only');
$yearly = $parameters->getParameter('yearly_report');
$noInfo = $parameters->getParameter('no_general_info');
$generalInfo = $parameters->getParameter('general_info');
$flex1 = $parameters->getParameter('flex1');
$flex2 = $parameters->getParameter('flex2');
$flex3 = $parameters->getParameter('flex3');
if ($noInfo || (!$action && !$news && !$yearly && !$flex1 && !$flex2 && !$flex3)) {
$removes = [
$this->configuration->getParameter('yearly_group_id'),
$this->configuration->getParameter('action_group_id'),
$this->configuration->getParameter('news_group_id'),
$this->configuration->getParameter('flex1_group_id'),
$this->configuration->getParameter('flex2_group_id'),
$this->configuration->getParameter('flex3_group_id'),
];
}
if ($yearly && !$action && !$news && !$noInfo) {
$removes = [
$this->configuration->getParameter('action_group_id'),
$this->configuration->getParameter('news_group_id'),
];
$adds = [$this->configuration->getParameter('yearly_group_id')];
}
if ($action && !$news && !$yearly && !$noInfo) {
$adds = [
$this->configuration->getParameter('action_group_id'),
$this->configuration->getParameter('news_group_id'),
];
$removes = [$this->configuration->getParameter('yearly_group_id')];
}
if ($news && !$action && !$yearly && !$noInfo) {
$adds = [$this->configuration->getParameter('news_group_id')];
$removes = [
$this->configuration->getParameter('action_group_id'),
$this->configuration->getParameter('yearly_group_id'),
];
switch ($generalInfo) {
case 1:
$removes = [
$this->configuration->getParameter('yearly_group_id'),
];
$adds = [
$this->configuration->getParameter('action_group_id'),
$this->configuration->getParameter('news_group_id'),
];
break;
case 2:
$removes = [
$this->configuration->getParameter('action_group_id'),
$this->configuration->getParameter('yearly_group_id'),
];
$adds = [
$this->configuration->getParameter('news_group_id'),
];
break;
case 3:
$removes = [
$this->configuration->getParameter('action_group_id'),
$this->configuration->getParameter('news_group_id'),
];
$adds = [
$this->configuration->getParameter('yearly_group_id'),
];
break;
case 4:
$removes = [
$this->configuration->getParameter('yearly_group_id'),
$this->configuration->getParameter('action_group_id'),
$this->configuration->getParameter('news_group_id'),
];
$adds = [];
}
// now add or remove the flexible ones
if ($flex1) {
......
......@@ -14,8 +14,8 @@
<url desc="Support">https://civicoop.org</url>
<url desc="Licensing">http://www.gnu.org/licenses/agpl-3.0.html</url>
</urls>
<releaseDate>2020-09-23</releaseDate>
<version>1.7</version>
<releaseDate>2020-11-18</releaseDate>
<version>1.8</version>
<develStage>beta</develStage>
<compatibility>
<ver>4.7</ver>
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment