ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilAdvancedMDRecordExportFiles.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21use ILIAS\AdvancedMetaData\Record\File\Factory as ilAMDRecordFileFactory;
24
31{
32 protected const SIZE = 'size';
33 protected const DATE = 'date';
34 protected const NAME = 'name';
35 protected ilAMDRecordFileFactory $amd_record_file_factory;
36 protected string $export_dir = '';
37 protected ObjectId|null $object_id;
38 protected int $user_id;
39
40 public function __construct(
41 int $user_id,
42 ?ObjectId $a_obj_id = null
43 ) {
44 $this->amd_record_file_factory = new ilAMDRecordFileFactory();
45 $this->user_id = $user_id;
46 $this->object_id = $a_obj_id;
47 }
48
52 public function readFilesInfo(): array
53 {
54 $file_info = [];
55 $elements = is_null($this->object_id)
56 ? $this->amd_record_file_factory->handler()->getGlobalFiles()
57 : $this->amd_record_file_factory->handler()->getFilesByObjectId($this->object_id);
58 foreach ($elements as $element) {
59 $file_id = $element->getIRSS()->getResourceIdSerialized();
60 $file_info[$file_id][self::SIZE] = $element->getIRSS()->getResourceSize();
61 $file_info[$file_id][self::DATE] = $element->getIRSS()->getCreationDate()->getTimestamp();
62 $file_info[$file_id][self::NAME] = $element->getIRSS()->getRecords();
63 }
64 return $file_info;
65 }
66
67 public function create(
68 string $a_xml
69 ): void {
70 $file_name = time() . '.xml';
71 $stream = Streams::ofString($a_xml);
72 if (is_null($this->object_id)) {
73 $this->amd_record_file_factory->handler()->addGlobalFile(
74 $this->user_id,
75 $file_name,
76 $stream
77 );
78 }
79 if (!is_null($this->object_id)) {
80 $this->amd_record_file_factory->handler()->addFile(
81 $this->object_id,
82 $this->user_id,
83 $file_name,
84 $stream
85 );
86 }
87 }
88
89 public function download(
90 string $file_id,
91 string|null $filename_overwrite = null
92 ): void {
93 if (is_null($this->object_id)) {
94 $this->amd_record_file_factory->handler()->downloadGlobal(
95 $file_id,
96 $filename_overwrite
97 );
98 }
99 if (!is_null($this->object_id)) {
100 $this->amd_record_file_factory->handler()->download(
101 $this->object_id,
102 $file_id,
103 $filename_overwrite
104 );
105 }
106 }
107
108 public function deleteByFileId(
109 int $user_id,
110 string $file_id
111 ): bool {
112 $global = is_null($this->object_id);
113 if ($global) {
114 $this->amd_record_file_factory->handler()->deleteGlobal(
115 $user_id,
116 $file_id
117 );
118 }
119 if (!$global) {
120 $this->amd_record_file_factory->handler()->delete(
121 $this->object_id,
122 $user_id,
123 $file_id
124 );
125 }
126 return true;
127 }
128}
Stream factory which enables the user to create streams without the knowledge of the concrete class.
Definition: Streams.php:32
download(string $file_id, string|null $filename_overwrite=null)
__construct(int $user_id, ?ObjectId $a_obj_id=null)
if(!file_exists('../ilias.ini.php'))