Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Partners
CiviCooP
AIVL
aivlspecificactions
Commits
8d7f6afe
Commit
8d7f6afe
authored
May 03, 2021
by
ErikHommel
Browse files
issue 7740 petition action updated for petition import
parent
36ad24ec
Changes
2
Hide whitespace changes
Inline
Side-by-side
Civi/Aivlspecificactions/Actions/PetitionActivity.php
View file @
8d7f6afe
...
...
@@ -32,8 +32,6 @@ class PetitionActivity extends AbstractAction {
$specs
->
addSpecification
(
new
Specification
(
'contact_id'
,
'Integer'
,
E
::
ts
(
'Contact ID'
),
TRUE
,
NULL
));
$specs
->
addSpecification
(
new
Specification
(
'petition_flag'
,
'Integer'
,
E
::
ts
(
'Petition Flag'
),
FALSE
,
0
));
$specs
->
addSpecification
(
new
Specification
(
'more_information'
,
'Integer'
,
E
::
ts
(
'More Information'
),
FALSE
,
0
));
$specs
->
addSpecification
(
new
Specification
(
'phone'
,
'String'
,
E
::
ts
(
'Phone'
),
FALSE
,
NULL
));
$specs
->
addSpecification
(
new
Specification
(
'mobile'
,
'String'
,
E
::
ts
(
'Mobile'
),
FALSE
,
NULL
));
$specs
->
addSpecification
(
new
Specification
(
'signature_date'
,
'Date'
,
E
::
ts
(
'Signature Date'
),
FALSE
,
NULL
));
return
$specs
;
}
...
...
@@ -66,98 +64,31 @@ class PetitionActivity extends AbstractAction {
/**
* Do the actual action - process petition signature
*
* @param ParameterBagInterface $parameter
s
* @param ParameterBagInterface $parameter
Bag
* @param ParameterBagInterface $output
* @throws ExecutionException
*/
public
function
doAction
(
ParameterBagInterface
$parameters
,
ParameterBagInterface
$output
)
{
// update phones
$this
->
updatePhones
(
$parameters
);
if
(
!
$this
->
signedPetitionEarlier
(
$parameters
))
{
$this
->
addPetitionActivity
(
$parameters
,
$output
);
public
function
doAction
(
ParameterBagInterface
$parameterBag
,
ParameterBagInterface
$output
)
{
if
(
!
$this
->
signedPetitionEarlier
(
$parameterBag
))
{
$this
->
addPetitionActivity
(
$parameterBag
,
$output
);
// temporarily: add to Nieuwsbrief group if more information ticked
$this
->
addNieuwsbrief
(
$parameter
s
);
$this
->
addNieuwsbrief
(
$parameter
Bag
);
}
else
{
throw
new
ExecutionException
(
E
::
ts
(
'Petition was already signed by this contact'
));
}
}
/**
* Method to update phones if required
* @param ParameterBagInterface $parameters
*/
private
function
updatePhones
(
ParameterBagInterface
$parameters
)
{
$phone
=
$parameters
->
getParameter
(
'phone'
);
$mobile
=
$parameters
->
getParameter
(
'mobile'
);
if
(
$phone
||
$mobile
)
{
$contactId
=
$parameters
->
getParameter
(
'contact_id'
);
try
{
$phoneTypes
=
civicrm_api3
(
'OptionValue'
,
'get'
,
[
'sequential'
=>
1
,
'return'
=>
[
"value"
,
"name"
],
'option_group_id'
=>
"phone_type"
,
'name'
=>
[
'IN'
=>
[
"Phone"
,
"Mobile"
]],
]);
foreach
(
$phoneTypes
[
'values'
]
as
$phoneType
)
{
switch
(
$phoneType
[
'name'
])
{
case
"Phone"
:
if
(
$phone
)
{
$this
->
addPhone
(
$contactId
,
$phoneType
[
'value'
],
$phone
);
}
break
;
case
"Mobile"
:
if
(
$mobile
)
{
$this
->
addPhone
(
$contactId
,
$phoneType
[
'value'
],
$mobile
);
}
break
;
}
}
}
catch
(
\
CiviCRM_API3_Exception
$ex
)
{
}
}
}
/**
* Method to add single phone if not exists for contact
*
* @param $contactId
* @param $phoneTypeId
* @param $phone
* @throws \CiviCRM_API3_Exception
*/
private
function
addPhone
(
$contactId
,
$phoneTypeId
,
$phone
)
{
$phoneNumeric
=
\
CRM_Aivlspecificactions_Utils
::
useOnlyNumericPhone
(
$phone
);
// first check if phone already exists
$query
=
"SELECT COUNT(*) FROM civicrm_phone WHERE contact_id = %1 AND phone_type_id = %2
AND phone_numeric = %3"
;
$count
=
\
CRM_Core_DAO
::
singleValueQuery
(
$query
,
[
1
=>
[(
int
)
$contactId
,
"Integer"
],
2
=>
[(
int
)
$phoneTypeId
,
"Integer"
],
3
=>
[(
int
)
$phoneNumeric
,
"Integer"
],
]);
if
(
$count
==
0
)
{
civicrm_api3
(
'Phone'
,
'create'
,
[
'contact_id'
=>
$contactId
,
'location_type_id'
=>
\
CRM_Aivlspecificactions_Utils
::
getDefaultLocationTypeId
(),
'phone_type_id'
=>
$phoneTypeId
,
'phone'
=>
$phone
,
'is_primary'
=>
\
CRM_Aivlspecificactions_Utils
::
setIsPrimary
(
'phone'
,
$contactId
),
]);
}
}
/**
* Method to check if the contact already signed this petition
*
* @param $parameter
s
* @param $parameter
Bag
* @return bool
* @throws
*/
private
function
signedPetitionEarlier
(
$parameter
s
)
{
$contactId
=
$parameter
s
->
getParameter
(
'contact_id'
);
$campaignId
=
$parameter
s
->
getParameter
(
'campaign_id'
);
private
function
signedPetitionEarlier
(
ParameterBagInterface
$parameter
Bag
)
{
$contactId
=
$parameter
Bag
->
getParameter
(
'contact_id'
);
$campaignId
=
$parameter
Bag
->
getParameter
(
'campaign_id'
);
$activityTypeId
=
$this
->
configuration
->
getParameter
(
'activity_type_id'
);
if
(
$contactId
&&
$campaignId
&&
$activityTypeId
)
{
$count
=
civicrm_api3
(
'Activity'
,
'getcount'
,
[
...
...
@@ -176,13 +107,13 @@ class PetitionActivity extends AbstractAction {
* Method to add contact to newsletter group (temp until we fixed email preferences
*
* @link https://issues.civicoop.org/issues/7337)
* @param ParameterBagInterface $parameter
s
* @param ParameterBagInterface $parameter
Bag
* @throws \CiviCRM_API3_Exception
*/
private
function
addNieuwsbrief
(
ParameterBagInterface
$parameter
s
)
{
private
function
addNieuwsbrief
(
ParameterBagInterface
$parameter
Bag
)
{
$groupId
=
$this
->
configuration
->
getParameter
(
'news_group_id'
);
$moreInfo
=
$parameter
s
->
getParameter
(
'more_information'
);
$contactId
=
$parameter
s
->
getParameter
(
'contact_id'
);
$moreInfo
=
$parameter
Bag
->
getParameter
(
'more_information'
);
$contactId
=
$parameter
Bag
->
getParameter
(
'contact_id'
);
if
(
$moreInfo
&&
$groupId
&&
$contactId
)
{
// first check if contact is already in group, if not add
$count
=
civicrm_api3
(
'GroupContact'
,
'getcount'
,
[
...
...
@@ -204,24 +135,24 @@ class PetitionActivity extends AbstractAction {
}
/**
* @param ParameterBagInterface $parameter
s
* @param ParameterBagInterface $parameter
Bag
* @param ParameterBagInterface $output
* @throws ExecutionException
*/
private
function
addPetitionActivity
(
ParameterBagInterface
$parameter
s
,
ParameterBagInterface
$output
)
{
$campaignId
=
$parameter
s
->
getParameter
(
'campaign_id'
);
$contactId
=
$parameter
s
->
getParameter
(
'contact_id'
);
$petitionFlag
=
$parameter
s
->
getParameter
(
'petition_flag'
);
private
function
addPetitionActivity
(
ParameterBagInterface
$parameter
Bag
,
ParameterBagInterface
$output
)
{
$campaignId
=
$parameter
Bag
->
getParameter
(
'campaign_id'
);
$contactId
=
$parameter
Bag
->
getParameter
(
'contact_id'
);
$petitionFlag
=
$parameter
Bag
->
getParameter
(
'petition_flag'
);
if
(
$campaignId
&&
$contactId
&&
$petitionFlag
)
{
$activityParams
=
[
'source_contact_id'
=>
'user_contact_id'
,
'target_id'
=>
$parameter
s
->
getParameter
(
'contact_id'
),
'target_id'
=>
$parameter
Bag
->
getParameter
(
'contact_id'
),
'campaign_id'
=>
$campaignId
,
'activity_type_id'
=>
$this
->
configuration
->
getParameter
(
'activity_type_id'
),
'status_id'
=>
$this
->
configuration
->
getParameter
(
'status_id'
),
'subject'
=>
$this
->
getCampaignTitle
(
$campaignId
),
];
$signatureDate
=
$parameter
s
->
getParameter
(
'signature_date'
);
$signatureDate
=
$parameter
Bag
->
getParameter
(
'signature_date'
);
if
(
$signatureDate
)
{
try
{
$activityDate
=
new
\
DateTime
(
$signatureDate
);
...
...
info.xml
View file @
8d7f6afe
...
...
@@ -14,7 +14,7 @@
<url
desc=
"Support"
>
https://civicoop.org
</url>
<url
desc=
"Licensing"
>
http://www.gnu.org/licenses/agpl-3.0.html
</url>
</urls>
<releaseDate>
2021-0
3-24
</releaseDate>
<releaseDate>
2021-0
5-03
</releaseDate>
<version>
1.14
</version>
<develStage>
stable
</develStage>
<compatibility>
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment