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
* fix error with empty panel and pack links when saving consent
*
## Version 1.1
* 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
*/
public static function hasContactIdentityForPackId(?int $contactId, string $packId): bool {
if ($packId && $contactId) {
$identityTypes = self::getPackIdentifierTypes();
try {
$contactIdentities = \Civi\Api4\CustomValue::get('contact_id_history')
$api = \Civi\Api4\CustomValue::get('contact_id_history')
->addSelect('*')
->addWhere('entity_id', '=', $contactId)
->addWhere('id_history_entry_type:name', '=', self::getPackIdentifierTypes())
->addWhere('id_history_entry', '=', $packId)
->setLimit(1)
->execute();
$count = $contactIdentities->count();
->setLimit(1);
if (!empty($identityTypes)) {
$api->addWhere('id_history_entry_type:name', 'IN', $identityTypes);
}
$count = $api->execute()->count();
if ($count > 0) {
return TRUE;
}
......@@ -77,7 +79,7 @@ class CRM_Nbrpanelconsentpack_BAO_ConsentPackLink extends CRM_Nbrpanelconsentpac
try {
$optionValues = \Civi\Api4\OptionValue::get()
->addSelect('name')
->addWhere('option_group_id', '=', Civi::service('nbrBackbone')->getContactIdentityCustomGroupId())
->addWhere('option_group_id:name', '=', "contact_id_history_type")
->addWhere('name', 'LIKE', '%pack%')
->execute();
foreach ($optionValues as $optionValue) {
......@@ -88,7 +90,7 @@ class CRM_Nbrpanelconsentpack_BAO_ConsentPackLink extends CRM_Nbrpanelconsentpac
}
catch (API_Exception $ex) {
}
return $types;
return $types;
}
/**
......
......@@ -171,7 +171,6 @@ class CRM_Nbrpanelconsentpack_Form_PackId extends CRM_Core_Form {
* @return string[]|true
*/
public static function validatePanelLinks(array $fields) {
$errors = [];
if ($fields['panel_links']) {
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."];
......@@ -219,6 +218,7 @@ class CRM_Nbrpanelconsentpack_Form_PackId extends CRM_Core_Form {
if ($this->_action == CRM_Core_Action::UPDATE) {
$this->updateConsentPanelPackLinks();
}
$this->ajaxResponse['updateTabs']['#tab_nbr_pack_id'] = 1;
parent::postProcess();
}
/**
......@@ -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']);
}
// if link to consent activity or panels, update link
if ($this->_submitValues['consent_activity_id'] && !$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");
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'] && $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_Core_Session::setStatus("Link between Pack ID and Consent Activity updated", "Saved", "success");
}
......
......@@ -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-03-06</releaseDate>
<version>1.2</version>
<releaseDate>2023-04-03</releaseDate>
<version>1.3</version>
<develStage>beta</develStage>
<compatibility>
<ver>5.0</ver>
......
......@@ -27,6 +27,7 @@ function nbrpanelconsentpack_civicrm_postProcess($formName, $form) {
if (CRM_Nbrpanelconsentpack_Utils::isValidActivityType($activityTypeId)) {
CRM_Nbrpanelconsentpack_BAO_ConsentPanelLink::savePanelLinks($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