ILIAS  trunk Revision v11.0_alpha-1811-gd2d5443e411
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
ilObjectCustomIcon Class Reference

Class ilObjectCustomIconImpl TODO: Inject database persistence in future instead of using . More...

+ Collaboration diagram for ilObjectCustomIcon:

Public Member Functions

 __construct (protected Filesystem $filesystem, protected FileUpload $upload, protected ilObjectCustomIconConfiguration $config, protected int $objId)
 
 copy (int $targetObjId)
 
 delete ()
 
 getSupportedFileExtensions ()
 
 saveFromSourceFile (string $sourceFilePath)
 
 saveFromTempFileName (string $tempfile_name)
 
 remove ()
 
 exists ()
 
 getFullPath ()
 
 createFromImportDir (string $source_dir)
 

Protected Member Functions

 getObjId ()
 
 persistIconState (string $fileName)
 
 createCustomIconDirectory ()
 
 getIconDirectory ()
 
 getIconFileName ()
 
 getRelativePath ()
 

Private Attributes

const ICON_BASENAME = 'icon_custom'
 

Detailed Description

Class ilObjectCustomIconImpl TODO: Inject database persistence in future instead of using .

Definition at line 31 of file class.ilObjectCustomIcon.php.

Constructor & Destructor Documentation

◆ __construct()

ilObjectCustomIcon::__construct ( protected Filesystem  $filesystem,
protected FileUpload  $upload,
protected ilObjectCustomIconConfiguration  $config,
protected int  $objId 
)

Definition at line 35 of file class.ilObjectCustomIcon.php.

40  {
41  }

Member Function Documentation

◆ copy()

ilObjectCustomIcon::copy ( int  $targetObjId)

Definition at line 48 of file class.ilObjectCustomIcon.php.

References Vendor\Package\$e, ilContainer\_writeContainerSetting(), exists(), ILIAS\Repository\filesystem(), and getRelativePath().

48  : void
49  {
50  if (!$this->exists()) {
51  ilContainer::_writeContainerSetting($targetObjId, 'icon_custom', '0');
52  return;
53  }
54 
55  try {
56  $this->filesystem->copy(
57  $this->getRelativePath(),
58  preg_replace(
59  '/(' . $this->config->getSubDirectoryPrefix() . ')(\d*)\/(.*)$/',
60  '${1}' . $targetObjId . '/${3}',
61  $this->getRelativePath()
62  )
63  );
64 
65  ilContainer::_writeContainerSetting($targetObjId, 'icon_custom', '1');
66  } catch (Exception $e) {
67  ilContainer::_writeContainerSetting($targetObjId, 'icon_custom', '0');
68  }
69  }
static _writeContainerSetting(int $a_id, string $a_keyword, string $a_value)
+ Here is the call graph for this function:

◆ createCustomIconDirectory()

ilObjectCustomIcon::createCustomIconDirectory ( )
protected
Exceptions
IOException

Definition at line 183 of file class.ilObjectCustomIcon.php.

References ILIAS\Repository\filesystem(), and getIconDirectory().

Referenced by saveFromSourceFile(), and saveFromTempFileName().

183  : void
184  {
185  $iconDirectory = $this->getIconDirectory();
186 
187  if (!$this->filesystem->has(dirname($iconDirectory))) {
188  $this->filesystem->createDir(dirname($iconDirectory));
189  }
190 
191  if (!$this->filesystem->has($iconDirectory)) {
192  $this->filesystem->createDir($iconDirectory);
193  }
194  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ createFromImportDir()

ilObjectCustomIcon::createFromImportDir ( string  $source_dir)

Definition at line 235 of file class.ilObjectCustomIcon.php.

References getIconDirectory(), getRelativePath(), ilFileUtils\getWebspaceDir(), persistIconState(), and ilFileUtils\rCopy().

235  : void
236  {
237  $target_dir = implode(DIRECTORY_SEPARATOR, [
239  $this->getIconDirectory()
240  ]);
241  ilFileUtils::rCopy($source_dir, $target_dir);
242  $this->persistIconState($this->getRelativePath());
243  }
static getWebspaceDir(string $mode="filesystem")
get webspace directory
static rCopy(string $a_sdir, string $a_tdir, bool $preserveTimeAttributes=false)
Copies content of a directory $a_sdir recursively to a directory $a_tdir.
persistIconState(string $fileName)
+ Here is the call graph for this function:

◆ delete()

ilObjectCustomIcon::delete ( )

Definition at line 71 of file class.ilObjectCustomIcon.php.

References Vendor\Package\$e, ilContainer\_deleteContainerSettings(), ILIAS\Repository\filesystem(), getIconDirectory(), and getObjId().

71  : void
72  {
73  if ($this->filesystem->hasDir($this->getIconDirectory())) {
74  try {
75  $this->filesystem->deleteDir($this->getIconDirectory());
76  } catch (Exception $e) {
77  }
78  }
79 
80  ilContainer::_deleteContainerSettings($this->getObjId(), 'icon_custom');
81  }
static _deleteContainerSettings(int $a_id, string $a_keyword="", bool $a_keyword_like=false)
+ Here is the call graph for this function:

◆ exists()

ilObjectCustomIcon::exists ( )

Definition at line 217 of file class.ilObjectCustomIcon.php.

References ilContainer\_lookupContainerSetting(), ILIAS\Repository\filesystem(), getObjId(), and getRelativePath().

Referenced by copy().

217  : bool
218  {
219  if (!ilContainer::_lookupContainerSetting($this->getObjId(), 'icon_custom', '0')) {
220  return false;
221  }
222 
223  return $this->filesystem->has($this->getRelativePath());
224  }
static _lookupContainerSetting(int $a_id, string $a_keyword, ?string $a_default_value=null)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getFullPath()

ilObjectCustomIcon::getFullPath ( )

Definition at line 226 of file class.ilObjectCustomIcon.php.

References getRelativePath(), and ilFileUtils\getWebspaceDir().

Referenced by saveFromTempFileName().

226  : string
227  {
228  // TODO: Currently there is no option to get the relative base directory of a filesystem
229  return implode(DIRECTORY_SEPARATOR, [
231  $this->getRelativePath()
232  ]);
233  }
static getWebspaceDir(string $mode="filesystem")
get webspace directory
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getIconDirectory()

ilObjectCustomIcon::getIconDirectory ( )
protected

Definition at line 196 of file class.ilObjectCustomIcon.php.

References getObjId().

Referenced by createCustomIconDirectory(), createFromImportDir(), delete(), getRelativePath(), and saveFromTempFileName().

196  : string
197  {
198  return implode(DIRECTORY_SEPARATOR, [
199  $this->config->getBaseDirectory(),
200  $this->config->getSubDirectoryPrefix() . $this->getObjId()
201  ]);
202  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getIconFileName()

ilObjectCustomIcon::getIconFileName ( )
protected

Definition at line 204 of file class.ilObjectCustomIcon.php.

Referenced by getRelativePath(), and saveFromTempFileName().

204  : string
205  {
206  return self::ICON_BASENAME . '.' . $this->config->getTargetFileExtension();
207  }
+ Here is the caller graph for this function:

◆ getObjId()

ilObjectCustomIcon::getObjId ( )
protected

Definition at line 43 of file class.ilObjectCustomIcon.php.

References $objId.

Referenced by delete(), exists(), getIconDirectory(), persistIconState(), and remove().

43  : int
44  {
45  return $this->objId;
46  }
$objId
Definition: xapitoken.php:57
+ Here is the caller graph for this function:

◆ getRelativePath()

ilObjectCustomIcon::getRelativePath ( )
protected

Definition at line 209 of file class.ilObjectCustomIcon.php.

References getIconDirectory(), and getIconFileName().

Referenced by copy(), createFromImportDir(), exists(), getFullPath(), remove(), saveFromSourceFile(), and saveFromTempFileName().

209  : string
210  {
211  return implode(DIRECTORY_SEPARATOR, [
212  $this->getIconDirectory(),
213  $this->getIconFileName()
214  ]);
215  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getSupportedFileExtensions()

ilObjectCustomIcon::getSupportedFileExtensions ( )
Returns
string[]

Definition at line 86 of file class.ilObjectCustomIcon.php.

86  : array
87  {
88  return $this->config->getSupportedFileExtensions();
89  }

◆ persistIconState()

ilObjectCustomIcon::persistIconState ( string  $fileName)
protected

Definition at line 160 of file class.ilObjectCustomIcon.php.

References ilContainer\_writeContainerSetting(), ILIAS\Repository\filesystem(), and getObjId().

Referenced by createFromImportDir(), saveFromSourceFile(), and saveFromTempFileName().

160  : void
161  {
162  if ($this->filesystem->has($fileName)) {
163  ilContainer::_writeContainerSetting($this->getObjId(), 'icon_custom', '1');
164  } else {
165  ilContainer::_writeContainerSetting($this->getObjId(), 'icon_custom', '0');
166  }
167  }
static _writeContainerSetting(int $a_id, string $a_keyword, string $a_value)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ remove()

ilObjectCustomIcon::remove ( )

Definition at line 169 of file class.ilObjectCustomIcon.php.

References ilContainer\_writeContainerSetting(), ILIAS\Repository\filesystem(), getObjId(), and getRelativePath().

169  : void
170  {
171  $fileName = $this->getRelativePath();
172 
173  if ($this->filesystem->has($fileName)) {
174  $this->filesystem->delete($fileName);
175  }
176 
177  ilContainer::_writeContainerSetting($this->getObjId(), 'icon_custom', '0');
178  }
static _writeContainerSetting(int $a_id, string $a_keyword, string $a_value)
+ Here is the call graph for this function:

◆ saveFromSourceFile()

ilObjectCustomIcon::saveFromSourceFile ( string  $sourceFilePath)

Definition at line 91 of file class.ilObjectCustomIcon.php.

References createCustomIconDirectory(), ILIAS\Repository\filesystem(), getRelativePath(), and persistIconState().

91  : void
92  {
94 
95  $fileName = $this->getRelativePath();
96 
97  if ($this->filesystem->has($fileName)) {
98  $this->filesystem->delete($fileName);
99  }
100 
101  $this->filesystem->copy($sourceFilePath, $fileName);
102 
103  $this->persistIconState($fileName);
104  }
persistIconState(string $fileName)
+ Here is the call graph for this function:

◆ saveFromTempFileName()

ilObjectCustomIcon::saveFromTempFileName ( string  $tempfile_name)

Definition at line 106 of file class.ilObjectCustomIcon.php.

References createCustomIconDirectory(), ILIAS\Repository\filesystem(), ilFileUtils\getDataDir(), getFullPath(), getIconDirectory(), getIconFileName(), getRelativePath(), persistIconState(), and ILIAS\Repository\upload().

106  : void
107  {
108  $this->createCustomIconDirectory();
109 
110  $relative_path = $this->getRelativePath();
111 
112  if ($this->filesystem->has($relative_path)) {
113  $this->filesystem->delete($relative_path);
114  }
115 
116  rename(ilFileUtils::getDataDir() . '/temp/' . $tempfile_name, $this->getFullPath());
117  $this->filesystem->setVisibility($relative_path, 'public');
118 
119 
120  foreach ($this->config->getUploadPostProcessors() as $processor) {
121  $processor->process($relative_path);
122  }
123 
124  $this->persistIconState($relative_path);
125  }
static getDataDir()
get data directory (outside webspace)
persistIconState(string $fileName)
+ Here is the call graph for this function:

Field Documentation

◆ ICON_BASENAME

const ilObjectCustomIcon::ICON_BASENAME = 'icon_custom'
private

Definition at line 33 of file class.ilObjectCustomIcon.php.


The documentation for this class was generated from the following file: