ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilIconUploadHandlerGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
33
40{
45
49 public function __construct()
50 {
51 global $DIC;
53 $this->storage = $DIC->resourceStorage();
54 $this->wrapper = $DIC->http()->wrapper();
55 $this->refinery = $DIC->refinery();
56 $this->stakeholder = new ilObjFileIconStakeholder();
57 }
58
62 protected function getUploadResult(): HandlerResult
63 {
64 $status = null;
65 $rid = null;
66 $message = null;
67 $this->upload->process();
71 $array = $this->upload->getResults();
72 $result = end($array);
73 $failed = false;
74 if ($result instanceof UploadResult && $result->isOK()) {
75 if ($this->wrapper->query()->has('rid')) { // entered when creating a new icon
76 $to_str = $this->refinery->to()->string();
77 $rid = $this->wrapper->query()->retrieve('rid', $to_str);
78 $id = $this->storage->manage()->find($rid);
79 if ($id !== null) {
80 $this->storage->manage()->appendNewRevision($id, $result, $this->stakeholder);
81 } else {
82 $failed = true;
83 }
84 } else { // entered when updating an existing icon
85 $i = $this->storage->manage()->upload($result, $this->stakeholder);
86 $rid = $i->serialize();
87 }
89 $message = 'Upload ok';
90 } else {
91 $failed = true;
92 }
93
94 if ($failed) {
96 $rid = '';
97 $message = $result->getStatus()->getMessage();
98 }
99
100 return new BasicHandlerResult($this->getFileIdentifierParameterName(), $status, $rid, $message);
101 }
102
103 protected function getRemoveResult(string $rid): HandlerResult
104 {
105 $id = $this->storage->manage()->find($rid);
106 if ($id !== null) {
107 $rev = $this->storage->manage()->getCurrentRevision($id);
108 $rev_num = $rev->getVersionNumber();
109 $this->storage->manage()->removeRevision($id, $rev_num);
110 return new BasicHandlerResult(
113 $rid,
114 'file deleted'
115 );
116 }
117 return new BasicHandlerResult(
120 $rid,
121 'file not found'
122 );
123 }
124
125 public function getInfoResult(string $rid): ?FileInfoResult
126 {
127 $id = $this->storage->manage()->find($rid);
128 if (!$id instanceof ResourceIdentification) {
129 return new BasicFileInfoResult($this->getFileIdentifierParameterName(), 'unknown', 'unknown', 0, 'unknown');
130 }
131 $r = $this->storage->manage()->getCurrentRevision($id)->getInformation();
132
133 return new BasicFileInfoResult(
135 $rid,
136 $r->getTitle(),
137 $r->getSize(),
138 $r->getMimeType()
139 );
140 }
141
145 public function getInfoForExistingFiles(array $resource_identifiers): array
146 {
147 $infos = [];
148 foreach ($resource_identifiers as $rid) {
149 $id = $this->storage->manage()->find($rid);
150 if (!$id instanceof ResourceIdentification) {
151 continue;
152 }
153 $r = $this->storage->manage()->getCurrentRevision($id)->getInformation();
154
155 $infos[] = new BasicFileInfoResult(
157 $rid,
158 $r->getTitle(),
159 $r->getSize(),
160 $r->getMimeType()
161 );
162 }
163
164 return $infos;
165 }
166}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
Builds a Color from either hex- or rgb values.
Definition: Factory.php:31
Builds data types.
Definition: Factory.php:36
__construct()
ilUIDemoFileUploadHandlerGUI constructor.
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
global $DIC
Definition: shib_login.php:26
$message
Definition: xapiexit.php:31