ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilMDCopyrightImageUploadHandlerGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
29
31{
33 protected Services $storage;
34 protected string $identification;
35
36 public function __construct(string $identification)
37 {
38 global $DIC;
39
40 $this->stakeholder = new ilMDCopyrightImageStakeholder();
41 $this->storage = $DIC->resourceStorage();
42 $this->identification = $identification;
43
45 }
46
47 protected function getUploadResult(): HandlerResult
48 {
49 $status = HandlerResult::STATUS_FAILED;
50 $new_identification = 'unknown';
51 $message = 'file upload failed';
52
53 $this->upload->process();
54 $uploadResults = $this->upload->getResults();
55 $result = end($uploadResults);
56
57 if ($result instanceof UploadResult && $result->isOK() && $result->getSize()) {
58 $resource_id = $this->storage->manage()->find($this->identification);
59 if (is_null($resource_id)) {
60 $new_identification = $this->storage->manage()->upload($result, $this->stakeholder)->serialize();
61 $status = HandlerResult::STATUS_OK;
62 $message = 'Upload ok';
63 } elseif ($this->identification !== '') {
64 $this->storage->manage()->replaceWithUpload($resource_id, $result, $this->stakeholder);
65 $new_identification = $this->identification;
66 $status = HandlerResult::STATUS_OK;
67 $message = 'Upload ok';
68 }
69 }
70 return new BasicHandlerResult(
72 $status,
73 $new_identification,
75 );
76 }
77
78 protected function getRemoveResult(string $identifier): HandlerResult
79 {
80 return new BasicHandlerResult(
82 HandlerResult::STATUS_OK,
83 $identifier,
84 'asynchronous removal blocked'
85 );
86 }
87
88 public function getInfoResult(string $identifier): ?FileInfoResult
89 {
90 if (null !== ($id = $this->storage->manage()->find($identifier))) {
91 $revision = $this->storage->manage()->getCurrentRevision($id)->getInformation();
92 $title = $revision->getTitle();
93 $size = $revision->getSize();
94 $mime = $revision->getMimeType();
95 } else {
96 $title = $mime = 'unknown';
97 $size = 0;
98 }
99
100 return new BasicFileInfoResult(
102 $identifier,
103 $title,
104 $size,
105 $mime
106 );
107 }
108
109 public function getInfoForExistingFiles(array $file_ids): array
110 {
111 $info_results = [];
112 foreach ($file_ids as $identifier) {
113 $info_results[] = $this->getInfoResult($identifier);
114 }
115
116 return $info_results;
117 }
118}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
global $DIC
Definition: shib_login.php:26
$message
Definition: xapiexit.php:31