ILIAS  trunk Revision v11.0_alpha-2638-g80c1d007f79
class.CustomIconUploadHandlerGUI.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
31 
37 {
39 
40  protected \ilLanguage $language;
41  protected bool $has_access = false;
42 
43  public function __construct(
44  protected ?Custom $custom_icon = null
45  ) {
47  global $DIC;
48  $this->language = $DIC->language();
49 
50  $ref_id = null;
51  if ($DIC->http()->wrapper()->query()->has('ref_id')) {
52  $transformation = $DIC->refinery()->kindlyTo()->int();
53  $ref_id = $DIC->http()->wrapper()->query()->retrieve('ref_id', $transformation);
54  }
55 
56  $this->has_access = $this->getAccess(
57  $ref_id,
58  $DIC->access()
59  );
60 
61  $DIC->ctrl()->setParameterByClass(self::class, 'ref_id', $ref_id);
62 
64  }
65 
69  protected function getUploadResult(): HandlerResult
70  {
71  $tempfile = '';
72  if ($this->has_access === false) {
73  return $this->getAccessFailureResult(
75  $tempfile,
76  $this->language
77  );
78  }
79 
80  $this->upload->process();
81 
82  $result_array = $this->upload->getResults();
83  $result = end($result_array);
84 
85  if ($result instanceof UploadResult
86  && in_array($result->getMimeType(), Icon::SUPPORTED_MIME_TYPES)
87  && $result->isOK()) {
88  $status = HandlerResult::STATUS_OK;
89  $message = 'Upload ok';
90  $tempfile = \ilFileUtils::ilTempnam();
91  rename($result->getPath(), $tempfile);
92  } else {
93  $status = HandlerResult::STATUS_FAILED;
94  $message = $result->getStatus()->getMessage();
95  }
96 
97  return new BasicHandlerResult(
99  $status,
100  basename($tempfile),
101  $message
102  );
103  }
104 
105  protected function getRemoveResult(string $file_name): HandlerResult
106  {
107  if ($this->has_access === false) {
108  return $this->getAccessFailureResult(
110  $file_name,
111  $this->language
112  );
113  }
114 
115  return new BasicHandlerResult(
117  HandlerResult::STATUS_OK,
118  $file_name,
119  'There is nothing to do here.'
120  );
121  }
122 
123  public function getInfoResult(string $file_name): ?FileInfoResult
124  {
125  if ($this->has_access === false) {
126  return null;
127  }
128 
129  $file_path = $this->custom_icon->getFullPath();
130 
131  return new BasicFileInfoResult(
133  'custom_icon',
134  $this->language->txt('custom_icon'),
135  filesize($file_path),
136  MimeType::IMAGE__SVG_XML
137  );
138  }
139 
143  public function getInfoForExistingFiles(array $file_names): array
144  {
145  return [$this->getInfoResult('custom_icon')];
146  }
147 }
custom_icon()
description: > Example for rendering custom icons.
Definition: custom_icon.php:33
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$ref_id
Definition: ltiauth.php:65
global $DIC
Definition: shib_login.php:26
static ilTempnam(?string $a_temp_path=null)
Returns a unique and non existing Path for e temporary file or directory.
__construct(Container $dic, ilPlugin $plugin)
$message
Definition: xapiexit.php:31
language()
description: > Example for rendring a language glyph.
Definition: language.php:41