mirror of
https://github.com/verdigado/organization_folders.git
synced 2024-11-22 04:38:09 +01:00
56 lines
No EOL
1.7 KiB
PHP
56 lines
No EOL
1.7 KiB
PHP
<?php
|
|
|
|
namespace OCA\OrganizationFolders\Manager;
|
|
|
|
use OCP\IConfig;
|
|
use OCP\Files\IRootFolder;
|
|
use OCP\Files\Node;
|
|
use OCP\Files\Folder;
|
|
|
|
use OCA\GroupFolders\Folder\FolderManager;
|
|
use OCA\GroupFolders\Mount\MountProvider;
|
|
|
|
use OCA\OrganizationFolders\Db\FolderResource;
|
|
use OCA\OrganizationFolders\Model\OrganizationFolder;
|
|
|
|
class PathManager {
|
|
public function __construct(
|
|
private IConfig $config,
|
|
private IRootFolder $rootFolder,
|
|
private FolderManager $groupfolderFolderManager,
|
|
private MountProvider $mountProvider,
|
|
){}
|
|
|
|
private function getRootFolderStorageId(): ?int {
|
|
return $this->rootFolder->getMountPoint()->getNumericStorageId();
|
|
}
|
|
|
|
public function getOrganizationFolderNode(OrganizationFolder $organizationFolder): ?Folder {
|
|
return $this->getOrganizationFolderNodeById($organizationFolder->getId());
|
|
}
|
|
/** Get underlying groupfolder folder node for the organization folder
|
|
* (or if it was never before used create it in the filesystem and filecache!)
|
|
*/
|
|
public function getOrganizationFolderNodeById(int $id)/*: ?Folder*/ {
|
|
return $this->mountProvider->getFolder(id: $id, create: True);
|
|
}
|
|
|
|
public function getOrganizationFolderSubfolder(OrganizationFolder $organizationFolder, array $path) {
|
|
return $this->getOrganizationFolderByIdSubfolder($organizationFolder->getId(), $path);
|
|
}
|
|
|
|
public function getOrganizationFolderByIdSubfolder(int $id, array $path): ?Folder {
|
|
$organizationFolderNode = $this->getOrganizationFolderNodeById($id);
|
|
$currentFolder = $organizationFolderNode;
|
|
|
|
foreach($path as $subfolder) {
|
|
try {
|
|
$currentFolder = $currentFolder->get($subfolder);
|
|
} catch (\OCP\Files\NotFoundException $e) {
|
|
return null;
|
|
}
|
|
}
|
|
|
|
return $currentFolder;
|
|
}
|
|
} |