diff --git a/CRM/TwingleCampaign/BAO/TwingleProject.php b/CRM/TwingleCampaign/BAO/TwingleProject.php index d274043..2c4113e 100644 --- a/CRM/TwingleCampaign/BAO/TwingleProject.php +++ b/CRM/TwingleCampaign/BAO/TwingleProject.php @@ -42,8 +42,6 @@ class TwingleProject { private $values; - private $options; - /** * TwingleProject constructor. @@ -63,12 +61,6 @@ class TwingleProject { // Fetch custom field mapping once self::init(); - // Create TwingleProjectOptions object - $this->options = new TwingleProjectOptions($project['options'], $origin); - - // Unset project options in $project array - unset($project['options']); - // If values come from CiviCRM Campaign API if ($origin == self::CIVICRM) { @@ -172,28 +164,11 @@ class TwingleProject { self::IN ); - // Prepare project option values for import into database - $options_prepared_for_import = $this->options->getValues(); - TwingleProjectOptions::formatValues( - $options_prepared_for_import, - self::IN - ); - self::translateCustomFields( - $options_prepared_for_import, - self::IN - ); - - // Merge project values and project options values - $merged = array_merge( - $values_prepared_for_import, - $options_prepared_for_import - ); - // Set id - $merged['id'] = $this->id; + $values_prepared_for_import['id'] = $this->id; // Create campaign - $result = civicrm_api3('Campaign', 'create', $merged); + $result = civicrm_api3('Campaign', 'create', $values_prepared_for_import); // Update id $this->id = $result['id']; @@ -226,12 +201,6 @@ class TwingleProject { */ public function update(array $values) { - // Update project options - $this->options->update($values['options']); - - // Unset options array in project values - unset($values['options']); - // Update project values $this->values = array_merge($this->values, $values); } @@ -250,7 +219,6 @@ class TwingleProject { $values = $this->values; self::formatValues($values, self::OUT); - self::translateKeys($values, self::OUT); // Get template for project $project = self::$templates['project']; @@ -265,37 +233,6 @@ class TwingleProject { return $values; } - /** - * Export options. Ensures that only those values will be exported which the - * Twingle API expects. Missing values will get complemented with default - * values. - * - * @return array - * Array with all options to send to the Twingle API - * - * @throws Exception - * - */ - public function exportOptions() { - - $options = $this->values['options']; - self::formatValues($options, self::OUT); - self::translateKeys($options, self::OUT); - - // Get Template for project options - $project_options_template = self::$templates['project_options']; - - // Replace array items which the Twingle API does not expect - foreach ($options as $key => $value) { - if (!key_exists($key, $project_options_template)) { - unset($options[$key]); - } - } - - // Complement missing options with default values - return array_merge($project_options_template, $options); - } - /** * Check if a TwingleProject campaign already exists and if so set attributes @@ -349,9 +286,6 @@ class TwingleProject { // Translate keys from CiviCRM format to Twingle format self::translateKeys($values, self::OUT); - // Separate options from project values - self::separateOptions($values); - // Set attributes to the values of the existing TwingleProject campaign // to reflect the state of the actual campaign in the database $this->update($values); @@ -379,9 +313,6 @@ class TwingleProject { 'id' => $id, ]); - // Separate options from project values - self::separateOptions($result['values']); - return new TwingleProject( $result['values'], self::CIVICRM @@ -484,14 +415,17 @@ class TwingleProject { elseif ($direction == self::OUT) { // Change DateTime string into timestamp - $values['last_modified_date'] = - self::getTimestamp($values['last_modified_date']); + $values['last_update'] = + self::getTimestamp($values['last_update']); - // default project_type to '' + // Default project_type to '' $values['type'] = $values['type'] == 'default' ? '' : $values['type']; + // Cast project target to integer + $values['project_target'] = (int) $values['project_target']; + } else { @@ -568,30 +502,31 @@ class TwingleProject { } /** - * A function that picks all option values from the values array and puts them - * into an own array. + * Set embed data fields * - * @param array $values + * @param array $embedData + * Array with embed data from Twingle API */ - private static function separateOptions(array &$values) { + public function setEmbedData(array $embedData) { - $options = []; + // Get all embed_data keys from template + $embed_data_keys = self::$templates['project_embed_data']; - // Get array with template for project values and options - $options_template = self::$templates['project_options']; - - // Map array items into $values and $options array - foreach ($values as $key => $value) { - if (key_exists($key, $options_template)) { - $options[$key] = $value; - unset($values[$key]); - } + // Transfer all embed_data values + foreach ($embed_data_keys as $key) { + $this->values[$key] = htmlspecialchars($embedData[$key]); } - - // Insert options array into values array - $values['options'] = $options; } + /** + * Set counter url + * + * @param String $counterUrl + * URL of the counter + */ + public function setCounterUrl(string $counterUrl) { + $this->values['counter'] = $counterUrl; + } /** * Deactivate this TwingleProject campaign @@ -654,10 +589,11 @@ class TwingleProject { */ public function getResponse(string $status) { return [ - 'title' => $this->values['name'], - 'id' => (int) $this->id, - 'project_id' => (int) $this->values['id'], - 'status' => $status, + 'title' => $this->values['name'], + 'id' => (int) $this->id, + 'project_id' => (int) $this->values['id'], + 'project_type' => $this->values['type'], + 'status' => $status, ]; } @@ -730,12 +666,8 @@ class TwingleProject { * @return int|null */ public function lastUpdate() { - $lastProjectUpdate = self::getTimestamp($this->values['last_update']); - $lastOptionsUpdate = self::getTimestamp($this->options->lastUpdate()); - $lastUpdate = $lastProjectUpdate > $lastOptionsUpdate - ? $lastProjectUpdate - : $lastOptionsUpdate; - return self::getTimestamp($lastUpdate); + + return self::getTimestamp($this->values['last_update']); } diff --git a/CRM/TwingleCampaign/BAO/TwingleProjectOptions.php b/CRM/TwingleCampaign/BAO/TwingleProjectOptions.php deleted file mode 100644 index b9db910..0000000 --- a/CRM/TwingleCampaign/BAO/TwingleProjectOptions.php +++ /dev/null @@ -1,243 +0,0 @@ -values = $options; - } - - - /** - * Update an this object - * - * @param array $options - * Array with values to update - * - * @throws Exception - */ - public function update(array $options) { - - // Update values - $this->values = array_merge($this->values, $options); - - } - - - /** - * Export values. Ensures that only those values will be exported which the - * Twingle API expects. - * - * @return array - * Array with all values to send to the Twingle API - * - * @throws Exception - */ - public function export() { - - $values = $this->values; - self::formatValues($values, TwingleProject::OUT); - TwingleProject::translateKeys($values, TwingleProject::OUT); - - // Get Template for project options - $project_options_template = TwingleProject::$templates['project_options']; - - // Replace array items which the Twingle API does not expect - foreach ($values as $key => $value) { - if (!key_exists($key, $project_options_template)) { - unset($values[$key]); - } - } - - // Format project target format - if (key_exists('has_projecttarget_as_money', $values)) { - $values['has_projecttarget_as_money'] = - $values['has_projecttarget_as_money'] ? 'in Euro' : 'percentage'; - } - - return $values; - } - - - /** - * Translate values between CiviCRM Campaigns and Twingle - * - * @param array $values - * array of which values shall be translated - * - * @param string $direction - * TwingleProject::IN -> translate array values from Twingle to CiviCRM
- * TwingleProject::OUT -> translate array values from CiviCRM to Twingle - * - * @throws Exception - */ - public static function formatValues(array &$values, string $direction) { - - if ($direction == TwingleProject::IN) { - - // Change timestamp into DateTime string - if ($values['last_update']) { - $values['last_update'] = - TwingleProject::getDateTime($values['last_update']); - } - - // format donation rhythm - if (is_array($values['donation_rhythm'])) { - $tmp = []; - foreach ($values['donation_rhythm'] as $key => $value) { - if ($value) { - $tmp[$key] = $key; - } - } - $values['donation_rhythm'] = CRM_Utils_Array::implodePadded($tmp); - } - - // Format contact fields - if ($values['exclude_contact_fields']) { - $possible_contact_fields = - TwingleProject::$campaigns['custom_fields'] - ['twingle_project_exclude_contact_fields']['option_values']; - - $exclude_contact_fields = explode( - ',', - $values['exclude_contact_fields'] - ); - - foreach ($exclude_contact_fields as $exclude_contact_field) { - unset($possible_contact_fields[$exclude_contact_field]); - } - - $values['exclude_contact_fields'] = - CRM_Utils_Array::implodePadded($possible_contact_fields); - } - - // Format languages - if ($values['languages']) { - $values['languages'] = - CRM_Utils_Array::implodePadded( - explode( - ',', - $values['languages'] - ) - ); - } - - // Format project target format - if (key_exists('has_projecttarget_as_money', $values)) { - $values['has_projecttarget_as_money'] = - $values['has_projecttarget_as_money'] ? 'in Euro' : 'percentage'; - } - } - - elseif ($direction == TwingleProject::OUT) { - - // Change DateTime string into timestamp - $values['last_update'] = - TwingleProject::getTimestamp($values['last_update']); - - // format donation rhythm - if (is_array($values['donation_rhythm'])) { - $tmp = []; - foreach ($values['donation_rhythm'] as $key => $value) { - if ($value) { - $tmp[$key] = $key; - } - } - $values['donation_rhythm'] = CRM_Utils_Array::implodePadded($tmp); - } - - // Format contact fields - if ($values['exclude_contact_fields']) { - $possible_contact_fields = - TwingleProject::$campaigns['custom_fields'] - ['twingle_project_exclude_contact_fields']['option_values']; - - $exclude_contact_fields = explode( - ',', - $values['exclude_contact_fields'] - ); - - foreach ($exclude_contact_fields as $exclude_contact_field) { - unset($possible_contact_fields[$exclude_contact_field]); - } - - $values['exclude_contact_fields'] = - CRM_Utils_Array::implodePadded($possible_contact_fields); - } - - // Format languages - if ($values['languages']) { - $values['languages'] = - CRM_Utils_Array::implodePadded( - explode( - ',', - $values['languages'] - ) - ); - } - - // Cast project_target to integer - $values['project_target'] = (int) $values['project_target']; - - } - else { - - throw new Exception( - "Invalid Parameter $direction for formatValues()" - ); - } - } - - /** - * @return array - */ - public function getValues(): array { - return $this->values; - } - - public function lastUpdate() { - return $this->values['last_update']; - } - -} diff --git a/CRM/TwingleCampaign/resources/campaigns.json b/CRM/TwingleCampaign/resources/campaigns.json index 0ceb2fd..221ab61 100644 --- a/CRM/TwingleCampaign/resources/campaigns.json +++ b/CRM/TwingleCampaign/resources/campaigns.json @@ -26,15 +26,9 @@ "name": "Twingle_Project_Embed_Codes", "extends": "Campaign", "campaign_type": "twingle_project", + "collapse_display": "1", "weight": "2" }, - "twingle_project_options": { - "title": "Twingle Project Settings", - "name": "Twingle_Project_Options", - "extends": "Campaign", - "campaign_type": "twingle_project", - "weight": "3" - }, "twingle_event_information": { "title": "Twingle Event Information", "name": "Twingle_Event_Information", @@ -172,7 +166,7 @@ "is_required": 0, "is_searchable": 0, "data_type": "Memo", - "html_type": "TextArea", + "html_type": "RichTextEditor", "text_length": 600, "is_active": 1, "is_view": 1, @@ -185,7 +179,7 @@ "is_required": 0, "is_searchable": 0, "data_type": "Memo", - "html_type": "TextArea", + "html_type": "RichTextEditor", "text_length": 600, "is_active": 1, "is_view": 1, @@ -198,7 +192,7 @@ "is_required": 0, "is_searchable": 0, "data_type": "Memo", - "html_type": "TextArea", + "html_type": "RichTextEditor", "text_length": 600, "is_active": 1, "is_view": 1, @@ -211,7 +205,7 @@ "is_required": 0, "is_searchable": 0, "data_type": "Memo", - "html_type": "TextArea", + "html_type": "RichTextEditor", "text_length": 600, "is_active": 1, "is_view": 1, @@ -224,7 +218,7 @@ "is_required": 0, "is_searchable": 0, "data_type": "Memo", - "html_type": "TextArea", + "html_type": "RichTextEditor", "text_length": 1300, "is_active": 1, "is_view": 1, @@ -237,7 +231,7 @@ "is_required": 0, "is_searchable": 0, "data_type": "Memo", - "html_type": "TextArea", + "html_type": "RichTextEditor", "text_length": 1300, "is_active": 1, "is_view": 1, @@ -249,970 +243,12 @@ "name": "twingle_project_counter", "is_required": 0, "is_searchable": 0, - "data_type": "Link", - "html_type": "Link", + "data_type": "Memo", + "html_type": "RichTextEditor", "text_length": 120, "is_active": 1, "is_view": 1, "weight": 7 - }, - "twingle_project_has_confirmation_mail": { - "custom_group_id": "Twingle_Project_Options", - "label": "Twingle Project Confirmation Mail", - "name": "twingle_project_has_confirmation_mail", - "is_required": 0, - "is_searchable": 0, - "data_type": "Boolean", - "html_type": "Radio", - "text_length": 6, - "is_active": 1, - "is_view": 0, - "weight": 1, - "help_post": "Send confirmation mail" - }, - "twingle_project_has_confirmation_mail_api": { - "custom_group_id": "Twingle_Project_Options", - "label": "Twingle Project Confirmation Mail API", - "name": "twingle_project_has_confirmation_mail_api", - "is_required": 0, - "is_searchable": 0, - "data_type": "Boolean", - "html_type": "Radio", - "text_length": 6, - "is_active": 1, - "is_view": 0, - "weight": 2 - }, - "twingle_project_has_donation_receipt": { - "custom_group_id": "Twingle_Project_Options", - "label": "Twingle Project Donation Receipt", - "name": "twingle_project_has_donation_receipt", - "is_required": 0, - "is_searchable": 0, - "data_type": "Boolean", - "html_type": "Radio", - "text_length": 6, - "is_active": 1, - "is_view": 0, - "weight": 3, - "help_post": "Offer donation receipts" - }, - "twingle_project_has_contact_data": { - "custom_group_id": "Twingle_Project_Options", - "label": "Twingle Project Contact Data", - "name": "twingle_project_has_contact_data", - "is_required": 0, - "is_searchable": 0, - "data_type": "Boolean", - "html_type": "Radio", - "text_length": 6, - "is_active": 1, - "is_view": 0, - "weight": 4 - }, - "twingle_project_donation_rhythm": { - "custom_group_id": "Twingle_Project_Options", - "label": "Twingle Project Donation Rhythm", - "name": "twingle_project_donation_rhythm", - "is_required": 0, - "is_searchable": 0, - "data_type": "String", - "html_type": "Multi-Select", - "option_values": { - "yearly": "yearly", - "halfyearly": "halfyearly", - "quarterly": "quarterly", - "monthly": "monthly", - "one_time": "one time" - }, - "text_length": 6, - "is_active": 1, - "is_view": 0, - "weight": 5 - }, - "twingle_project_has_newsletter_registration": { - "custom_group_id": "Twingle_Project_Options", - "label": "Twingle Project Newsletter Registration", - "name": "twingle_project_has_newsletter_registration", - "is_required": 0, - "is_searchable": 0, - "data_type": "Boolean", - "html_type": "Radio", - "text_length": 6, - "is_active": 1, - "is_view": 0, - "weight": 6, - "help_post": "Enable newsletter registration" - }, - "twingle_project_has_postinfo_registration": { - "custom_group_id": "Twingle_Project_Options", - "label": "Twingle Project Postinfo Registration", - "name": "twingle_project_has_postinfo_registration", - "is_required": 0, - "is_searchable": 0, - "data_type": "Boolean", - "html_type": "Radio", - "text_length": 6, - "is_active": 1, - "is_view": 0, - "weight": 7, - "help_post": "Enable post info registration" - }, - "twingle_project_design_background_color": { - "custom_group_id": "Twingle_Project_Options", - "label": "Twingle Project Background Color", - "name": "twingle_project_design_background_color", - "is_required": 0, - "is_searchable": 0, - "data_type": "String", - "html_type": "Text", - "text_length": 6, - "is_active": 1, - "is_view": 0, - "weight": 8, - "help_post": "Hex color code (e.g. ffffff for white)" - }, - "twingle_project_design_primary_color": { - "custom_group_id": "Twingle_Project_Options", - "label": "Twingle Project Primary Color", - "name": "twingle_project_design_primary_color", - "is_required": 0, - "is_searchable": 0, - "data_type": "String", - "html_type": "Text", - "text_length": 6, - "is_active": 1, - "is_view": 0, - "weight": 9, - "help_post": "Hex color code (e.g. ffffff for white)" - }, - "twingle_project_design_font": { - "custom_group_id": "Twingle_Project_Options", - "label": "Twingle Project Font", - "name": "twingle_project_design_font", - "is_required": 0, - "is_searchable": 0, - "data_type": "String", - "html_type": "Text", - "text_length": 6, - "is_active": 1, - "is_view": 0, - "weight": 10, - "help_post": "Font name" - }, - "twingle_project_design_font_color": { - "custom_group_id": "Twingle_Project_Options", - "label": "Twingle Project Font Color", - "name": "twingle_project_design_font_color", - "is_required": 0, - "is_searchable": 0, - "data_type": "String", - "html_type": "Text", - "text_length": 6, - "is_active": 1, - "is_view": 0, - "weight": 11, - "help_post": "Hex color code (e.g. ffffff for white)" - }, - "twingle_project_design_button_font_color": { - "custom_group_id": "Twingle_Project_Options", - "label": "Twingle Project Button Font Color", - "name": "twingle_project_design_button_font_color", - "is_required": 0, - "is_searchable": 0, - "data_type": "String", - "html_type": "Text", - "text_length": 6, - "is_active": 1, - "is_view": 0, - "weight": 12, - "help_post": "Hex color code (e.g. ffffff for white)" - }, - "twingle_project_design_button_font_color_light": { - "custom_group_id": "Twingle_Project_Options", - "label": "Twingle Project Button Font Color Light", - "name": "twingle_project_design_button_font_color_light", - "is_required": 0, - "is_searchable": 0, - "data_type": "String", - "html_type": "Text", - "text_length": 6, - "is_active": 1, - "is_view": 0, - "weight": 13, - "help_post": "Hex color code (e.g. ffffff for white)" - }, - "twingle_project_image": { - "custom_group_id": "Twingle_Project_Options", - "label": "Twingle Project Image", - "name": "twingle_project_image", - "is_required": 0, - "is_searchable": 0, - "data_type": "File", - "html_type": "File", - "is_active": 1, - "is_view": 0, - "weight": 14 - }, - "twingle_project_bcc_email_address": { - "custom_group_id": "Twingle_Project_Options", - "label": "Twingle Project BCC Email", - "name": "twingle_project_bcc_email_address", - "is_required": 0, - "is_searchable": 0, - "data_type": "String", - "html_type": "Text", - "text_length": 64, - "is_active": 1, - "is_view": 0, - "weight": 15, - "help_post": "Email address used as bcc addresses for confirmation mail which is send to an user" - }, - "twingle_project_donation_value_min": { - "custom_group_id": "Twingle_Project_Options", - "label": "Twingle Project Donation Min", - "name": "twingle_project_donation_value_min", - "is_required": 0, - "is_searchable": 0, - "data_type": "String", - "html_type": "Text", - "text_length": 10, - "is_active": 1, - "is_view": 0, - "weight": 16, - "help_post": "Minimum donation value", - "default_value": "5" - }, - "twingle_project_donation_value_max": { - "custom_group_id": "Twingle_Project_Options", - "label": "Twingle Project Donation Max", - "name": "twingle_project_donation_value_max", - "is_required": 0, - "is_searchable": 0, - "data_type": "String", - "html_type": "Text", - "text_length": 10, - "is_active": 1, - "is_view": 0, - "weight": 17, - "help_post": "Maximum donation value", - "default_value": "500" - }, - "twingle_project_donation_value_default": { - "custom_group_id": "Twingle_Project_Options", - "label": "Twingle Project Donation Default", - "name": "twingle_project_donation_value_default", - "is_required": 0, - "is_searchable": 0, - "data_type": "String", - "html_type": "Text", - "text_length": 10, - "is_active": 1, - "is_view": 0, - "weight": 18, - "help_post": "Default donation value", - "default_value": "50" - }, - "twingle_project_exclude_contact_fields": { - "custom_group_id": "Twingle_Project_Options", - "label": "Twingle Project Contact Fields", - "name": "twingle_project_exclude_contact_fields", - "is_required": 0, - "is_searchable": 0, - "data_type": "String", - "html_type": "Multi-Select", - "option_values": { - "salutation": "Salutation", - "firstname": "First name", - "lastname": "Last name", - "company": "Company", - "birthday": "Birthday", - "street": "Street", - "postal_code": "Postal Code", - "city": "City", - "country": "Country", - "telephone": "Telephone" - }, - "is_active": 1, - "is_view": 0, - "weight": 19, - "help_post": "Fields to include in contact form" - }, - "twingle_project_custom_js": { - "custom_group_id": "Twingle_Project_Options", - "label": "Twingle Project Custom JavaScript", - "name": "twingle_project_custom_js", - "is_required": 0, - "is_searchable": 0, - "data_type": "Link", - "html_type": "Link", - "text_length": 120, - "is_active": 1, - "is_view": 0, - "weight": 20, - "help_post": "URL to a custom JavaScript file that will be included in the frontend" - }, - "twingle_project_custom_css": { - "custom_group_id": "Twingle_Project_Options", - "label": "Twingle Project Custom CSS", - "name": "twingle_project_custom_css", - "is_required": 0, - "is_searchable": 0, - "data_type": "Link", - "html_type": "Link", - "text_length": 120, - "is_active": 1, - "is_view": 0, - "weight": 21, - "help_post": "URL to a custom CSS file that will be included in the frontend" - }, - "twingle_project_share_url": { - "custom_group_id": "Twingle_Project_Options", - "label": "Twingle Project Share URL", - "name": "twingle_project_share_url", - "is_required": 0, - "is_searchable": 0, - "data_type": "Link", - "html_type": "Link", - "text_length": 120, - "is_active": 1, - "is_view": 0, - "weight": 22, - "help_post": "URL for the sharing component on the last page and doi page" - }, - "twingle_project_has_contact_mandatory": { - "custom_group_id": "Twingle_Project_Options", - "label": "Twingle Project Contact Mandatory", - "name": "twingle_project_has_contact_mandatory", - "is_required": 0, - "is_searchable": 0, - "data_type": "Boolean", - "html_type": "Radio", - "is_active": 1, - "is_view": 0, - "weight": 23, - "help_post": "If the contact data should be requested mandatory as second step" - }, - "twingle_project_has_doi": { - "custom_group_id": "Twingle_Project_Options", - "label": "Twingle Project Double Opt-In", - "name": "twingle_project_has_doi", - "is_required": 0, - "is_searchable": 0, - "data_type": "Boolean", - "html_type": "Radio", - "is_active": 1, - "is_view": 0, - "weight": 24, - "help_post": "Enable Twingle's double opt-in (Do not enable, if you use CiviCRM's double opt-in!)" - }, - "twingle_project_doi_redirect": { - "custom_group_id": "Twingle_Project_Options", - "label": "Twingle Project Double Opt-In Redirect", - "name": "twingle_project_doi_redirect", - "is_required": 0, - "is_searchable": 0, - "data_type": "String", - "html_type": "Text", - "text_length": 120, - "is_active": 1, - "is_view": 0, - "weight": 25, - "help_post": "Redirect url or urls (each per language) after successful DOIs" - }, - "twingle_project_has_force_donation_target_buttons": { - "custom_group_id": "Twingle_Project_Options", - "label": "Twingle Project Force Donation Taget as Button", - "name": "twingle_project_has_force_donation_target_buttons", - "is_required": 0, - "is_searchable": 0, - "data_type": "Boolean", - "html_type": "Radio", - "is_active": 1, - "is_view": 0, - "weight": 26, - "help_post": "Force showing the donation targets as buttons" - }, - "twingle_project_has_show_single_target": { - "custom_group_id": "Twingle_Project_Options", - "label": "Twingle Project Show Single Target", - "name": "twingle_project_has_show_single_target", - "is_required": 0, - "is_searchable": 0, - "data_type": "Boolean", - "html_type": "Radio", - "is_active": 1, - "is_view": 0, - "weight": 27, - "help_post": "Show the donation button if we have only one set" - }, - "twingle_project_options_last_update": { - "custom_group_id": "Twingle_Project_Options", - "label": "Twingle Project Last Update", - "name": "twingle_project_options_last_update", - "is_required": 0, - "is_searchable": 0, - "data_type": "String", - "html_type": "Text", - "is_active": 1, - "is_view": 1, - "weight": 28 - }, - "twingle_project_slidericon": { - "custom_group_id": "Twingle_Project_Options", - "label": "Twingle Project Slider Icon", - "name": "twingle_project_slidericon", - "is_required": 0, - "is_searchable": 0, - "data_type": "String", - "html_type": "Select", - "option_values": { - "heart": "Heart", - "asterisk": "Asterisk", - "animal": "Animal", - "Rettungsring": "Lifebelt", - "angellist": "Angellist", - "handshake": "Handshake", - "dollar": "Dollar", - "menue_burger_fine": "Menue", - "office": "Office", - "leaf": "Leaf", - "cog": "Cog", - "wvg": "SVG", - "euro": "Euro", - "stats-dots": "Stats", - "circle_fine": "Circle", - "waterdrop_outline": "Water drop outline", - "waterdrop": "Water drop", - "gift": "Gift", - "biene_b": "Bee", - "blume": "Flower", - "train": "Train", - "empty": "No Icon" - }, - "is_active": 1, - "is_view": 0, - "weight": 29 - }, - "twingle_project_use_extra_field": { - "custom_group_id": "Twingle_Project_Options", - "label": "Twingle Project Use Extra Field", - "name": "twingle_project_use_extra_field", - "is_required": 0, - "is_searchable": 0, - "data_type": "Boolean", - "html_type": "Radio", - "is_active": 1, - "is_view": 0, - "weight": 30, - "help_post": "Create extra field" - }, - "twingle_project_extra_field_headline": { - "custom_group_id": "Twingle_Project_Options", - "label": "Twingle Project Use Extra Field Headline", - "name": "twingle_project_extra_field_headline", - "is_required": 0, - "is_searchable": 0, - "data_type": "String", - "html_type": "Text", - "text_length": 80, - "is_active": 1, - "is_view": 0, - "weight": 31 - }, - "twingle_project_extra_field_type": { - "custom_group_id": "Twingle_Project_Options", - "label": "Twingle Project Use Extra Field Type", - "name": "twingle_project_extra_field_type", - "is_required": 0, - "is_searchable": 0, - "data_type": "String", - "html_type": "Text", - "text_length": 80, - "is_active": 1, - "is_view": 0, - "weight": 32 - }, - "twingle_project_extra_field_label": { - "custom_group_id": "Twingle_Project_Options", - "label": "Twingle Project Use Extra Field Label", - "name": "twingle_project_extra_field_label", - "is_required": 0, - "is_searchable": 0, - "data_type": "String", - "html_type": "Text", - "text_length": 80, - "is_active": 1, - "is_view": 0, - "weight": 33 - }, - "twingle_project_extra_field_mandatory": { - "custom_group_id": "Twingle_Project_Options", - "label": "Twingle Project Use Extra Field Mandatory", - "name": "twingle_project_extra_field_mandatory", - "is_required": 0, - "is_searchable": 0, - "data_type": "Boolean", - "html_type": "Radio", - "is_active": 1, - "is_view": 0, - "weight": 34 - }, - "twingle_project_has_hidden_logo": { - "custom_group_id": "Twingle_Project_Options", - "label": "Twingle Project Hidden Logo", - "name": "twingle_project_has_hidden_logo", - "is_required": 0, - "is_searchable": 0, - "data_type": "Boolean", - "html_type": "Radio", - "is_active": 1, - "is_view": 0, - "weight": 35, - "help_post": "Hide the Logo on the project page" - }, - "twingle_project_has_projecttarget_as_money": { - "custom_group_id": "Twingle_Project_Options", - "label": "Twingle Project Target Format", - "name": "twingle_project_has_projecttarget_as_money", - "is_required": 0, - "is_searchable": 0, - "data_type": "String", - "html_type": "Radio", - "option_values": { - "1": "in Euro", - "0": "percentage" - }, - "is_active": 1, - "is_view": 0, - "weight": 36, - "help_post": "Format of the reached portion of the donation target", - "default_value": "0" - }, - "twingle_project_has_donationtarget_textfield": { - "custom_group_id": "Twingle_Project_Options", - "label": "Twingle Project Donation Purpose as Textfield", - "name": "twingle_project_has_donationtarget_textfield", - "is_required": 0, - "is_searchable": 0, - "data_type": "Boolean", - "html_type": "Radio", - "is_active": 1, - "is_view": 0, - "weight": 37, - "help_post": "Let donors enter their own donation purpose" - }, - "twingle_project_has_civi_crm_activated": { - "custom_group_id": "Twingle_Project_Options", - "label": "Twingle Project Activate CiviCRM Support", - "name": "twingle_project_has_civi_crm_activated", - "is_required": 0, - "is_searchable": 0, - "data_type": "Boolean", - "html_type": "Radio", - "is_active": 1, - "is_view": 0, - "weight": 38, - "help_post": "Activate support for Twingle Extension (de.systopia.twingle)" - }, - "twingle_project_has_step_index": { - "custom_group_id": "Twingle_Project_Options", - "label": "Twingle Project Show Step Index", - "name": "twingle_project_has_step_index", - "is_required": 0, - "is_searchable": 0, - "data_type": "Boolean", - "html_type": "Radio", - "is_active": 1, - "is_view": 0, - "weight": 39, - "help_post": "Show a step index during donation process" - }, - "twingle_project_gift_donation": { - "custom_group_id": "Twingle_Project_Options", - "label": "Twingle Project Donation Certificate ", - "name": "twingle_project_gift_donation", - "is_required": 0, - "is_searchable": 0, - "data_type": "String", - "html_type": "Select", - "option_values": { - "": "no", - "optional": "optional", - "mandatory": "mandatory" - }, - "is_active": 1, - "is_view": 0, - "weight": 40, - "help_post": "Should donors get a donation certificate?" - }, - "twingle_project_gift_donation_icon": { - "custom_group_id": "Twingle_Project_Options", - "label": "Twingle Project Donation Certificate Icon", - "name": "twingle_project_gift_donation_icon", - "is_required": 0, - "is_searchable": 0, - "data_type": "String", - "html_type": "Select", - "option_values": { - "": "Gift", - "letter_light": "Letter", - "profile": "Profile", - "file-text2": "Sheet", - "heart": "Heart", - "handshake": "Handshake", - "star-full": "Star", - "aid-kit": "Aid kit", - "diplom_urkunde": "Certificate", - "empty": "No Icon" - }, - "is_active": 1, - "is_view": 0, - "weight": 41 - }, - "twingle_project_gift_donation_image": { - "custom_group_id": "Twingle_Project_Options", - "label": "Twingle Project Donation Certificate Image", - "name": "twingle_project_gift_donation_image", - "is_required": 0, - "is_searchable": 0, - "data_type": "File", - "html_type": "File", - "is_active": 1, - "is_view": 0, - "weight": 42 - }, - "twingle_project_languages": { - "custom_group_id": "Twingle_Project_Options", - "label": "Twingle Project Languages", - "name": "twingle_project_languages", - "is_required": 0, - "is_searchable": 0, - "data_type": "String", - "html_type": "Multi-Select", - "option_values": { - "de": "German", - "en": "English", - "fr": "French", - "es": "Spanish" - }, - "is_active": 1, - "is_view": 0, - "weight": 43 - }, - "twingle_project_has_buttons": { - "custom_group_id": "Twingle_Project_Options", - "label": "Twingle Project Buttons", - "name": "twingle_project_has_buttons", - "is_required": 0, - "is_searchable": 0, - "data_type": "Boolean", - "html_type": "Radio", - "is_active": 1, - "is_view": 0, - "weight": 44, - "help_post": "Up to three buttons can be configured. If you leave the amount blank, the button will not be displayed." - }, - "twingle_project_has_no_slider": { - "custom_group_id": "Twingle_Project_Options", - "label": "Twingle Project Slider", - "name": "twingle_project_has_no_slider", - "is_required": 0, - "is_searchable": 0, - "data_type": "Boolean", - "html_type": "Radio", - "is_active": 1, - "is_view": 0, - "weight": 44, - "help_post": "Show a slider that allows the donor to choose the donation amount." - }, - "twingle_project_button1": { - "custom_group_id": "Twingle_Project_Options", - "label": "Twingle Project Button 1", - "name": "twingle_project_button1", - "is_required": 0, - "is_searchable": 0, - "data_type": "String", - "html_type": "Text", - "text_length": 10, - "is_active": 1, - "is_view": 0, - "weight": 44, - "help_post": "Amount to be displayed on Button 1" - }, - "twingle_project_button2": { - "custom_group_id": "Twingle_Project_Options", - "label": "Twingle Project Button 2", - "name": "twingle_project_button2", - "is_required": 0, - "is_searchable": 0, - "data_type": "String", - "html_type": "Text", - "text_length": 10, - "is_active": 1, - "is_view": 0, - "weight": 44, - "help_post": "Amount to be displayed on Button 2" - }, - "twingle_project_button3": { - "custom_group_id": "Twingle_Project_Options", - "label": "Twingle Project Button 3", - "name": "twingle_project_button3", - "is_required": 0, - "is_searchable": 0, - "data_type": "String", - "html_type": "Text", - "text_length": 10, - "is_active": 1, - "is_view": 0, - "weight": 44, - "help_post": "Amount to be displayed on Button 3" - }, - "twingle_project_has_newsletter_namerequest": { - "custom_group_id": "Twingle_Project_Options", - "label": "Twingle Project Newsletter Name Requested", - "name": "twingle_project_has_newsletter_namerequest", - "is_required": 0, - "is_searchable": 0, - "data_type": "Boolean", - "html_type": "Radio", - "is_active": 1, - "is_view": 0, - "weight": 44, - "help_post": "Must a donor give his name for newsletter sign-up?" - }, - "twingle_project_has_show_donator_data": { - "custom_group_id": "Twingle_Project_Options", - "label": "Twingle Project Show List of Donations", - "name": "twingle_project_has_show_donator_data", - "is_required": 0, - "is_searchable": 0, - "data_type": "Boolean", - "html_type": "Radio", - "is_active": 1, - "is_view": 0, - "weight": 44, - "help_post": "Display a list of public donations" - }, - "twingle_event_initiator": { - "custom_group_id": "Twingle_Event_Information", - "label": "Twingle Event Initiator", - "name": "twingle_event_initiator", - "is_required": 1, - "is_searchable": 1, - "data_type": "ContactReference", - "html_type": "Autocomplete-Select", - "text_length": 255, - "is_active": 1, - "weight": 1 - }, - "twingle_event_identifier": { - "custom_group_id": "Twingle_Event_Information", - "label": "Twingle Event Identifier", - "name": "twingle_event_identifier", - "is_required": 1, - "is_searchable": 1, - "data_type": "String", - "html_type": "Text", - "text_length": 30, - "is_active": 1, - "is_view": 1, - "weight": 2 - }, - "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": 10, - "is_active": 1, - "is_view": 1, - "weight": 3 - }, - "twingle_event_project_id": { - "custom_group_id": "Twingle_Event_Information", - "label": "Twingle Event Project ID", - "name": "twingle_event_project_id", - "is_required": 1, - "is_searchable": 1, - "data_type": "String", - "html_type": "Text", - "text_length": 16, - "is_active": 1, - "is_view": 1, - "weight": 4 - }, - "twingle_event_created_at": { - "custom_group_id": "Twingle_Event_Information", - "label": "Twingle Event Created at", - "name": "twingle_event_created_at", - "is_required": 1, - "is_searchable": 1, - "data_type": "String", - "html_type": "Text", - "text_length": 32, - "is_active": 1, - "is_view": 1, - "weight": 5 - }, - "twingle_event_creation_url": { - "custom_group_id": "Twingle_Event_Information", - "label": "Twingle Event Creation URL", - "name": "twingle_event_creation_url", - "is_required": 1, - "is_searchable": 1, - "data_type": "String", - "html_type": "Text", - "text_length": 300, - "is_active": 1, - "is_view": 1, - "weight": 6 - }, - "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": "Text", - "text_length": 4, - "is_active": 1, - "is_view": 0, - "weight": 7 - }, - "twingle_event_description": { - "custom_group_id": "Twingle_Event_Information", - "label": "Twingle Event Description", - "name": "twingle_event_description", - "is_required": 0, - "is_searchable": 0, - "data_type": "String", - "html_type": "Text", - "text_length": 3000, - "is_active": 1, - "is_view": 0, - "weight": 8 - }, - "twingle_event_slug": { - "custom_group_id": "Twingle_Event_Information", - "label": "Twingle Event Slug", - "name": "twingle_event_slug", - "is_required": 0, - "is_searchable": 1, - "data_type": "String", - "html_type": "Text", - "text_length": 120, - "is_active": 1, - "is_view": 0, - "weight": 9 - }, - "twingle_event_target": { - "custom_group_id": "Twingle_Event_Information", - "label": "Twingle Event Target", - "name": "twingle_event_target", - "is_required": 0, - "is_searchable": 1, - "data_type": "String", - "html_type": "Text", - "text_length": 120, - "is_active": 1, - "is_view": 0, - "weight": 10 - }, - "twingle_event_text_teaser": { - "custom_group_id": "Twingle_Event_Information", - "label": "Twingle Event Teaser text", - "name": "twingle_event_text_teaser", - "is_required": 0, - "is_searchable": 0, - "data_type": "String", - "html_type": "Text", - "text_length": 3000, - "is_active": 1, - "is_view": 0, - "weight": 11 - }, - "twingle_event_text_thankyou": { - "custom_group_id": "Twingle_Event_Information", - "label": "Twingle Event Thank you text", - "name": "twingle_event_text_thankyou", - "is_required": 0, - "is_searchable": 0, - "data_type": "String", - "html_type": "Text", - "text_length": 3000, - "is_active": 1, - "is_view": 0, - "weight": 12 - }, - "twingle_event_type": { - "custom_group_id": "Twingle_Event_Information", - "label": "Twingle Event Type", - "name": "twingle_event_type", - "is_required": 0, - "is_searchable": 0, - "data_type": "String", - "html_type": "Text", - "text_length": 120, - "is_active": 1, - "is_view": 0, - "weight": 13 - }, - "twingle_event_updated_at": { - "custom_group_id": "Twingle_Event_Information", - "label": "Twingle Event Updated at", - "name": "twingle_event_updated_at", - "is_required": 0, - "is_searchable": 0, - "data_type": "String", - "html_type": "Text", - "text_length": 32, - "is_active": 1, - "is_view": 1, - "weight": 14 - }, - "twingle_event_user_email": { - "custom_group_id": "Twingle_Event_Information", - "label": "Twingle Event User email", - "name": "twingle_event_user_email", - "is_required": 0, - "is_searchable": 0, - "data_type": "String", - "html_type": "Text", - "text_length": 64, - "is_active": 1, - "is_view": 0, - "weight": 15 - }, - "twingle_event_user_name": { - "custom_group_id": "Twingle_Event_Information", - "label": "Twingle Event User name", - "name": "twingle_event_user_name", - "is_required": 0, - "is_searchable": 0, - "data_type": "String", - "html_type": "Text", - "text_length": 64, - "is_active": 1, - "is_view": 0, - "weight": 16 - }, - "twingle_campaign_id": { - "custom_group_id": "Twingle_Campaign_Information", - "label": "Twingle Campaign ID", - "name": "twingle_c_id", - "is_required": 1, - "is_searchable": 1, - "data_type": "String", - "html_type": "Text", - "text_length": 15, - "is_active": 1, - "is_view": 1, - "weight": 1 } } } diff --git a/CRM/TwingleCampaign/resources/twingle_api_templates.json b/CRM/TwingleCampaign/resources/twingle_api_templates.json index 248a3bb..2e5fe85 100644 --- a/CRM/TwingleCampaign/resources/twingle_api_templates.json +++ b/CRM/TwingleCampaign/resources/twingle_api_templates.json @@ -10,77 +10,14 @@ "type", "last_update" ], - "event": [ + "project_embed_data": [ + "widget", + "form", + "form-single", + "widget-single", + "eventall", + "eventlist" ], - "project_options": { - "has_confirmation_mail": false, - "has_confirmation_mail_api": false, - "has_donation_receipt": true, - "has_contact_data": false, - "donation_rhythm": { - "yearly": true, - "halfyearly": false, - "quarterly": false, - "monthly": true, - "one_time": true - }, - "has_newsletter_registration": false, - "has_postinfo_registration": false, - "design_background_color": "", - "design_primary_color": "", - "design_font": "", - "design_font_color": "", - "design_button_font_color": "", - "design_button_font_color_light": "", - "image": "", - "bcc_email_address": "", - "donation_value_min": 5, - "donation_value_max": 500, - "donation_value_default": 50, - "exclude_contact_fields": "birthday", - "custom_js": null, - "custom_css": null, - "share_url": null, - "has_contact_mandatory": false, - "has_doi": true, - "doi_redirect": null, - "has_force_donation_target_buttons": false, - "has_show_single_target": false, - "betterpayment_credit_card_theme": null, - "app_js": null, - "slidericon": "heart", - "extra_field": [], - "has_hidden_logo": false, - "has_projecttarget_as_money": false, - "rapidmail_recipient_list": null, - "mailchimp_recipient_list": null, - "has_mailchimp_add_all_user": null, - "has_mail_hide_paymentblock": false, - "has_mail_hide_paymentblock_api": false, - "has_donationtarget_textfield": false, - "has_civi_crm_activated": false, - "has_step_index": false, - "gift_donation": "", - "gift_donation_icon": null, - "gift_donation_image": null, - "languages": "de", - "has_buttons": false, - "has_no_slider": false, - "buttons": { - "button1": { - "amount": "" - }, - "button2": { - "amount": "" - }, - "button3": { - "amount": "" - } - }, - "has_newsletter_namerequest": false, - "has_show_donator_data": false, - "has_donation_letter": false, - "has_donation_letter_api": false, - "amount_images": [] - } + "event": [ + ] } \ No newline at end of file diff --git a/api/v3/TwingleSync/BAO/TwingleApiCall.php b/api/v3/TwingleSync/BAO/TwingleApiCall.php index c219484..d71ad4e 100644 --- a/api/v3/TwingleSync/BAO/TwingleApiCall.php +++ b/api/v3/TwingleSync/BAO/TwingleApiCall.php @@ -74,18 +74,6 @@ class TwingleApiCall { return $response; } - - public function getProjectOptions(int $projectId) { - $response = []; - foreach ($this->organisationId as $organisationId) { - $url = $this->protocol . 'project' . $this->baseUrl . $projectId . - '/options'; - - $response = array_merge($this->curlGet($url)); - } - return $response; - } - /** * * Returns all Events for the given $projectId @@ -138,25 +126,6 @@ class TwingleApiCall { // If $values is an array if (is_array($values)) { - // Get project options - try { - $values['options'] = $this->getProjectOptions($values['id']); - } catch (Exception $e) { - - // Log Exception - Civi::log()->error( - "Failed to instantiate TwingleProject: $e->getMessage()" - ); - - // Return result array with error description - return [ - "title" => $values['name'], - "project_id" => (int) $values['id'], - "status" => - "Failed to get project options from Twingle: $e->getMessage()", - ]; - } - // Instantiate TwingleProject try { $project = new TwingleProject( @@ -182,8 +151,9 @@ class TwingleApiCall { // Check if the TwingleProject campaign already exists if (!$project->exists()) { - // ... if not, create it + // ... if not, get embed data and create project try { + $this->getEmbedData($project); $result = $project->create($is_test); } catch (Exception $e) { @@ -206,12 +176,10 @@ class TwingleApiCall { // If Twingle's version of the project is newer than the CiviCRM // TwingleProject campaign update the campaign - $lastUpdate = $values['last_update'] > $values['options']['last_update'] - ? $values['last_update'] - : $values['options']['last_update']; - if ($lastUpdate > $project->lastUpdate()) { + if ($values['last_update'] > $project->lastUpdate()) { try { $project->update($values); + $this->getEmbedData($project); $result = $project->create(); $result['status'] = $result['status'] == 'TwingleProject created' ? 'TwingleProject updated' @@ -229,7 +197,7 @@ class TwingleApiCall { } // If the CiviCRM TwingleProject campaign was changed, update the project // on Twingle's side - elseif ($lastUpdate < $project->lastUpdate()) { + elseif ($values['last_update'] < $project->lastUpdate()) { // If this is a test do not make database changes if ($is_test) { $result = $project->getResponse( @@ -243,10 +211,8 @@ class TwingleApiCall { elseif ($result['status'] == 'TwingleProject exists') { $result = $project->getResponse('TwingleProject up to date'); } - } - // Return a response of the synchronization return $result; } @@ -256,6 +222,25 @@ class TwingleApiCall { } + /** + * @param \CRM\TwingleCampaign\BAO\TwingleProject $project + */ + private function getEmbedData(TwingleProject &$project) { + + // Prepare url for curl + $url = $this->protocol . 'project' . $this->baseUrl . $project->getProjectId(); + + // Send curl + $result = $this->curlGet($url); + + // Set embed data + $project->setEmbedData($result['embed']); + + // Set counter-url + $project->setCounterUrl($result['counter-url']['url']); + + } + /** * Sends an curl post call to Twingle to update an existing project and then * updates the TwingleProject campaign. @@ -267,7 +252,7 @@ class TwingleApiCall { * Returns a response array that contains title, id, project_id and status * */ - public function updateProject(TwingleProject &$project) { + private function updateProject(TwingleProject &$project) { try { $values = $project->export(); @@ -292,7 +277,8 @@ class TwingleApiCall { if (is_array($result) && !array_key_exists('message', $result)) { // Try to update the local TwingleProject campaign try { - $project->update($result, TwingleProject::TWINGLE); + $project->update($result); + $this->getEmbedData($project); $project->create(); return $project->getResponse('TwingleProject pushed to Twingle'); } catch (Exception $e) {