ILIAS  release_10 Revision v10.1-43-ga1241a92c2f
ExportCollector.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
25 
27 {
28  protected string $rid = "";
29 
30  public function __construct(
31  protected DataService $data,
32  protected ExportFileDBRepository $repo,
33  protected int $obj_id,
34  protected string $type = ""
35  )
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  $this->repo->addFile(
91  $this->rid,
92  $fullpath,
93  $target_path
94  );
95  }
96 
100  public function addDirectory(
101  string $source_dir,
102  string $target_path
103  ): void {
104  if ($this->rid === "") {
105  throw $this->data->exportException("HTML Export has not been initialised.");
106  }
107  $this->repo->addDirectory(
108  $this->rid,
109  $source_dir,
110  $target_path
111  );
112  }
113 
114  public function addContainerDirectory(
115  string $source_container_id,
116  string $source_dir_path = "",
117  string $target_dir_path = ""
118  ): void {
119  if ($this->rid === "") {
120  throw $this->data->exportException("HTML Export has not been initialised.");
121  }
122  $this->repo->addContainerDirToTargetContainer(
123  $source_container_id,
124  $this->rid,
125  $source_dir_path,
126  $target_dir_path
127  );
128  }
129 
130  public function getFilePath(): string
131  {
132  return $this->repo->getFilePath($this->rid);
133  }
134 
135  public function deliver(string $filename) : void
136  {
137  $this->repo->deliverFile($this->rid);
138  }
139 
140  public function delete() : void
141  {
142  $this->repo->delete($this->obj_id, $this->rid);
143  }
144 
145 }
const IL_INST_ID
Definition: constants.php:40
$path
Definition: ltiservices.php:30
addFile(string $fullpath, string $target_path)
addDirectory(string $source_dir, string $target_path)
addContainerDirectory(string $source_container_id, string $source_dir_path="", string $target_dir_path="")
$filename
Definition: buildRTE.php:78
__construct(protected DataService $data, protected ExportFileDBRepository $repo, protected int $obj_id, protected string $type="")
static _lookupType(int $id, bool $reference=false)
addString(string $content, string $path)