Compare commits

...

38 commits
1.0 ... 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
Marc Michalsky
2abf1676bd 🔖 1.0.1 stable release
Changes:
-  #4 improve hex color validation
- 🐛 #5 fix bug: error when altering any case type
- 🗑️ get rid of the warning about using an deprecated constant 
- 🩹 call the right API to fetch OptionValues
2021-12-17 12:28:15 +01:00
Marc Michalsky
841028a435 Merge branch 'dev' into main 2021-12-17 12:24:15 +01:00
Marc Michalsky
0ab5bb1fa9 🩹 call the right API to fetch OptionValues 2021-12-17 12:23:38 +01:00
Marc Michalsky
fbe30b0ce5 🗑️ get rid of the warning about using an deprecated constant 2021-12-17 12:19:46 +01:00
Marc Michalsky
3e73ed733b improve hex color validation #4 2021-12-17 12:13:13 +01:00
Marc Michalsky
482b8e2d0d 🐛 Fix bug #5: Error when altering any case type 2021-12-17 09:05:51 +01:00
20 changed files with 304 additions and 200 deletions

View file

@ -7,7 +7,8 @@ class CRM_TwingleCampaign_BAO_Configuration {
'twingle_api_key',
'twinglecampaign_xcm_profile',
'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);
}
// 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);
}

View file

@ -62,10 +62,11 @@ class CRM_TwingleCampaign_BAO_CustomField {
* @param bool $upgrade
* 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
*/
public function create(bool $upgrade = FALSE): ?array {
public function create(bool $upgrade = FALSE) {
// Check if the field already exists
$field = civicrm_api3(
@ -129,52 +130,74 @@ class CRM_TwingleCampaign_BAO_CustomField {
return NULL;
}
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;
try {
$this->result = civicrm_api3(
'CustomField',
'create',
$this->getSetAttributes());
if (key_exists('option_group_id', $attributes)) {
$this->addOptions($attributes);
}
// Log field creation
if ($this->result['is_error'] == 0) {
Civi::log()->info("$this->extensionName has updated a custom field.
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 {
$this->result = civicrm_api3(
'CustomField',
'create',
$this->getSetAttributes());
// Log field creation
if ($this->result['is_error'] == 0) {
Civi::log()->info("$this->extensionName has updated a custom field.
label: $this->label
name: $this->name
id: $this->id
group: $this->custom_group_id"
);
);
return $this->result;
}
else {
throw new CiviCRM_API3_Exception($this->result['error_message']);
}
}
catch (CiviCRM_API3_Exception $e) {
// If the field could not get created: log error
$errorMessage = $e->getMessage();
if ($this->name && $this->custom_group_id) {
Civi::log()
->error("$this->extensionName could not create new custom field \"$this->name\" for group \"$this->custom_group_id\": $errorMessage");
CRM_Utils_System::setUFMessage(E::ts('Creation of custom field \'%1\' failed. Find more information in the logs.', [1 => $this->name]));
}
// If there is not enough information: log simple error message
else {
Civi::log()
->error("$this->extensionName could not create new custom field: $errorMessage");
CRM_Utils_System::setUFMessage(E::ts("Creation of custom field failed. Find more information in the logs."));
}
return $this->result;
}
else {
throw new CiviCRM_API3_Exception($this->result['error_message']);
}
} catch (CiviCRM_API3_Exception $e) {
// If the field could not get created: log error
$errorMessage = $e->getMessage();
if ($this->name && $this->custom_group_id) {
Civi::log()
->error("$this->extensionName could not create new custom field \"$this->name\" for group \"$this->custom_group_id\": $errorMessage");
CRM_Utils_System::setUFMessage(E::ts('Creation of custom field \'%1\' failed. Find more information in the logs.', [1 => $this->name]));
}
// If there is not enough information: log simple error message
else {
Civi::log()
->error("$this->extensionName could not create new custom field: $errorMessage");
CRM_Utils_System::setUFMessage(E::ts("Creation of custom field failed. Find more information in the logs."));
}
return $this->result;
}
return False;
}
/**
@ -188,32 +211,42 @@ class CRM_TwingleCampaign_BAO_CustomField {
$result = [];
try {
$option_group_id = civicrm_api3(
'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])
);
}
foreach ($this->option_values as $key => $value) {
try {
foreach ($options as $key => $value) {
$result[] = civicrm_api3(
$option_value_exists = civicrm_api3(
'OptionValue',
'create',
'get',
[
'option_group_id' => $option_group_id,
'sequential' => 1,
'option_group_id' => $options['option_group_id'],
'value' => $key,
'label' => $value,
]
);
// If the option value does not yet exist, create it
if ($option_value_exists['count'] == 0) {
$result[] = civicrm_api3(
'OptionValue',
'create',
[
'option_group_id' => $options['option_group_id'],
'value' => $key,
'label' => $value,
]
);
}
// If the option value already exist, update it
else {
$result[] = civicrm_api3(
'OptionValue',
'create',
[
'id' => $option_value_exists['values'][0]['id'],
'label' => $value,
'value' => $key,
]
);
}
}
} catch (CiviCRM_API3_Exception $e) {
$errorMessage = $e->getMessage();

View file

@ -158,7 +158,7 @@ class CRM_TwingleCampaign_BAO_OptionValue {
// If a specific option value is required
try {
$option_value = civicrm_api3(
'CustomValue',
'OptionValue',
'get',
[
'sequential' => 1,

View file

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

View file

@ -31,6 +31,15 @@ class CRM_TwingleCampaign_BAO_TwingleProject extends Campaign {
'one_time',
];
// All fields for hex color codes
const colorFields = [
'design_background_color',
'design_primary_color',
'design_font_color',
'design_button_font_color',
'design_button_font_color_light',
];
/**
* ## TwingleProject constructor
*
@ -143,11 +152,13 @@ class CRM_TwingleCampaign_BAO_TwingleProject extends Campaign {
*/
private function strToInt(array &$values) {
foreach ($values as $key => $value) {
if (ctype_digit($value)) {
$values[$key] = intval($value);
}
elseif (is_array($value)) {
$this->strToInt($values[$key]);
if (!in_array($key, self::colorFields)) {
if (ctype_digit($value)) {
$values[$key] = intval($value);
}
elseif (is_array($value)) {
$this->strToInt($values[$key]);
}
}
}
}
@ -170,15 +181,8 @@ class CRM_TwingleCampaign_BAO_TwingleProject extends Campaign {
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']);
}
}
/**
@ -298,21 +302,18 @@ class CRM_TwingleCampaign_BAO_TwingleProject extends Campaign {
}
// Validate hexadecimal color fields
$colorFields =
[
'design_background_color',
'design_primary_color',
'design_font_color',
];
foreach ($colorFields as $colorField) {
foreach (self::colorFields as $colorField) {
if (
!empty($this->values['project_options'][$colorField]) &&
(
!empty($this->values['project_options'][$colorField]) ||
$this->values['project_options'][$colorField] === "0"
) &&
(
!(
ctype_xdigit($this->values['project_options'][$colorField]) ||
is_integer($this->values['project_options'][$colorField])
) ||
strlen((string) $this->values['project_options'][$colorField]) > 6
strlen((string) $this->values['project_options'][$colorField]) != 6
)
) {
$valid = FALSE;

View file

@ -1,7 +1,7 @@
<?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 {

View file

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

View file

@ -20,7 +20,7 @@ class CRM_TwingleCampaign_Upgrader extends CRM_TwingleCampaign_Upgrader_Base {
* changed campaigns will get pulled from Twingle.
* @throws \CiviCRM_API3_Exception
*/
public function upgrade_02(): bool {
public function upgrade_03(): bool {
$campaign_info = require E::path() .
'/CRM/TwingleCampaign/resources/campaigns.php';
@ -96,7 +96,7 @@ class CRM_TwingleCampaign_Upgrader extends CRM_TwingleCampaign_Upgrader_Base {
[1 => $e->getMessage()]
),
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');
}
/**
* 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;
// Create soft credit for contribution
if (array_key_exists('contribution', $response['values'])) {
$contribution = array_shift($response_copy['values']['contribution']);
if (array_key_exists('contribution', $response)) {
$contribution = array_shift($response_copy['contribution']);
if (array_key_exists('campaign_id', $contribution)) {
try {
$twingle_event = civicrm_api3(
@ -49,7 +49,7 @@ class CRM_TwingleCampaign_Utils_APIWrapper {
'getsingle',
['id' => $contribution['campaign_id']]
);
$response['values']['soft_credit'] =
$response['soft_credit'] =
self::createSoftCredit($contribution, $twingle_event)['values'];
$event->setResponse($response);
} catch (CiviCRM_API3_Exception $e) {
@ -58,8 +58,8 @@ class CRM_TwingleCampaign_Utils_APIWrapper {
}
}
// Create soft credit for sepa mandate
elseif (array_key_exists('sepa_mandate', $response['values'])) {
$sepa_mandate = array_pop($response_copy['values']['sepa_mandate']);
elseif (array_key_exists('sepa_mandate', $response)) {
$sepa_mandate = array_pop($response_copy['sepa_mandate']);
try {
$contribution = civicrm_api3(
@ -84,7 +84,7 @@ class CRM_TwingleCampaign_Utils_APIWrapper {
'getsingle',
['id' => $contribution['contribution_campaign_id']]
);
$response['values']['soft_credit'] =
$response['soft_credit'] =
self::createSoftCredit($contribution, $twingle_event)['values'];
$event->setResponse($response);
} 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
* contribution which it will create.
*
* @param $apiRequest
* @param $callsame
* @param array $apiRequest
* @param callable $callsame
*
* @return mixed
*/
public function mapDonation($apiRequest, $callsame) {
public static function mapDonation(array $apiRequest, callable $callsame) {
if (array_key_exists(
'campaign_id',
@ -129,11 +129,7 @@ class CRM_TwingleCampaign_Utils_APIWrapper {
}
}
}
elseif (array_key_exists(
'event',
$apiRequest['params']['custom_fields']) &&
!empty($apiRequest['params']['custom_fields']['event'])
) {
elseif (!empty($apiRequest['params']['custom_fields']['event'])) {
try {
$targetCampaign = civicrm_api3(
'TwingleEvent',
@ -204,6 +200,8 @@ class CRM_TwingleCampaign_Utils_APIWrapper {
'contribution_id' => $contribution['id'],
]
);
throw $e;
}
}

View file

@ -8,7 +8,6 @@ use CRM_TwingleCampaign_ExtensionUtil as E;
* @return array
*/
function getCaseTypes(): array {
$caseTypes = [NULL => E::ts('none')];
try {
$result = civicrm_api3('CaseType', 'get', [
'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);
return ['firstnames' => $firstnames, 'lastname' => $lastname];
}
return $string;
return ['display_name' => $string];
}
/**

View file

@ -113,7 +113,9 @@ return [
"option_values" => [
"default" => E::ts("Default"),
"event" => E::ts("Events"),
"membership" => E::ts("Membership")
"membership" => E::ts("Membership"),
"shop" => E::ts("Shop"),
"giftshop" => E::ts("Gift Shop")
],
"text_length" => 32,
"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
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
- 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_Utils_ExtensionCache as Cache;
use CRM_TwingleCampaign_Utils_MatomoSnippet as MatomoSnippet;
/**
* 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) {
$spec['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'),
'type' => CRM_Utils_Type::T_INT,
'api.required' => 0,
@ -66,6 +74,13 @@ function civicrm_api3_twingle_form_Get(array $params): array {
// Get custom fields
$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
if (key_exists('twingle_project_type', $params)) {
$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']],
'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']]) {
case 'event':
$returnValues[$value['id']]['embed_code'] =
$value[$custom_field_mapping['twingle_project_eventall']];
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'] =
$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;
default:
$returnValues[$value['id']]['embed_code'] =
$value[$custom_field_mapping['twingle_project_widget']];
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'] =
$value[$custom_field_mapping['twingle_project_widget']];
}
}
}
return civicrm_api3_create_success($returnValues, $query, 'TwingleForm', 'Get');
}
else {

View file

@ -12,6 +12,13 @@ use CRM_TwingleCampaign_ExtensionUtil as E;
function _civicrm_api3_twingle_form_Getsingle_spec(array &$spec) {
$spec['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'),
'type' => CRM_Utils_Type::T_INT,
'api.required' => 0,

View file

@ -176,8 +176,7 @@ function civicrm_api3_twingle_project_Sync(array $params): array {
$projects_from_twingle = $twingleApi->getProject();
// Get all TwingleProjects from CiviCRM
$projects_from_civicrm = civicrm_api3('TwingleProject', 'get',
['is_active' => 1,]);
$projects_from_civicrm = civicrm_api3('TwingleProject', 'get');
// If call to TwingleProject.get failed, forward error message
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) {
if (
!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
$id = $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="Licensing">http://www.gnu.org/licenses/agpl-3.0.html</url>
</urls>
<releaseDate>2021-12-15</releaseDate>
<version>1.0</version>
<releaseDate>2024-06-15</releaseDate>
<version>1.0.8</version>
<develStage>stable</develStage>
<compatibility>
<ver>5.14.0</ver>
<ver>5.74</ver>
</compatibility>
<comments></comments>
<requires>
<ext>de.systopia.xcm</ext>
<ext>de.systopia.campaign</ext>

View file

@ -26,6 +26,11 @@
<div class="content">{$form.twinglecampaign_soft_credits.html}</div>
<div class="clear"></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>

View file

@ -411,8 +411,7 @@ function _validateAndSendInput($id, $campaign_type_id): bool {
CRM_Core_Session::setStatus(
$errorMessage,
E::ts("Input validation failed"),
error,
[unique => TRUE]
error
);
// Validation failed
return FALSE;