Compare commits

...

32 commits
1.0.1 ... main

Author SHA1 Message Date
Marc Michalsky
012f4901e4
🔖 bump version to 1.0.8 2024-07-18 15:38:42 +02:00
Marc Michalsky
7415fac88d
Cover the case where an event creator passes only one name part 2024-07-18 15:37:30 +02:00
Marc Michalsky
91c70c645a
Push only active campaigns to Twingle 2024-07-18 15:35:31 +02:00
Marc Michalsky
de9cd894b7
🔖 bump version to 1.0.7 2024-06-15 12:12:35 +02:00
Marc Michalsky
711ccd7469
Merge branch 'twingle_api_adaptions' 2024-06-15 12:02:47 +02:00
Marc Michalsky
beb9d8f170
take into account the latest changes to the Twingle API 2024-06-15 11:36:12 +02:00
Marc_Michalsky
65c7e668b3 Merge branch 'rethrow-exception' into 'main'
APIWrapper: Rethrow exception

See merge request Marc_Michalsky/de-forumzfd-twinglecampaign!3
2024-06-15 09:26:47 +00:00
Marc_Michalsky
93c1ab649d Merge branch 'avoid-array_key_exists-on-null' into 'main'
Avoid `array_key_exists()` on `NULL`

See merge request Marc_Michalsky/de-forumzfd-twinglecampaign!4
2024-06-15 09:25:59 +00:00
Marc_Michalsky
ee32f19f31 Merge branch 'fix-mapDonation' into 'main'
APIWrapper: Make `mapDonation()` static becauts it's called static

See merge request Marc_Michalsky/de-forumzfd-twinglecampaign!2
2024-06-15 09:22:55 +00:00
Dominic Tubach
cbb148b22f Avoid array_key_exists() on NULL 2024-04-22 10:10:51 +02:00
Dominic Tubach
9118b622d0 APIWrapper: Rethrow exception 2024-04-19 10:29:04 +02:00
Dominic Tubach
db1ab69138 APIWrapper: Make mapDonation() static becauts it's called static 2024-04-19 10:15:55 +02:00
Marc Michalsky
bcd2b448d2
fix udefined constant "error" 2024-04-08 12:19:48 +02:00
Marc Michalsky
571a86ea66
🔖 bump version to 1.0.5 2023-08-14 18:44:36 +02:00
Marc Michalsky
dc723ed8aa
🐛 bug fix: wrong value for option values 2023-08-14 17:52:23 +02:00
Marc Michalsky
e5ab52f24b
🐛 fix bug: double escaping of \n 2023-08-14 17:20:24 +02:00
Marc Michalsky
8863bbeed0
🔖 bump version to 1.0.4 2023-08-14 16:53:47 +02:00
Marc Michalsky
c45f275fc3
🐛 bug fix: do not create empty option values 2023-08-14 16:50:25 +02:00
Marc Michalsky
de19c3991c
🔖 bump version to 1.0.4-dev 2023-08-14 16:18:56 +02:00
Marc Michalsky
82b4632d63
implement matomo integration 2023-08-14 16:16:50 +02:00
Marc Michalsky
2949ab0168
create new option values when custom field is changed 2023-08-14 16:15:05 +02:00
Marc Michalsky
54adee32a9
Add new project types 'shop' and 'giftshop' 2023-08-14 16:12:56 +02:00
Marc Michalsky
bfa3ae7e32
fix wrong return type 2023-08-14 16:11:30 +02:00
Marc Michalsky
a4cda1427b
🔖 bump version to 1.0.3
- 🐛 fix bug: cannot search for TwingleForm by twingle_project_id
- Documentation to enable scheduled job in nonproductive sites by @RoWo-DS
2023-02-28 15:25:28 +01:00
Marc Michalsky
2908e11582
Merge remote-tracking branch 'origin/main' into main 2023-02-28 15:17:24 +01:00
Marc_Michalsky
2e2f77d3aa Merge branch 'main' into 'main'
Documentation to enable scheduled job in nonproductive sites

See merge request Marc_Michalsky/de-forumzfd-twinglecampaign!1
2023-02-28 14:16:25 +00:00
Marc Michalsky
51b19ac68d
🐛 fix bug: cannot search for TwingleForm by twingle_project_id 2023-02-28 15:14:31 +01:00
Marc Michalsky
6476a163fc
🔖 bump version to 1.0.2 2022-11-21 16:52:38 +01:00
Marc Michalsky
425de0b6ab
Merge branch 'dev' into main 2022-11-21 16:51:07 +01:00
Marc Michalsky
975b77eaf2
🔧 do not only fetch active campaigns from campaign.get 2022-11-21 16:12:04 +01:00
Daniel Scholten
6a50ea2c16
Documentation to enable scheduled job in nonproductive sites 2022-07-21 10:42:37 +02:00
Marc Michalsky
cb4c11feee 🐛 bug fix: color fields were converted from hex to dec values
Added this two color fields to $colorFields:
- design_button_font_color
- design_button_font_color_light
2022-01-20 16:53:15 +01:00
18 changed files with 256 additions and 182 deletions

View file

@ -7,7 +7,8 @@ class CRM_TwingleCampaign_BAO_Configuration {
'twingle_api_key', 'twingle_api_key',
'twinglecampaign_xcm_profile', 'twinglecampaign_xcm_profile',
'twinglecampaign_default_case', 'twinglecampaign_default_case',
'twinglecampaign_soft_credits' 'twinglecampaign_soft_credits',
'twinglecampaign_matomo_integration'
]; ];
@ -27,6 +28,12 @@ class CRM_TwingleCampaign_BAO_Configuration {
Civi::settings()->set('twinglecampaign_soft_credits', 0); Civi::settings()->set('twinglecampaign_soft_credits', 0);
} }
// Set twinglecampaign_matomo_integration to '0' if checkbox is unchecked
if (!array_key_exists('twinglecampaign_matomo_integration', $settings)) {
Civi::settings()->set('twinglecampaign_matomo_integration', 0);
}
Civi::settings()->add($settings); Civi::settings()->add($settings);
} }

View file

@ -62,10 +62,11 @@ class CRM_TwingleCampaign_BAO_CustomField {
* @param bool $upgrade * @param bool $upgrade
* If true: Does not show UF message if custom field already exists * If true: Does not show UF message if custom field already exists
* *
* @returns array Result of custom field creation api call * @returns array|False Result of custom field creation api call. False if
* field already existed und wasn't upgraded.
* @throws \CiviCRM_API3_Exception * @throws \CiviCRM_API3_Exception
*/ */
public function create(bool $upgrade = FALSE): ?array { public function create(bool $upgrade = FALSE) {
// Check if the field already exists // Check if the field already exists
$field = civicrm_api3( $field = civicrm_api3(
@ -129,17 +130,36 @@ class CRM_TwingleCampaign_BAO_CustomField {
return NULL; return NULL;
} }
else { else {
return NULL; $this->id = $field['values'][0]['id'];
$this->custom_group_id = $field['values'][0]['custom_group_id'];
return $this->upgrade($field['values'][0]);
} }
} }
/** /**
* Update an existing custom field * Upgrade an existing custom field
* *
* @returns array Result of custom field creation api call * @param $attributes
* Custom Field data
* @returns array|False Result of custom field creation api call, False if
* field was not upgraded
*/ */
public function update(): array { private function upgrade($attributes) {
$upgrade_necessary = False;
if (key_exists('option_group_id', $attributes)) {
$this->addOptions($attributes);
}
foreach ($this as $var => $value) {
// put array items into attributes
if (array_key_exists($var, $attributes) && $attributes[$var] != $value) {
$this->$var = $attributes[$var];
$upgrade_necessary = True;
}
}
if ($upgrade_necessary) {
try { try {
$this->result = civicrm_api3( $this->result = civicrm_api3(
'CustomField', 'CustomField',
@ -159,7 +179,8 @@ class CRM_TwingleCampaign_BAO_CustomField {
else { else {
throw new CiviCRM_API3_Exception($this->result['error_message']); throw new CiviCRM_API3_Exception($this->result['error_message']);
} }
} catch (CiviCRM_API3_Exception $e) { }
catch (CiviCRM_API3_Exception $e) {
// If the field could not get created: log error // If the field could not get created: log error
$errorMessage = $e->getMessage(); $errorMessage = $e->getMessage();
if ($this->name && $this->custom_group_id) { if ($this->name && $this->custom_group_id) {
@ -176,6 +197,8 @@ class CRM_TwingleCampaign_BAO_CustomField {
return $this->result; return $this->result;
} }
} }
return False;
}
/** /**
* Add additional options to custom field * Add additional options to custom field
@ -188,30 +211,14 @@ class CRM_TwingleCampaign_BAO_CustomField {
$result = []; $result = [];
try { try {
$option_group_id = civicrm_api3( foreach ($this->option_values as $key => $value) {
'CustomField',
'getsingle',
['id' => $this->id]
)['option_group_id'];
} catch (CiviCRM_API3_Exception $e) {
$errorMessage = $e->getMessage();
Civi::log()
->error("$this->extensionName could not get get option group id for custom field \"$this->name\": $errorMessage");
CRM_Utils_System::setUFMessage(
E::ts('%1 could not get option group id for custom field \'%2\'. Find more information in the logs.',
[1 => $this->extensionName, 2 => $this->name])
);
}
try {
foreach ($options as $key => $value) {
$option_value_exists = civicrm_api3( $option_value_exists = civicrm_api3(
'OptionValue', 'OptionValue',
'get', 'get',
[ [
'sequential' => 1, 'sequential' => 1,
'option_group_id' => $option_group_id, 'option_group_id' => $options['option_group_id'],
'value' => $key, 'value' => $key,
] ]
); );
@ -222,7 +229,7 @@ class CRM_TwingleCampaign_BAO_CustomField {
'OptionValue', 'OptionValue',
'create', 'create',
[ [
'option_group_id' => $option_group_id, 'option_group_id' => $options['option_group_id'],
'value' => $key, 'value' => $key,
'label' => $value, 'label' => $value,
] ]
@ -236,6 +243,7 @@ class CRM_TwingleCampaign_BAO_CustomField {
[ [
'id' => $option_value_exists['values'][0]['id'], 'id' => $option_value_exists['values'][0]['id'],
'label' => $value, 'label' => $value,
'value' => $key,
] ]
); );
} }

View file

@ -219,13 +219,15 @@ class CRM_TwingleCampaign_BAO_TwingleEvent extends Campaign {
private private
static function matchContact(string $names, string $email): ?int { static function matchContact(string $names, string $email): ?int {
$names = StringOps::split_names($names); // Hopefully just a temporary solution $names = StringOps::split_names($names); // Hopefully just a temporary solution
$firstnames = $names['firstnames']; $firstnames = $names['firstnames'] ?? NULL;
$lastname = $names['lastname']; $lastname = $names['lastname'] ?? NULL;
$display_name = $names['display_name'] ?? NULL;
try { try {
$contact = civicrm_api3('Contact', 'getorcreate', [ $contact = civicrm_api3('Contact', 'getorcreate', [
'xcm_profile' => Civi::settings()->get('twinglecampaign_xcm_profile'), 'xcm_profile' => Civi::settings()->get('twinglecampaign_xcm_profile'),
'first_name' => $firstnames, 'first_name' => $firstnames,
'last_name' => $lastname, 'last_name' => $lastname,
'display_name' => $display_name,
'email' => $email, 'email' => $email,
]); ]);
return (int) $contact['id']; return (int) $contact['id'];

View file

@ -36,6 +36,8 @@ class CRM_TwingleCampaign_BAO_TwingleProject extends Campaign {
'design_background_color', 'design_background_color',
'design_primary_color', 'design_primary_color',
'design_font_color', 'design_font_color',
'design_button_font_color',
'design_button_font_color_light',
]; ];
/** /**
@ -179,15 +181,8 @@ class CRM_TwingleCampaign_BAO_TwingleProject extends Campaign {
return FALSE; return FALSE;
} }
$result = parent::create($no_hook); return parent::create($no_hook);
// Check if campaign was created successfully
if ($result['is_error'] == 0) {
return TRUE;
}
else {
throw new Exception($result['error_message']);
}
} }
/** /**

View file

@ -1,7 +1,7 @@
<?php <?php
/* /*
* A simple custom exception that indicates a problem with the TwingleCampaign class * A simple custom exception that indicates a problem within the TwingleCampaign class
*/ */
class CRM_TwingleCampaign_Exceptions_TwingleCampaignException extends Exception { class CRM_TwingleCampaign_Exceptions_TwingleCampaignException extends Exception {

View file

@ -46,6 +46,13 @@ class CRM_TwingleCampaign_Form_Settings extends CRM_Core_Form {
FALSE FALSE
); );
$this->addElement(
'checkbox',
'twinglecampaign_matomo_integration',
E::ts('Use Matomo to track user interaction with Twingle forms'),
FALSE
);
$this->addButtons([ $this->addButtons([
[ [
'type' => 'submit', 'type' => 'submit',

View file

@ -20,7 +20,7 @@ class CRM_TwingleCampaign_Upgrader extends CRM_TwingleCampaign_Upgrader_Base {
* changed campaigns will get pulled from Twingle. * changed campaigns will get pulled from Twingle.
* @throws \CiviCRM_API3_Exception * @throws \CiviCRM_API3_Exception
*/ */
public function upgrade_02(): bool { public function upgrade_03(): bool {
$campaign_info = require E::path() . $campaign_info = require E::path() .
'/CRM/TwingleCampaign/resources/campaigns.php'; '/CRM/TwingleCampaign/resources/campaigns.php';
@ -96,7 +96,7 @@ class CRM_TwingleCampaign_Upgrader extends CRM_TwingleCampaign_Upgrader_Base {
[1 => $e->getMessage()] [1 => $e->getMessage()]
), ),
E::ts('Scheduled Job'), E::ts('Scheduled Job'),
error 'error'
); );
} }
@ -294,83 +294,4 @@ class CRM_TwingleCampaign_Upgrader extends CRM_TwingleCampaign_Upgrader_Base {
Civi::settings()->revert('twingle_api_key'); Civi::settings()->revert('twingle_api_key');
} }
/**
* Example: Run a couple simple queries.
*
* @return TRUE on success
* @throws Exception
*
* public function upgrade_4200() {
* $this->ctx->log->info('Applying update 4200');
* CRM_Core_DAO::executeQuery('UPDATE foo SET bar = "whiz"');
* CRM_Core_DAO::executeQuery('DELETE FROM bang WHERE willy = wonka(2)');
* return TRUE;
* } // */
/**
* Example: Run an external SQL script.
*
* @return TRUE on success
* @throws Exception
* public function upgrade_4201() {
* $this->ctx->log->info('Applying update 4201');
* // this path is relative to the extension base dir
* $this->executeSqlFile('sql/upgrade_4201.sql');
* return TRUE;
* } // */
/**
* Example: Run a slow upgrade process by breaking it up into smaller chunk.
*
* @return TRUE on success
* @throws Exception
* public function upgrade_4202() {
* $this->ctx->log->info('Planning update 4202'); // PEAR Log interface
*
* $this->addTask(E::ts('Process first step'), 'processPart1', $arg1, $arg2);
* $this->addTask(E::ts('Process second step'), 'processPart2', $arg3, $arg4);
* $this->addTask(E::ts('Process second step'), 'processPart3', $arg5);
* return TRUE;
* }
* public function processPart1($arg1, $arg2) { sleep(10); return TRUE; }
* public function processPart2($arg3, $arg4) { sleep(10); return TRUE; }
* public function processPart3($arg5) { sleep(10); return TRUE; }
* // */
/**
* Example: Run an upgrade with a query that touches many (potentially
* millions) of records by breaking it up into smaller chunks.
*
* @return TRUE on success
* @throws Exception
* public function upgrade_4203() {
* $this->ctx->log->info('Planning update 4203'); // PEAR Log interface
*
* $minId = CRM_Core_DAO::singleValueQuery('SELECT coalesce(min(id),0) FROM
* civicrm_contribution');
* $maxId = CRM_Core_DAO::singleValueQuery('SELECT coalesce(max(id),0) FROM
* civicrm_contribution'); for ($startId = $minId; $startId <= $maxId;
* $startId += self::BATCH_SIZE) {
* $endId = $startId + self::BATCH_SIZE - 1;
* $title = E::ts('Upgrade Batch (%1 => %2)', array(
* 1 => $startId,
* 2 => $endId,
* ));
* $sql = '
* UPDATE civicrm_contribution SET foobar = whiz(wonky()+wanker)
* WHERE id BETWEEN %1 and %2
* ';
* $params = array(
* 1 => array($startId, 'Integer'),
* 2 => array($endId, 'Integer'),
* );
* $this->addTask($title, 'executeSql', $sql, $params);
* }
* return TRUE;
* } // */
} }

View file

@ -40,8 +40,8 @@ class CRM_TwingleCampaign_Utils_APIWrapper {
$response_copy = $response; $response_copy = $response;
// Create soft credit for contribution // Create soft credit for contribution
if (array_key_exists('contribution', $response['values'])) { if (array_key_exists('contribution', $response)) {
$contribution = array_shift($response_copy['values']['contribution']); $contribution = array_shift($response_copy['contribution']);
if (array_key_exists('campaign_id', $contribution)) { if (array_key_exists('campaign_id', $contribution)) {
try { try {
$twingle_event = civicrm_api3( $twingle_event = civicrm_api3(
@ -49,7 +49,7 @@ class CRM_TwingleCampaign_Utils_APIWrapper {
'getsingle', 'getsingle',
['id' => $contribution['campaign_id']] ['id' => $contribution['campaign_id']]
); );
$response['values']['soft_credit'] = $response['soft_credit'] =
self::createSoftCredit($contribution, $twingle_event)['values']; self::createSoftCredit($contribution, $twingle_event)['values'];
$event->setResponse($response); $event->setResponse($response);
} catch (CiviCRM_API3_Exception $e) { } catch (CiviCRM_API3_Exception $e) {
@ -58,8 +58,8 @@ class CRM_TwingleCampaign_Utils_APIWrapper {
} }
} }
// Create soft credit for sepa mandate // Create soft credit for sepa mandate
elseif (array_key_exists('sepa_mandate', $response['values'])) { elseif (array_key_exists('sepa_mandate', $response)) {
$sepa_mandate = array_pop($response_copy['values']['sepa_mandate']); $sepa_mandate = array_pop($response_copy['sepa_mandate']);
try { try {
$contribution = civicrm_api3( $contribution = civicrm_api3(
@ -84,7 +84,7 @@ class CRM_TwingleCampaign_Utils_APIWrapper {
'getsingle', 'getsingle',
['id' => $contribution['contribution_campaign_id']] ['id' => $contribution['contribution_campaign_id']]
); );
$response['values']['soft_credit'] = $response['soft_credit'] =
self::createSoftCredit($contribution, $twingle_event)['values']; self::createSoftCredit($contribution, $twingle_event)['values'];
$event->setResponse($response); $event->setResponse($response);
} catch (CiviCRM_API3_Exception $e) { } catch (CiviCRM_API3_Exception $e) {
@ -103,12 +103,12 @@ class CRM_TwingleCampaign_Utils_APIWrapper {
* the de.systopia.twingle extension can include the campaign into the * the de.systopia.twingle extension can include the campaign into the
* contribution which it will create. * contribution which it will create.
* *
* @param $apiRequest * @param array $apiRequest
* @param $callsame * @param callable $callsame
* *
* @return mixed * @return mixed
*/ */
public function mapDonation($apiRequest, $callsame) { public static function mapDonation(array $apiRequest, callable $callsame) {
if (array_key_exists( if (array_key_exists(
'campaign_id', 'campaign_id',
@ -129,11 +129,7 @@ class CRM_TwingleCampaign_Utils_APIWrapper {
} }
} }
} }
elseif (array_key_exists( elseif (!empty($apiRequest['params']['custom_fields']['event'])) {
'event',
$apiRequest['params']['custom_fields']) &&
!empty($apiRequest['params']['custom_fields']['event'])
) {
try { try {
$targetCampaign = civicrm_api3( $targetCampaign = civicrm_api3(
'TwingleEvent', 'TwingleEvent',
@ -204,6 +200,8 @@ class CRM_TwingleCampaign_Utils_APIWrapper {
'contribution_id' => $contribution['id'], 'contribution_id' => $contribution['id'],
] ]
); );
throw $e;
} }
} }

View file

@ -8,7 +8,6 @@ use CRM_TwingleCampaign_ExtensionUtil as E;
* @return array * @return array
*/ */
function getCaseTypes(): array { function getCaseTypes(): array {
$caseTypes = [NULL => E::ts('none')];
try { try {
$result = civicrm_api3('CaseType', 'get', [ $result = civicrm_api3('CaseType', 'get', [
'sequential' => 1, 'sequential' => 1,

View file

@ -0,0 +1,75 @@
<?php
/**
* A simple class which helps to generate JavaScript snippets which can be
* embedded in a website to track user interaction with Twingle forms via
* Matomo.
*/
class CRM_TwingleCampaign_Utils_MatomoSnippet {
private static function embed_in_base_function($code) {
return implode("\n",[
"<!-- matomo -->",
"<script>",
"window.addEventListener('message', function(event){",
"if(event && event.data && event.data.type === 'donationFinished') {",
$code,
"}",
"} , false);",
"</script>",
"<!-- matomo -->",
]);
}
/**
* Returns JavaScript snippet to track events in Matomo.
*
* @return string
*/
public static function get_event_tracker() {
$code = "_paq.push(['trackEvent', 'twingle', 'donation', event.data.value.recurringRythm, event.data.value.amount]);";
return self::embed_in_base_function($code);
}
/**
* Returns JavaScript snippet to track Matomo goals.
*
* @param $goal_id
* The ID of your Matomo goal.
*
* @return string
*/
public static function get_goal_tracker($goal_id) {
$code = "_paq.push(['trackGoal', $goal_id]);";
return self::embed_in_base_function($code);
}
/**
* Returns JavaScript snippet to track ecommerce activity in Matomo.
*
* @return string
*/
public static function get_ecommerce_tracker() {
$code = implode("\n", [
"_paq.push(['addEcommerceItem', event.data.value.rythm, '', event.data.value.target, event.data.value.amount]);",
"_paq.push(['trackEcommerceOrder', 'anonymizedData', event.data.value.amount]);",
]);
return self::embed_in_base_function($code);
}
/**
* Appends the given code to the original code.
*
* @param $original
* The original code.
* @param $appendix
* The code you want to append to the original code.
*
* @return string
* The combined code after appending the appendix.
*/
public static function append_code($original, $appendix) {
return $original . $appendix;
}
}

View file

@ -49,7 +49,7 @@ class CRM_TwingleCampaign_Utils_StringOperations {
$firstnames = implode(" ", $names); $firstnames = implode(" ", $names);
return ['firstnames' => $firstnames, 'lastname' => $lastname]; return ['firstnames' => $firstnames, 'lastname' => $lastname];
} }
return $string; return ['display_name' => $string];
} }
/** /**

View file

@ -113,7 +113,9 @@ return [
"option_values" => [ "option_values" => [
"default" => E::ts("Default"), "default" => E::ts("Default"),
"event" => E::ts("Events"), "event" => E::ts("Events"),
"membership" => E::ts("Membership") "membership" => E::ts("Membership"),
"shop" => E::ts("Shop"),
"giftshop" => E::ts("Gift Shop")
], ],
"text_length" => 32, "text_length" => 32,
"is_active" => 1, "is_active" => 1,

View file

@ -72,6 +72,8 @@ decrease this interval by changing the configuration of the scheduled job named
Furthermore, the synchronization may get triggered also if a donation for an unknown event arrives via the Twingle API Furthermore, the synchronization may get triggered also if a donation for an unknown event arrives via the Twingle API
extension. extension.
A CiviCRM site running [not in productive mode](https://docs.civicrm.org/sysadmin/en/latest/misc/staging-production/) will by default not run any scheduled jobs. In that case you can individually enable the TwingleSync job by adding the parameter runInNonProductionEnvironment=TRUE to the job.
## Known Issues ## Known Issues
- The **Campaign Manager** displays a *«Campaign XY has been saved»* message even if the input validation failed and the - The **Campaign Manager** displays a *«Campaign XY has been saved»* message even if the input validation failed and the

View file

@ -2,6 +2,7 @@
use CRM_TwingleCampaign_ExtensionUtil as E; use CRM_TwingleCampaign_ExtensionUtil as E;
use CRM_TwingleCampaign_Utils_ExtensionCache as Cache; use CRM_TwingleCampaign_Utils_ExtensionCache as Cache;
use CRM_TwingleCampaign_Utils_MatomoSnippet as MatomoSnippet;
/** /**
* TwingleForm.Get API specification (optional) * TwingleForm.Get API specification (optional)
@ -14,6 +15,13 @@ use CRM_TwingleCampaign_Utils_ExtensionCache as Cache;
function _civicrm_api3_twingle_form_Get_spec(array &$spec) { function _civicrm_api3_twingle_form_Get_spec(array &$spec) {
$spec['id'] = [ $spec['id'] = [
'name' => 'id', 'name' => 'id',
'title' => E::ts('Campaign ID'),
'type' => CRM_Utils_Type::T_INT,
'api.required' => 0,
'description' => E::ts('The campaign ID'),
];
$spec['twingle_project_id'] = [
'name' => 'twingle_project_id',
'title' => E::ts('TwingleProject ID'), 'title' => E::ts('TwingleProject ID'),
'type' => CRM_Utils_Type::T_INT, 'type' => CRM_Utils_Type::T_INT,
'api.required' => 0, 'api.required' => 0,
@ -66,6 +74,13 @@ function civicrm_api3_twingle_form_Get(array $params): array {
// Get custom fields // Get custom fields
$custom_field_mapping = Cache::getInstance()->getCustomFieldMapping(); $custom_field_mapping = Cache::getInstance()->getCustomFieldMapping();
// Replace twingle_project_id key with custom field name
if (key_exists('twingle_project_id', $params)) {
$params[$custom_field_mapping['twingle_project_id']] =
$params['twingle_project_id'];
unset($params['twingle_project_id']);
}
// Replace twingle_project_type key with custom field name // Replace twingle_project_type key with custom field name
if (key_exists('twingle_project_type', $params)) { if (key_exists('twingle_project_type', $params)) {
$params[$custom_field_mapping['twingle_project_type']] = $params[$custom_field_mapping['twingle_project_type']] =
@ -96,16 +111,49 @@ function civicrm_api3_twingle_form_Get(array $params): array {
'project_type' => $value[$custom_field_mapping['twingle_project_type']], 'project_type' => $value[$custom_field_mapping['twingle_project_type']],
'counter' => $value[$custom_field_mapping['twingle_project_counter']] 'counter' => $value[$custom_field_mapping['twingle_project_counter']]
]; ];
$matomo_integration_enabled = Civi::settings()->get('twinglecampaign_matomo_integration', False);
switch ($value[$custom_field_mapping['twingle_project_type']]) { switch ($value[$custom_field_mapping['twingle_project_type']]) {
case 'event': case 'event':
if ($matomo_integration_enabled) {
$returnValues[$value['id']]['embed_code'] =
MatomoSnippet::append_code(
$value[$custom_field_mapping['twingle_project_eventall']],
MatomoSnippet::get_event_tracker()
);
}
else {
$returnValues[$value['id']]['embed_code'] = $returnValues[$value['id']]['embed_code'] =
$value[$custom_field_mapping['twingle_project_eventall']]; $value[$custom_field_mapping['twingle_project_eventall']];
}
break;
case 'shop':
if ($matomo_integration_enabled) {
$returnValues[$value['id']]['embed_code'] =
MatomoSnippet::append_code(
$value[$custom_field_mapping['twingle_project_widget']],
MatomoSnippet::get_ecommerce_tracker()
);
}
else {
$returnValues[$value['id']]['embed_code'] =
$value[$custom_field_mapping['twingle_project_widget']];
}
break; break;
default: default:
if ($matomo_integration_enabled) {
$returnValues[$value['id']]['embed_code'] =
MatomoSnippet::append_code(
$value[$custom_field_mapping['twingle_project_widget']],
MatomoSnippet::get_event_tracker()
);
}
else {
$returnValues[$value['id']]['embed_code'] = $returnValues[$value['id']]['embed_code'] =
$value[$custom_field_mapping['twingle_project_widget']]; $value[$custom_field_mapping['twingle_project_widget']];
} }
} }
}
return civicrm_api3_create_success($returnValues, $query, 'TwingleForm', 'Get'); return civicrm_api3_create_success($returnValues, $query, 'TwingleForm', 'Get');
} }
else { else {

View file

@ -12,6 +12,13 @@ use CRM_TwingleCampaign_ExtensionUtil as E;
function _civicrm_api3_twingle_form_Getsingle_spec(array &$spec) { function _civicrm_api3_twingle_form_Getsingle_spec(array &$spec) {
$spec['id'] = [ $spec['id'] = [
'name' => 'id', 'name' => 'id',
'title' => E::ts('Campaign ID'),
'type' => CRM_Utils_Type::T_INT,
'api.required' => 0,
'description' => E::ts('The campaign ID'),
];
$spec['twingle_project_id'] = [
'name' => 'twingle_project_id',
'title' => E::ts('TwingleProject ID'), 'title' => E::ts('TwingleProject ID'),
'type' => CRM_Utils_Type::T_INT, 'type' => CRM_Utils_Type::T_INT,
'api.required' => 0, 'api.required' => 0,

View file

@ -176,8 +176,7 @@ function civicrm_api3_twingle_project_Sync(array $params): array {
$projects_from_twingle = $twingleApi->getProject(); $projects_from_twingle = $twingleApi->getProject();
// Get all TwingleProjects from CiviCRM // Get all TwingleProjects from CiviCRM
$projects_from_civicrm = civicrm_api3('TwingleProject', 'get', $projects_from_civicrm = civicrm_api3('TwingleProject', 'get');
['is_active' => 1,]);
// If call to TwingleProject.get failed, forward error message // If call to TwingleProject.get failed, forward error message
if ($projects_from_civicrm['is_error'] != 0) { if ($projects_from_civicrm['is_error'] != 0) {
@ -194,8 +193,8 @@ function civicrm_api3_twingle_project_Sync(array $params): array {
foreach ($projects_from_civicrm['values'] as $project_from_civicrm) { foreach ($projects_from_civicrm['values'] as $project_from_civicrm) {
if ( if (
!in_array($project_from_civicrm['project_id'], !in_array($project_from_civicrm['project_id'],
array_column($projects_from_twingle, 'id') array_column($projects_from_twingle, 'id'),
)) { ) && $project_from_civicrm['is_active'] == 1) {
// store campaign id in $id // store campaign id in $id
$id = $project_from_civicrm['id']; $id = $project_from_civicrm['id'];
unset($project_from_civicrm['id']); unset($project_from_civicrm['id']);

View file

@ -14,13 +14,12 @@
<url desc="Support">https://lab.civicrm.org/Marc_Michalsky/de-forumzfd-twinglecampaign/-/issues</url> <url desc="Support">https://lab.civicrm.org/Marc_Michalsky/de-forumzfd-twinglecampaign/-/issues</url>
<url desc="Licensing">http://www.gnu.org/licenses/agpl-3.0.html</url> <url desc="Licensing">http://www.gnu.org/licenses/agpl-3.0.html</url>
</urls> </urls>
<releaseDate>2021-12-15</releaseDate> <releaseDate>2024-06-15</releaseDate>
<version>1.0.1</version> <version>1.0.8</version>
<develStage>stable</develStage> <develStage>stable</develStage>
<compatibility> <compatibility>
<ver>5.14.0</ver> <ver>5.74</ver>
</compatibility> </compatibility>
<comments></comments>
<requires> <requires>
<ext>de.systopia.xcm</ext> <ext>de.systopia.xcm</ext>
<ext>de.systopia.campaign</ext> <ext>de.systopia.campaign</ext>

View file

@ -26,6 +26,11 @@
<div class="content">{$form.twinglecampaign_soft_credits.html}</div> <div class="content">{$form.twinglecampaign_soft_credits.html}</div>
<div class="clear"></div> <div class="clear"></div>
</div> </div>
<div class="crm-section">
<div class="label">{$form.twinglecampaign_matomo_integration.label}</div>
<div class="content">{$form.twinglecampaign_matomo_integration.html}</div>
<div class="clear"></div>
</div>
</div> </div>