ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
class.ilIconUploadHandlerGUI.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
21 namespace ILIAS\File\Icon;
22 
32 
39 {
40  private Services $storage;
43  private Factory $refinery;
44 
48  public function __construct()
49  {
50  global $DIC;
52  $this->storage = $DIC->resourceStorage();
53  $this->wrapper = $DIC->http()->wrapper();
54  $this->refinery = $DIC->refinery();
55  $this->stakeholder = new ilObjFileIconStakeholder();
56  }
57 
61  protected function getUploadResult(): HandlerResult
62  {
63  $status = null;
64  $rid = null;
65  $message = null;
66  $this->upload->process();
70  $array = $this->upload->getResults();
71  $result = end($array);
72  $failed = false;
73  if ($result instanceof UploadResult && $result->isOK()) {
74  if ($this->wrapper->query()->has('rid')) { // entered when creating a new icon
75  $to_str = $this->refinery->to()->string();
76  $rid = $this->wrapper->query()->retrieve('rid', $to_str);
77  $id = $this->storage->manage()->find($rid);
78  if ($id !== null) {
79  $this->storage->manage()->appendNewRevision($id, $result, $this->stakeholder);
80  } else {
81  $failed = true;
82  }
83  } else { // entered when updating an existing icon
84  $i = $this->storage->manage()->upload($result, $this->stakeholder);
85  $rid = $i->serialize();
86  }
87  $status = HandlerResult::STATUS_OK;
88  $message = 'Upload ok';
89  } else {
90  $failed = true;
91  }
92 
93  if ($failed) {
95  $rid = '';
96  $message = $result->getStatus()->getMessage();
97  }
98 
99  return new BasicHandlerResult($this->getFileIdentifierParameterName(), $status, $rid, $message);
100  }
101 
102  protected function getRemoveResult(string $rid): HandlerResult
103  {
104  $id = $this->storage->manage()->find($rid);
105  if ($id !== null) {
106  $rev = $this->storage->manage()->getCurrentRevision($id);
107  $rev_num = $rev->getVersionNumber();
108  $this->storage->manage()->removeRevision($id, $rev_num);
109  return new BasicHandlerResult(
112  $rid,
113  'file deleted'
114  );
115  }
116  return new BasicHandlerResult(
119  $rid,
120  'file not found'
121  );
122  }
123 
124  public function getInfoResult(string $rid): ?FileInfoResult
125  {
126  $id = $this->storage->manage()->find($rid);
127  if (!$id instanceof \ILIAS\ResourceStorage\Identification\ResourceIdentification) {
128  return new BasicFileInfoResult($this->getFileIdentifierParameterName(), 'unknown', 'unknown', 0, 'unknown');
129  }
130  $r = $this->storage->manage()->getCurrentRevision($id)->getInformation();
131 
132  return new BasicFileInfoResult(
134  $rid,
135  $r->getTitle(),
136  $r->getSize(),
137  $r->getMimeType()
138  );
139  }
140 
144  public function getInfoForExistingFiles(array $resource_identifiers): array
145  {
146  $infos = [];
147  foreach ($resource_identifiers as $rid) {
148  $id = $this->storage->manage()->find($rid);
149  if (!$id instanceof \ILIAS\ResourceStorage\Identification\ResourceIdentification) {
150  continue;
151  }
152  $r = $this->storage->manage()->getCurrentRevision($id)->getInformation();
153 
154  $infos[] = new BasicFileInfoResult(
156  $rid,
157  $r->getTitle(),
158  $r->getSize(),
159  $r->getMimeType()
160  );
161  }
162 
163  return $infos;
164  }
165 }
Class ChatMainBarProvider .
global $DIC
Definition: feed.php:28
__construct(VocabulariesInterface $vocabularies)
__construct()
ilUIDemoFileUploadHandlerGUI constructor.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
$message
Definition: xapiexit.php:32
$r