ILIAS  release_10 Revision v10.1-43-ga1241a92c2f
ExportFileDBRepository.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
21 namespace ILIAS\Export\HTML;
22 
23 use ilDBInterface;
27 
29 {
30  public function __construct(
31  protected ilDBInterface $db,
32  protected IRSSWrapper $irss,
33  protected DataService $data,
34  protected \ilExportHTMLStakeholder $stakeholder
35  )
36  {
37  }
38 
39  public function create(
40  int $object_id,
41  string $type,
42  string $title
43  ): string
44  {
45  $rid = $this->irss->createContainer(
46  $this->stakeholder,
47  $title
48  );
49  $this->db->insert('export_files_html', [
50  'object_id' => ['integer', $object_id],
51  'rid' => ['text', $rid],
52  'timestamp' => ['timestamp', \ilUtil::now()],
53  'type' => ['text', $type]
54  ]);
55  return $rid;
56  }
57 
58  public function addString(
59  string $rid,
60  string $content,
61  string $path,
62  ): void {
63  $this->irss->addStringToContainer(
64  $rid,
65  $content,
66  $path
67  );
68  }
69 
70  public function addFile(
71  string $rid,
72  string $fullpath,
73  string $path,
74  ): void {
75  $this->irss->addLocalFileToContainer(
76  $rid,
77  $fullpath,
78  $path
79  );
80  }
81 
82  public function addDirectory(
83  string $rid,
84  string $source_dir,
85  string $target_path = ""
86  ): void
87  {
88  $this->irss->addDirectoryToContainer(
89  $rid,
90  $source_dir,
91  $target_path
92  );
93  }
94 
96  string $source_container_id,
97  string $target_container_id,
98  string $source_dir_path = "",
99  string $target_dir_path = ""
100  ): void {
101  $this->irss->addContainerDirToTargetContainer(
102  $source_container_id,
103  $target_container_id,
104  $source_dir_path,
105  $target_dir_path
106  );
107  }
108 
109  public function update(ExportFile $file): void
110  {
111  $this->db->update('export_files_html', [
112  'timestamp' => ['timestamp', $file->getTimestamp()],
113  'type' => ['text', $file->getType()]
114  ], [
115  'object_id' => ['integer', $file->getObjectId()],
116  'rid' => ['text', $file->getRid()]
117  ]);
118  }
119 
120  public function delete(
121  int $object_id,
122  string $rid
123  ): void
124  {
125  $this->irss->deleteResource(
126  $rid,
127  $this->stakeholder
128  );
129  $this->db->manipulateF(
130  'DELETE FROM export_files_html WHERE object_id = %s AND rid = %s',
131  ['integer', 'text'],
132  [$object_id, $rid]
133  );
134  }
135 
136  public function getFilePath(
137  string $rid
138  ): string
139  {
140  return $this->irss->getResourcePath($rid);
141  }
142 
143  public function getById(int $object_id, string $rid): ?ExportFile
144  {
145  $set = $this->db->queryF(
146  'SELECT * FROM export_files_html WHERE object_id = %s AND rid = %s',
147  ['integer', 'text'],
148  [$object_id, $rid]
149  );
150 
151  $record = $this->db->fetchAssoc($set);
152  return $record ? $this->getExportFileFromRecord($record) : null;
153  }
154 
158  public function getAllOfObjectId(int $object_id): \Generator
159  {
160  $set = $this->db->queryF("SELECT * FROM export_files_html " .
161  " WHERE object_id = %s ORDER BY timestamp DESC",
162  ["integer"],
163  [$object_id]
164  );
165  while ($record = $this->db->fetchAssoc($set)) {
166  yield $this->getExportFileFromRecord($record);
167  }
168  }
169 
170  public function getLatestOfObjectIdAndType(int $object_id, string $type = ""): ?ExportFile
171  {
172  $set = $this->db->queryF("SELECT * FROM export_files_html " .
173  " WHERE object_id = %s AND type = %s ORDER BY timestamp DESC",
174  ["integer", "text"],
175  [$object_id, $type]
176  );
177  if ($record = $this->db->fetchAssoc($set)) {
178  return $this->getExportFileFromRecord($record);
179  }
180  return null;
181  }
182 
183  public function getResourceIdForIdString(string $rid): ?ResourceIdentification
184  {
185  return $this->irss->getResourceIdForIdString($rid);
186  }
187 
188  protected function getExportFileFromRecord(array $record): ExportFile
189  {
190  return $this->data->exportFile(
191  (int) $record['object_id'],
192  (string) $record['rid'],
193  (string) $record['timestamp'],
194  (string) $record['type']
195  );
196  }
197 
198  public function deliverFile(string $rid): void
199  {
200  $this->irss->deliverFile($rid);
201  }
202 
203  // currently broken, see https://mantis.ilias.de/view.php?id=44135
204  public function rename(
205  string $rid,
206  string $title
207  ): void
208  {
209  $this->irss->renameContainer($rid, $title);
210  }
211 
212 
213 }
getLatestOfObjectIdAndType(int $object_id, string $type="")
addFile(string $rid, string $fullpath, string $path,)
addDirectory(string $rid, string $source_dir, string $target_path="")
__construct(protected ilDBInterface $db, protected IRSSWrapper $irss, protected DataService $data, protected \ilExportHTMLStakeholder $stakeholder)
create(int $object_id, string $type, string $title)
static now()
Return current timestamp in Y-m-d H:i:s format.
$path
Definition: ltiservices.php:30
addContainerDirToTargetContainer(string $source_container_id, string $target_container_id, string $source_dir_path="", string $target_dir_path="")
addString(string $rid, string $content, string $path,)