ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
All Data Structures Namespaces Files Functions Variables Modules Pages
ResourceBuilder.php
Go to the documentation of this file.
1 <?php declare(strict_types=1);
2 
4 
5 use Generator;
14 
23 {
24 
41 
42 
52  {
53  $this->storage_handler = $storage_handler;
54  $this->revision_repository = $revision_repository;
55  $this->resource_repository = $resource_repository;
56  $this->information_repository = $information_repository;
57  }
58 
59 
63  public function new(UploadResult $result) : StorableResource
64  {
65  $resource = $this->resource_repository->blank($this->storage_handler->getIdentificationGenerator()->getUniqueResourceIdentification());
66  $revision = $this->revision_repository->blank($resource, $result);
67 
68  $info = $revision->getInformation();
69  $info->setTitle($result->getName());
70  $info->setMimeType($result->getMimeType());
71  $info->setSize($result->getSize());
72  $info->setCreationDate(new \DateTimeImmutable());
73  $revision->setInformation($info);
74 
75  $resource->addRevision($revision);
76  $resource->setStorageID($this->storage_handler->getID());
77 
78  return $resource;
79  }
80 
81 
82  public function has(ResourceIdentification $identification) : bool
83  {
84  return $this->resource_repository->has($identification) && $this->storage_handler->has($identification);
85  }
86 
87 
91  public function store(StorableResource $resource) : void
92  {
93  $this->resource_repository->store($resource);
94 
95  foreach ($resource->getAllRevisions() as $revision) {
96  if ($revision instanceof UploadedFileRevision) {
97  $this->storage_handler->storeUpload($revision);
98  }
99  $this->revision_repository->store($revision);
100  $this->information_repository->store($revision->getInformation(), $revision);
101  }
102  }
103 
104 
108  public function get(ResourceIdentification $identification) : StorableResource
109  {
110  $resource = $this->resource_repository->get($identification);
111 
112  return $this->populateNakedResourceWithRevisionsAndStakeholders($resource);
113  }
114 
115 
122  {
123  $revisions = $this->revision_repository->get($resource);
124  $resource->setRevisions($revisions);
125 
126  foreach ($resource->getAllRevisions() as $revision) {
127  $information = $this->information_repository->get($revision);
128  $revision->setInformation($information);
129  }
130 
131  return $resource;
132  }
133 
134 
138  public function remove(StorableResource $resource) : void
139  {
140  foreach ($resource->getAllRevisions() as $revision) {
141  $this->information_repository->delete($revision->getInformation(), $revision);
142  $this->revision_repository->delete($revision);
143  }
144  $this->storage_handler->deleteResource($resource);
145  $this->resource_repository->delete($resource);
146  }
147 
148 
152  public function getAll() : Generator
153  {
157  foreach ($this->resource_repository->getAll() as $resource) {
159  }
160  }
161 }
$result
setRevisions(RevisionCollection $collection)
__construct(StorageHandler $storage_handler, RevisionRepository $revision_repository, ResourceRepository $resource_repository, InformationRepository $information_repository)
ResourceBuilder constructor.
populateNakedResourceWithRevisionsAndStakeholders(StorableResource $resource)
has(ResourceIdentification $identification)