ILIAS  trunk Revision v12.0_alpha-1338-g8f7e531aa3c
ExportCollector.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
25
27{
28 protected string $rid = "";
29 protected array $paths_added = [];
30
31 public function __construct(
32 protected DataService $data,
33 protected ExportFileDBRepository $repo,
34 protected int $obj_id,
35 protected string $type = ""
36 ) {
37 }
38
42 public function init(string $zipname = ""): string
43 {
44 if ($this->rid !== "") {
45 throw $this->data->exportException("HTML Export has been initialised twice.");
46 }
47 if ($zipname === "") {
48 $date = time();
49 $zipname = $date . "__" . IL_INST_ID . "__" .
50 \ilObject::_lookupType($this->obj_id) . "_" . $this->obj_id . ".zip";
51 }
52 $this->rid = $this->repo->create(
53 $this->obj_id,
54 $this->type,
55 $zipname
56 );
57
58 //$this->repo->rename($this->rid, $zipname);
59
60 return $this->rid;
61 }
62
66 public function addString(
67 string $content,
68 string $path
69 ): void {
70 if ($this->rid === "") {
71 throw $this->data->exportException("HTML Export has not been initialised.");
72 }
73 $this->repo->addString(
74 $this->rid,
75 $content,
76 $path
77 );
78 }
79
83 public function addFile(
84 string $fullpath,
85 string $target_path
86 ): void {
87 if ($this->rid === "") {
88 throw $this->data->exportException("HTML Export has not been initialised.");
89 }
90 if (in_array($target_path, $this->paths_added, true)) {
91 return;
92 }
93 $this->paths_added[] = $target_path;
94 $this->repo->addFile(
95 $this->rid,
96 $fullpath,
97 $target_path
98 );
99 }
100
104 public function addDirectory(
105 string $source_dir,
106 string $target_path
107 ): void {
108 if ($this->rid === "") {
109 throw $this->data->exportException("HTML Export has not been initialised.");
110 }
111 $this->repo->addDirectory(
112 $this->rid,
113 $source_dir,
114 $target_path
115 );
116 }
117
118 public function addContainerDirectory(
119 string $source_container_id,
120 string $source_dir_path = "",
121 string $target_dir_path = ""
122 ): void {
123 if ($this->rid === "") {
124 throw $this->data->exportException("HTML Export has not been initialised.");
125 }
126 $this->repo->addContainerDirToTargetContainer(
127 $source_container_id,
128 $this->rid,
129 $source_dir_path,
130 $target_dir_path
131 );
132 }
133
134 public function getFilePath(): string
135 {
136 return $this->repo->getFilePath($this->rid);
137 }
138
139 public function deliver(string $filename): void
140 {
141 $this->repo->deliverFile($this->rid);
142 }
143
144 public function delete(): void
145 {
146 $this->repo->delete($this->obj_id, $this->rid);
147 }
148
149}
$filename
Definition: buildRTE.php:78
addDirectory(string $source_dir, string $target_path)
addFile(string $fullpath, string $target_path)
addString(string $content, string $path)
__construct(protected DataService $data, protected ExportFileDBRepository $repo, protected int $obj_id, protected string $type="")
addContainerDirectory(string $source_container_id, string $source_dir_path="", string $target_dir_path="")
static _lookupType(int $id, bool $reference=false)
const IL_INST_ID
Definition: constants.php:40
$path
Definition: ltiservices.php:30
if(!file_exists('../ilias.ini.php'))