Commit 8d14d66f authored by Cyril Vazquez's avatar Cyril Vazquez
Browse files

FIX search messages to allow access to ancestors of recipients and senders

parent c128ca71
......@@ -83,7 +83,7 @@ class ArchiveRestitutionRequest extends abstractMessage
$queryParts[] = "senderOrgRegNumber=$registrationNumber";
$queryParts[] = "active=true";
return $this->sdoFactory->find('medona/message', implode(' and ', $queryParts), null, false, false, 300);
return $this->sdoFactory->find('medona/message', '('.implode(') and (', $queryParts).')', null, false, false, 300);
}
/**
......
......@@ -262,7 +262,7 @@ class message
{
$queryParts = $this->searchMessage($type, $reference, $archiver, $originator, $depositor, $archivalAgreement, $fromDate, $toDate);
return $this->sdoFactory->find('medona/message', implode(' and ', $queryParts), null, false, false, 300);
return $this->sdoFactory->find('medona/message', '('.implode(') and (', $queryParts).')', null, false, false, 300);
}
/**
......@@ -325,37 +325,44 @@ class message
$queryParts[] = "reference='$reference'";
}
if ($type) {
$clause = "";
$clause = [];
if ($type == "ArchiveDelivery") {
if (in_array('originator', $currentService->orgRoleCodes) || in_array('archiver', $currentService->orgRoleCodes)) {
$clause .= "type='*$type*'";
$clause[] = "type='*$type*'";
}
if (in_array('controlAuthority', $currentService->orgRoleCodes)) {
$clause .= "type='AuthorizationControlAuthorityRequest' AND authorizationReason='ArchiveDeliveryRequest'";
$clause[] = "type='AuthorizationControlAuthorityRequest' AND authorizationReason='ArchiveDeliveryRequest'";
}
} elseif ($type == "ArchiveDestruction") {
if (in_array('archiver', $currentService->orgRoleCodes)) {
$clause .= "type='*$type*'";
$clause[] = "type='*$type*'";
}
if (in_array('originator', $currentService->orgRoleCodes)) {
$clause .= "type='AuthorizationOriginatingRequest' AND authorizationReason='ArchiveDestructionRequest'";
$clause[] = "type='AuthorizationOriginatingRequest' AND authorizationReason='ArchiveDestructionRequest'";
}
if (in_array('controlAuthority', $currentService->orgRoleCodes)) {
$clause .= "type='AuthorizationControlAuthorityRequest' AND authorizationReason='ArchiveDestructionRequest'";
$clause[] = "type='AuthorizationControlAuthorityRequest' AND authorizationReason='ArchiveDestructionRequest'";
}
} elseif ($type == "ArchiveRestitution") {
$clause .= "type=['ArchiveRestitutionRequest','ArchiveRestitution']";
$clause[] = "type=['ArchiveRestitutionRequest','ArchiveRestitution']";
} else {
$clause = "type='$type' AND status !='template'";
$clause[] = "type='$type' AND status !='template'";
}
$queryParts[] = $clause;
if (!empty($clause)) {
$queryParts[] =
'('
.\laabs\implode(') OR (', $clause)
.')';
}
}
$orgUnitsClause = $this->getCurrentRegistrationNumber();
$queryParts[] = "(recipientOrgRegNumber='$currentService->registrationNumber' OR senderOrgRegNumber='$currentService->registrationNumber')";
$queryParts[] = "(recipientOrgRegNumber=$orgUnitsClause OR senderOrgRegNumber=$orgUnitsClause)";
return $queryParts;
}
......@@ -1012,7 +1019,7 @@ class message
{
$queryParts = $this->searchMessage(null, $reference);
$message = $this->sdoFactory->find('medona/message', implode(' and ', $queryParts), null, false, false, 300);
$message = $this->sdoFactory->find('medona/message', '('.implode(') and (', $queryParts).')', null, false, false, 300);
if (!$message) {
return null;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment