diff --git a/CRM/TwingleCampaign/BAO/Configuration.php b/CRM/TwingleCampaign/BAO/Configuration.php index 38e8d5e..6d2614e 100644 --- a/CRM/TwingleCampaign/BAO/Configuration.php +++ b/CRM/TwingleCampaign/BAO/Configuration.php @@ -6,7 +6,7 @@ class CRM_TwingleCampaign_BAO_Configuration { private static $settingsKeys = [ 'twingle_api_key', 'twinglecampaign_xcm_profile', - 'twinglecampaign_start_case', + 'twinglecampaign_default_case', 'twinglecampaign_soft_credits' ]; diff --git a/CRM/TwingleCampaign/BAO/TwingleEvent.php b/CRM/TwingleCampaign/BAO/TwingleEvent.php index fd7eddd..4248c1d 100644 --- a/CRM/TwingleCampaign/BAO/TwingleEvent.php +++ b/CRM/TwingleCampaign/BAO/TwingleEvent.php @@ -53,32 +53,39 @@ class CRM_TwingleCampaign_BAO_TwingleEvent extends Campaign { if (parent::create()) { - // check for existence - $result = civicrm_api3('Case', 'get', [ - 'contact_id' => $this->formattedValues['contact'], - 'case_type_id' => Configuration::get('twinglecampaign_start_case'), - 'subject' => $this->formattedValues['title'] . ' | Event-ID: ' . - $this->formattedValues['id'], - ]); + // Get case type + $parentProject = civicrm_api3( + 'TwingleProject', + 'getsingle', + ['id' => $this->values['parent_id']] + ); + $caseType = $parentProject['case'] + ?? Configuration::get('twinglecampaign_default_case'); - // Open a case - if ( - Configuration::get('twinglecampaign_start_case') && - $result['count'] == 0 - ) { - $result = civicrm_api3('Case', 'create', [ + if ($caseType) { + // check for existence + $result = civicrm_api3('Case', 'get', [ 'contact_id' => $this->formattedValues['contact'], - 'case_type_id' => Configuration::get('twinglecampaign_start_case'), + 'case_type_id' => $caseType, 'subject' => $this->formattedValues['title'] . ' | Event-ID: ' . $this->formattedValues['id'], - 'start_date' => $this->formattedValues['created_at'], - 'status_id' => "Open", ]); - } - if ($result['is_error'] != 0) { - throw new Exception('Could not create case'); - } + // Open a case + if ($result['count'] == 0) { + $result = civicrm_api3('Case', 'create', [ + 'contact_id' => $this->formattedValues['contact'], + 'case_type_id' => $caseType, + 'subject' => $this->formattedValues['title'] . ' | Event-ID: ' . + $this->formattedValues['id'], + 'start_date' => $this->formattedValues['created_at'], + 'status_id' => "Open", + ]); + } + if ($result['is_error'] != 0) { + throw new Exception('Could not create case'); + } + } return TRUE; } return FALSE; diff --git a/CRM/TwingleCampaign/Form/Settings.php b/CRM/TwingleCampaign/Form/Settings.php index d28b7cc..f614ce5 100644 --- a/CRM/TwingleCampaign/Form/Settings.php +++ b/CRM/TwingleCampaign/Form/Settings.php @@ -4,6 +4,7 @@ use CRM_TwingleCampaign_BAO_Configuration as Configuration; use CRM_TwingleCampaign_ExtensionUtil as E; include_once E::path() . '/CRM/TwingleCampaign/BAO/Configuration.php'; +include_once E::path() . '/CRM/TwingleCampaign/Utils/CaseTypes.php'; /** * Form controller class @@ -32,9 +33,9 @@ class CRM_TwingleCampaign_Form_Settings extends CRM_Core_Form { $this->addElement( 'select', - 'twinglecampaign_start_case', - E::ts('Start a case for event initiators'), - $this->getCaseTypes(), + 'twinglecampaign_default_case', + E::ts('Default case to open for event initiators'), + getCaseTypes(), ['class' => 'crm-select2 huge'] ); @@ -92,30 +93,5 @@ class CRM_TwingleCampaign_Form_Settings extends CRM_Core_Form { return $xcmProfiles; } - /** - * Retrieves all case types - * - * @return array - */ - private function getCaseTypes(): array { - $caseTypes = [NULL => E::ts('none')]; - try { - $result = civicrm_api3('CaseType', 'get', [ - 'sequential' => 1, - 'options' => ['limit' => 0] - ]); - if (is_array($result['values'])) { - foreach ($result['values'] as $case) { - $caseTypes[$case['name']] = $case['title']; - } - } - } catch (CiviCRM_API3_Exception $e) { - Civi::log()->error( - E::LONG_NAME . ' could not retrieve case types: ' . - $e->getMessage()); - } - return $caseTypes; - } - } diff --git a/CRM/TwingleCampaign/Upgrader.php b/CRM/TwingleCampaign/Upgrader.php index 3d4d94d..5c1a706 100644 --- a/CRM/TwingleCampaign/Upgrader.php +++ b/CRM/TwingleCampaign/Upgrader.php @@ -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_01(): bool { + public function upgrade_02(): bool { $campaign_info = require E::path() . '/CRM/TwingleCampaign/resources/campaigns.php'; diff --git a/CRM/TwingleCampaign/Utils/CaseTypes.php b/CRM/TwingleCampaign/Utils/CaseTypes.php new file mode 100644 index 0000000..312a23f --- /dev/null +++ b/CRM/TwingleCampaign/Utils/CaseTypes.php @@ -0,0 +1,28 @@ + E::ts('none')]; + try { + $result = civicrm_api3('CaseType', 'get', [ + 'sequential' => 1, + 'options' => ['limit' => 0] + ]); + if (is_array($result['values'])) { + foreach ($result['values'] as $case) { + $caseTypes[$case['name']] = $case['title']; + } + } + } catch (CiviCRM_API3_Exception $e) { + Civi::log()->error( + E::LONG_NAME . ' could not retrieve case types: ' . + $e->getMessage()); + } + return $caseTypes; +} diff --git a/CRM/TwingleCampaign/resources/campaigns.php b/CRM/TwingleCampaign/resources/campaigns.php index 1dbeba8..ffd097c 100644 --- a/CRM/TwingleCampaign/resources/campaigns.php +++ b/CRM/TwingleCampaign/resources/campaigns.php @@ -1,6 +1,7 @@ [ @@ -121,6 +122,21 @@ return [ "help_post" => E::ts("Choose the project type. Allow users to create own events or to pay a membership fee."), "default_value" => "default" ], + "twingle_project_case" => [ + "custom_group_id" => "Twingle_Project_Information", + "label" => E::ts("Case"), + "name" => "twingle_project_case", + "is_required" => FALSE, + "is_searchable" => 1, + "data_type" => "String", + "html_type" => "Select", + "option_values" => getCaseTypes(), + "text_length" => 32, + "is_active" => 1, + "is_view" => FALSE, + "weight" => 3, + "help_post" => E::ts("Which case should get opened for event creators?") + ], "twingle_project_allow_more" => [ "custom_group_id" => "Twingle_Project_Information", "label" => E::ts("allow more"), diff --git a/l10n/de_DE/LC_MESSAGES/twinglecampaign.mo b/l10n/de_DE/LC_MESSAGES/twinglecampaign.mo index 47867c3..6527e9a 100644 Binary files a/l10n/de_DE/LC_MESSAGES/twinglecampaign.mo and b/l10n/de_DE/LC_MESSAGES/twinglecampaign.mo differ diff --git a/l10n/de_DE/LC_MESSAGES/twinglecampaign.po b/l10n/de_DE/LC_MESSAGES/twinglecampaign.po index 7e83507..dc16d5d 100644 --- a/l10n/de_DE/LC_MESSAGES/twinglecampaign.po +++ b/l10n/de_DE/LC_MESSAGES/twinglecampaign.po @@ -7,7 +7,7 @@ msgstr "" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" -"X-Generator: Poedit 2.4.2\n" +"X-Generator: Poedit 2.4.3\n" "Last-Translator: \n" "Plural-Forms: nplurals=2; plural=(n != 1);\n" "Language: de_DE\n" @@ -120,8 +120,8 @@ msgid "XCM Profile to match event initiators" msgstr "XCM-Profil zum Abgleichen von Event-Initiatoren" #: CRM/TwingleCampaign/Form/Settings.php -msgid "Start a case for event initiators" -msgstr "Einen Fall für Event-Initiatoren anlegen" +msgid "Default case to open for event initiators" +msgstr "Standarfdall, der für Event-Initiatoren eröffnet werden soll" #: CRM/TwingleCampaign/Form/Settings.php msgid "Create soft credits for event initiators" @@ -135,10 +135,6 @@ msgstr "Speichern" msgid "TwingleCampaign configuration saved" msgstr "TwingleCampaign Konfiguration gespeichert" -#: CRM/TwingleCampaign/Form/Settings.php -msgid "none" -msgstr "keine" - #: CRM/TwingleCampaign/Upgrader/Base.php msgid "Upgrade %1 to revision %2" msgstr "Upgrade %1 auf Revision %2" @@ -182,6 +178,10 @@ msgstr "" msgid "Could not disable scheduled job \"TwingleSync\"." msgstr "Geplante Aufgabe \"TwingleSync\" konnte nicht deaktiviert werden." +#: CRM/TwingleCampaign/Utils/CaseTypes.php +msgid "none" +msgstr "keine" + #: CRM/TwingleCampaign/resources/campaigns.php msgid "Twingle Information" msgstr "Twingle Informationen" @@ -250,6 +250,14 @@ msgstr "" "Wähle den Projekt-Typ: erlaube Benutzern ihre eigenen Spenden-Events " "anzulegen oder eine Mitgliedschaft zu bezahlen." +#: CRM/TwingleCampaign/resources/campaigns.php +msgid "Case" +msgstr "Fall" + +#: CRM/TwingleCampaign/resources/campaigns.php +msgid "Which case should get triggered for event creators?" +msgstr "Welcher Fall soll für Event-Initiatoren eröffnet werden?" + #: CRM/TwingleCampaign/resources/campaigns.php msgid "allow more" msgstr "Mehr zulassen" diff --git a/l10n/pot/twinglecampaign.pot b/l10n/pot/twinglecampaign.pot index b4a3038..3a92564 100644 --- a/l10n/pot/twinglecampaign.pot +++ b/l10n/pot/twinglecampaign.pot @@ -75,7 +75,7 @@ msgid "XCM Profile to match event initiators" msgstr "" #: ./CRM/TwingleCampaign/Form/Settings.php -msgid "Start a case for event initiators" +msgid "Default case to open for event initiators" msgstr "" #: ./CRM/TwingleCampaign/Form/Settings.php @@ -90,10 +90,6 @@ msgstr "" msgid "TwingleCampaign configuration saved" msgstr "" -#: ./CRM/TwingleCampaign/Form/Settings.php -msgid "none" -msgstr "" - #: ./CRM/TwingleCampaign/Upgrader/Base.php msgid "Upgrade %1 to revision %2" msgstr "" @@ -126,6 +122,10 @@ msgstr "" msgid "Could not disable scheduled job \"TwingleSync\"." msgstr "" +#: ./CRM/TwingleCampaign/Utils/CaseTypes.php +msgid "none" +msgstr "" + #: ./CRM/TwingleCampaign/resources/campaigns.php msgid "Twingle Information" msgstr "" @@ -186,6 +186,14 @@ msgstr "" msgid "Choose the project type. Allow users to create own events or to pay a membership fee." msgstr "" +#: ./CRM/TwingleCampaign/resources/campaigns.php +msgid "Case" +msgstr "" + +#: ./CRM/TwingleCampaign/resources/campaigns.php +msgid "Which case should get triggered for event creators?" +msgstr "" + #: ./CRM/TwingleCampaign/resources/campaigns.php msgid "allow more" msgstr "" diff --git a/templates/CRM/TwingleCampaign/Form/Settings.tpl b/templates/CRM/TwingleCampaign/Form/Settings.tpl index 9ba2175..a7c7c14 100644 --- a/templates/CRM/TwingleCampaign/Form/Settings.tpl +++ b/templates/CRM/TwingleCampaign/Form/Settings.tpl @@ -17,8 +17,8 @@
-
{$form.twinglecampaign_start_case.label}
-
{$form.twinglecampaign_start_case.html}
+
{$form.twinglecampaign_default_case.label}
+
{$form.twinglecampaign_default_case.html}