ILIAS  release_10 Revision v10.1-43-ga1241a92c2f
class.ilFileExporter.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
29 {
33  public function init(): void
34  {
35  }
36 
44  public function getXmlExportTailDependencies(string $a_entity, string $a_target_release, array $a_ids): array
45  {
46  $md_ids = [];
47  foreach ($a_ids as $file_id) {
48  $md_ids[] = $file_id . ":0:file";
49  }
50 
51  return [
52  [
53  "component" => "components/ILIAS/MetaData",
54  "entity" => "md",
55  "ids" => $md_ids,
56  ],
57  [
58  "component" => "components/ILIAS/ILIASObject",
59  "entity" => "common",
60  "ids" => $a_ids
61  ]
62  ];
63  }
64 
72  public function getXmlRepresentation(string $a_entity, string $a_schema_version, string $a_id): string
73  {
74  $xml = '';
75  if (ilObject::_lookupType((int) $a_id) == 'file') {
76  $file = new ilObjFile((int) $a_id, false);
77  $writer = new ilFileXMLWriter();
78  $writer->setFile($file);
79  $writer->setOmitHeader(true);
80  $writer->setAttachFileContents(ilFileXMLWriter::$CONTENT_ATTACH_COPY);
81  $this->prepareExportDirectories($writer);
82  $writer->start();
83  $xml = $writer->getXml();
84  }
85  return $xml;
86  }
87 
88  protected function prepareExportDirectories(
89  ilFileXMLWriter $writer
90  ): void {
91  $path = str_replace('\\', '/', $this->exp->getExportDirInContainer());
92  $segments = explode('/', $path);
93  array_shift($segments);
94  $target_dir_relative = implode('/', $segments) . '/expDir_1';
95  $target_dir_absolute = rtrim($this->getAbsoluteExportDirectory(), '/') . '/' . $target_dir_relative;
96  ilFileUtils::makeDirParents($target_dir_absolute);
97  $writer->setFileTargetDirectories(
98  $target_dir_relative,
99  $target_dir_absolute
100  );
101  }
102 
108  public function getValidSchemaVersions(string $a_entity): array
109  {
110  return [
111  "4.1.0" => [
112  "namespace" => "http://www.ilias.de/Modules/File/file/4_1",
113  "xsd_file" => "ilias_file_4_1.xsd",
114  "min" => "4.1.0",
115  "max" => ""
116  ]
117  ];
118  }
119 }
Exporter class for files.
prepareExportDirectories(ilFileXMLWriter $writer)
getXmlRepresentation(string $a_entity, string $a_schema_version, string $a_id)
Get xml representation.
static makeDirParents(string $a_dir)
Create a new directory and all parent directories.
$path
Definition: ltiservices.php:30
init()
Initialisation.
Class ilObjFile.
static int $CONTENT_ATTACH_COPY
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
getValidSchemaVersions(string $a_entity)
Returns schema versions that the component can export to.
getXmlExportTailDependencies(string $a_entity, string $a_target_release, array $a_ids)
Get tail dependencies.
static _lookupType(int $id, bool $reference=false)
setFileTargetDirectories(?string $a_rel, ?string $a_abs)
Set file target directories.