ILIAS  trunk Revision v11.0_alpha-1723-g8e69f309bab
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
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  public function create(
39  int $object_id,
40  string $type,
41  string $title
42  ): string {
43  $rid = $this->irss->createContainer(
44  $this->stakeholder,
45  $title
46  );
47  $this->db->insert('export_files_html', [
48  'object_id' => ['integer', $object_id],
49  'rid' => ['text', $rid],
50  'timestamp' => ['timestamp', \ilUtil::now()],
51  'type' => ['text', $type]
52  ]);
53  return $rid;
54  }
55 
56  public function addString(
57  string $rid,
58  string $content,
59  string $path,
60  ): void {
61  $this->irss->addStringToContainer(
62  $rid,
63  $content,
64  $path
65  );
66  }
67 
68  public function addFile(
69  string $rid,
70  string $fullpath,
71  string $path,
72  ): void {
73  $this->irss->addLocalFileToContainer(
74  $rid,
75  $fullpath,
76  $path
77  );
78  }
79 
80  public function addDirectory(
81  string $rid,
82  string $source_dir,
83  string $target_path = ""
84  ): void {
85  $this->irss->addDirectoryToContainer(
86  $rid,
87  $source_dir,
88  $target_path
89  );
90  }
91 
93  string $source_container_id,
94  string $target_container_id,
95  string $source_dir_path = "",
96  string $target_dir_path = ""
97  ): void {
98  $this->irss->addContainerDirToTargetContainer(
99  $source_container_id,
100  $target_container_id,
101  $source_dir_path,
102  $target_dir_path
103  );
104  }
105 
106  public function update(ExportFile $file): void
107  {
108  $this->db->update('export_files_html', [
109  'timestamp' => ['timestamp', $file->getTimestamp()],
110  'type' => ['text', $file->getType()]
111  ], [
112  'object_id' => ['integer', $file->getObjectId()],
113  'rid' => ['text', $file->getRid()]
114  ]);
115  }
116 
117  public function delete(
118  int $object_id,
119  string $rid
120  ): void {
121  $this->irss->deleteResource(
122  $rid,
123  $this->stakeholder
124  );
125  $this->db->manipulateF(
126  'DELETE FROM export_files_html WHERE object_id = %s AND rid = %s',
127  ['integer', 'text'],
128  [$object_id, $rid]
129  );
130  }
131 
132  public function getFilePath(
133  string $rid
134  ): string {
135  return $this->irss->getResourcePath($rid);
136  }
137 
138  public function getById(int $object_id, string $rid): ?ExportFile
139  {
140  $set = $this->db->queryF(
141  'SELECT * FROM export_files_html WHERE object_id = %s AND rid = %s',
142  ['integer', 'text'],
143  [$object_id, $rid]
144  );
145 
146  $record = $this->db->fetchAssoc($set);
147  return $record ? $this->getExportFileFromRecord($record) : null;
148  }
149 
153  public function getAllOfObjectId(int $object_id): \Generator
154  {
155  $set = $this->db->queryF(
156  "SELECT * FROM export_files_html " .
157  " WHERE object_id = %s ORDER BY timestamp DESC",
158  ["integer"],
159  [$object_id]
160  );
161  while ($record = $this->db->fetchAssoc($set)) {
162  yield $this->getExportFileFromRecord($record);
163  }
164  }
165 
166  public function getResourceIdForIdString(string $rid): ?ResourceIdentification
167  {
168  return $this->irss->getResourceIdForIdString($rid);
169  }
170 
171  protected function getExportFileFromRecord(array $record): ExportFile
172  {
173  return $this->data->exportFile(
174  (int) $record['object_id'],
175  (string) $record['rid'],
176  (string) $record['timestamp'],
177  (string) $record['type']
178  );
179  }
180 
181  public function deliverFile(string $rid): void
182  {
183  $this->irss->deliverFile($rid);
184  }
185 
186  // currently broken, see https://mantis.ilias.de/view.php?id=44135
187  public function rename(
188  string $rid,
189  string $title
190  ): void {
191  $this->irss->renameContainer($rid, $title);
192  }
193 
194 
195 }
addString(string $rid, string $content, string $path,)
addFile(string $rid, string $fullpath, string $path,)
static now()
Return current timestamp in Y-m-d H:i:s format.
$path
Definition: ltiservices.php:29
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
addDirectory(string $rid, string $source_dir, string $target_path="")
create(int $object_id, string $type, string $title)
addContainerDirToTargetContainer(string $source_container_id, string $target_container_id, string $source_dir_path="", string $target_dir_path="")
__construct(protected ilDBInterface $db, protected IRSSWrapper $irss, protected DataService $data, protected \ilExportHTMLStakeholder $stakeholder)