ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
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)
 

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

ILIAS ResourceStorage Services $irss
 
ILIAS FileUpload FileUpload $upload
 
array $collection_cache = []
 
array $posting_cache = []
 
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 38 of file class.ilFileDataForumRCImplementation.php.

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

39  {
40  global $DIC;
41  $this->irss = $DIC->resourceStorage();
42  $this->upload = $DIC->upload();
43  $this->stakeholder = new ilForumPostingFileStakeholder();
44  }
global $DIC
Definition: feed.php:28
+ 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 143 of file class.ilFileDataForumRCImplementation.php.

References $stakeholder, and getPostingById().

143  : bool
144  {
145  if ($posting_ids_to_delete === null) {
146  return true;
147  }
148 
149  foreach ($posting_ids_to_delete as $post_id) {
150  $this->irss->collection()->remove(
151  $this->irss->collection()->id(
152  $this->getPostingById($post_id)->getRCID()
153  ),
155  true
156  );
157  }
158 
159  return true;
160  }
getPostingById(int $posting_id, bool $use_cache=true)
+ Here is the call graph for this function:

◆ deliverFile()

ilFileDataForumRCImplementation::deliverFile ( string  $file)

Implements ilFileDataForumInterface.

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

References getResourceIdByHash().

239  : void
240  {
241  $rid = $this->getResourceIdByHash($file);
242  if ($rid !== null) {
243  $this->irss->consume()->download($rid)->run();
244  }
245  }
+ Here is the call graph for this function:

◆ deliverZipFile()

ilFileDataForumRCImplementation::deliverZipFile ( )

Implements ilFileDataForumInterface.

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

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

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

◆ getCurrentCollection()

ilFileDataForumRCImplementation::getCurrentCollection ( )
private

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

References getCurrentPosting().

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

