Commit ebc6fae3 authored by Arnaud Pauget's avatar Arnaud Pauget
Browse files

feat(18079) : change way to get available originator services

parent 1f2a3e61
Pipeline #14416 failed with stages
in 58 seconds
......@@ -976,6 +976,54 @@ trait archiveModificationTrait
return true;
}
/**
* Get available originators for an archive
* @param string $archiveId The archive identifier
*
* @return [type] [description]
*/
public function indexAvailableOriginators($archiveId)
{
$archive = $this->sdoFactory->read('recordsManagement/archive', $archiveId);
$availableOriginatingServices = $this->getDescendantServices($archive->originatorOwnerOrgId, $archive->archivalAgreementReference);
return $availableOriginatingServices;
}
protected function getDescendantServices($orgId, $archivalAgreementReference)
{
$archivalAgreementController = \laabs::newController('medona/archivalAgreement');
$organizationController = \laabs::newController('organization/organization');
$orgs = [];
if (!is_null($archivalAgreementReference)) {
$archivalAgreement = $archivalAgreementController->getByReference($archivalAgreementReference);
foreach ($archivalAgreement->originatorOrgIds as $originatorOrgId) {
$orgs[] = $organizationController->read((string) $originatorOrgId);
array_merge($organizationController->readDescendantServices((string) $originatorOrgId), $orgs);
}
} else {
$orgs = \laabs::callService('organization/organization/readDescendantServices', $orgId);
}
$descendantServices = [];
foreach ($orgs as $key => $org) {
// May be empty if archivalAgreement originatorOrgId has no descendant service
if (!empty($org)) {
$descendantServices[$key] = new \stdClass();
$descendantServices[$key]->orgId = (string) $org->orgId;
$descendantServices[$key]->displayName = $org->displayName;
}
}
// sort by alphabetical order of displayName (php 8)
usort($descendantServices, function ($a, $b) {
return $a->displayName <=> $b->displayName;
});
return $descendantServices;
}
/**
* Update originator service of an array of archives
*
......
......@@ -135,6 +135,13 @@ interface archiveInterface
*/
public function read_archiveId_Retentionrule();
/**
* Get available orignators for an archive before to modify
*
* @action recordsManagement/archive/indexAvailableOriginators
*/
public function read_archiveId_Availableoriginators();
/**
* Read the access rule of archive
*
......
......@@ -251,8 +251,6 @@ class archive
}
}
$archive->availableOriginatingServices = json_encode($this->getDescendantServices($archive->originatorOwnerOrgId, $archive->archivalAgreementReference));
$hasReachMaxResults = false;
if (
isset(\laabs::configuration('presentation.maarchRM')['maxResults'])
......@@ -313,37 +311,6 @@ class archive
return $resultList;
}
protected function getDescendantServices($orgId, $archivalAgreementReference)
{
$orgs = [];
if (!is_null($archivalAgreementReference)) {
$archivalAgreement = \laabs::callService('medona/archivalAgreement/readGetByReference', $archivalAgreementReference);
foreach ($archivalAgreement->originatorOrgIds as $originatorOrgId) {
$orgs[] = \laabs::callService('organization/organization/read_orgId_', (string) $originatorOrgId);
array_merge(\laabs::callService('organization/organization/readDescendantServices', (string) $originatorOrgId), $orgs);
}
} else {
$orgs = \laabs::callService('organization/organization/readDescendantServices', $orgId);
}
$descendantServices = [];
foreach ($orgs as $key => $org) {
// May be empty if archivalAgreement originatorOrgId has no descendant service
if (!empty($org)) {
$descendantServices[$key] = new \stdClass();
$descendantServices[$key]->orgId = (string) $org->orgId;
$descendantServices[$key]->displayName = $org->displayName;
}
}
// sort by alphabetical order of displayName (php 8)
usort($descendantServices, function ($a, $b) {
return $a->displayName <=> $b->displayName;
});
return $descendantServices;
}
/**
* Get resource contents
* @param digitalResource/digitalResource $digitalResource The resource object
......
<script>
var editOriginator_load = function (archiveId, archiveName, type) {
var url = '/recordsManagement/archive/availableoriginators/' + archiveId
var type = 'GET';
$.ajax({
url : url,
type : type,
contentType : 'application/json',
dataType : 'json',
success : function (response) {
displayOrignator(response);
},
error : function(response) {
gritter.show(response.responseJSON.message, response.responseJSON.status, response.responseJSON.errors);
}
});
}
var displayOrignator = function(originatorTab) {
$('#selectedOriginator').remove();
var selectedOriginatorTr = $('<tr>').attr('id', "selectedOriginator");
selectedOriginatorTr.append($('<td>').append($('<strong>').text($('#mtext_editOriginator').text())));
var td = $('<td>');
var availableOriginatingServices = $('#' + archiveId).data('availableoriginatingservices');
var availableOriginatingServices = originatorTab;
var select = $('<select>').attr('name', "originatorList").attr("id", "originatorList").addClass('form-control');
availableOriginatingServices.forEach(org => {
select.append($('<option>').val(org.orgId).text(org.displayName));
......
......@@ -38,7 +38,7 @@
</thead>
<tbody>
<?merge archive ?>
<tr id="[?merge .archiveId ?]" name="[?merge .archiveName ?]" class="[?merge .disposable.bool().then('danger') ?] [?merge .hasRights.bool().not().then('text-muted') ?]" data-iscommunicable="[?merge .isCommunicable ?]" data-hasRights="[?merge .hasRights.bool().then('true', 'false') ?]" data-availableoriginatingservices="[?merge .availableOriginatingServices ?]">
<tr id="[?merge .archiveId ?]" name="[?merge .archiveName ?]" class="[?merge .disposable.bool().then('danger') ?] [?merge .hasRights.bool().not().then('text-muted') ?]" data-iscommunicable="[?merge .isCommunicable ?]" data-hasRights="[?merge .hasRights.bool().then('true', 'false') ?]">
<td>
<input type="checkbox"
data-archive-status="[?merge .status ?]"
......
......@@ -29,6 +29,13 @@ namespace presentation\maarchRM\UserStory\archiveManagement;
interface adminOriginatorInterface
{
/**
* Get available originators for an archive
*
* @uses recordsManagement/archive/read_archiveId_Availableoriginators
*/
public function readRecordsmanagementArchiveAvailableoriginators_archiveId_();
/**
* @uses recordsManagement/archives/updateOriginator
* @return recordsManagement/archive/setOriginator
......
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