ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ilFileDataForumRCImplementation Class Reference
+ Inheritance diagram for ilFileDataForumRCImplementation:
+ Collaboration diagram for ilFileDataForumRCImplementation:

Public Member Functions

 __construct (private readonly int $obj_id=0, private int $pos_id=0)
 
 getObjId ()
 
 getPosId ()
 
 setPosId (int $posting_id)
 
 getForumPath ()
 
 getFilesOfPost ()
 
 moveFilesOfPost (int $new_frm_id=0)
 
 ilClone (int $new_obj_id, int $new_posting_id)
 
 delete (?array $posting_ids_to_delete=null)
 
 storeUploadedFiles ()
 
 unlinkFile (string $filename)
 
 getFileDataByMD5Filename (string $hashed_filename)
 
 unlinkFilesByMD5Filenames ($hashed_filename_or_filenames)
 
 deliverFile (string $file)
 
 deliverZipFile ()
 
 importFileToCollection (string $path_to_file, ilForumPost $post)
 
 getObjId ()
 
 getPosId ()
 
 setPosId (int $posting_id)
 
 getForumPath ()
 
 getFilesOfPost ()
 
 moveFilesOfPost (int $new_frm_id=0)
 
 ilClone (int $new_obj_id, int $new_posting_id)
 
 delete (?array $posting_ids_to_delete=null)
 
 storeUploadedFiles ()
 
 unlinkFile (string $filename)
 
 getFileDataByMD5Filename (string $hashed_filename)
 
 unlinkFilesByMD5Filenames ($hashed_filename_or_filenames)
 
 deliverFile (string $file)
 
 deliverZipFile ()
 

Data Fields

const FORUM_PATH_RCID = 'RCID'
 

Private Member Functions

 getCurrentPosting (bool $use_cache=true)
 
 getPostingById (int $posting_id, bool $use_cache=true)
 
 getCurrentCollection ()
 
 getResourceIdByHash (string $hash)
 

Private Attributes

readonly ILIAS ResourceStorage Services $irss
 
readonly ILIAS FileUpload FileUpload $upload
 
array $collection_cache = []
 
array $posting_cache = []
 
readonly ilForumPostingFileStakeholder $stakeholder
 

Detailed Description

Definition at line 25 of file class.ilFileDataForumRCImplementation.php.

Constructor & Destructor Documentation

◆ __construct()

ilFileDataForumRCImplementation::__construct ( private readonly int  $obj_id = 0,
private int  $pos_id = 0 
)

Definition at line 37 of file class.ilFileDataForumRCImplementation.php.

38 {
39 global $DIC;
40 $this->irss = $DIC->resourceStorage();
41 $this->upload = $DIC->upload();
42 $this->stakeholder = new ilForumPostingFileStakeholder();
43 }
global $DIC
Definition: shib_login.php:26

References $DIC, and ILIAS\Repository\upload().

+ Here is the call graph for this function:

Member Function Documentation

◆ delete()

ilFileDataForumRCImplementation::delete ( ?array  $posting_ids_to_delete = null)
Parameters
list<int>|null$posting_ids_to_delete

Implements ilFileDataForumInterface.

Definition at line 139 of file class.ilFileDataForumRCImplementation.php.

139 : bool
140 {
141 if ($posting_ids_to_delete === null) {
142 return true;
143 }
144
145 foreach ($posting_ids_to_delete as $post_id) {
146 $this->irss->collection()->remove(
147 $this->irss->collection()->id(
148 $this->getPostingById($post_id)->getRCID()
149 ),
150 $this->stakeholder,
151 true
152 );
153 }
154
155 return true;
156 }

References $stakeholder, getPostingById(), and true.

+ Here is the call graph for this function:

◆ deliverFile()

ilFileDataForumRCImplementation::deliverFile ( string  $file)

Implements ilFileDataForumInterface.

Definition at line 235 of file class.ilFileDataForumRCImplementation.php.

235 : void
236 {
237 $rid = $this->getResourceIdByHash($file);
238 if ($rid !== null) {
239 $this->irss->consume()->download($rid)->run();
240 }
241 }

