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

Merge branch 'editbug' into 'main'

Editbug

See merge request !3
parents 5a8fa365 6dc0c6b4
No related branches found
Tags 1.4
1 merge request!3Editbug
## Version 1.3
* allow edit of Pack ID
* fix error -> duplicate Pack ID when adding consent activity link
## Version 1.2 ## Version 1.2
* fix error with empty panel and pack links when saving consent * fix error with empty panel and pack links when saving consent
*
## Version 1.1 ## Version 1.1
* fixed comments from first prototype and discussion 6 Jan 2023 (see https://www.wrike.com/open.htm?id=886793367) * fixed comments from first prototype and discussion 6 Jan 2023 (see https://www.wrike.com/open.htm?id=886793367)
......
...@@ -48,15 +48,17 @@ class CRM_Nbrpanelconsentpack_BAO_ConsentPackLink extends CRM_Nbrpanelconsentpac ...@@ -48,15 +48,17 @@ class CRM_Nbrpanelconsentpack_BAO_ConsentPackLink extends CRM_Nbrpanelconsentpac
*/ */
public static function hasContactIdentityForPackId(?int $contactId, string $packId): bool { public static function hasContactIdentityForPackId(?int $contactId, string $packId): bool {
if ($packId && $contactId) { if ($packId && $contactId) {
$identityTypes = self::getPackIdentifierTypes();
try { try {
$contactIdentities = \Civi\Api4\CustomValue::get('contact_id_history') $api = \Civi\Api4\CustomValue::get('contact_id_history')
->addSelect('*') ->addSelect('*')
->addWhere('entity_id', '=', $contactId) ->addWhere('entity_id', '=', $contactId)
->addWhere('id_history_entry_type:name', '=', self::getPackIdentifierTypes())
->addWhere('id_history_entry', '=', $packId) ->addWhere('id_history_entry', '=', $packId)
->setLimit(1) ->setLimit(1);
->execute(); if (!empty($identityTypes)) {
$count = $contactIdentities->count(); $api->addWhere('id_history_entry_type:name', 'IN', $identityTypes);
}
$count = $api->execute()->count();
if ($count > 0) { if ($count > 0) {
return TRUE; return TRUE;
} }
...@@ -77,7 +79,7 @@ class CRM_Nbrpanelconsentpack_BAO_ConsentPackLink extends CRM_Nbrpanelconsentpac ...@@ -77,7 +79,7 @@ class CRM_Nbrpanelconsentpack_BAO_ConsentPackLink extends CRM_Nbrpanelconsentpac
try { try {
$optionValues = \Civi\Api4\OptionValue::get() $optionValues = \Civi\Api4\OptionValue::get()
->addSelect('name') ->addSelect('name')
->addWhere('option_group_id', '=', Civi::service('nbrBackbone')->getContactIdentityCustomGroupId()) ->addWhere('option_group_id:name', '=', "contact_id_history_type")
->addWhere('name', 'LIKE', '%pack%') ->addWhere('name', 'LIKE', '%pack%')
->execute(); ->execute();
foreach ($optionValues as $optionValue) { foreach ($optionValues as $optionValue) {
...@@ -88,7 +90,7 @@ class CRM_Nbrpanelconsentpack_BAO_ConsentPackLink extends CRM_Nbrpanelconsentpac ...@@ -88,7 +90,7 @@ class CRM_Nbrpanelconsentpack_BAO_ConsentPackLink extends CRM_Nbrpanelconsentpac
} }
catch (API_Exception $ex) { catch (API_Exception $ex) {
} }
return $types; return $types;
} }
/** /**
......
...@@ -171,7 +171,6 @@ class CRM_Nbrpanelconsentpack_Form_PackId extends CRM_Core_Form { ...@@ -171,7 +171,6 @@ class CRM_Nbrpanelconsentpack_Form_PackId extends CRM_Core_Form {
* @return string[]|true * @return string[]|true
*/ */
public static function validatePanelLinks(array $fields) { public static function validatePanelLinks(array $fields) {
$errors = [];
if ($fields['panel_links']) { if ($fields['panel_links']) {
if (empty($fields['consent_activity_id'])) { if (empty($fields['consent_activity_id'])) {
return ['consent_activity_id' => "You can only add links to panel-centre-site-source if the pack ID is linked to a consent activity."]; return ['consent_activity_id' => "You can only add links to panel-centre-site-source if the pack ID is linked to a consent activity."];
...@@ -219,6 +218,7 @@ class CRM_Nbrpanelconsentpack_Form_PackId extends CRM_Core_Form { ...@@ -219,6 +218,7 @@ class CRM_Nbrpanelconsentpack_Form_PackId extends CRM_Core_Form {
if ($this->_action == CRM_Core_Action::UPDATE) { if ($this->_action == CRM_Core_Action::UPDATE) {
$this->updateConsentPanelPackLinks(); $this->updateConsentPanelPackLinks();
} }
$this->ajaxResponse['updateTabs']['#tab_nbr_pack_id'] = 1;
parent::postProcess(); parent::postProcess();
} }
/** /**
...@@ -231,11 +231,13 @@ class CRM_Nbrpanelconsentpack_Form_PackId extends CRM_Core_Form { ...@@ -231,11 +231,13 @@ class CRM_Nbrpanelconsentpack_Form_PackId extends CRM_Core_Form {
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']);
} }
// if link to consent activity or panels, update link // if link to consent activity or panels, update link
if ($this->_submitValues['consent_activity_id'] && !$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'] && $this->_defaultValues['consent_activity_id'] && $this->_submitValues['consent_activity_id'] != $this->_defaultValues['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_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"); CRM_Core_Session::setStatus("Link between Pack ID and Consent Activity updated", "Saved", "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-03-06</releaseDate> <releaseDate>2023-04-03</releaseDate>
<version>1.2</version> <version>1.3</version>
<develStage>beta</develStage> <develStage>beta</develStage>
<compatibility> <compatibility>
<ver>5.0</ver> <ver>5.0</ver>
......
...@@ -27,6 +27,7 @@ function nbrpanelconsentpack_civicrm_postProcess($formName, $form) { ...@@ -27,6 +27,7 @@ function nbrpanelconsentpack_civicrm_postProcess($formName, $form) {
if (CRM_Nbrpanelconsentpack_Utils::isValidActivityType($activityTypeId)) { if (CRM_Nbrpanelconsentpack_Utils::isValidActivityType($activityTypeId)) {
CRM_Nbrpanelconsentpack_BAO_ConsentPanelLink::savePanelLinks($form); CRM_Nbrpanelconsentpack_BAO_ConsentPanelLink::savePanelLinks($form);
CRM_Nbrpanelconsentpack_BAO_ConsentPackLink::savePackLinks($form); CRM_Nbrpanelconsentpack_BAO_ConsentPackLink::savePackLinks($form);
$form->ajaxResponse['updateTabs']['#tab_nbr_pack_id'] = 1;
} }
} }
} }
......
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