mirror of
https://github.com/verdigado/organization_folders.git
synced 2024-12-06 11:22:41 +01:00
50 lines
No EOL
1.6 KiB
PHP
50 lines
No EOL
1.6 KiB
PHP
<?php
|
|
|
|
namespace OCA\OrganizationFolders\Model;
|
|
|
|
use OCA\OrganizationFolders\Enum\PrincipalType;
|
|
use OCA\OrganizationFolders\OrganizationProvider\OrganizationProviderManager;
|
|
|
|
class RolePrincipal extends Principal {
|
|
private ?OrganizationRole $role;
|
|
|
|
public function __construct(
|
|
private OrganizationProviderManager $organizationProviderManager,
|
|
private string $providerId,
|
|
private string $roleId,
|
|
) {
|
|
try {
|
|
$this->role = $this->organizationProviderManager->getOrganizationProvider($providerId)->getRole($roleId);
|
|
$this->valid = !is_null($this->role);
|
|
} catch (\Exception $e) {
|
|
$this->valid = false;
|
|
}
|
|
}
|
|
|
|
public function getType(): PrincipalType {
|
|
return PrincipalType::ROLE;
|
|
}
|
|
|
|
public function getId(): string {
|
|
return $this->providerId . ":" . $this->roleId;
|
|
}
|
|
|
|
public function getFriendlyName(): string {
|
|
return $this->role->getFriendlyName();
|
|
}
|
|
|
|
public function getFullHierarchyNames(): array {
|
|
$result = [];
|
|
$result[] = $this->getFriendlyName();
|
|
|
|
$organizationProvider = $this->organizationProviderManager->getOrganizationProvider($this->providerId);
|
|
$organization = $organizationProvider->getOrganization($this->role->getOrganizationId());
|
|
$result[] = $organization->getFriendlyName();
|
|
|
|
while($organization->getParentOrganizationId() && $organization = $organizationProvider->getOrganization($organization->getParentOrganizationId())) {
|
|
$result[] = $organization->getFriendlyName();
|
|
}
|
|
|
|
return array_reverse($result);
|
|
}
|
|
} |