ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
ilFileDataForumDraftsRCImplementation Class Reference
+ Inheritance diagram for ilFileDataForumDraftsRCImplementation:
+ Collaboration diagram for ilFileDataForumDraftsRCImplementation:

Public Member Functions

 __construct (private readonly int $obj_id=0, private int $draft_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 ()
 

Data Fields

const FORUM_PATH_RCID = 'RCID'
 

Private Member Functions

 getCurrentDraft (bool $use_cache=true)
 
 getDraftById (int $draft_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

Constructor & Destructor Documentation

◆ __construct()

ilFileDataForumDraftsRCImplementation::__construct ( private readonly int  $obj_id = 0,
private int  $draft_id = 0 
)

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

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

38  {
39  global $DIC;
40  $this->irss = $DIC->resourceStorage();
41  $this->upload = $DIC->upload();
42  $this->stakeholder = new ilForumPostingFileStakeholder();
43  }
global $DIC
Definition: feed.php:28
+ Here is the call graph for this function:

Member Function Documentation

◆ delete()

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

Implements ilFileDataForumInterface.

Definition at line 142 of file class.ilFileDataForumDraftsRCImplementation.php.

References $stakeholder, and getDraftById().

142  : bool
143  {
144  // Each element of $posting_ids_to_delete represents a "Draft Id", NOT a "Posting Id"
145  if ($posting_ids_to_delete === null) {
146  return true;
147  }
148 
149  foreach ($posting_ids_to_delete as $draft_id) {
150  $this->irss->collection()->remove(
151  $this->irss->collection()->id(
152  $this->getDraftById($draft_id)->getRCID()
153  ),
155  true
156  );
157  }
158 
159  return true;
160  }
+ Here is the call graph for this function:

◆ deliverFile()

ilFileDataForumDraftsRCImplementation::deliverFile ( string  $file)

Implements ilFileDataForumInterface.

Definition at line 231 of file class.ilFileDataForumDraftsRCImplementation.php.

References getResourceIdByHash().

231  : void
232  {
233  $rid = $this->getResourceIdByHash($file);
234  if ($rid !== null) {
235  $this->irss->consume()->download($rid)->run();
236  }
237  }
+ Here is the call graph for this function:

◆ deliverZipFile()

ilFileDataForumDraftsRCImplementation::deliverZipFile ( )

Implements ilFileDataForumInterface.

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

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

239  : bool
240  {
241  // https://mantis.ilias.de/view.php?id=39910
243  $this->getCurrentDraft()->getPostSubject() . '.zip'
244  );
245  $rcid = $this->getCurrentCollection()->getIdentification();
246 
247  $this->irss->consume()->downloadCollection($rcid, $zip_filename)
248  ->useRevisionTitlesForFileNames(false)
249  ->run();
250 
251  return true;
252  }
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()

ilFileDataForumDraftsRCImplementation::getCurrentCollection ( )
private

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

References getCurrentDraft().

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

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

◆ getCurrentDraft()

ilFileDataForumDraftsRCImplementation::getCurrentDraft ( bool  $use_cache = true)
private

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

References getDraftById().

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

46  {
47  return $this->getDraftById($this->draft_id, $use_cache);
48  }
Class ilForumPostDraft.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getDraftById()

ilFileDataForumDraftsRCImplementation::getDraftById ( int  $draft_id,
bool  $use_cache = true 
)
private

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

References ilForumPostDraft\newInstanceByDraftId().

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

51  {
52  if ($use_cache && isset($this->posting_cache[$draft_id])) {
53  return $this->posting_cache[$draft_id];
54  }
55 
56  return $this->posting_cache[$draft_id] = ilForumPostDraft::newInstanceByDraftId($draft_id);
57  }
Class ilForumPostDraft.
static newInstanceByDraftId(int $draft_id)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getFileDataByMD5Filename()

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

Implements ilFileDataForumInterface.

Definition at line 196 of file class.ilFileDataForumDraftsRCImplementation.php.

References getCurrentCollection().

196  : ?array
197  {
198  foreach ($this->getCurrentCollection()->getResourceIdentifications() as $identification) {
199  $revision = $this->irss->manage()->getCurrentRevision($identification);
200  if ($revision->getTitle() === $hashed_filename) {
201  $info = $revision->getInformation();
202  return [
203  'path' => '',
204  'filename' => $info->getTitle(),
205  'clean_filename' => $info->getTitle()
206  ];
207  }
208  }
209 
210  return null;
211  }
+ Here is the call graph for this function:

◆ getFilesOfPost()

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

Implements ilFileDataForumInterface.

Definition at line 107 of file class.ilFileDataForumDraftsRCImplementation.php.

References getCurrentCollection().

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

◆ getForumPath()

ilFileDataForumDraftsRCImplementation::getForumPath ( )

Implements ilFileDataForumInterface.

Definition at line 99 of file class.ilFileDataForumDraftsRCImplementation.php.

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

◆ getObjId()

ilFileDataForumDraftsRCImplementation::getObjId ( )

Implements ilFileDataForumInterface.

Definition at line 84 of file class.ilFileDataForumDraftsRCImplementation.php.

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

◆ getPosId()

ilFileDataForumDraftsRCImplementation::getPosId ( )

Implements ilFileDataForumInterface.

Definition at line 89 of file class.ilFileDataForumDraftsRCImplementation.php.

89  : int
90  {
91  return $this->draft_id;
92  }

◆ getResourceIdByHash()

ilFileDataForumDraftsRCImplementation::getResourceIdByHash ( string  $hash)
private

Definition at line 72 of file class.ilFileDataForumDraftsRCImplementation.php.

References getCurrentCollection().

Referenced by deliverFile(), and unlinkFilesByMD5Filenames().

73  {
74  foreach ($this->getCurrentCollection()->getResourceIdentifications() as $identification) {
75  $revision = $this->irss->manage()->getCurrentRevision($identification);
76  if ($revision->getTitle() === $hash) {
77  return $identification;
78  }
79  }
80 
81  return null;
82  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ilClone()

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

Implements ilFileDataForumInterface.

Definition at line 131 of file class.ilFileDataForumDraftsRCImplementation.php.

References getCurrentCollection(), and getDraftById().

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

◆ moveFilesOfPost()

ilFileDataForumDraftsRCImplementation::moveFilesOfPost ( int  $new_frm_id = 0)

Implements ilFileDataForumInterface.

Definition at line 125 of file class.ilFileDataForumDraftsRCImplementation.php.

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

◆ setPosId()

ilFileDataForumDraftsRCImplementation::setPosId ( int  $posting_id)

Implements ilFileDataForumInterface.

Definition at line 94 of file class.ilFileDataForumDraftsRCImplementation.php.

94  : void
95  {
96  $this->draft_id = $posting_id;
97  }

◆ storeUploadedFiles()

ilFileDataForumDraftsRCImplementation::storeUploadedFiles ( )

Implements ilFileDataForumInterface.

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

References getCurrentCollection(), getCurrentDraft(), 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  $draft = $this->getCurrentDraft(false);
182  $draft->setRCID($collection->getIdentification()->serialize());
183  $draft->update();
184 
185  return true;
186  }
+ Here is the call graph for this function:

◆ unlinkFile()

ilFileDataForumDraftsRCImplementation::unlinkFile ( string  $filename)

Implements ilFileDataForumInterface.

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

188  : bool
189  {
190  throw new DomainException('Not implemented');
191  }

◆ unlinkFilesByMD5Filenames()

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

Implements ilFileDataForumInterface.

Definition at line 216 of file class.ilFileDataForumDraftsRCImplementation.php.

References getResourceIdByHash().

216  : bool
217  {
218  $hashes = is_array($hashed_filename_or_filenames)
219  ? $hashed_filename_or_filenames
220  : [$hashed_filename_or_filenames];
221 
222  foreach ($hashes as $hash) {
223  $identification = $this->getResourceIdByHash($hash);
224  if ($identification !== null) {
225  $this->irss->manage()->remove($identification, $this->stakeholder);
226  }
227  }
228  return true;
229  }
+ Here is the call graph for this function:

Field Documentation

◆ $collection_cache

array ilFileDataForumDraftsRCImplementation::$collection_cache = []
private

◆ $irss

ILIAS ResourceStorage Services ilFileDataForumDraftsRCImplementation::$irss
private

◆ $posting_cache

array ilFileDataForumDraftsRCImplementation::$posting_cache = []
private

◆ $stakeholder

ilForumPostingFileStakeholder ilFileDataForumDraftsRCImplementation::$stakeholder
private

Definition at line 33 of file class.ilFileDataForumDraftsRCImplementation.php.

Referenced by delete().

◆ $upload

ILIAS FileUpload FileUpload ilFileDataForumDraftsRCImplementation::$upload
private

◆ FORUM_PATH_RCID

const ilFileDataForumDraftsRCImplementation::FORUM_PATH_RCID = 'RCID'

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