ILIAS  trunk Revision v11.0_alpha-1713-gd8962da2f67
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
Consumers.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
30 
36 class Consumers
37 {
41  public function __construct(private ConsumerFactory $consumer_factory, private ResourceBuilder $resource_builder, private CollectionBuilder $collection_builder, private SrcBuilder $src_builder = new InlineSrcBuilder())
42  {
43  }
44 
45  public function download(ResourceIdentification $identification): DownloadConsumer
46  {
47  return $this->consumer_factory->download($this->resource_builder->get($identification));
48  }
49 
50  public function inline(ResourceIdentification $identification): InlineConsumer
51  {
52  return $this->consumer_factory->inline($this->resource_builder->get($identification));
53  }
54 
55  public function stream(ResourceIdentification $identification): FileStreamConsumer
56  {
57  return $this->consumer_factory->fileStream($this->resource_builder->get($identification));
58  }
59 
60  public function src(ResourceIdentification $identification): SrcConsumer
61  {
62  return $this->consumer_factory->src($this->resource_builder->get($identification), $this->src_builder);
63  }
64 
65  public function downloadCollection(
66  ResourceCollectionIdentification $identification,
67  ?string $zip_filename = null
69  return $this->downloadResources(
70  iterator_to_array($this->collection_builder->getResourceIds($identification)),
71  $zip_filename
72  );
73  }
74 
75  public function downloadResources(
76  array $identifications,
77  ?string $zip_filename = null
79  $resources = [];
80  foreach ($identifications as $rid) {
81  if (!$rid instanceof ResourceIdentification) {
82  throw new \InvalidArgumentException('Expected ResourceIdentification');
83  }
84  $resources[] = $this->resource_builder->get($rid);
85  }
86 
87  return $this->consumer_factory->downloadMultiple(
88  $resources,
89  $zip_filename
90  );
91  }
92 
93  public function flavourUrls(Flavour $flavour): FlavourURLs
94  {
95  return $this->consumer_factory->flavourUrl($flavour, $this->src_builder);
96  }
97 
102  {
103  $resource = $this->resource_builder->get($identification);
104  if ($resource->getType() !== ResourceType::CONTAINER || !$resource instanceof StorableContainerResource) {
105  throw new \InvalidArgumentException('Expected StorableContainerResource');
106  }
107 
108  return $this->consumer_factory->containerZIP(
109  $resource
110  );
111  }
112 
113  public function containerURI(
114  ResourceIdentification $identification,
115  string $start_file = 'index.html',
116  float $valid_for_at_least_minutes = 60.0
118  $resource = $this->resource_builder->get($identification);
119  if ($resource->getType() !== ResourceType::CONTAINER || !$resource instanceof StorableContainerResource) {
120  throw new \InvalidArgumentException('Expected StorableContainerResource');
121  }
122  return $this->consumer_factory->containerURI(
123  $resource,
124  $this->src_builder,
125  ltrim($start_file, '/'),
126  $valid_for_at_least_minutes
127  );
128  }
129 }
$resources
Definition: ltiservices.php:65
downloadCollection(ResourceCollectionIdentification $identification, ?string $zip_filename=null)
Definition: Consumers.php:65
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
downloadResources(array $identifications, ?string $zip_filename=null)
Definition: Consumers.php:75
containerURI(ResourceIdentification $identification, string $start_file='index.html', float $valid_for_at_least_minutes=60.0)
Definition: Consumers.php:113
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
stream(ResourceIdentification $identification)
Definition: Consumers.php:55
containerZIP(ResourceIdentification $identification)
This consumer can be used to obtain a StorageContainerResource as a ZIP.
Definition: Consumers.php:101
src(ResourceIdentification $identification)
Definition: Consumers.php:60
download(ResourceIdentification $identification)
Definition: Consumers.php:45
__construct(private ConsumerFactory $consumer_factory, private ResourceBuilder $resource_builder, private CollectionBuilder $collection_builder, private SrcBuilder $src_builder=new InlineSrcBuilder())
Consumers constructor.
Definition: Consumers.php:41