61  {
62  if (isset($this->collection_cache[$this->pos_id])) {
63  return $this->collection_cache[$this->pos_id];
64  }
65 
66  return $this->collection_cache[$this->pos_id] = $this->irss->collection()->get(
67  $this->irss->collection()->id(
68  $this->getCurrentPosting()->getRCID()
69  )
70  );
71  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getCurrentPosting()

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

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

References getPostingById().

Referenced by deliverZipFile(), getCurrentCollection(), and storeUploadedFiles().

46  : ilForumPost
47  {
48  return $this->getPostingById($this->pos_id, $use_cache);
49  }
getPostingById(int $posting_id, bool $use_cache=true)
+ 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 203 of file class.ilFileDataForumRCImplementation.php.

References getCurrentCollection().

203  : ?array
204  {
205  foreach ($this->getCurrentCollection()->getResourceIdentifications() as $identification) {
206  $revision = $this->irss->manage()->getCurrentRevision($identification);
207  if ($revision->getTitle() === $hashed_filename) {
208  $info = $revision->getInformation();
209  return [
210  'path' => '',
211  'filename' => $info->getTitle(),
212  'clean_filename' => $info->getTitle()
213  ];
214  }
215  }
216 
217  return null;
218  }
+ 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 108 of file class.ilFileDataForumRCImplementation.php.

References getCurrentCollection().

108  : array
109  {
110  $files = [];
111  foreach ($this->getCurrentCollection()->getResourceIdentifications() as $identification) {
112  $revision = $this->irss->manage()->getCurrentRevision($identification);
113  $info = $revision->getInformation();
114  $files[$info->getTitle()] = [
115  'path' => $this->irss->consume()->stream($identification)->getStream()->getMetadata('uri'),
116  'md5' => $revision->getTitle(),
117  'name' => $info->getTitle(),
118  'size' => $info->getSize(),
119  'ctime' => $info->getCreationDate()->format('Y-m-d H:i:s')
120  ];
121  }
122 
123  return $files;
124  }
+ Here is the call graph for this function:

◆ getForumPath()

ilFileDataForumRCImplementation::getForumPath ( )

Implements ilFileDataForumInterface.

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

100  : string
101  {
102  return self::FORUM_PATH_RCID;
103  }

◆ getObjId()

ilFileDataForumRCImplementation::getObjId ( )

Implements ilFileDataForumInterface.

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

85  : int
86  {
87  return $this->obj_id;
88  }

◆ getPosId()

ilFileDataForumRCImplementation::getPosId ( )

Implements ilFileDataForumInterface.

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

90  : int
91  {
92  return $this->pos_id;
93  }

◆ getPostingById()

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

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

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

51  : ilForumPost
52  {
53  if ($use_cache && isset($this->posting_cache[$posting_id])) {
54  return $this->posting_cache[$posting_id];
55  }
56 
57  return $this->posting_cache[$posting_id] = new ilForumPost($posting_id);
58  }
+ Here is the caller graph for this function:

◆ getResourceIdByHash()

ilFileDataForumRCImplementation::getResourceIdByHash ( string  $hash)
private

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

References getCurrentCollection().

Referenced by deliverFile(), and unlinkFilesByMD5Filenames().

74  {
75  foreach ($this->getCurrentCollection()->getResourceIdentifications() as $identification) {
76  $revision = $this->irss->manage()->getCurrentRevision($identification);
77  if ($revision->getTitle() === $hash) {
78  return $identification;
79  }
80  }
81 
82  return null;
83  }
+ 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 132 of file class.ilFileDataForumRCImplementation.php.

References getCurrentCollection(), and getPostingById().

132  : bool
133  {
134  $current_collection_id = $this->getCurrentCollection()->getIdentification();
135  $new_collection_id = $this->irss->collection()->clone($current_collection_id);
136  $new_posting = $this->getPostingById($new_posting_id);
137  $new_posting->setRCID($new_collection_id->serialize());
138  $new_posting->update();
139 
140  return true;
141  }
getPostingById(int $posting_id, bool $use_cache=true)
+ Here is the call graph for this function:

◆ importFileToCollection()

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

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

References ilForumPost\getRCID(), ilForumPost\NO_RCID, ilForumPost\setRCID(), and ilForumPost\update().

262  : void
263  {
264  if ($post->getRCID() === ilForumPost::NO_RCID || empty($post->getRCID())) {
265  $rcid = $this->irss->collection()->id();
266  $post->setRCID($rcid->serialize());
267  $post->update();
268  } else {
269  $rcid = $this->irss->collection()->id($post->getRCID());
270  }
271 
272  $collection = $this->irss->collection()->get($rcid);
273  $rid = $this->irss->manage()->stream(
274  Streams::ofResource(fopen($path_to_file, 'rb')),
275  $this->stakeholder,
276  md5(basename($path_to_file))
277  );
278  $collection->add($rid);
279  $this->irss->collection()->store($collection);
280  }
setRCID(string $rcid)
+ Here is the call graph for this function:

◆ moveFilesOfPost()

ilFileDataForumRCImplementation::moveFilesOfPost ( int  $new_frm_id = 0)

Implements ilFileDataForumInterface.

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

126  : bool
127  {
128  // nothing to do here since collections are related to the post
129  return true;
130  }

◆ setPosId()

ilFileDataForumRCImplementation::setPosId ( int  $posting_id)

Implements ilFileDataForumInterface.

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

95  : void
96  {
97  $this->pos_id = $posting_id;
98  }

◆ storeUploadedFiles()

ilFileDataForumRCImplementation::storeUploadedFiles ( )

Implements ilFileDataForumInterface.

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

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

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

◆ unlinkFile()

ilFileDataForumRCImplementation::unlinkFile ( string  $filename)

Implements ilFileDataForumInterface.

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

References getCurrentCollection().

188  : bool
189  {
190  foreach ($this->getCurrentCollection()->getResourceIdentifications() as $identification) {
191  $revision = $this->irss->manage()->getCurrentRevision($identification);
192  if ($revision->getTitle() === md5($filename)) {
193  $this->irss->manage()->remove($identification, $this->stakeholder);
194  }
195  }
196 
197  return true;
198  }
$filename
Definition: buildRTE.php:78
+ 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 223 of file class.ilFileDataForumRCImplementation.php.

References getResourceIdByHash().

223  : bool
224  {
225  $hashes = is_array($hashed_filename_or_filenames)
226  ? $hashed_filename_or_filenames
227  : [$hashed_filename_or_filenames];
228 
229  foreach ($hashes as $hash) {
230  $identification = $this->getResourceIdByHash($hash);
231  if ($identification !== null) {
232  $this->irss->manage()->remove($identification, $this->stakeholder);
233  }
234  }
235 
236  return true;
237  }
+ 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

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

ilForumPostingFileStakeholder ilFileDataForumRCImplementation::$stakeholder
private

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

Referenced by delete().

◆ $upload

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.


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