️ change json files to php files and add custom fields for projects

Changeing the file type is necessary to use the ts() function during custom field creation.

Added new custom fields to map the donation form settings.
This commit is contained in:
Marc Michalsky forumZFD 2021-04-12 09:47:42 +02:00
parent 968bb9d831
commit 0d9b312a9b
Signed by untrusted user who does not match committer: marc.koch
GPG key ID: 12406554CFB028B9
12 changed files with 1262 additions and 606 deletions

View file

@ -96,7 +96,7 @@ class CRM_TwingleCampaign_BAO_TwingleCampaign {
// Get campaign type id for TwingleProject // Get campaign type id for TwingleProject
$twingle_project_campaign_type_id = $twingle_project_campaign_type_id =
ExtensionCache::getInstance() ExtensionCache::getInstance()
->getCampaigns()['campaign_types']['twingle_project']['id']; ->getCampaignIds()['campaign_types']['twingle_project']['id'];
// Determine the parent project id by looping through the campaign tree // Determine the parent project id by looping through the campaign tree
// until the parent campaign type is a TwingleProject // until the parent campaign type is a TwingleProject

View file

@ -13,13 +13,7 @@ class CRM_TwingleCampaign_Utils_ExtensionCache {
private $customFieldMapping; private $customFieldMapping;
private $translations; private $campaignIds;
private $campaigns;
private $templates;
private $option_values;
/** /**
* ## Get an instance (singleton) * ## Get an instance (singleton)
@ -44,37 +38,11 @@ class CRM_TwingleCampaign_Utils_ExtensionCache {
// Get a mapping of custom fields // Get a mapping of custom fields
$this->customFieldMapping = CustomField::getMapping(); $this->customFieldMapping = CustomField::getMapping();
// Initialize json files as arrays
$file_paths = [
'translations' => '/CRM/TwingleCampaign/resources/dictionary.json',
'templates' => '/CRM/TwingleCampaign/resources/twingle_api_templates.json',
'campaigns' => '/CRM/TwingleCampaign/resources/campaigns.json',
'option_values' => '/CRM/TwingleCampaign/resources/option_values.json',
];
foreach ($file_paths as $key => $file_path) {
// Get array from json file
$file_path = E::path() . $file_path;
$json_file = file_get_contents($file_path);
$json_file_name = pathinfo($file_path)['filename'];
$array = json_decode($json_file, TRUE);
// Throw and log an error if json file can't be read
if (!$array) {
$message = ($json_file_name)
? "Could not read json file $json_file_name"
: "Could not locate json file in path: $file_path";
Civi::log()->error($message);
throw new Exception($message);
}
// Set attribute
$this->$key = $array;
}
// Get ids for Twingle related campaign types // Get ids for Twingle related campaign types
foreach ($this->campaigns['campaign_types'] as $campaign_type) { $this->campaignIds = require(
E::path() . '/CRM/TwingleCampaign/resources/campaigns.php'
);
foreach ($this->campaignIds['campaign_types'] as $campaign_type) {
$campaign_type_id = civicrm_api3( $campaign_type_id = civicrm_api3(
'OptionValue', 'OptionValue',
'get', 'get',
@ -85,7 +53,7 @@ class CRM_TwingleCampaign_Utils_ExtensionCache {
] ]
)['values']; )['values'];
if ($campaign_type_id) { if ($campaign_type_id) {
$this->campaigns['campaign_types'][$campaign_type['name']]['id'] = $this->campaignIds['campaign_types'][$campaign_type['name']]['id'] =
$campaign_type_id[0]['value']; $campaign_type_id[0]['value'];
} }
} }
@ -114,28 +82,43 @@ class CRM_TwingleCampaign_Utils_ExtensionCache {
* @return array * @return array
*/ */
public function getTranslations(): array { public function getTranslations(): array {
return $this->translations; return require(
E::path() . '/CRM/TwingleCampaign/resources/dictionary.php'
);
} }
/** /**
* @return array * @return array
*/ */
public function getCampaigns(): array { public function getCampaigns(): array {
return $this->campaigns; return require(
E::path() . '/CRM/TwingleCampaign/resources/campaigns.php'
);
}
/**
* @return array
*/
public function getCampaignIds(): array {
return $this->campaignIds;
} }
/** /**
* @return array * @return array
*/ */
public function getTemplates(): array { public function getTemplates(): array {
return $this->templates; return require(
E::path() . '/CRM/TwingleCampaign/resources/twingle_api_templates.php'
);
} }
/** /**
* @return mixed * @return mixed
*/ */
public function getOptionValues() { public function getOptionValues() {
return $this->option_values; return require(
E::path() . '/CRM/TwingleCampaign/resources/option_values.php'
);
} }
} }

View file

@ -1,469 +0,0 @@
{
"campaign_types": {
"twingle_project": {
"name": "twingle_project",
"label": "Twingle Project"
},
"twingle_event": {
"name": "twingle_event",
"label": "Twingle Event"
},
"twingle_campaign": {
"name": "twingle_campaign",
"label": "Twingle Campaign"
}
},
"custom_groups": {
"twingle_project_information": {
"title": "Twingle Project Information",
"name": "Twingle_Project_Information",
"extends": "Campaign",
"campaign_type": "twingle_project",
"weight": "1"
},
"twingle_project_embed_codes": {
"title": "Twingle Project Embed Codes",
"name": "Twingle_Project_Embed_Codes",
"extends": "Campaign",
"campaign_type": "twingle_project",
"collapse_display": "1",
"weight": "2"
},
"twingle_event_information": {
"title": "Twingle Event Information",
"name": "Twingle_Event_Information",
"extends": "Campaign",
"campaign_type": "twingle_event"
},
"twingle_campaign_information": {
"title": "Twingle Campaign Information",
"name": "Twingle_Campaign_Information",
"extends": "Campaign",
"campaign_type": "twingle_campaign"
}
},
"custom_fields": {
"twingle_project_id": {
"custom_group_id": "Twingle_Project_Information",
"label": "Twingle Project ID",
"name": "twingle_project_id",
"is_required": 0,
"is_searchable": 1,
"data_type": "String",
"html_type": "Text",
"text_length": 16,
"is_active": 1,
"is_view": 1,
"weight": 1
},
"twingle_project_organisation_id": {
"custom_group_id": "Twingle_Project_Information",
"label": "Twingle Project organisation ID",
"name": "twingle_project_organisation_id",
"is_required": 0,
"is_searchable": 1,
"data_type": "String",
"html_type": "Text",
"text_length": 32,
"is_active": 1,
"is_view": 1,
"weight": 6
},
"twingle_project_identifier": {
"custom_group_id": "Twingle_Project_Information",
"label": "Twingle Project identifier",
"name": "twingle_project_identifier",
"is_required": 0,
"is_searchable": 1,
"data_type": "String",
"html_type": "Text",
"text_length": 15,
"is_active": 1,
"is_view": 1,
"weight": 3,
"help_post": "An unique identifier for a project (auto generated)"
},
"twingle_project_type": {
"custom_group_id": "Twingle_Project_Information",
"label": "Twingle Project Type",
"name": "twingle_project_type",
"is_required": 0,
"is_searchable": 1,
"data_type": "String",
"html_type": "Select",
"option_values": {
"default": "Default",
"event": "Events",
"membership": "Membership"
},
"text_length": 32,
"is_active": 1,
"is_view": 0,
"weight": 2,
"help_post": "Choose the project type. Allow users to create own events or to pay a membership fee.",
"default_value": "default"
},
"twingle_project_allow_more": {
"custom_group_id": "Twingle_Project_Information",
"label": "Twingle Project allow more",
"name": "twingle_project_allow_more",
"is_required": 0,
"is_searchable": 1,
"data_type": "Boolean",
"html_type": "Radio",
"text_length": 4,
"is_active": 1,
"is_view": 0,
"weight": 4,
"help_post": "Allow to donate more than is defined in the target"
},
"twingle_project_transaction_type": {
"custom_group_id": "Twingle_Project_Information",
"label": "Twingle Project transaction type",
"name": "twingle_project_transaction_type",
"is_required": 0,
"is_searchable": 1,
"data_type": "String",
"html_type": "Text",
"text_length": 32,
"is_active": 1,
"is_view": 0,
"weight": 5
},
"twingle_project_url": {
"custom_group_id": "Twingle_Project_Information",
"label": "Twingle Project URL",
"name": "twingle_project_url",
"is_required": 0,
"is_searchable": 0,
"data_type": "Memo",
"html_type": "TextArea",
"text_length": 600,
"is_active": 1,
"is_view": 0,
"weight": 6
},
"twingle_project_widget": {
"custom_group_id": "Twingle_Project_Embed_Codes",
"label": "Twingle Project Widget",
"name": "twingle_project_widget",
"is_required": 0,
"is_searchable": 0,
"data_type": "Memo",
"html_type": "TextArea",
"text_length": 600,
"is_active": 1,
"is_view": 1,
"weight": 1
},
"twingle_project_form": {
"custom_group_id": "Twingle_Project_Embed_Codes",
"label": "Twingle Project Form",
"name": "twingle_project_form",
"is_required": 0,
"is_searchable": 0,
"data_type": "Memo",
"html_type": "TextArea",
"text_length": 600,
"is_active": 1,
"is_view": 1,
"weight": 2
},
"twingle_project_widget-single": {
"custom_group_id": "Twingle_Project_Embed_Codes",
"label": "Twingle Project Widget Single",
"name": "twingle_project_widget-single",
"is_required": 0,
"is_searchable": 0,
"data_type": "Memo",
"html_type": "TextArea",
"text_length": 600,
"is_active": 1,
"is_view": 1,
"weight": 3
},
"twingle_project_form-single": {
"custom_group_id": "Twingle_Project_Embed_Codes",
"label": "Twingle Project Form Single",
"name": "twingle_project_form-single",
"is_required": 0,
"is_searchable": 0,
"data_type": "Memo",
"html_type": "TextArea",
"text_length": 600,
"is_active": 1,
"is_view": 1,
"weight": 4
},
"twingle_project_eventall": {
"custom_group_id": "Twingle_Project_Embed_Codes",
"label": "Twingle Project All Events",
"name": "twingle_project_eventall",
"is_required": 0,
"is_searchable": 0,
"data_type": "Memo",
"html_type": "TextArea",
"text_length": 1300,
"is_active": 1,
"is_view": 1,
"weight": 5
},
"twingle_project_eventlist": {
"custom_group_id": "Twingle_Project_Embed_Codes",
"label": "Twingle Project Event List",
"name": "twingle_project_eventlist",
"is_required": 0,
"is_searchable": 0,
"data_type": "Memo",
"html_type": "TextArea",
"text_length": 1300,
"is_active": 1,
"is_view": 1,
"weight": 6
},
"twingle_project_counter": {
"custom_group_id": "Twingle_Project_Embed_Codes",
"label": "Twingle Project Counter",
"name": "twingle_project_counter",
"is_required": 0,
"is_searchable": 0,
"data_type": "Memo",
"html_type": "TextArea",
"text_length": 120,
"is_active": 1,
"is_view": 1,
"weight": 7
},
"twingle_project_page": {
"custom_group_id": "Twingle_Project_Embed_Codes",
"label": "Twingle Project Page",
"name": "twingle_project_page",
"is_required": 0,
"is_searchable": 0,
"data_type": "Memo",
"html_type": "TextArea",
"text_length": 600,
"is_active": 1,
"is_view": 1,
"weight": 8
},
"twingle_event_id": {
"custom_group_id": "Twingle_Event_Information",
"label": "Twingle Event ID",
"name": "twingle_event_id",
"is_required": 1,
"is_searchable": 1,
"data_type": "String",
"html_type": "Text",
"text_length": 16,
"is_active": 1,
"is_view": 1,
"weight": 1
},
"twingle_event_project_id": {
"custom_group_id": "Twingle_Event_Information",
"label": "Twingle Project ID",
"name": "twingle_event_project_id",
"is_required": 0,
"is_searchable": 1,
"data_type": "String",
"html_type": "Text",
"text_length": 16,
"is_active": 1,
"is_view": 1,
"weight": 2
},
"twingle_event_identifier": {
"custom_group_id": "Twingle_Event_Information",
"label": "Twingle Event Identifier",
"name": "twingle_event_identifier",
"is_required": 0,
"is_searchable": 0,
"data_type": "String",
"html_type": "Text",
"text_length": 16,
"is_active": 1,
"is_view": 1,
"weight": 3
},
"twingle_event_contact": {
"custom_group_id": "Twingle_Event_Information",
"label": "Twingle Event Initiator",
"name": "twingle_event_contact",
"is_required": 0,
"is_searchable": 1,
"data_type": "ContactReference",
"html_type": "Autocomplete-Select",
"is_active": 1,
"is_view": 0,
"weight": 5
},
"twingle_event_user_email": {
"custom_group_id": "Twingle_Event_Information",
"label": "Twingle Event Initiator Email",
"name": "twingle_event_user_email",
"is_required": 0,
"is_searchable": 0,
"data_type": "String",
"html_type": "Text",
"text_length": 128,
"is_active": 1,
"is_view": 1,
"weight": 6
},
"twingle_event_is_public": {
"custom_group_id": "Twingle_Event_Information",
"label": "Twingle Event is public",
"name": "twingle_event_is_public",
"is_required": 0,
"is_searchable": 1,
"data_type": "Boolean",
"html_type": "Radio",
"is_active": 1,
"is_view": 1,
"weight": 7
},
"twingle_event_deleted": {
"custom_group_id": "Twingle_Event_Information",
"label": "Twingle Event Deleted",
"name": "twingle_event_deleted",
"is_required": 0,
"is_searchable": 1,
"data_type": "Boolean",
"html_type": "Radio",
"is_active": 1,
"is_view": 1,
"weight": 8
},
"twingle_event_confirmed_at": {
"custom_group_id": "Twingle_Event_Information",
"label": "Twingle Event Confirmed At",
"name": "twingle_event_confirmed_at",
"is_required": 0,
"is_searchable": 0,
"data_type": "String",
"html_type": "Text",
"text_length": 64,
"is_active": 1,
"is_view": 1,
"weight": 9
},
"twingle_event_created_at": {
"custom_group_id": "Twingle_Event_Information",
"label": "Twingle Event Created At",
"name": "twingle_event_created_at",
"is_required": 0,
"is_searchable": 0,
"data_type": "String",
"html_type": "Text",
"text_length": 64,
"is_active": 1,
"is_view": 1,
"weight": 10
},
"twingle_event_creation_url": {
"custom_group_id": "Twingle_Event_Information",
"label": "Twingle Event Creation URL",
"name": "twingle_event_creation_url",
"is_required": 0,
"is_searchable": 0,
"data_type": "String",
"html_type": "Text",
"text_length": 256,
"is_active": 1,
"is_view": 1,
"weight": 11
},
"twingle_event_url_internal": {
"custom_group_id": "Twingle_Event_Information",
"label": "Twingle Event Internal URL",
"name": "twingle_event_url_internal",
"is_required": 0,
"is_searchable": 0,
"data_type": "String",
"html_type": "Text",
"text_length": 256,
"is_active": 1,
"is_view": 1,
"weight": 12
},
"twingle_event_url_external": {
"custom_group_id": "Twingle_Event_Information",
"label": "Twingle Event External URL",
"name": "twingle_event_url_external",
"is_required": 0,
"is_searchable": 0,
"data_type": "String",
"html_type": "Text",
"text_length": 256,
"is_active": 1,
"is_view": 1,
"weight": 13
},
"twingle_event_url_edit_internal": {
"custom_group_id": "Twingle_Event_Information",
"label": "Twingle Event Edit Internal URL",
"name": "twingle_event_url_edit_internal",
"is_required": 0,
"is_searchable": 0,
"data_type": "String",
"html_type": "Text",
"text_length": 256,
"is_active": 1,
"is_view": 1,
"weight": 14
},
"twingle_event_url_edit_external": {
"custom_group_id": "Twingle_Event_Information",
"label": "Twingle Event Edit External URL",
"name": "twingle_event_url_edit_external",
"is_required": 0,
"is_searchable": 0,
"data_type": "String",
"html_type": "Text",
"text_length": 256,
"is_active": 1,
"is_view": 1,
"weight": 15
},
"twingle_campaign_parent_project_id": {
"custom_group_id": "Twingle_Campaign_Information",
"label": "Parent TwingleProject ID",
"name": "twingle_campaign_parent_project_id",
"is_required": 0,
"is_searchable": 1,
"data_type": "String",
"html_type": "Text",
"text_length": 16,
"is_active": 1,
"is_view": 1,
"weight": 1
},
"twingle_campaign_cid": {
"custom_group_id": "Twingle_Campaign_Information",
"label": "Twingle Campaign CID",
"name": "twingle_campaign_cid",
"is_required": 0,
"is_searchable": 0,
"data_type": "Memo",
"html_type": "Text",
"text_length": 32,
"is_active": 1,
"is_view": 1,
"weight": 2
},
"twingle_campaign_url": {
"custom_group_id": "Twingle_Campaign_Information",
"label": "Twingle Campaign URL",
"name": "twingle_campaign_url",
"is_required": 0,
"is_searchable": 0,
"data_type": "Memo",
"html_type": "TextArea",
"text_length": 600,
"is_active": 1,
"is_view": 1,
"weight": 3
}
}
}

File diff suppressed because it is too large Load diff

View file

@ -1,13 +0,0 @@
{
"TwingleProject": {
"name": "title",
"last_update": "last_modified_date",
"project_target": "goal_revenue"
},
"TwingleEvent": {
"description": "title",
"updated_at": "last_modified_date",
"created_at": "start_date",
"target": "goal_revenue"
}
}

View file

@ -0,0 +1,18 @@
<?php
return [
"TwingleProject" => [
"name" => "title",
"last_update" => "last_modified_date",
"project_target" => "goal_revenue",
"counter-url" => "counter",
"embed" => "embed_codes"
],
"TwingleEvent" => [
"description" => "title",
"updated_at" => "last_modified_date",
"created_at" => "start_date",
"target" => "goal_revenue"
]
];

View file

@ -1,8 +0,0 @@
{
"twingle_event_donation": {
"name": "twingle_event_donation",
"label": "Twingle Event",
"description": "A soft credit type for TwingleEvent initiators.",
"option_group_id": "soft_credit_type"
}
}

View file

@ -0,0 +1,10 @@
<?php
return [
"twingle_event_donation" => [
"name" => "twingle_event_donation",
"label" => "Twingle Event",
"description" => "A soft credit type for TwingleEvent initiators.",
"option_group_id" => "soft_credit_type"
]
];

View file

@ -1,61 +0,0 @@
{
"TwingleProject": [
"id",
"identifier",
"allow_more",
"name",
"organisation_id",
"project_target",
"transaction_type",
"type",
"last_update",
"url"
],
"project_embed_data": [
"page",
"widget",
"form",
"form-single",
"widget-single",
"eventall",
"eventlist",
"counter"
],
"TwingleEvent": [
"id",
"project_id",
"identifier",
"description",
"user_name",
"user_email",
"is_public",
"deleted",
"confirmed_at",
"created_at",
"updated_at",
"target",
"creation_url",
"show_internal",
"show_external",
"edit_internal",
"edit_external",
"urls"
],
"event_embed_data": [
"page",
"eventpage",
"widget",
"form",
"widget-single",
"form-single",
"eventall",
"eventlist",
"eventeditcreate"
],
"TwingleCampaign": [
"id",
"parent_id",
"name",
"title"
]
}

View file

@ -0,0 +1,114 @@
<?php
return [
"TwingleProject" => [
"project_data" => [
"id",
"identifier",
"allow_more",
"name",
"organisation_id",
"project_target",
"transaction_type",
"type",
"last_update",
"url"
],
"project_embed_data" => [
"page",
"widget",
"form",
"form-single",
"widget-single",
"eventall",
"eventlist",
"counter"
],
"project_options" => [
"has_confirmation_mail",
"has_donation_receipt",
"has_contact_data",
"donation_rhythm",
"default_rhythm",
"has_newsletter_registration",
"has_postinfo_registration",
"design_background_color",
"design_primary_color",
"design_font_color",
"bcc_email_address",
"donation_value_min",
"donation_value_max",
"donation_value_default",
"contact_fields",
"exclude_contact_fields",
"mandatory_contact_fields",
"custom_css",
"share_url",
"has_contact_mandatory",
"has_doi",
"has_force_donation_target_buttons",
"slidericon",
"has_hidden_logo",
"has_projecttarget_as_money",
"has_donationtarget_textfield",
"has_civi_crm_activated",
"has_step_index",
"languages",
"has_buttons",
"has_no_slider",
"buttons",
"has_newsletter_namerequest",
"has_show_donator_data"
],
"payment_methods" => [
"has_paypal",
"has_banktransfer",
"has_debit",
"has_sofortueberweisung",
"has_paypal_recurring",
"has_debit_recurring"
]
],
"TwingleEvent" => [
"event_data" => [
"id",
"project_id",
"identifier",
"description",
"user_name",
"user_email",
"is_public",
"deleted",
"confirmed_at",
"created_at",
"updated_at",
"target",
"creation_url",
"show_internal",
"show_external",
"edit_internal",
"edit_external",
"urls"
],
"event_embed_data" => [
"page",
"eventpage",
"widget",
"form",
"widget-single",
"form-single",
"eventall",
"eventlist",
"eventeditcreate"
]
],
"TwingleCampaign" => [
"campaign_data" => [
"id",
"parent_id",
"name",
"title"
]
]
];

View file

@ -105,7 +105,7 @@ function civicrm_api3_twingle_campaign_Get(array $params): array {
// Get campaign type id for TwingleCampaign // Get campaign type id for TwingleCampaign
$twingle_campaign_campaign_type_id = $twingle_campaign_campaign_type_id =
Cache::getInstance() Cache::getInstance()
->getCampaigns()['campaign_types']['twingle_campaign']['id']; ->getCampaignIds()['campaign_types']['twingle_campaign']['id'];
// If no id but a project_id is provided, get all TwingleCampaign children of // If no id but a project_id is provided, get all TwingleCampaign children of
// this TwingleProject // this TwingleProject

View file

@ -173,17 +173,17 @@ function twinglecampaign_postSave_campaign_callback (
try { try {
civicrm_api3('TwingleProject', 'sync', ['id' => $campaign_id]); civicrm_api3('TwingleProject', 'sync', ['id' => $campaign_id]);
CRM_Utils_System::setUFMessage('TwingleProject was saved.'); CRM_Utils_System::setUFMessage('TwingleProject was saved.');
} catch (CiviCRM_API3_Exception $e) {
Civi::log()->error( function _get_campaign_type_id_twingle_project() {
'twinglecampaign_postSave_callback ' . $e->getMessage() return ExtensionCache::getInstance()
); ->getCampaignIds()['campaign_types']['twingle_project']['id'];
} }
} else {
try { function _get_campaign_type_id_twingle_campaign() {
civicrm_api3('TwingleCampaign', 'create', ['id' => $campaign_id]); return ExtensionCache::getInstance()
CRM_Utils_System::setUFMessage('TwingleCampaign was saved.'); ->getCampaignIds()['campaign_types']['twingle_campaign']['id'];
} catch (CiviCRM_API3_Exception $e) { }
Civi::log()->error(
'twinglecampaign_postSave_callback ' . $e->getMessage() 'twinglecampaign_postSave_callback ' . $e->getMessage()
); );
} }