️ define cases for each TwingleProject

This commit is contained in:
Marc Michalsky forumZFD 2021-05-26 19:01:35 +02:00
parent ba9ab9f324
commit cef8c31f31
Signed by untrusted user who does not match committer: marc.koch
GPG key ID: 12406554CFB028B9
10 changed files with 107 additions and 64 deletions

View file

@ -6,7 +6,7 @@ class CRM_TwingleCampaign_BAO_Configuration {
private static $settingsKeys = [ private static $settingsKeys = [
'twingle_api_key', 'twingle_api_key',
'twinglecampaign_xcm_profile', 'twinglecampaign_xcm_profile',
'twinglecampaign_start_case', 'twinglecampaign_default_case',
'twinglecampaign_soft_credits' 'twinglecampaign_soft_credits'
]; ];

View file

@ -53,22 +53,29 @@ class CRM_TwingleCampaign_BAO_TwingleEvent extends Campaign {
if (parent::create()) { if (parent::create()) {
// Get case type
$parentProject = civicrm_api3(
'TwingleProject',
'getsingle',
['id' => $this->values['parent_id']]
);
$caseType = $parentProject['case']
?? Configuration::get('twinglecampaign_default_case');
if ($caseType) {
// check for existence // check for existence
$result = civicrm_api3('Case', 'get', [ $result = civicrm_api3('Case', 'get', [
'contact_id' => $this->formattedValues['contact'], 'contact_id' => $this->formattedValues['contact'],
'case_type_id' => Configuration::get('twinglecampaign_start_case'), 'case_type_id' => $caseType,
'subject' => $this->formattedValues['title'] . ' | Event-ID: ' . 'subject' => $this->formattedValues['title'] . ' | Event-ID: ' .
$this->formattedValues['id'], $this->formattedValues['id'],
]); ]);
// Open a case // Open a case
if ( if ($result['count'] == 0) {
Configuration::get('twinglecampaign_start_case') &&
$result['count'] == 0
) {
$result = civicrm_api3('Case', 'create', [ $result = civicrm_api3('Case', 'create', [
'contact_id' => $this->formattedValues['contact'], 'contact_id' => $this->formattedValues['contact'],
'case_type_id' => Configuration::get('twinglecampaign_start_case'), 'case_type_id' => $caseType,
'subject' => $this->formattedValues['title'] . ' | Event-ID: ' . 'subject' => $this->formattedValues['title'] . ' | Event-ID: ' .
$this->formattedValues['id'], $this->formattedValues['id'],
'start_date' => $this->formattedValues['created_at'], 'start_date' => $this->formattedValues['created_at'],
@ -78,7 +85,7 @@ class CRM_TwingleCampaign_BAO_TwingleEvent extends Campaign {
if ($result['is_error'] != 0) { if ($result['is_error'] != 0) {
throw new Exception('Could not create case'); throw new Exception('Could not create case');
} }
}
return TRUE; return TRUE;
} }
return FALSE; return FALSE;

View file

@ -4,6 +4,7 @@ use CRM_TwingleCampaign_BAO_Configuration as Configuration;
use CRM_TwingleCampaign_ExtensionUtil as E; use CRM_TwingleCampaign_ExtensionUtil as E;
include_once E::path() . '/CRM/TwingleCampaign/BAO/Configuration.php'; include_once E::path() . '/CRM/TwingleCampaign/BAO/Configuration.php';
include_once E::path() . '/CRM/TwingleCampaign/Utils/CaseTypes.php';
/** /**
* Form controller class * Form controller class
@ -32,9 +33,9 @@ class CRM_TwingleCampaign_Form_Settings extends CRM_Core_Form {
$this->addElement( $this->addElement(
'select', 'select',
'twinglecampaign_start_case', 'twinglecampaign_default_case',
E::ts('Start a case for event initiators'), E::ts('Default case to open for event initiators'),
$this->getCaseTypes(), getCaseTypes(),
['class' => 'crm-select2 huge'] ['class' => 'crm-select2 huge']
); );
@ -92,30 +93,5 @@ class CRM_TwingleCampaign_Form_Settings extends CRM_Core_Form {
return $xcmProfiles; 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;
}
} }

View file

@ -20,7 +20,7 @@ class CRM_TwingleCampaign_Upgrader extends CRM_TwingleCampaign_Upgrader_Base {
* changed campaigns will get pulled from Twingle. * changed campaigns will get pulled from Twingle.
* @throws \CiviCRM_API3_Exception * @throws \CiviCRM_API3_Exception
*/ */
public function upgrade_01(): bool { public function upgrade_02(): bool {
$campaign_info = require E::path() . $campaign_info = require E::path() .
'/CRM/TwingleCampaign/resources/campaigns.php'; '/CRM/TwingleCampaign/resources/campaigns.php';

View file

@ -0,0 +1,28 @@
<?php
use CRM_TwingleCampaign_ExtensionUtil as E;
/**
* Retrieves all case types
*
* @return array
*/
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;
}

View file

@ -1,6 +1,7 @@
<?php <?php
use CRM_TwingleCampaign_ExtensionUtil as E; use CRM_TwingleCampaign_ExtensionUtil as E;
require_once E::path() . '/CRM/TwingleCampaign/Utils/CaseTypes.php';
return [ return [
"campaign_types" => [ "campaign_types" => [
@ -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."), "help_post" => E::ts("Choose the project type. Allow users to create own events or to pay a membership fee."),
"default_value" => "default" "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" => [ "twingle_project_allow_more" => [
"custom_group_id" => "Twingle_Project_Information", "custom_group_id" => "Twingle_Project_Information",
"label" => E::ts("allow more"), "label" => E::ts("allow more"),

View file

@ -7,7 +7,7 @@ msgstr ""
"MIME-Version: 1.0\n" "MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n" "Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n" "Content-Transfer-Encoding: 8bit\n"
"X-Generator: Poedit 2.4.2\n" "X-Generator: Poedit 2.4.3\n"
"Last-Translator: \n" "Last-Translator: \n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n" "Plural-Forms: nplurals=2; plural=(n != 1);\n"
"Language: de_DE\n" "Language: de_DE\n"
@ -120,8 +120,8 @@ msgid "XCM Profile to match event initiators"
msgstr "XCM-Profil zum Abgleichen von Event-Initiatoren" msgstr "XCM-Profil zum Abgleichen von Event-Initiatoren"
#: CRM/TwingleCampaign/Form/Settings.php #: CRM/TwingleCampaign/Form/Settings.php
msgid "Start a case for event initiators" msgid "Default case to open for event initiators"
msgstr "Einen Fall für Event-Initiatoren anlegen" msgstr "Standarfdall, der für Event-Initiatoren eröffnet werden soll"
#: CRM/TwingleCampaign/Form/Settings.php #: CRM/TwingleCampaign/Form/Settings.php
msgid "Create soft credits for event initiators" msgid "Create soft credits for event initiators"
@ -135,10 +135,6 @@ msgstr "Speichern"
msgid "TwingleCampaign configuration saved" msgid "TwingleCampaign configuration saved"
msgstr "TwingleCampaign Konfiguration gespeichert" msgstr "TwingleCampaign Konfiguration gespeichert"
#: CRM/TwingleCampaign/Form/Settings.php
msgid "none"
msgstr "keine"
#: CRM/TwingleCampaign/Upgrader/Base.php #: CRM/TwingleCampaign/Upgrader/Base.php
msgid "Upgrade %1 to revision %2" msgid "Upgrade %1 to revision %2"
msgstr "Upgrade %1 auf Revision %2" msgstr "Upgrade %1 auf Revision %2"
@ -182,6 +178,10 @@ msgstr ""
msgid "Could not disable scheduled job \"TwingleSync\"." msgid "Could not disable scheduled job \"TwingleSync\"."
msgstr "Geplante Aufgabe \"TwingleSync\" konnte nicht deaktiviert werden." msgstr "Geplante Aufgabe \"TwingleSync\" konnte nicht deaktiviert werden."
#: CRM/TwingleCampaign/Utils/CaseTypes.php
msgid "none"
msgstr "keine"
#: CRM/TwingleCampaign/resources/campaigns.php #: CRM/TwingleCampaign/resources/campaigns.php
msgid "Twingle Information" msgid "Twingle Information"
msgstr "Twingle Informationen" msgstr "Twingle Informationen"
@ -250,6 +250,14 @@ msgstr ""
"Wähle den Projekt-Typ: erlaube Benutzern ihre eigenen Spenden-Events " "Wähle den Projekt-Typ: erlaube Benutzern ihre eigenen Spenden-Events "
"anzulegen oder eine Mitgliedschaft zu bezahlen." "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 #: CRM/TwingleCampaign/resources/campaigns.php
msgid "allow more" msgid "allow more"
msgstr "Mehr zulassen" msgstr "Mehr zulassen"

View file

@ -75,7 +75,7 @@ msgid "XCM Profile to match event initiators"
msgstr "" msgstr ""
#: ./CRM/TwingleCampaign/Form/Settings.php #: ./CRM/TwingleCampaign/Form/Settings.php
msgid "Start a case for event initiators" msgid "Default case to open for event initiators"
msgstr "" msgstr ""
#: ./CRM/TwingleCampaign/Form/Settings.php #: ./CRM/TwingleCampaign/Form/Settings.php
@ -90,10 +90,6 @@ msgstr ""
msgid "TwingleCampaign configuration saved" msgid "TwingleCampaign configuration saved"
msgstr "" msgstr ""
#: ./CRM/TwingleCampaign/Form/Settings.php
msgid "none"
msgstr ""
#: ./CRM/TwingleCampaign/Upgrader/Base.php #: ./CRM/TwingleCampaign/Upgrader/Base.php
msgid "Upgrade %1 to revision %2" msgid "Upgrade %1 to revision %2"
msgstr "" msgstr ""
@ -126,6 +122,10 @@ msgstr ""
msgid "Could not disable scheduled job \"TwingleSync\"." msgid "Could not disable scheduled job \"TwingleSync\"."
msgstr "" msgstr ""
#: ./CRM/TwingleCampaign/Utils/CaseTypes.php
msgid "none"
msgstr ""
#: ./CRM/TwingleCampaign/resources/campaigns.php #: ./CRM/TwingleCampaign/resources/campaigns.php
msgid "Twingle Information" msgid "Twingle Information"
msgstr "" msgstr ""
@ -186,6 +186,14 @@ msgstr ""
msgid "Choose the project type. Allow users to create own events or to pay a membership fee." msgid "Choose the project type. Allow users to create own events or to pay a membership fee."
msgstr "" 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 #: ./CRM/TwingleCampaign/resources/campaigns.php
msgid "allow more" msgid "allow more"
msgstr "" msgstr ""

View file

@ -17,8 +17,8 @@
<div class="clear"></div> <div class="clear"></div>
</div> </div>
<div class="crm-section"> <div class="crm-section">
<div class="label">{$form.twinglecampaign_start_case.label}</div> <div class="label">{$form.twinglecampaign_default_case.label}</div>
<div class="content">{$form.twinglecampaign_start_case.html}</div> <div class="content">{$form.twinglecampaign_default_case.html}</div>
<div class="clear"></div> <div class="clear"></div>
</div> </div>
<div class="crm-section"> <div class="crm-section">