ILIAS  trunk Revision v11.0_alpha-2662-g519ff7d528f
ILIAS\LegalDocuments\Consumer\DownloadMultipleConsumer Class Reference
+ Inheritance diagram for ILIAS\LegalDocuments\Consumer\DownloadMultipleConsumer:
+ Collaboration diagram for ILIAS\LegalDocuments\Consumer\DownloadMultipleConsumer:

Public Member Functions

 __construct (protected array $resources, private StreamAccess $stream_access, protected FileNamePolicy $file_name_policy, protected string $zip_file_name)
 
 run ()
 This runs the actual DeliveryConsumer. More...
 
 useRevisionTitlesForFileNames (bool $use_revision_titles)
 
 setRevisionNumber (int $revision_number)
 
 overrideFileName (string $file_name)
 

Protected Attributes

ResourceCollection $collection
 
int $revision_number = null
 
bool $use_revision_titles = false
 

Detailed Description

Definition at line 35 of file DownloadMultipleConsumer.php.

Constructor & Destructor Documentation

◆ __construct()

ILIAS\LegalDocuments\Consumer\DownloadMultipleConsumer::__construct ( protected array  $resources,
private StreamAccess  $stream_access,
protected FileNamePolicy  $file_name_policy,
protected string  $zip_file_name 
)
Parameters
StorableResource[]$resources

Definition at line 44 of file DownloadMultipleConsumer.php.

45  {
46  }

Member Function Documentation

◆ overrideFileName()

ILIAS\LegalDocuments\Consumer\DownloadMultipleConsumer::overrideFileName ( string  $file_name)

Implements ILIAS\LegalDocuments\Consumer\DeliveryConsumer.

Definition at line 105 of file DownloadMultipleConsumer.php.

105  : DeliveryConsumer
106  {
107  $this->zip_file_name = $file_name;
108  return $this;
109  }

◆ run()

ILIAS\LegalDocuments\Consumer\DownloadMultipleConsumer::run ( )

This runs the actual DeliveryConsumer.

E.g. a DownloadConsumer will pass the Stream of a Ressource to the HTTP-Service and download the file.

Implements ILIAS\LegalDocuments\Consumer\DeliveryConsumer.

Definition at line 49 of file DownloadMultipleConsumer.php.

References $DIC, $response, ILIAS\StaticURL\Response\Response\ResponseHeader\ACCEPT_RANGES, ILIAS\FileUpload\MimeType\APPLICATION__ZIP, CLIENT_DATA_DIR, ILIAS\StaticURL\Response\Response\ResponseHeader\CONNECTION, ILIAS\StaticURL\Response\Response\ResponseHeader\CONTENT_DISPOSITION, ILIAS\StaticURL\Response\Response\ResponseHeader\CONTENT_TYPE, ILIAS\Filesystem\Stream\Streams\ofResource(), and ILIAS\Repository\resources().

49  : void
50  {
51  global $DIC;
52 
53  $directory = CLIENT_DATA_DIR . '/temp';
54  $temp = tempnam($directory, 'zip');
55  $zip = new \ZipArchive();
56  $zip->open($temp, \ZipArchive::CREATE | \ZipArchive::OVERWRITE);
57 
58  foreach ($this->resources as $resource) {
59  $revision = $this->stream_access->populateRevision($resource->getCurrentRevision());
60  if ($this->use_revision_titles) {
61  $file_name = $this->file_name_policy->prepareFileNameForConsumer($revision->getTitle());
62  } else {
63  $file_name = $this->file_name_policy->prepareFileNameForConsumer(
64  $revision->getInformation()->getTitle()
65  );
66  }
67 
68  $zip->addFile($revision->maybeStreamResolver()->getStream()->getMetadata('uri'), $file_name);
69  }
70 
71  $zip->close();
72  $response = $DIC->http()->response();
74  $response = $response->withHeader(ResponseHeader::CONNECTION, 'close');
75  $response = $response->withHeader(ResponseHeader::ACCEPT_RANGES, 'bytes');
76  $response = $response->withHeader(
78  'attachment'
79  . '; filename="'
80  . $this->zip_file_name
81  . '"'
82  );
83  $fopen = fopen($temp, 'rb');
84  $response = $response->withBody(Streams::ofResource($fopen));
85  $DIC->http()->saveResponse($response);
86  $DIC->http()->sendResponse();
87  fclose($fopen);
88  unlink($temp);
89  $DIC->http()->close();
90  }
$response
Definition: xapitoken.php:93
const CLIENT_DATA_DIR
Definition: constants.php:46
static ofResource($resource)
Wraps an already created resource with the stream abstraction.
Definition: Streams.php:64
global $DIC
Definition: shib_login.php:26
+ Here is the call graph for this function:

◆ setRevisionNumber()

ILIAS\LegalDocuments\Consumer\DownloadMultipleConsumer::setRevisionNumber ( int  $revision_number)
Parameters
int$revision_numberof a specific revision. otherwise the latest will be chosen during run()

Implements ILIAS\LegalDocuments\Consumer\DeliveryConsumer.

Definition at line 99 of file DownloadMultipleConsumer.php.

References ILIAS\LegalDocuments\Consumer\DownloadMultipleConsumer\$revision_number.

99  : DeliveryConsumer
100  {
101  $this->revision_number = $revision_number;
102  return $this;
103  }

◆ useRevisionTitlesForFileNames()

ILIAS\LegalDocuments\Consumer\DownloadMultipleConsumer::useRevisionTitlesForFileNames ( bool  $use_revision_titles)

Definition at line 93 of file DownloadMultipleConsumer.php.

References ILIAS\LegalDocuments\Consumer\DownloadMultipleConsumer\$use_revision_titles.

93  : self
94  {
95  $this->use_revision_titles = $use_revision_titles;
96  return $this;
97  }

Field Documentation

◆ $collection

ResourceCollection ILIAS\LegalDocuments\Consumer\DownloadMultipleConsumer::$collection
protected

Definition at line 37 of file DownloadMultipleConsumer.php.

◆ $revision_number

int ILIAS\LegalDocuments\Consumer\DownloadMultipleConsumer::$revision_number = null
protected

◆ $use_revision_titles

bool ILIAS\LegalDocuments\Consumer\DownloadMultipleConsumer::$use_revision_titles = false
protected

The documentation for this class was generated from the following file: