ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
ilObjectCustomIconImpl Class Reference

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

+ Inheritance diagram for ilObjectCustomIconImpl:
+ Collaboration diagram for ilObjectCustomIconImpl:

Public Member Functions

 __construct (Filesystem $webDirectory, FileUpload $uploadService, \ilCustomIconObjectConfiguration $config, int $objId)
 ilObjectCustomIconImpl constructor. More...
 
 copy (int $targetObjId)
 
Parameters
int$targetObjId
More...
 
 delete ()
 Should be called if a consuming object is removed from system.The implementer MUST delete all object specific custom icon data (folders, icons, persistent data) More...
 
 getSupportedFileExtensions ()
 
 saveFromSourceFile (string $sourceFilePath)
 
Parameters
string$sourceFilePath
Exceptions
More...
 
 remove ()
 Should be called if a consuming object just wants to delete the icon The implementer MUST only delete the icon itself and corresponding persistent data (e.g.stored in a database) More...
 
 exists ()
 
Returns
bool
More...
 
 getFullPath ()
 
Returns
string
More...
 
 createFromImportDir ($source_dir)
 
- Public Member Functions inherited from ilObjectCustomIcon
 saveFromHttpRequest ()
 

Data Fields

const ICON_BASENAME = 'icon_custom'
 

Protected Member Functions

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

Protected Attributes

 $webDirectory
 
 $upload
 
 $config
 
 $objId
 

Detailed Description

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

Definition at line 11 of file class.ilObjectCustomIconImpl.php.

Constructor & Destructor Documentation

◆ __construct()

ilObjectCustomIconImpl::__construct ( Filesystem  $webDirectory,
FileUpload  $uploadService,
\ilCustomIconObjectConfiguration  $config,
int  $objId 
)

ilObjectCustomIconImpl constructor.

Parameters
Filesystem$webDirectory
FileUpload$uploadService
ilCustomIconObjectConfiguration$config
$objId

Definition at line 34 of file class.ilObjectCustomIconImpl.php.

References $config, $objId, and $webDirectory.

35  {
36  $this->objId = $objId;
37 
38  $this->webDirectory = $webDirectory;
39  $this->upload = $uploadService;
40  $this->config = $config;
41  }

Member Function Documentation

◆ copy()

ilObjectCustomIconImpl::copy ( int  $targetObjId)

Parameters
int$targetObjId

Implements ilObjectCustomIcon.

Definition at line 54 of file class.ilObjectCustomIconImpl.php.

References ilContainer\_writeContainerSetting(), exists(), and getRelativePath().

55  {
56  if (!$this->exists()) {
57  \ilContainer::_writeContainerSetting($targetObjId, 'icon_custom', 0);
58  return;
59  }
60 
61  try {
62  $this->webDirectory->copy(
63  $this->getRelativePath(),
64  preg_replace(
65  '/(' . $this->config->getSubDirectoryPrefix() . ')(\d*)\/(.*)$/',
66  '${1}' . $targetObjId . '/${3}',
67  $this->getRelativePath()
68  )
69  );
70 
71  \ilContainer::_writeContainerSetting($targetObjId, 'icon_custom', 1);
72  } catch (\Exception $e) {
73  \ilContainer::_writeContainerSetting($targetObjId, 'icon_custom', 0);
74  }
75  }
static _writeContainerSetting($a_id, $a_keyword, $a_value)
+ Here is the call graph for this function:

◆ createCustomIconDirectory()

ilObjectCustomIconImpl::createCustomIconDirectory ( )
protected
Exceptions

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

References getIconDirectory().

Referenced by saveFromSourceFile().

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

◆ createFromImportDir()

ilObjectCustomIconImpl::createFromImportDir (   $source_dir)
Parameters
$source_dir
$filename
Exceptions

Definition at line 257 of file class.ilObjectCustomIconImpl.php.

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

258  {
259  $target_dir = implode(DIRECTORY_SEPARATOR, [
261  $this->getIconDirectory()
262  ]);
263  ilUtil::rCopy($source_dir, $target_dir);
264  $this->persistIconState($this->getRelativePath());
265  }
static rCopy($a_sdir, $a_tdir, $preserveTimeAttributes=false)
Copies content of a directory $a_sdir recursively to a directory $a_tdir.
static getWebspaceDir($mode="filesystem")
get webspace directory
+ Here is the call graph for this function:

◆ delete()

ilObjectCustomIconImpl::delete ( )

Should be called if a consuming object is removed from system.The implementer MUST delete all object specific custom icon data (folders, icons, persistent data)

Implements ilObjectCustomIcon.

Definition at line 80 of file class.ilObjectCustomIconImpl.php.

References ilContainer\_deleteContainerSettings(), getIconDirectory(), and getObjId().

81  {
82  if ($this->webDirectory->hasDir($this->getIconDirectory())) {
83  try {
84  $this->webDirectory->deleteDir($this->getIconDirectory());
85  } catch (\Exception $e) {
86  }
87  }
88 
89  \ilContainer::_deleteContainerSettings($this->getObjId(), 'icon_custom');
90  }
static _deleteContainerSettings($a_id, $a_keyword=null, $a_keyword_like=false)
+ Here is the call graph for this function:

◆ exists()

ilObjectCustomIconImpl::exists ( )

Returns
bool

Implements ilObjectCustomIcon.

Definition at line 229 of file class.ilObjectCustomIconImpl.php.

References ilContainer\_lookupContainerSetting(), getObjId(), and getRelativePath().

Referenced by copy().

229  : bool
230  {
231  if (!\ilContainer::_lookupContainerSetting($this->getObjId(), 'icon_custom', 0)) {
232  return false;
233  }
234 
235  return $this->webDirectory->has($this->getRelativePath());
236  }
static _lookupContainerSetting($a_id, $a_keyword, $a_default_value=null)
Lookup a container setting.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getFullPath()

ilObjectCustomIconImpl::getFullPath ( )

Returns
string

Implements ilObjectCustomIcon.

Definition at line 241 of file class.ilObjectCustomIconImpl.php.

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

241  : string
242  {
243  // TODO: Currently there is no option to get the relative base directory of a filesystem
244  return implode(DIRECTORY_SEPARATOR, [
246  $this->getRelativePath()
247  ]);
248  }
static getWebspaceDir($mode="filesystem")
get webspace directory
+ Here is the call graph for this function:

◆ getIconDirectory()

ilObjectCustomIconImpl::getIconDirectory ( )
protected
Returns
string

Definition at line 199 of file class.ilObjectCustomIconImpl.php.

References getObjId().

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

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

◆ getIconFileName()

ilObjectCustomIconImpl::getIconFileName ( )
protected
Returns
string

Definition at line 210 of file class.ilObjectCustomIconImpl.php.

Referenced by getRelativePath(), and saveFromSourceFile().

210  : string
211  {
212  return self::ICON_BASENAME . '.' . $this->config->getTargetFileExtension();
213  }
+ Here is the caller graph for this function:

◆ getObjId()

ilObjectCustomIconImpl::getObjId ( )
protected
Returns
int

Definition at line 46 of file class.ilObjectCustomIconImpl.php.

References $objId.

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

46  : int
47  {
48  return $this->objId;
49  }
+ Here is the caller graph for this function:

◆ getRelativePath()

ilObjectCustomIconImpl::getRelativePath ( )
protected
Returns
string

Definition at line 218 of file class.ilObjectCustomIconImpl.php.

References getIconDirectory(), and getIconFileName().

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

218  : string
219  {
220  return implode(DIRECTORY_SEPARATOR, [
221  $this->getIconDirectory(),
222  $this->getIconFileName()
223  ]);
224  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getSupportedFileExtensions()

ilObjectCustomIconImpl::getSupportedFileExtensions ( )
Returns
string[]

Implements ilObjectCustomIcon.

Definition at line 95 of file class.ilObjectCustomIconImpl.php.

95  : array
96  {
97  return $this->config->getSupportedFileExtensions();
98  }

◆ persistIconState()

ilObjectCustomIconImpl::persistIconState ( string  $fileName)
protected
Parameters
string$fileName

Definition at line 157 of file class.ilObjectCustomIconImpl.php.

References ilContainer\_writeContainerSetting(), and getObjId().

Referenced by createFromImportDir(), and saveFromSourceFile().

158  {
159  if ($this->webDirectory->has($fileName)) {
160  \ilContainer::_writeContainerSetting($this->getObjId(), 'icon_custom', 1);
161  } else {
162  \ilContainer::_writeContainerSetting($this->getObjId(), 'icon_custom', 0);
163  }
164  }
static _writeContainerSetting($a_id, $a_keyword, $a_value)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ remove()

ilObjectCustomIconImpl::remove ( )

Should be called if a consuming object just wants to delete the icon The implementer MUST only delete the icon itself and corresponding persistent data (e.g.stored in a database)

Implements ilObjectCustomIcon.

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

References ilContainer\_writeContainerSetting(), getObjId(), and getRelativePath().

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

◆ saveFromSourceFile()

ilObjectCustomIconImpl::saveFromSourceFile ( string  $sourceFilePath)

Parameters
string$sourceFilePath
Exceptions

Implements ilObjectCustomIcon.

Definition at line 103 of file class.ilObjectCustomIconImpl.php.

References $result, createCustomIconDirectory(), getIconDirectory(), getIconFileName(), getRelativePath(), ILIAS\FileUpload\DTO\ProcessingStatus\OK, persistIconState(), and ilObjectCustomIcon\saveFromHttpRequest().

104  {
105  $this->createCustomIconDirectory();
106 
107  $fileName = $this->getRelativePath();
108 
109  if ($this->webDirectory->has($fileName)) {
110  $this->webDirectory->delete($fileName);
111  }
112 
113  $this->webDirectory->copy($sourceFilePath, $fileName);
114 
115  $this->persistIconState($fileName);
116  }
+ Here is the call graph for this function:

Field Documentation

◆ $config

ilObjectCustomIconImpl::$config
protected

Definition at line 22 of file class.ilObjectCustomIconImpl.php.

Referenced by __construct().

◆ $objId

ilObjectCustomIconImpl::$objId
protected

Definition at line 25 of file class.ilObjectCustomIconImpl.php.

Referenced by __construct(), and getObjId().

◆ $upload

ilObjectCustomIconImpl::$upload
protected

Definition at line 19 of file class.ilObjectCustomIconImpl.php.

◆ $webDirectory

ilObjectCustomIconImpl::$webDirectory
protected

Definition at line 16 of file class.ilObjectCustomIconImpl.php.

Referenced by __construct().

◆ ICON_BASENAME

const ilObjectCustomIconImpl::ICON_BASENAME = 'icon_custom'

Definition at line 13 of file class.ilObjectCustomIconImpl.php.


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