Skip to content
Snippets Groups Projects
Commit eef35846 authored by ErikHommel's avatar ErikHommel :homes:
Browse files

Merge branch 'upperandfix' into 'main'

fix error when updating pack ID and make pack ID uppercase automatically

See merge request !4
parents 8b851b74 c8ee91eb
No related branches found
Tags 1.4
1 merge request!4fix error when updating pack ID and make pack ID uppercase automatically
## Version 1.4
* make input Pack ID uppercase
* fix error when on update of Pack ID links are removed
## Version 1.3 ## Version 1.3
* allow edit of Pack ID * allow edit of Pack ID
* fix error -> duplicate Pack ID when adding consent activity link * fix error -> duplicate Pack ID when adding consent activity link
......
...@@ -451,5 +451,32 @@ class CRM_Nbrpanelconsentpack_BAO_ConsentPackLink extends CRM_Nbrpanelconsentpac ...@@ -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());
}
}
}
} }
...@@ -20,10 +20,10 @@ class CRM_Nbrpanelconsentpack_Form_PackId extends CRM_Core_Form { ...@@ -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) { if ($this->_action == CRM_Core_Action::ADD || $this->_action == CRM_Core_Action::UPDATE) {
$this->add('hidden', 'contact_id'); $this->add('hidden', 'contact_id');
if ($this->_action == CRM_Core_Action::ADD) { 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) { 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) if ($this->_action)
$this->add('select', 'panel_links', 'Panel-Centre-Site-Source(s)', CRM_Nbrpanelconsentpack_BAO_ConsentPanelLink::getPanelEtcList($this->_contactId),FALSE, [ $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 { ...@@ -152,7 +152,7 @@ class CRM_Nbrpanelconsentpack_Form_PackId extends CRM_Core_Form {
public static function validatePackId(array $fields) { public static function validatePackId(array $fields) {
$errors = []; $errors = [];
if ($fields['pack_id']) { 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) { foreach ($messages as $message) {
$errors['pack_id'] = $message; $errors['pack_id'] = $message;
} }
...@@ -209,7 +209,7 @@ class CRM_Nbrpanelconsentpack_Form_PackId extends CRM_Core_Form { ...@@ -209,7 +209,7 @@ class CRM_Nbrpanelconsentpack_Form_PackId extends CRM_Core_Form {
$this->_contactId = (int) $this->_submitValues['contact_id']; $this->_contactId = (int) $this->_submitValues['contact_id'];
} }
if ($this->_submitValues['pack_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) { if ($this->_action == CRM_Core_Action::ADD) {
CRM_Nbrpanelconsentpack_BAO_ConsentPackLink::addContactIdentityForPackId($this->_contactId, $this->_packId); CRM_Nbrpanelconsentpack_BAO_ConsentPackLink::addContactIdentityForPackId($this->_contactId, $this->_packId);
...@@ -229,38 +229,41 @@ class CRM_Nbrpanelconsentpack_Form_PackId extends CRM_Core_Form { ...@@ -229,38 +229,41 @@ class CRM_Nbrpanelconsentpack_Form_PackId extends CRM_Core_Form {
public function updateConsentPanelPackLinks() { public function updateConsentPanelPackLinks() {
if ($this->_defaultValues['pack_id'] && $this->_packId != $this->_defaultValues['pack_id']) { 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::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 else {
if ($this->_submitValues['consent_activity_id']) { // if link to consent activity or panels, update link
if (!isset($this->_defaultValues['consent_activity_id']) || empty($this->_defaultValues['consent_activity_id'])) { if ($this->_submitValues['consent_activity_id']) {
CRM_Nbrpanelconsentpack_BAO_ConsentPackLink::createPackLink((int) $this->_submitValues['consent_activity_id'], $this->_contactId, $this->_packId); if (!isset($this->_defaultValues['consent_activity_id']) || empty($this->_defaultValues['consent_activity_id'])) {
CRM_Core_Session::setStatus("Link between Pack ID and Consent Activity saved", "Saved", "success"); 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");
} }
} }
} elseif ($this->_submitValues['consent_activity_id'] && isset($this->_defaultValues['consent_activity_id']) && $this->_submitValues['consent_activity_id'] != $this->_defaultValues['consent_activity_id']) {
elseif ($this->_defaultValues['panel_links'] && !$this->_submitValues['panel_links']) { CRM_Nbrpanelconsentpack_BAO_ConsentPackLink::updatePackLink((int) $this->_submitValues['consent_activity_id'], $this->_contactId, $this->_packId, $this->_defaultValues['consent_activity_id']);
$activityId = NULL; CRM_Core_Session::setStatus("Link between Pack ID and Consent Activity updated", "Saved", "success");
if (isset($this->_submitValues['consent_activity_id'])) {
$activityId = $this->_submitValues['consent_activity_id'];
} }
elseif ($this->_defaultValues['consent_activity_id']) { if ($this->_submitValues['panel_links']) {
$activityId = $this->_defaultValues['consent_activity_id']; $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) { elseif ($this->_defaultValues['panel_links'] && !$this->_submitValues['panel_links']) {
CRM_Nbrpanelconsentpack_BAO_ConsentPanelLink::deleteRedundantPanelLinks($activityId, []); $activityId = NULL;
CRM_Core_Session::setStatus("Link between Consent Activity and Panel-Centre-Site-Source removed", "Removed", "success"); 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");
}
} }
} }
} }
......
...@@ -14,8 +14,8 @@ ...@@ -14,8 +14,8 @@
<url desc="Support">https://civicoop.org</url> <url desc="Support">https://civicoop.org</url>
<url desc="Licensing">http://www.gnu.org/licenses/agpl-3.0.html</url> <url desc="Licensing">http://www.gnu.org/licenses/agpl-3.0.html</url>
</urls> </urls>
<releaseDate>2023-04-03</releaseDate> <releaseDate>2023-04-07</releaseDate>
<version>1.3</version> <version>1.4</version>
<develStage>beta</develStage> <develStage>beta</develStage>
<compatibility> <compatibility>
<ver>5.0</ver> <ver>5.0</ver>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment