✨ make TwingleCampaings clonable
TwingleCampaings can be cloned. Cloned campaigns will generate a new cid and url.
This commit is contained in:
parent
f059abf5a8
commit
a01367a161
6 changed files with 66 additions and 18 deletions
|
@ -32,15 +32,30 @@ class CRM_TwingleCampaign_BAO_TwingleCampaign {
|
||||||
$this->id = $values['id'] ?? NULL;
|
$this->id = $values['id'] ?? NULL;
|
||||||
$this->values['campaign_type_id'] = 'twingle_campaign';
|
$this->values['campaign_type_id'] = 'twingle_campaign';
|
||||||
|
|
||||||
|
// If there is already an ID for this TwingleProject, get its values from
|
||||||
|
// the database
|
||||||
if ($this->id != NULL) {
|
if ($this->id != NULL) {
|
||||||
$this->fetch($this->id);
|
$this->fetch($this->id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Update the campaign values
|
||||||
$this->update($values);
|
$this->update($values);
|
||||||
|
|
||||||
|
// Get the parent TwingleProject
|
||||||
|
// (it doesn't matter how many levels above in the campaign tree it is)
|
||||||
$this->getParentProject();
|
$this->getParentProject();
|
||||||
if (!isset($this->values['cid'])) {
|
|
||||||
|
// If this is a new TwingleCampaign or if it is a cloned TwingleCampaign,
|
||||||
|
// calculate a cid
|
||||||
|
if (
|
||||||
|
!isset($this->values['cid']) ||
|
||||||
|
(isset($values['clone']) && $values['clone'])
|
||||||
|
) {
|
||||||
$this->createCid();
|
$this->createCid();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Create an url from the parent TwingleProject url and the cid of this
|
||||||
|
// TwingleCampaign
|
||||||
$this->createUrl();
|
$this->createUrl();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -351,20 +366,6 @@ class CRM_TwingleCampaign_BAO_TwingleCampaign {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* ## Clone this TwingleProject
|
|
||||||
*
|
|
||||||
* This method removes the id from this instance and in the next step it
|
|
||||||
* creates the clone as a new TwingleCampaign with the same values to
|
|
||||||
* Twingle.
|
|
||||||
*
|
|
||||||
* @throws \CiviCRM_API3_Exception
|
|
||||||
*/
|
|
||||||
public
|
|
||||||
function clone() {
|
|
||||||
// TODO: implement cloning
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ## Get ID
|
* ## Get ID
|
||||||
*
|
*
|
||||||
|
|
|
@ -40,6 +40,13 @@ function _civicrm_api3_twingle_campaign_Create_spec(array &$spec) {
|
||||||
'api.required' => 1,
|
'api.required' => 1,
|
||||||
'description' => E::ts('Optional parent id for this Campaign'),
|
'description' => E::ts('Optional parent id for this Campaign'),
|
||||||
];
|
];
|
||||||
|
$spec['clone'] = [
|
||||||
|
'name' => 'clone',
|
||||||
|
'title' => E::ts('Clone'),
|
||||||
|
'type' => CRM_Utils_Type::T_BOOLEAN,
|
||||||
|
'api.required' => 0,
|
||||||
|
'description' => E::ts('Set this value to true if this campaign is about to be cloned to recreate cid'),
|
||||||
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Binary file not shown.
|
@ -3,14 +3,14 @@ msgstr ""
|
||||||
"Project-Id-Version: \n"
|
"Project-Id-Version: \n"
|
||||||
"POT-Creation-Date: \n"
|
"POT-Creation-Date: \n"
|
||||||
"PO-Revision-Date: \n"
|
"PO-Revision-Date: \n"
|
||||||
|
"Last-Translator: \n"
|
||||||
"Language-Team: \n"
|
"Language-Team: \n"
|
||||||
|
"Language: de_DE\n"
|
||||||
"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.3\n"
|
"X-Generator: Poedit 3.0\n"
|
||||||
"Last-Translator: \n"
|
|
||||||
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
|
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
|
||||||
"Language: de_DE\n"
|
|
||||||
|
|
||||||
#: CRM/TwingleCampaign/BAO/CustomField.php
|
#: CRM/TwingleCampaign/BAO/CustomField.php
|
||||||
msgid ""
|
msgid ""
|
||||||
|
@ -907,6 +907,17 @@ msgstr "Elternkampagne"
|
||||||
msgid "Optional parent id for this Campaign"
|
msgid "Optional parent id for this Campaign"
|
||||||
msgstr "Optionale Eltern-ID für diese Kampagne"
|
msgstr "Optionale Eltern-ID für diese Kampagne"
|
||||||
|
|
||||||
|
#: api/v3/TwingleCampaign/Create.php
|
||||||
|
msgid "Clone"
|
||||||
|
msgstr "Klonen"
|
||||||
|
|
||||||
|
#: api/v3/TwingleCampaign/Create.php
|
||||||
|
msgid ""
|
||||||
|
"Set this value to true if this campaign is about to be cloned to recreate cid"
|
||||||
|
msgstr ""
|
||||||
|
"Setze diesen Wert auf true, wenn diese Kampagne gerade geklont wird, damit "
|
||||||
|
"die cid neu berechnet wird"
|
||||||
|
|
||||||
#: api/v3/TwingleCampaign/Get.php api/v3/TwingleCampaign/Getsingle.php
|
#: api/v3/TwingleCampaign/Get.php api/v3/TwingleCampaign/Getsingle.php
|
||||||
msgid "Twingle Campaign CID"
|
msgid "Twingle Campaign CID"
|
||||||
msgstr "Twingle Campaign CID"
|
msgstr "Twingle Campaign CID"
|
||||||
|
@ -1197,6 +1208,10 @@ msgstr "Twingle Event Einstellungen"
|
||||||
msgid "Campaign cloning failed"
|
msgid "Campaign cloning failed"
|
||||||
msgstr "Klonen der Kampagne fehlgeschlagen"
|
msgstr "Klonen der Kampagne fehlgeschlagen"
|
||||||
|
|
||||||
|
#: twinglecampaign.php
|
||||||
|
msgid "TwingleCampaign was cloned."
|
||||||
|
msgstr "TwingleCampaign wurde geklont"
|
||||||
|
|
||||||
#: twinglecampaign.php
|
#: twinglecampaign.php
|
||||||
msgid "TwingleCampaign update failed"
|
msgid "TwingleCampaign update failed"
|
||||||
msgstr "TwingleCampaign-Update fehlgeschlagen"
|
msgstr "TwingleCampaign-Update fehlgeschlagen"
|
||||||
|
|
|
@ -806,6 +806,14 @@ msgstr ""
|
||||||
msgid "Optional parent id for this Campaign"
|
msgid "Optional parent id for this Campaign"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
|
#: ./api/v3/TwingleCampaign/Create.php
|
||||||
|
msgid "Clone"
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
|
#: ./api/v3/TwingleCampaign/Create.php
|
||||||
|
msgid "Set this value to true if this campaign is about to be cloned to recreate cid"
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
#: ./api/v3/TwingleCampaign/Get.php ./api/v3/TwingleCampaign/Getsingle.php
|
#: ./api/v3/TwingleCampaign/Get.php ./api/v3/TwingleCampaign/Getsingle.php
|
||||||
msgid "Twingle Campaign CID"
|
msgid "Twingle Campaign CID"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
@ -1038,6 +1046,10 @@ msgstr ""
|
||||||
msgid "Campaign cloning failed"
|
msgid "Campaign cloning failed"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
|
#: ./twinglecampaign.php
|
||||||
|
msgid "TwingleCampaign was cloned."
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
#: ./twinglecampaign.php
|
#: ./twinglecampaign.php
|
||||||
msgid "TwingleCampaign update failed"
|
msgid "TwingleCampaign update failed"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
|
@ -180,6 +180,19 @@ function twinglecampaign_postSave_campaign_update_callback(
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if ($_POST['action'] == 'clone' && $entity == 'TwingleCampaign') {
|
||||||
|
unset($_POST['action']);
|
||||||
|
try {
|
||||||
|
civicrm_api3('TwingleCampaign', 'create',
|
||||||
|
['id' => $campaign_id, 'clone' => true]
|
||||||
|
);
|
||||||
|
CRM_Utils_System::setUFMessage(E::ts('TwingleCampaign was cloned.'));
|
||||||
|
} catch (CiviCRM_API3_Exception $e) {
|
||||||
|
Civi::log()->error(
|
||||||
|
'twinglecampaign_postSave_callback ' . $e->getMessage()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// If a TwingleProject is getting saved
|
// If a TwingleProject is getting saved
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue