2024-10-31 17:29:15 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace OCA\OrganizationFolders\Db;
|
|
|
|
|
|
|
|
use JsonSerializable;
|
|
|
|
use OCA\OrganizationFolders\Interface\TableSerializable;
|
|
|
|
|
|
|
|
use OCP\AppFramework\Db\Entity;
|
|
|
|
|
|
|
|
use OCA\OrganizationFolders\Enum\MemberPermissionLevel;
|
2024-11-12 15:36:07 +01:00
|
|
|
use OCA\OrganizationFolders\Enum\PrincipalType;
|
|
|
|
use OCA\OrganizationFolders\Model\Principal;
|
2024-10-31 17:29:15 +01:00
|
|
|
|
|
|
|
class ResourceMember extends Entity implements JsonSerializable, TableSerializable {
|
|
|
|
protected $resourceId;
|
|
|
|
protected $permissionLevel;
|
2024-11-12 15:36:07 +01:00
|
|
|
protected $principalType;
|
|
|
|
protected $principalId;
|
2024-10-31 17:29:15 +01:00
|
|
|
protected $createdTimestamp;
|
|
|
|
protected $lastUpdatedTimestamp;
|
|
|
|
|
|
|
|
public function __construct() {
|
|
|
|
$this->addType('resourceId','integer');
|
|
|
|
$this->addType('permissionLevel','integer');
|
2024-11-12 15:36:07 +01:00
|
|
|
$this->addType('principalType','integer');
|
2024-10-31 17:29:15 +01:00
|
|
|
$this->addType('createdTimestamp','integer');
|
|
|
|
$this->addType('lastUpdatedTimestamp','integer');
|
|
|
|
}
|
2024-11-12 15:36:07 +01:00
|
|
|
public function getPrincipal(): Principal {
|
|
|
|
return new Principal(PrincipalType::from($this->principalType), $this->principalId);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setPrincipal(Principal $principal) {
|
|
|
|
$this->setPrincipalType($principal->getType()->value);
|
|
|
|
$this->setPrincipalId($principal->getId());
|
|
|
|
}
|
2024-10-31 17:29:15 +01:00
|
|
|
|
|
|
|
public function jsonSerialize(): array {
|
|
|
|
return [
|
2024-11-05 00:45:44 +01:00
|
|
|
'id' => $this->id,
|
2024-10-31 17:29:15 +01:00
|
|
|
'resourceId' => $this->resourceId,
|
|
|
|
'permissionLevel' => $this->permissionLevel,
|
2024-11-12 15:36:07 +01:00
|
|
|
'principal' => $this->getPrincipal(),
|
2024-10-31 17:29:15 +01:00
|
|
|
'createdTimestamp' => $this->createdTimestamp,
|
|
|
|
'lastUpdatedTimestamp' => $this->lastUpdatedTimestamp,
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
public function tableSerialize(?array $params = null): array {
|
|
|
|
return [
|
2024-11-05 00:45:44 +01:00
|
|
|
'Id' => $this->id,
|
2024-10-31 17:29:15 +01:00
|
|
|
'Resource Id' => $this->resourceId,
|
|
|
|
'Permission Level' => MemberPermissionLevel::from($this->permissionLevel)->name,
|
2024-11-12 15:36:07 +01:00
|
|
|
'Principal Type' => PrincipalType::from($this->principalType)->name,
|
|
|
|
'Principal Id' => $this->principalId,
|
2024-10-31 17:29:15 +01:00
|
|
|
'Created' => $this->createdTimestamp,
|
|
|
|
'LastUpdated' => $this->lastUpdatedTimestamp,
|
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|