diff --git a/CRM/TwingleCampaign/BAO/TwingleCampaign.php b/CRM/TwingleCampaign/BAO/TwingleCampaign.php index 1e773c2..2cbc865 100644 --- a/CRM/TwingleCampaign/BAO/TwingleCampaign.php +++ b/CRM/TwingleCampaign/BAO/TwingleCampaign.php @@ -32,15 +32,30 @@ class CRM_TwingleCampaign_BAO_TwingleCampaign { $this->id = $values['id'] ?? NULL; $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) { $this->fetch($this->id); } + + // Update the campaign values $this->update($values); + // Get the parent TwingleProject + // (it doesn't matter how many levels above in the campaign tree it is) $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(); } + + // Create an url from the parent TwingleProject url and the cid of this + // TwingleCampaign $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 * diff --git a/api/v3/TwingleCampaign/Create.php b/api/v3/TwingleCampaign/Create.php index d4d9db8..e42c00a 100644 --- a/api/v3/TwingleCampaign/Create.php +++ b/api/v3/TwingleCampaign/Create.php @@ -40,6 +40,13 @@ function _civicrm_api3_twingle_campaign_Create_spec(array &$spec) { 'api.required' => 1, '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'), + ]; } diff --git a/l10n/de_DE/LC_MESSAGES/de_DE.mo b/l10n/de_DE/LC_MESSAGES/de_DE.mo index b69812f..7a64892 100644 Binary files a/l10n/de_DE/LC_MESSAGES/de_DE.mo and b/l10n/de_DE/LC_MESSAGES/de_DE.mo differ diff --git a/l10n/de_DE/LC_MESSAGES/de_DE.po b/l10n/de_DE/LC_MESSAGES/de_DE.po index 5736cb0..5f83de4 100644 --- a/l10n/de_DE/LC_MESSAGES/de_DE.po +++ b/l10n/de_DE/LC_MESSAGES/de_DE.po @@ -3,14 +3,14 @@ msgstr "" "Project-Id-Version: \n" "POT-Creation-Date: \n" "PO-Revision-Date: \n" +"Last-Translator: \n" "Language-Team: \n" +"Language: de_DE\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" -"X-Generator: Poedit 2.4.3\n" -"Last-Translator: \n" +"X-Generator: Poedit 3.0\n" "Plural-Forms: nplurals=2; plural=(n != 1);\n" -"Language: de_DE\n" #: CRM/TwingleCampaign/BAO/CustomField.php msgid "" @@ -907,6 +907,17 @@ msgstr "Elternkampagne" msgid "Optional parent id for this Campaign" 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 msgid "Twingle Campaign CID" msgstr "Twingle Campaign CID" @@ -1197,6 +1208,10 @@ msgstr "Twingle Event Einstellungen" msgid "Campaign cloning failed" msgstr "Klonen der Kampagne fehlgeschlagen" +#: twinglecampaign.php +msgid "TwingleCampaign was cloned." +msgstr "TwingleCampaign wurde geklont" + #: twinglecampaign.php msgid "TwingleCampaign update failed" msgstr "TwingleCampaign-Update fehlgeschlagen" diff --git a/l10n/pot/twinglecampaign.pot b/l10n/pot/twinglecampaign.pot index 156eafd..62ac159 100644 --- a/l10n/pot/twinglecampaign.pot +++ b/l10n/pot/twinglecampaign.pot @@ -806,6 +806,14 @@ msgstr "" msgid "Optional parent id for this Campaign" 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 msgid "Twingle Campaign CID" msgstr "" @@ -1038,6 +1046,10 @@ msgstr "" msgid "Campaign cloning failed" msgstr "" +#: ./twinglecampaign.php +msgid "TwingleCampaign was cloned." +msgstr "" + #: ./twinglecampaign.php msgid "TwingleCampaign update failed" msgstr "" diff --git a/twinglecampaign.php b/twinglecampaign.php index a6a9b31..195ceb4 100644 --- a/twinglecampaign.php +++ b/twinglecampaign.php @@ -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