Commit 4e8641fd authored by Alexandre Morin's avatar Alexandre Morin

Fix search by originator

parent 524a47b5
......@@ -79,22 +79,7 @@ class Content
}
}
$ownerOriginatorOrgs = [];
foreach ($userServices as $userService) {
foreach ($originators as $originator) {
if ($owner || $originator->registrationNumber == $userService->registrationNumber) {
if (!isset($ownerOriginatorOrgs[(string) $originator->ownerOrgId])) {
$orgObject = \laabs::callService('organization/organization/read_orgId_', (string) $originator->ownerOrgId);
$ownerOriginatorOrgs[(string) $orgObject->orgId] = new \stdClass();
$ownerOriginatorOrgs[(string) $orgObject->orgId]->displayName = $orgObject->displayName;
$ownerOriginatorOrgs[(string) $orgObject->orgId]->originators = [];
}
$ownerOriginatorOrgs[(string) $orgObject->orgId]->originators[] = $originator;
}
}
}
$ownerOriginatorOrgs = $this->getOwnerOrgs($currentService,'originator');
$this->view->translate();
$this->view->setSource('ownerOriginatorOrgs', $ownerOriginatorOrgs);
......@@ -168,6 +153,70 @@ class Content
}
/**
* Get the list of user accessible oranizations
* @param object $currentService The user's current service
* @param string $role The org unit role to select
*
* @return The list of user accessible orgs
*/
protected function getOwnerOrgs($currentService, $role)
{
$orgUnits = \laabs::callService('organization/organization/readByrole_role_', $role);
$userPositionController = \laabs::newController('organization/userPosition');
$orgController = \laabs::newController('organization/organization');
$owner = false;
$archiver = false;
$userOrgUnits = [];
$userOrgs = [];
$userOrgUnitOrgRegNumbers = array_merge(array($currentService->registrationNumber), $userPositionController->readDescandantService((string) $currentService->orgId));
foreach ($userOrgUnitOrgRegNumbers as $userOrgUnitOrgRegNumber) {
$userOrgUnit = $orgController->getOrgByRegNumber($userOrgUnitOrgRegNumber);
$userOrgUnits[] = $userOrgUnit;
if (isset($userOrgUnit->orgRoleCodes)) {
foreach ($userOrgUnit->orgRoleCodes as $orgRoleCode) {
if ($orgRoleCode == 'owner') {
$owner = true;
}
if ($orgRoleCode == 'archiver') {
$archiver = true;
}
}
}
}
foreach ($userOrgUnits as $userOrgUnit) {
foreach ($orgUnits as $orgUnit) {
if (
// Owner = all originators
$owner
// Archiver = all originators fo the same org
|| ($archiver && $orgUnit->ownerOrgId == $userOrgUnit->ownerOrgId)
// Originator = all originators at position and sub-services
|| ($role == 'originator' && $orgUnit->registrationNumber == $userOrgUnit->registrationNumber)
// Depositor = all
|| $role == 'depositor'
) {
if (!isset($userOrgs[(string) $orgUnit->ownerOrgId])) {
$orgObject = \laabs::callService('organization/organization/read_orgId_', (string) $orgUnit->ownerOrgId);
$userOrgs[(string) $orgObject->orgId] = new \stdClass();
$userOrgs[(string) $orgObject->orgId]->displayName = $orgObject->displayName;
$userOrgs[(string) $orgObject->orgId]->{$role} = [];
}
if (!in_array($orgUnit,$userOrgs[(string) $orgObject->orgId]->{$role})) {
$userOrgs[(string)$orgObject->orgId]->{$role}[] = $orgUnit;
}
}
}
}
return $userOrgs;
}
/**
* Read users privileges on archives
*/
protected function readPrivilegesOnArchives()
......
......@@ -59,7 +59,7 @@
<option value=""></option>
<?merge ownerOriginatorOrgs ?>
<optgroup label="[?merge .displayName ?]">
<?merge .originators ?>
<?merge .originator ?>
<option value="[?merge .registrationNumber ?]"><?merge .displayName ?></option>
</optgroup>
</select>
......
Markdown is supported
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