ILIAS  release_8 Revision v8.19-1-g4e8f2f9140c
All Data Structures Namespaces Files Functions Variables Modules Pages
ilDidacticTemplateIconHandler Class Reference

Icon handler for didactic template custom icons. More...

+ Collaboration diagram for ilDidacticTemplateIconHandler:

Public Member Functions

 __construct (ilDidacticTemplateSetting $setting)
 
 handleUpload (FileUpload $upload, string $tmpname)
 
 writeSvg (string $svg)
 
 getAbsolutePath ()
 
 copy (ilDidacticTemplateSetting $original)
 
 delete ()
 
 toXml (ilXmlWriter $writer)
 

Protected Attributes

const WEBDIR_PREFIX = 'ilDidacticTemplateIcons'
 
ilDidacticTemplateSetting $settings
 
ilLogger $logger
 
Filesystem $webDirectory
 

Private Member Functions

 initWebDir ()
 

Detailed Description

Icon handler for didactic template custom icons.

Author
Stefan Meyer meyer.nosp@m.@lei.nosp@m.fos.c.nosp@m.om

Definition at line 20 of file class.ilDidacticTemplateIconHandler.php.

Constructor & Destructor Documentation

◆ __construct()

ilDidacticTemplateIconHandler::__construct ( ilDidacticTemplateSetting  $setting)

Definition at line 28 of file class.ilDidacticTemplateIconHandler.php.

References $DIC, ILIAS\Repository\logger(), and ILIAS\Repository\settings().

29  {
30  global $DIC;
31 
32  $this->settings = $setting;
33  $this->webDirectory = $DIC->filesystem()->web();
34  $this->logger = $DIC->logger()->otpl();
35  }
global $DIC
Definition: feed.php:28
+ Here is the call graph for this function:

Member Function Documentation

◆ copy()

ilDidacticTemplateIconHandler::copy ( ilDidacticTemplateSetting  $original)

Definition at line 85 of file class.ilDidacticTemplateIconHandler.php.

References Vendor\Package\$e, ilDidacticTemplateSetting\getIconHandler(), ilDidacticTemplateSetting\getIconIdentifier(), ILIAS\Repository\logger(), and ILIAS\Repository\settings().

85  : void
86  {
87  if ($original->getIconHandler()->getAbsolutePath()) {
88  try {
89  $this->webDirectory->copy(
90  self::WEBDIR_PREFIX . '/' . $original->getIconIdentifier() . '.svg',
91  self::WEBDIR_PREFIX . '/' . $this->settings->getId() . '.svg'
92  );
93  } catch (Exception $e) {
94  $this->logger->warning('Copying icon failed with message: ' . $e->getMessage());
95  }
96  $this->settings->setIconIdentifier((string) $this->settings->getId());
97  } else {
98  $this->settings->setIconIdentifier("0");
99  }
100  $this->settings->update();
101  }
+ Here is the call graph for this function:

◆ delete()

ilDidacticTemplateIconHandler::delete ( )

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

References Vendor\Package\$e, ILIAS\Repository\logger(), and ILIAS\Repository\settings().

103  : void
104  {
105  if ($this->webDirectory->has(self::WEBDIR_PREFIX . '/' . $this->settings->getIconIdentifier() . '.svg')) {
106  try {
107  $this->webDirectory->delete(self::WEBDIR_PREFIX . '/' . $this->settings->getIconIdentifier() . '.svg');
108  $this->settings->setIconIdentifier('');
109  $this->settings->update();
110  } catch (Exception $e) {
111  $this->logger->warning('Deleting icon dfailed with message: ' . $e->getMessage());
112  }
113  }
114  }
+ Here is the call graph for this function:

◆ getAbsolutePath()

ilDidacticTemplateIconHandler::getAbsolutePath ( )

Definition at line 76 of file class.ilDidacticTemplateIconHandler.php.

References ilFileUtils\getWebspaceDir(), and ILIAS\Repository\settings().

76  : string
77  {
78  if ($this->webDirectory->has(self::WEBDIR_PREFIX . '/' . $this->settings->getIconIdentifier() . '.svg')) {
79  return ilFileUtils::getWebspaceDir() . '/' . self::WEBDIR_PREFIX . '/' . $this->settings->getIconIdentifier() . '.svg';
80  }
81 
82  return '';
83  }
static getWebspaceDir(string $mode="filesystem")
get webspace directory
+ Here is the call graph for this function:

◆ handleUpload()

ilDidacticTemplateIconHandler::handleUpload ( FileUpload  $upload,
string  $tmpname 
)

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

References Vendor\Package\$e, ILIAS\FileUpload\FileUpload\getResults(), ILIAS\FileUpload\FileUpload\hasBeenProcessed(), ILIAS\FileUpload\FileUpload\hasUploads(), initWebDir(), ILIAS\FileUpload\DTO\UploadResult\isOK(), ILIAS\Repository\logger(), ILIAS\FileUpload\FileUpload\moveOneFileTo(), ILIAS\FileUpload\FileUpload\process(), and ILIAS\Repository\settings().

37  : void
38  {
39  if ($upload->hasUploads() && !$upload->hasBeenProcessed()) {
40  try {
41  $upload->process();
42  } catch (IllegalStateException $e) {
43  $this->logger->warning('File upload already processed: ' . $e->getMessage());
44  }
45  }
46  $this->initWebDir();
47  $result = $upload->getResults()[$tmpname] ?? false;
48  if ($result instanceof UploadResult && $result->isOK() && $result->getSize()) {
49  $this->delete();
50  $upload->moveOneFileTo(
51  $result,
52  self::WEBDIR_PREFIX,
53  Location::WEB,
54  $this->settings->getId() . '.svg'
55  );
56 
57  $this->settings->setIconIdentifier((string) $this->settings->getId());
58  $this->settings->update();
59  }
60  }
process()
Invokes all preprocessors for each uploaded file in the sequence they got registered.
hasUploads()
Return (bool)true if one ore more file-uploads are in the current request, (bool)false if not...
moveOneFileTo(UploadResult $uploadResult, string $destination, int $location=Location::STORAGE, string $file_name='', bool $override_existing=false)
Moves a single File (the attributes, metadata and upload-status of which are contained in UploadResul...
getResults()
Returns the results of the processing and moving operation of the uploaded files. ...
hasBeenProcessed()
Return (bool)true if the current upload has already been processed.
+ Here is the call graph for this function:

◆ initWebDir()

ilDidacticTemplateIconHandler::initWebDir ( )
private

Definition at line 116 of file class.ilDidacticTemplateIconHandler.php.

References Vendor\Package\$e, and ILIAS\Repository\logger().

Referenced by handleUpload().

116  : void
117  {
118  if (!$this->webDirectory->has(self::WEBDIR_PREFIX)) {
119  try {
120  $this->webDirectory->createDir(self::WEBDIR_PREFIX);
121  } catch (IOException $e) {
122  $this->logger->error('Creating icon directory failed with message: ' . $e->getMessage());
123  } catch (IllegalStateException $e) {
124  $this->logger->warning('Creating icon directory failed with message: ' . $e->getMessage());
125  }
126  }
127  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ toXml()

ilDidacticTemplateIconHandler::toXml ( ilXmlWriter  $writer)

Definition at line 129 of file class.ilDidacticTemplateIconHandler.php.

References Vendor\Package\$e, ILIAS\Repository\logger(), ILIAS\Repository\settings(), and ilXmlWriter\xmlElement().

129  : ilXmlWriter
130  {
131  if ($this->settings->getIconIdentifier()) {
132  try {
133  if ($this->webDirectory->has(self::WEBDIR_PREFIX . '/' . $this->settings->getIconIdentifier() . '.svg')) {
134  $writer->xmlElement('icon', [], $this->webDirectory->read(
135  self::WEBDIR_PREFIX . '/' . $this->settings->getIconIdentifier() . '.svg'
136  ));
137  }
138  } catch (Exception $e) {
139  $this->logger->warning('Export xml failed with message: ' . $e->getMessage());
140  }
141  }
142  return $writer;
143  }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
xmlElement(string $tag, $attrs=null, $data=null, $encode=true, $escape=true)
Writes a basic element (no children, just textual content)
+ Here is the call graph for this function:

◆ writeSvg()

ilDidacticTemplateIconHandler::writeSvg ( string  $svg)

Definition at line 62 of file class.ilDidacticTemplateIconHandler.php.

References Vendor\Package\$e, ILIAS\Repository\logger(), and ILIAS\Repository\settings().

62  : void
63  {
64  try {
65  $this->webDirectory->write(
66  self::WEBDIR_PREFIX . '/' . $this->settings->getId() . '.svg',
67  trim($svg)
68  );
69  $this->settings->setIconIdentifier((string) $this->settings->getId());
70  $this->settings->update();
71  } catch (Exception $e) {
72  $this->logger->warning('Error writing svg image from xml: ' . $e->getMessage());
73  }
74  }
+ Here is the call graph for this function:

Field Documentation

◆ $logger

ilLogger ilDidacticTemplateIconHandler::$logger
protected

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

◆ $settings

ilDidacticTemplateSetting ilDidacticTemplateIconHandler::$settings
protected

Definition at line 24 of file class.ilDidacticTemplateIconHandler.php.

◆ $webDirectory

Filesystem ilDidacticTemplateIconHandler::$webDirectory
protected

Definition at line 26 of file class.ilDidacticTemplateIconHandler.php.

◆ WEBDIR_PREFIX

const ilDidacticTemplateIconHandler::WEBDIR_PREFIX = 'ilDidacticTemplateIcons'
protected

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


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