ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilSkillProfileUploadHandlerGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
26use ILIAS\FileUpload\Handler\HandlerResult as HandlerResultInterface;
27use ILIAS\ResourceStorage\Services as ResourceStorage;
28
37{
38 private ResourceStorage $storage;
40
41 public function __construct()
42 {
43 global $DIC;
45 $this->storage = $DIC['resource_storage'];
46 $this->stakeholder = new ilSkillProfileStorageStakeHolder();
47 }
48
49 protected function getUploadResult(): HandlerResultInterface
50 {
51 $this->upload->process();
55 $array = $this->upload->getResults();
56 $result = end($array);
57 if ($result instanceof UploadResult && $result->isOK()) {
58 $i = $this->storage->manage()->upload($result, $this->stakeholder);
59 $status = HandlerResultInterface::STATUS_OK;
60 $identifier = $i->serialize();
61 $message = 'Upload ok';
62 } else {
63 $status = HandlerResultInterface::STATUS_FAILED;
64 $identifier = '';
65 $message = $result->getStatus()->getMessage();
66 }
67
68 return new BasicHandlerResult($this->getFileIdentifierParameterName(), $status, $identifier, $message);
69 }
70
71 protected function getRemoveResult(string $identifier): HandlerResultInterface
72 {
73 $id = $this->storage->manage()->find($identifier);
74 if ($id !== null) {
75 $this->storage->manage()->remove($id, $this->stakeholder);
76
77 return new BasicHandlerResult($this->getFileIdentifierParameterName(), HandlerResultInterface::STATUS_OK, $identifier, 'file deleted');
78 } else {
79 return new BasicHandlerResult($this->getFileIdentifierParameterName(), HandlerResultInterface::STATUS_FAILED, $identifier, 'file not found');
80 }
81 }
82
83 public function getInfoResult(string $identifier): ?FileInfoResult
84 {
85 $id = $this->storage->manage()->find($identifier);
86 if ($id === null) {
87 return new BasicFileInfoResult($this->getFileIdentifierParameterName(), 'unknown', 'unknown', 0, 'unknown');
88 }
89 $r = $this->storage->manage()->getCurrentRevision($id)->getInformation();
90
91 return new BasicFileInfoResult(
93 $identifier,
94 $r->getTitle(),
95 $r->getSize(),
96 $r->getMimeType()
97 );
98 }
99
100 public function getInfoForExistingFiles(array $file_ids): array
101 {
102 $infos = [];
103 foreach ($file_ids as $file_id) {
104 $id = $this->storage->manage()->find($file_id);
105 if ($id === null) {
106 continue;
107 }
108 $r = $this->storage->manage()->getCurrentRevision($id)->getInformation();
109
110 $infos[] = new BasicFileInfoResult($this->getFileIdentifierParameterName(), $file_id, $r->getTitle(), $r->getSize(), $r->getMimeType());
111 }
112
113 return $infos;
114 }
115}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
Class ilSkillProfileUploadHandlerGUI.
__construct()
ilUIDemoFileUploadHandlerGUI constructor.
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
global $DIC
Definition: shib_login.php:26
$message
Definition: xapiexit.php:31