ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
class.ilMDCopyrightImageUploadHandlerGUI.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
29 
34 {
36  protected Services $storage;
37  protected string $identification;
38 
39  public function __construct(string $identification)
40  {
41  global $DIC;
42 
43  $this->stakeholder = new ilMDCopyrightImageStakeholder();
44  $this->storage = $DIC->resourceStorage();
45  $this->identification = $identification;
46 
48  }
49 
50  protected function getUploadResult(): HandlerResult
51  {
52  $status = HandlerResult::STATUS_FAILED;
53  $new_identification = 'unknown';
54  $message = 'file upload failed';
55 
56  $this->upload->process();
57  $uploadResults = $this->upload->getResults();
58  $result = end($uploadResults);
59 
60  if ($result instanceof UploadResult && $result->isOK() && $result->getSize()) {
61  $resource_id = $this->storage->manage()->find($this->identification);
62  if (is_null($resource_id)) {
63  $new_identification = $this->storage->manage()->upload($result, $this->stakeholder)->serialize();
64  $status = HandlerResult::STATUS_OK;
65  $message = 'Upload ok';
66  } elseif ($this->identification !== '') {
67  $this->storage->manage()->replaceWithUpload($resource_id, $result, $this->stakeholder);
68  $new_identification = $this->identification;
69  $status = HandlerResult::STATUS_OK;
70  $message = 'Upload ok';
71  }
72  }
73  return new BasicHandlerResult(
75  $status,
76  $new_identification,
77  $message
78  );
79  }
80 
81  protected function getRemoveResult(string $identifier): HandlerResult
82  {
83  return new BasicHandlerResult(
85  HandlerResult::STATUS_OK,
86  $identifier,
87  'asynchronous removal blocked'
88  );
89  }
90 
91  public function getInfoResult(string $identifier): ?FileInfoResult
92  {
93  if (null !== ($id = $this->storage->manage()->find($identifier))) {
94  $revision = $this->storage->manage()->getCurrentRevision($id)->getInformation();
95  $title = $revision->getTitle();
96  $size = $revision->getSize();
97  $mime = $revision->getMimeType();
98  } else {
99  $title = $mime = 'unknown';
100  $size = 0;
101  }
102 
103  return new BasicFileInfoResult(
105  $identifier,
106  $title,
107  $size,
108  $mime
109  );
110  }
111 
112  public function getInfoForExistingFiles(array $file_ids): array
113  {
114  $info_results = [];
115  foreach ($file_ids as $identifier) {
116  $info_results[] = $this->getInfoResult($identifier);
117  }
118 
119  return $info_results;
120  }
121 }
global $DIC
Definition: feed.php:28
__construct(VocabulariesInterface $vocabularies)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
ilMDCopyrightImageUploadHandlerGUI: ilMDCopyrightSelectionGUI
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
$message
Definition: xapiexit.php:32