ILIAS  release_10 Revision v10.1-43-ga1241a92c2f
class.ilSkillProfileUploadHandlerGUI.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
29 
38 {
41 
42  public function __construct()
43  {
44  global $DIC;
46  $this->storage = $DIC['resource_storage'];
47  $this->stakeholder = new ilSkillProfileStorageStakeHolder();
48  }
49 
50  protected function getUploadResult(): HandlerResultInterface
51  {
52  $this->upload->process();
56  $array = $this->upload->getResults();
57  $result = end($array);
58  if ($result instanceof UploadResult && $result->isOK()) {
59  $i = $this->storage->manage()->upload($result, $this->stakeholder);
60  $status = HandlerResultInterface::STATUS_OK;
61  $identifier = $i->serialize();
62  $message = 'Upload ok';
63  } else {
64  $status = HandlerResultInterface::STATUS_FAILED;
65  $identifier = '';
66  $message = $result->getStatus()->getMessage();
67  }
68 
69  return new BasicHandlerResult($this->getFileIdentifierParameterName(), $status, $identifier, $message);
70  }
71 
72  protected function getRemoveResult(string $identifier): HandlerResultInterface
73  {
74  $id = $this->storage->manage()->find($identifier);
75  if ($id !== null) {
76  $this->storage->manage()->remove($id, $this->stakeholder);
77 
78  return new BasicHandlerResult($this->getFileIdentifierParameterName(), HandlerResultInterface::STATUS_OK, $identifier, 'file deleted');
79  } else {
80  return new BasicHandlerResult($this->getFileIdentifierParameterName(), HandlerResultInterface::STATUS_FAILED, $identifier, 'file not found');
81  }
82  }
83 
84  public function getInfoResult(string $identifier): ?FileInfoResult
85  {
86  $id = $this->storage->manage()->find($identifier);
87  if ($id === null) {
88  return new BasicFileInfoResult($this->getFileIdentifierParameterName(), 'unknown', 'unknown', 0, 'unknown');
89  }
90  $r = $this->storage->manage()->getCurrentRevision($id)->getInformation();
91 
92  return new BasicFileInfoResult(
94  $identifier,
95  $r->getTitle(),
96  $r->getSize(),
97  $r->getMimeType()
98  );
99  }
100 
101  public function getInfoForExistingFiles(array $file_ids): array
102  {
103  $infos = [];
104  foreach ($file_ids as $file_id) {
105  $id = $this->storage->manage()->find($file_id);
106  if ($id === null) {
107  continue;
108  }
109  $r = $this->storage->manage()->getCurrentRevision($id)->getInformation();
110 
111  $infos[] = new BasicFileInfoResult($this->getFileIdentifierParameterName(), $file_id, $r->getTitle(), $r->getSize(), $r->getMimeType());
112  }
113 
114  return $infos;
115  }
116 }
Class ilSkillProfileUploadHandlerGUI.
Class ilSkillProfileStorageStakeHolder.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
global $DIC
Definition: shib_login.php:25
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:24
__construct(Container $dic, ilPlugin $plugin)
$r