diff --git a/CHANGELOG.md b/CHANGELOG.md index 52af433ac37e60835be195f7baa74b0584da30c7..83b5111e46368c36bf0bd2a6cd73ff91fd04e870 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## Version 1.4 +* make input Pack ID uppercase +* fix error when on update of Pack ID links are removed + ## Version 1.3 * allow edit of Pack ID * fix error -> duplicate Pack ID when adding consent activity link diff --git a/CRM/Nbrpanelconsentpack/BAO/ConsentPackLink.php b/CRM/Nbrpanelconsentpack/BAO/ConsentPackLink.php index 75426e898fb36ea6f5fff5a76af296445fc02dde..4bfc50062e7d581e5fdd39f9e9705c21a0e3f9bb 100644 --- a/CRM/Nbrpanelconsentpack/BAO/ConsentPackLink.php +++ b/CRM/Nbrpanelconsentpack/BAO/ConsentPackLink.php @@ -451,5 +451,32 @@ class CRM_Nbrpanelconsentpack_BAO_ConsentPackLink extends CRM_Nbrpanelconsentpac } } + /** + * Method to move the link to the consent activity from the old to the new pack ID + * + * @param int $contactId + * @param string $newPackId + * @param string $oldPackId + * @return void + */ + public static function updateLinkForChangedPackId(int $contactId, string $newPackId, string $oldPackId): void { + if ($contactId && $newPackId && $oldPackId) { + try { + \Civi\Api4\ConsentPackLink::update() + ->addWhere('contact_id', '=', $contactId) + ->addWhere('pack_id', '=', $oldPackId) + ->addValue('pack_id', $newPackId) + ->execute(); + CRM_Core_Session::setStatus("Pack ID changed from " . $oldPackId . " to " . $newPackId, "Pack ID Updated", 'success'); + } + catch (API_Exception $ex) { + CRM_Core_Session::setStatus("Could not update the link to the consent activity for pack ID " . $oldPackId + . " to new Pack ID " . $newPackId . ", contact the system administrator.", "Error updating", 'error'); + Civi::log()->error("Could not update ConsentPackLink from old Pack ID " . $oldPackId . " to new Pack ID " + . $newPackId . " in " . __METHOD__ . ", error message from API4 ConsentPackLink update: " . $ex->getMessage()); + } + } + } + } diff --git a/CRM/Nbrpanelconsentpack/Form/PackId.php b/CRM/Nbrpanelconsentpack/Form/PackId.php index 8341012139fb0edfd8aef8478ca0d115bd31f810..3f0a2935bb8ae6fc3b07e2b7394dd10b167b04da 100644 --- a/CRM/Nbrpanelconsentpack/Form/PackId.php +++ b/CRM/Nbrpanelconsentpack/Form/PackId.php @@ -20,10 +20,10 @@ class CRM_Nbrpanelconsentpack_Form_PackId extends CRM_Core_Form { if ($this->_action == CRM_Core_Action::ADD || $this->_action == CRM_Core_Action::UPDATE) { $this->add('hidden', 'contact_id'); if ($this->_action == CRM_Core_Action::ADD) { - $this->add('text', 'pack_id', "Pack ID", [], TRUE); + $this->add('text', 'pack_id', "Pack ID", ['style' => "text-transform: uppercase"], TRUE); } if ($this->_action == CRM_Core_Action::UPDATE) { - $this->add('text', 'pack_id', "Pack ID"); + $this->add('text', 'pack_id', "Pack ID", ['style' => "text-transform: uppercase"]); } if ($this->_action) $this->add('select', 'panel_links', 'Panel-Centre-Site-Source(s)', CRM_Nbrpanelconsentpack_BAO_ConsentPanelLink::getPanelEtcList($this->_contactId),FALSE, [ @@ -152,7 +152,7 @@ class CRM_Nbrpanelconsentpack_Form_PackId extends CRM_Core_Form { public static function validatePackId(array $fields) { $errors = []; if ($fields['pack_id']) { - $messages = CRM_Nihrbackbone_NbrPackId::isValidPackId($fields['pack_id']); + $messages = CRM_Nihrbackbone_NbrPackId::isValidPackId(strtoupper($fields['pack_id'])); foreach ($messages as $message) { $errors['pack_id'] = $message; } @@ -209,7 +209,7 @@ class CRM_Nbrpanelconsentpack_Form_PackId extends CRM_Core_Form { $this->_contactId = (int) $this->_submitValues['contact_id']; } if ($this->_submitValues['pack_id']) { - $this->_packId = $this->_submitValues['pack_id']; + $this->_packId = strtoupper($this->_submitValues['pack_id']); } if ($this->_action == CRM_Core_Action::ADD) { CRM_Nbrpanelconsentpack_BAO_ConsentPackLink::addContactIdentityForPackId($this->_contactId, $this->_packId); @@ -229,38 +229,41 @@ class CRM_Nbrpanelconsentpack_Form_PackId extends CRM_Core_Form { public function updateConsentPanelPackLinks() { if ($this->_defaultValues['pack_id'] && $this->_packId != $this->_defaultValues['pack_id']) { CRM_Nbrpanelconsentpack_BAO_ConsentPackLink::updateContactIdentityForPackId($this->_contactId, $this->_packId, $this->_defaultValues['pack_id']); + CRM_Nbrpanelconsentpack_BAO_ConsentPackLink::updateLinkForChangedPackId($this->_contactId, $this->_packId, $this->_defaultValues['pack_id']); } - // if link to consent activity or panels, update link - if ($this->_submitValues['consent_activity_id']) { - if (!isset($this->_defaultValues['consent_activity_id']) || empty($this->_defaultValues['consent_activity_id'])) { - CRM_Nbrpanelconsentpack_BAO_ConsentPackLink::createPackLink((int) $this->_submitValues['consent_activity_id'], $this->_contactId, $this->_packId); - CRM_Core_Session::setStatus("Link between Pack ID and Consent Activity saved", "Saved", "success"); - } - } - elseif ($this->_submitValues['consent_activity_id'] && isset($this->_defaultValues['consent_activity_id']) && $this->_submitValues['consent_activity_id'] != $this->_defaultValues['consent_activity_id']) { - CRM_Nbrpanelconsentpack_BAO_ConsentPackLink::updatePackLink((int) $this->_submitValues['consent_activity_id'], $this->_contactId, $this->_packId, $this->_defaultValues['consent_activity_id']); - CRM_Core_Session::setStatus("Link between Pack ID and Consent Activity updated", "Saved", "success"); - } - if ($this->_submitValues['panel_links']) { - $currentPanelLinks = CRM_Nbrpanelconsentpack_BAO_ConsentPanelLink::deleteRedundantPanelLinks($this->_submitValues['consent_activity_id'], $this->_submitValues['panel_links']); - foreach ($this->_submitValues['panel_links'] as $panelLink) { - if (!empty($panelLink) && !in_array($panelLink, $currentPanelLinks)) { - CRM_Nbrpanelconsentpack_BAO_ConsentPanelLink::createPanelLink((int)$this->_submitValues['consent_activity_id'], $this->_contactId, $panelLink); - CRM_Core_Session::setStatus("Link between Consent Activity and Panel-Centre-Site-Source updated", "Saved", "success"); + else { + // if link to consent activity or panels, update link + if ($this->_submitValues['consent_activity_id']) { + if (!isset($this->_defaultValues['consent_activity_id']) || empty($this->_defaultValues['consent_activity_id'])) { + CRM_Nbrpanelconsentpack_BAO_ConsentPackLink::createPackLink((int) $this->_submitValues['consent_activity_id'], $this->_contactId, $this->_packId); + CRM_Core_Session::setStatus("Link between Pack ID and Consent Activity saved", "Saved", "success"); } } - } - elseif ($this->_defaultValues['panel_links'] && !$this->_submitValues['panel_links']) { - $activityId = NULL; - if (isset($this->_submitValues['consent_activity_id'])) { - $activityId = $this->_submitValues['consent_activity_id']; + elseif ($this->_submitValues['consent_activity_id'] && isset($this->_defaultValues['consent_activity_id']) && $this->_submitValues['consent_activity_id'] != $this->_defaultValues['consent_activity_id']) { + CRM_Nbrpanelconsentpack_BAO_ConsentPackLink::updatePackLink((int) $this->_submitValues['consent_activity_id'], $this->_contactId, $this->_packId, $this->_defaultValues['consent_activity_id']); + CRM_Core_Session::setStatus("Link between Pack ID and Consent Activity updated", "Saved", "success"); } - elseif ($this->_defaultValues['consent_activity_id']) { - $activityId = $this->_defaultValues['consent_activity_id']; + if ($this->_submitValues['panel_links']) { + $currentPanelLinks = CRM_Nbrpanelconsentpack_BAO_ConsentPanelLink::deleteRedundantPanelLinks($this->_submitValues['consent_activity_id'], $this->_submitValues['panel_links']); + foreach ($this->_submitValues['panel_links'] as $panelLink) { + if (!empty($panelLink) && !in_array($panelLink, $currentPanelLinks)) { + CRM_Nbrpanelconsentpack_BAO_ConsentPanelLink::createPanelLink((int)$this->_submitValues['consent_activity_id'], $this->_contactId, $panelLink); + CRM_Core_Session::setStatus("Link between Consent Activity and Panel-Centre-Site-Source updated", "Saved", "success"); + } + } } - if ($activityId) { - CRM_Nbrpanelconsentpack_BAO_ConsentPanelLink::deleteRedundantPanelLinks($activityId, []); - CRM_Core_Session::setStatus("Link between Consent Activity and Panel-Centre-Site-Source removed", "Removed", "success"); + elseif ($this->_defaultValues['panel_links'] && !$this->_submitValues['panel_links']) { + $activityId = NULL; + if (isset($this->_submitValues['consent_activity_id'])) { + $activityId = $this->_submitValues['consent_activity_id']; + } + elseif ($this->_defaultValues['consent_activity_id']) { + $activityId = $this->_defaultValues['consent_activity_id']; + } + if ($activityId) { + CRM_Nbrpanelconsentpack_BAO_ConsentPanelLink::deleteRedundantPanelLinks($activityId, []); + CRM_Core_Session::setStatus("Link between Consent Activity and Panel-Centre-Site-Source removed", "Removed", "success"); + } } } } diff --git a/info.xml b/info.xml index 7d8a21817634f48e34c492db7ca01bf441b49671..5056e138b19166b36c8f2d5a5de0b2c7022c38fb 100644 --- a/info.xml +++ b/info.xml @@ -14,8 +14,8 @@ <url desc="Support">https://civicoop.org</url> <url desc="Licensing">http://www.gnu.org/licenses/agpl-3.0.html</url> </urls> - <releaseDate>2023-04-03</releaseDate> - <version>1.3</version> + <releaseDate>2023-04-07</releaseDate> + <version>1.4</version> <develStage>beta</develStage> <compatibility> <ver>5.0</ver>