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

Class ilObjectCustomIconImpl TODO: Inject database persistence in future instead of using \ilContainer. 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

ILIAS\Filesystem\Exception\FileAlreadyExistsException

Exceptions

ILIAS\Filesystem\Exception\FileNotFoundException

Exceptions

ILIAS\Filesystem\Exception\IOException 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
 getSupportedFileExtensions ()
 
 saveFromSourceFile (string $sourceFilePath)
 
 saveFromHttpRequest ()
 
 copy (int $targetObjId)
 
 delete ()
 Should be called if a consuming object is removed from system. 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. More...
 
 exists ()
 
 getFullPath ()
 

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 \ilContainer.

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.

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

References $config, $objId, and $webDirectory.

Member Function Documentation

◆ copy()

ilObjectCustomIconImpl::copy ( int  $targetObjId)

Parameters
int$targetObjId

Implements ilObjectCustomIcon.

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

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)

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

+ Here is the call graph for this function:

◆ createCustomIconDirectory()

ilObjectCustomIconImpl::createCustomIconDirectory ( )
protected
Exceptions

ILIAS\Filesystem\Exception\IOException

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

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 }

References getIconDirectory().

Referenced by saveFromSourceFile().

+ 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

ILIAS\Filesystem\Exception\DirectoryNotFoundException

Exceptions

ILIAS\Filesystem\Exception\FileNotFoundException

Exceptions

ILIAS\Filesystem\Exception\IOException

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

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 getWebspaceDir($mode="filesystem")
get webspace directory
static rCopy($a_sdir, $a_tdir, $preserveTimeAttributes=false)
Copies content of a directory $a_sdir recursively to a directory $a_tdir.

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

+ 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.

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)

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

+ Here is the call graph for this function:

◆ exists()

ilObjectCustomIconImpl::exists ( )

Returns
bool

Implements ilObjectCustomIcon.

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

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.

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

Referenced by copy().

+ 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.

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 }

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

+ Here is the call graph for this function:

◆ getIconDirectory()

ilObjectCustomIconImpl::getIconDirectory ( )
protected
Returns
string

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

199 : string
200 {
201 return implode(DIRECTORY_SEPARATOR, [
202 $this->config->getBaseDirectory(),
203 $this->config->getSubDirectoryPrefix() . $this->getObjId()
204 ]);
205 }

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

+ Here is the caller graph for this function:

◆ getIconFileName()

ilObjectCustomIconImpl::getIconFileName ( )
protected
Returns
string

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

210 : string
211 {
212 return self::ICON_BASENAME . '.' . $this->config->getTargetFileExtension();
213 }

Referenced by getRelativePath().

+ Here is the caller graph for this function:

◆ getObjId()

ilObjectCustomIconImpl::getObjId ( )
protected
Returns
int

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

46 : int
47 {
48 return $this->objId;
49 }

References $objId.

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

+ Here is the caller graph for this function:

◆ getRelativePath()

ilObjectCustomIconImpl::getRelativePath ( )
protected
Returns
string

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

218 : string
219 {
220 return implode(DIRECTORY_SEPARATOR, [
221 $this->getIconDirectory(),
222 $this->getIconFileName()
223 ]);
224 }

References getIconDirectory(), and getIconFileName().

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

+ 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.

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 }

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

Referenced by createFromImportDir(), and saveFromSourceFile().

+ 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.

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 }

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

+ Here is the call graph for this function:

◆ saveFromSourceFile()

ilObjectCustomIconImpl::saveFromSourceFile ( string  $sourceFilePath)

Parameters
string$sourceFilePath
Exceptions

ILIAS\Filesystem\Exception\FileAlreadyExistsException

Exceptions

ILIAS\Filesystem\Exception\FileNotFoundException

Exceptions

ILIAS\Filesystem\Exception\IOException

Implements ilObjectCustomIcon.

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

104 {
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 }

References createCustomIconDirectory(), getRelativePath(), and persistIconState().

+ 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: