ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
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)
 
 copy (int $targetObjId)
 
 delete ()
 Should be called if a consuming object is removed from system. More...
 
 getSupportedFileExtensions ()
 
 saveFromSourceFile (string $sourceFilePath)
 
 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 ()
 
 createFromImportDir (string $source_dir)
 
- Public Member Functions inherited from ilObjectCustomIcon
 saveFromHttpRequest ()
 

Protected Member Functions

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

Protected Attributes

Filesystem $webDirectory
 
FileUpload $upload
 
ilCustomIconObjectConfiguration $config
 
int $objId
 

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.ilObjectCustomIconImpl.php.

Constructor & Destructor Documentation

◆ __construct()

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

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

References $config, $objId, $webDirectory, and ILIAS\Repository\upload().

45  {
46  $this->objId = $objId;
47 
48  $this->webDirectory = $webDirectory;
49  $this->upload = $uploadService;
50  $this->config = $config;
51  }
ilCustomIconObjectConfiguration $config
+ Here is the call graph for this function:

Member Function Documentation

◆ copy()

ilObjectCustomIconImpl::copy ( int  $targetObjId)

Implements ilObjectCustomIcon.

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

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

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

◆ createCustomIconDirectory()

ilObjectCustomIconImpl::createCustomIconDirectory ( )
protected
Exceptions
IOException

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

References getIconDirectory().

Referenced by saveFromSourceFile().

174  : void
175  {
176  $iconDirectory = $this->getIconDirectory();
177 
178  if (!$this->webDirectory->has(dirname($iconDirectory))) {
179  $this->webDirectory->createDir(dirname($iconDirectory));
180  }
181 
182  if (!$this->webDirectory->has($iconDirectory)) {
183  $this->webDirectory->createDir($iconDirectory);
184  }
185  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ createFromImportDir()

ilObjectCustomIconImpl::createFromImportDir ( string  $source_dir)
Exceptions
DirectoryNotFoundException
FileNotFoundException
IOException

Implements ilObjectCustomIcon.

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

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

226  : void
227  {
228  $target_dir = implode(DIRECTORY_SEPARATOR, [
230  $this->getIconDirectory()
231  ]);
232  ilFileUtils::rCopy($source_dir, $target_dir);
233  $this->persistIconState($this->getRelativePath());
234  }
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.
+ 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 81 of file class.ilObjectCustomIconImpl.php.

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

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

◆ exists()

ilObjectCustomIconImpl::exists ( )

Implements ilObjectCustomIcon.

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

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

Referenced by copy().

208  : bool
209  {
210  if (!ilContainer::_lookupContainerSetting($this->getObjId(), 'icon_custom', '0')) {
211  return false;
212  }
213 
214  return $this->webDirectory->has($this->getRelativePath());
215  }
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()

ilObjectCustomIconImpl::getFullPath ( )

Implements ilObjectCustomIcon.

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

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

217  : string
218  {
219  // TODO: Currently there is no option to get the relative base directory of a filesystem
220  return implode(DIRECTORY_SEPARATOR, [
222  $this->getRelativePath()
223  ]);
224  }
static getWebspaceDir(string $mode="filesystem")
get webspace directory
+ Here is the call graph for this function:

◆ getIconDirectory()

ilObjectCustomIconImpl::getIconDirectory ( )
protected

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

References getObjId().

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

187  : string
188  {
189  return implode(DIRECTORY_SEPARATOR, [
190  $this->config->getBaseDirectory(),
191  $this->config->getSubDirectoryPrefix() . $this->getObjId()
192  ]);
193  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getIconFileName()

ilObjectCustomIconImpl::getIconFileName ( )
protected

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

Referenced by getRelativePath(), and saveFromSourceFile().

195  : string
196  {
197  return self::ICON_BASENAME . '.' . $this->config->getTargetFileExtension();
198  }
+ Here is the caller graph for this function:

◆ getObjId()

ilObjectCustomIconImpl::getObjId ( )
protected

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

References $objId.

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

53  : int
54  {
55  return $this->objId;
56  }
+ Here is the caller graph for this function:

◆ getRelativePath()

ilObjectCustomIconImpl::getRelativePath ( )
protected

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

References getIconDirectory(), and getIconFileName().

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

200  : string
201  {
202  return implode(DIRECTORY_SEPARATOR, [
203  $this->getIconDirectory(),
204  $this->getIconFileName()
205  ]);
206  }
+ 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 96 of file class.ilObjectCustomIconImpl.php.

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

◆ persistIconState()

ilObjectCustomIconImpl::persistIconState ( string  $fileName)
protected

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

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

Referenced by createFromImportDir(), and saveFromSourceFile().

151  : void
152  {
153  if ($this->webDirectory->has($fileName)) {
154  ilContainer::_writeContainerSetting($this->getObjId(), 'icon_custom', '1');
155  } else {
156  ilContainer::_writeContainerSetting($this->getObjId(), 'icon_custom', '0');
157  }
158  }
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()

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 160 of file class.ilObjectCustomIconImpl.php.

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

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

◆ saveFromSourceFile()

ilObjectCustomIconImpl::saveFromSourceFile ( string  $sourceFilePath)
Exceptions
FileAlreadyExistsException
FileNotFoundException
IOException

Implements ilObjectCustomIcon.

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

References createCustomIconDirectory(), getIconDirectory(), getIconFileName(), getRelativePath(), persistIconState(), ilObjectCustomIcon\saveFromHttpRequest(), and ILIAS\Repository\upload().

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

Field Documentation

◆ $config

ilCustomIconObjectConfiguration ilObjectCustomIconImpl::$config
protected

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

Referenced by __construct().

◆ $objId

int ilObjectCustomIconImpl::$objId
protected

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

Referenced by __construct(), and getObjId().

◆ $upload

FileUpload ilObjectCustomIconImpl::$upload
protected

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

◆ $webDirectory

Filesystem ilObjectCustomIconImpl::$webDirectory
protected

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

Referenced by __construct().

◆ ICON_BASENAME

const ilObjectCustomIconImpl::ICON_BASENAME = 'icon_custom'
private

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


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