References getResourceIdByHash().

+ Here is the call graph for this function:

◆ deliverZipFile()

ilFileDataForumRCImplementation::deliverZipFile ( )

Implements ilFileDataForumInterface.

Definition at line 243 of file class.ilFileDataForumRCImplementation.php.

243 : bool
244 {
245 // https://mantis.ilias.de/view.php?id=39910
247 $this->getCurrentPosting()->getSubject() . '.zip'
248 );
249 $rcid = $this->getCurrentCollection()->getIdentification();
250
251 $this->irss
252 ->consume()
253 ->downloadCollection($rcid, $zip_filename)
254 ->useRevisionTitlesForFileNames(false)
255 ->run();
256
257 return true;
258 }
static returnASCIIFileName(string $original_filename)
Converts a UTF-8 filename to ASCII.
Definition: Delivery.php:513

References getCurrentCollection(), getCurrentPosting(), and ILIAS\FileDelivery\Delivery\returnASCIIFileName().

+ Here is the call graph for this function:

◆ getCurrentCollection()

ilFileDataForumRCImplementation::getCurrentCollection ( )
private

Definition at line 59 of file class.ilFileDataForumRCImplementation.php.

60 {
61 return $this->collection_cache[$this->pos_id] ?? ($this->collection_cache[$this->pos_id] = $this->irss->collection(
62 )->get(
63 $this->irss->collection()->id(
64 $this->getCurrentPosting()->getRCID()
65 )
66 ));
67 }

Referenced by deliverZipFile(), getFileDataByMD5Filename(), getFilesOfPost(), getResourceIdByHash(), ilClone(), storeUploadedFiles(), and unlinkFile().

+ Here is the caller graph for this function:

◆ getCurrentPosting()

ilFileDataForumRCImplementation::getCurrentPosting ( bool  $use_cache = true)
private

Definition at line 45 of file class.ilFileDataForumRCImplementation.php.

46 {
47 return $this->getPostingById($this->pos_id, $use_cache);
48 }
getPostingById(int $posting_id, bool $use_cache=true)

References getPostingById().

Referenced by deliverZipFile(), and storeUploadedFiles().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getFileDataByMD5Filename()

ilFileDataForumRCImplementation::getFileDataByMD5Filename ( string  $hashed_filename)
Returns
array{path: string, filename: string, clean_filename: string}|null

Implements ilFileDataForumInterface.

Definition at line 199 of file class.ilFileDataForumRCImplementation.php.

199 : ?array
200 {
201 foreach ($this->getCurrentCollection()->getResourceIdentifications() as $identification) {
202 $revision = $this->irss->manage()->getCurrentRevision($identification);
203 if ($revision->getTitle() === $hashed_filename) {
204 $info = $revision->getInformation();
205 return [
206 'path' => '',
207 'filename' => $info->getTitle(),
208 'clean_filename' => $info->getTitle()
209 ];
210 }
211 }
212
213 return null;
214 }
$info
Definition: entry_point.php:21

References $info, and getCurrentCollection().

+ Here is the call graph for this function:

◆ getFilesOfPost()

ilFileDataForumRCImplementation::getFilesOfPost ( )
Returns
array<string, array{path: string, md5: string, name: string, size: int, ctime: string}>

Implements ilFileDataForumInterface.

Definition at line 104 of file class.ilFileDataForumRCImplementation.php.

104 : array
105 {
106 $files = [];
107 foreach ($this->getCurrentCollection()->getResourceIdentifications() as $identification) {
108 $revision = $this->irss->manage()->getCurrentRevision($identification);
109 $info = $revision->getInformation();
110 $files[$info->getTitle()] = [
111 'path' => $this->irss->consume()->stream($identification)->getStream()->getMetadata('uri'),
112 'md5' => $revision->getTitle(),
113 'name' => $info->getTitle(),
114 'size' => $info->getSize(),
115 'ctime' => $info->getCreationDate()->format('Y-m-d H:i:s')
116 ];
117 }
118
119 return $files;
120 }

References $info, and getCurrentCollection().

+ Here is the call graph for this function:

◆ getForumPath()

ilFileDataForumRCImplementation::getForumPath ( )

◆ getObjId()

ilFileDataForumRCImplementation::getObjId ( )

Implements ilFileDataForumInterface.

Definition at line 81 of file class.ilFileDataForumRCImplementation.php.

81 : int
82 {
83 return $this->obj_id;
84 }

◆ getPosId()

ilFileDataForumRCImplementation::getPosId ( )

Implements ilFileDataForumInterface.

Definition at line 86 of file class.ilFileDataForumRCImplementation.php.

86 : int
87 {
88 return $this->pos_id;
89 }

◆ getPostingById()

ilFileDataForumRCImplementation::getPostingById ( int  $posting_id,
bool  $use_cache = true 
)
private

Definition at line 50 of file class.ilFileDataForumRCImplementation.php.

51 {
52 if ($use_cache && isset($this->posting_cache[$posting_id])) {
53 return $this->posting_cache[$posting_id];
54 }
55
56 return $this->posting_cache[$posting_id] = new ilForumPost($posting_id);
57 }

Referenced by delete(), getCurrentPosting(), and ilClone().

+ Here is the caller graph for this function:

◆ getResourceIdByHash()

ilFileDataForumRCImplementation::getResourceIdByHash ( string  $hash)
private

Definition at line 69 of file class.ilFileDataForumRCImplementation.php.

70 {
71 foreach ($this->getCurrentCollection()->getResourceIdentifications() as $identification) {
72 $revision = $this->irss->manage()->getCurrentRevision($identification);
73 if ($revision->getTitle() === $hash) {
74 return $identification;
75 }
76 }
77
78 return null;
79 }

References getCurrentCollection().

Referenced by deliverFile(), and unlinkFilesByMD5Filenames().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ilClone()

ilFileDataForumRCImplementation::ilClone ( int  $new_obj_id,
int  $new_posting_id 
)

Implements ilFileDataForumInterface.

Definition at line 128 of file class.ilFileDataForumRCImplementation.php.

128 : bool
129 {
130 $current_collection_id = $this->getCurrentCollection()->getIdentification();
131 $new_collection_id = $this->irss->collection()->clone($current_collection_id);
132 $new_posting = $this->getPostingById($new_posting_id);
133 $new_posting->setRCID($new_collection_id->serialize());
134 $new_posting->update();
135
136 return true;
137 }

References getCurrentCollection(), and getPostingById().

+ Here is the call graph for this function:

◆ importFileToCollection()

ilFileDataForumRCImplementation::importFileToCollection ( string  $path_to_file,
ilForumPost  $post 
)

Definition at line 260 of file class.ilFileDataForumRCImplementation.php.

260 : void
261 {
262 if ($post->getRCID() === ilForumPost::NO_RCID || empty($post->getRCID())) {
263 $rcid = $this->irss->collection()->id();
264 $post->setRCID($rcid->serialize());
265 $post->update();
266 } else {
267 $rcid = $this->irss->collection()->id($post->getRCID());
268 }
269
270 $collection = $this->irss->collection()->get($rcid);
271 $rid = $this->irss->manage()->stream(
272 Streams::ofResource(fopen($path_to_file, 'rb')),
273 $this->stakeholder,
274 md5(basename($path_to_file))
275 );
276 $collection->add($rid);
277 $this->irss->collection()->store($collection);
278 }
$post
Definition: ltitoken.php:46

References $post, and ilForumPost\NO_RCID.

◆ moveFilesOfPost()

ilFileDataForumRCImplementation::moveFilesOfPost ( int  $new_frm_id = 0)

Implements ilFileDataForumInterface.

Definition at line 122 of file class.ilFileDataForumRCImplementation.php.

122 : bool
123 {
124 // nothing to do here since collections are related to the post
125 return true;
126 }

◆ setPosId()

ilFileDataForumRCImplementation::setPosId ( int  $posting_id)

Implements ilFileDataForumInterface.

Definition at line 91 of file class.ilFileDataForumRCImplementation.php.

91 : void
92 {
93 $this->pos_id = $posting_id;
94 }

◆ storeUploadedFiles()

ilFileDataForumRCImplementation::storeUploadedFiles ( )

Implements ilFileDataForumInterface.

Definition at line 158 of file class.ilFileDataForumRCImplementation.php.

158 : bool
159 {
160 if (!$this->upload->hasBeenProcessed()) {
161 $this->upload->process();
162 }
163 $collection = $this->getCurrentCollection();
164
165 foreach ($this->upload->getResults() as $result) {
166 if (!$result->isOK()) {
167 continue;
168 }
169 $rid = $this->irss->manage()->upload(
170 $result,
171 $this->stakeholder,
172 md5($result->getName())
173 );
174 $collection->add($rid);
175 }
176 $this->irss->collection()->store($collection);
177 $posting = $this->getCurrentPosting(false);
178 $posting->setRCID($collection->getIdentification()->serialize());
179 $posting->update();
180
181 return true;
182 }

References getCurrentCollection(), getCurrentPosting(), and ILIAS\Repository\upload().

+ Here is the call graph for this function:

◆ unlinkFile()

ilFileDataForumRCImplementation::unlinkFile ( string  $filename)

Implements ilFileDataForumInterface.

Definition at line 184 of file class.ilFileDataForumRCImplementation.php.

184 : bool
185 {
186 foreach ($this->getCurrentCollection()->getResourceIdentifications() as $identification) {
187 $revision = $this->irss->manage()->getCurrentRevision($identification);
188 if ($revision->getTitle() === md5($filename)) {
189 $this->irss->manage()->remove($identification, $this->stakeholder);
190 }
191 }
192
193 return true;
194 }
$filename
Definition: buildRTE.php:78

References $filename, and getCurrentCollection().

+ Here is the call graph for this function:

◆ unlinkFilesByMD5Filenames()

ilFileDataForumRCImplementation::unlinkFilesByMD5Filenames (   $hashed_filename_or_filenames)
Parameters
string | string[]$hashed_filename_or_filenames

Implements ilFileDataForumInterface.

Definition at line 219 of file class.ilFileDataForumRCImplementation.php.

219 : bool
220 {
221 $hashes = is_array($hashed_filename_or_filenames)
222 ? $hashed_filename_or_filenames
223 : [$hashed_filename_or_filenames];
224
225 foreach ($hashes as $hash) {
226 $identification = $this->getResourceIdByHash($hash);
227 if ($identification !== null) {
228 $this->irss->manage()->remove($identification, $this->stakeholder);
229 }
230 }
231
232 return true;
233 }

References getResourceIdByHash().

+ Here is the call graph for this function:

Field Documentation

◆ $collection_cache

array ilFileDataForumRCImplementation::$collection_cache = []
private

Definition at line 32 of file class.ilFileDataForumRCImplementation.php.

◆ $irss

readonly ILIAS ResourceStorage Services ilFileDataForumRCImplementation::$irss
private

Definition at line 29 of file class.ilFileDataForumRCImplementation.php.

◆ $posting_cache

array ilFileDataForumRCImplementation::$posting_cache = []
private

Definition at line 34 of file class.ilFileDataForumRCImplementation.php.

◆ $stakeholder

readonly ilForumPostingFileStakeholder ilFileDataForumRCImplementation::$stakeholder
private

Definition at line 35 of file class.ilFileDataForumRCImplementation.php.

Referenced by delete().

◆ $upload

readonly ILIAS FileUpload FileUpload ilFileDataForumRCImplementation::$upload
private

Definition at line 30 of file class.ilFileDataForumRCImplementation.php.

◆ FORUM_PATH_RCID

const ilFileDataForumRCImplementation::FORUM_PATH_RCID = 'RCID'

Definition at line 27 of file class.ilFileDataForumRCImplementation.php.

Referenced by getForumPath().


The documentation for this class was generated from the following file: