ILIAS  release_7 Revision v7.30-3-g800a261c036
ilDidacticTemplateIconHandler Class Reference

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

+ Collaboration diagram for ilDidacticTemplateIconHandler:

Public Member Functions

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

Protected Attributes

const WEBDIR_PREFIX = 'ilDidacticTemplateIcons'
 
 $settings
 
 $logger
 
 $webDirectory
 

Private Member Functions

 initWebDir ()
 Init web directory. More...
 

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 21 of file class.ilDidacticTemplateIconHandler.php.

Constructor & Destructor Documentation

◆ __construct()

ilDidacticTemplateIconHandler::__construct ( ilDidacticTemplateSetting  $setting)

ilDidacticTemplateIconHandler constructor.

Parameters
ilDidacticTemplateSetting$setting

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

46 {
47 global $DIC;
48
49 $this->settings = $setting;
50 $this->webDirectory = $DIC->filesystem()->web();
51 $this->logger = $DIC->logger()->otpl();
52 }
global $DIC
Definition: goto.php:24
settings()
Definition: settings.php:2

References $DIC, and settings().

+ Here is the call graph for this function:

Member Function Documentation

◆ copy()

ilDidacticTemplateIconHandler::copy ( ilDidacticTemplateSetting  $original)
Parameters
ilDidacticTemplateSetting$original

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

114 {
115 if ($original->getIconHandler()->getAbsolutePath()) {
116
117 try {
118 $this->webDirectory->copy(
119 self::WEBDIR_PREFIX . '/' . $original->getIconIdentifier() . '.svg',
120 self::WEBDIR_PREFIX . '/' . $this->settings->getId() . '.svg'
121 );
122 } catch (Exception $e) {
123 $this->logger->warning('Copying icon failed with message: ' . $e->getMessage());
124 }
125 $this->settings->setIconIdentifier((string) $this->settings->getId());
126 $this->settings->update();
127 } else {
128 $this->settings->setIconIdentifier((string) 0 );
129 $this->settings->update();
130 }
131 }

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

+ Here is the call graph for this function:

◆ delete()

ilDidacticTemplateIconHandler::delete ( )

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

137 {
138 if ($this->webDirectory->has(self::WEBDIR_PREFIX . '/' . $this->settings->getIconIdentifier() . '.svg')) {
139 try {
140 $this->webDirectory->delete(self::WEBDIR_PREFIX . '/' . $this->settings->getIconIdentifier() . '.svg');
141 $this->settings->setIconIdentifier('');
142 $this->settings->update();
143 } catch (Exception $e) {
144 $this->logger->warning('Deleting icon dfailed with message: ' . $e->getMessage());
145 }
146 }
147 }

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

+ Here is the call graph for this function:

◆ getAbsolutePath()

ilDidacticTemplateIconHandler::getAbsolutePath ( )
Returns
string

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

102 : string
103 {
104 if ($this->webDirectory->has(self::WEBDIR_PREFIX . '/' . $this->settings->getIconIdentifier() . '.svg')) {
105 return ilUtil::getWebspaceDir() . '/' . self::WEBDIR_PREFIX . '/' . $this->settings->getIconIdentifier() . '.svg';
106 }
107 return '';
108 }
static getWebspaceDir($mode="filesystem")
get webspace directory

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

+ Here is the call graph for this function:

◆ handleUpload()

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

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

58 {
59 if ($upload->hasUploads() && !$upload->hasBeenProcessed()) {
60 try {
61 $upload->process();
62 } catch (IllegalStateException $e) {
63 $this->logger->warning('File upload already processed: ' . $e->getMessage());
64 }
65 }
66 $this->initWebDir();
67 $result = isset($upload->getResults()[$tmpname]) ? $upload->getResults()[$tmpname] : false;
68 if ($result instanceof UploadResult && $result->isOK() && $result->getSize()) {
69 $this->delete();
70 $upload->moveOneFileTo(
71 $result,
72 self::WEBDIR_PREFIX,
73 Location::WEB,
74 $this->settings->getId() . '.svg'
75 );
76
77 $this->settings->setIconIdentifier((string) $this->settings->getId());
78 $this->settings->update();
79 }
80 }
$result
Class IllegalStateException The IllegalStateException indicates a wrong state of the object.
getResults()
Returns the results of the processing and moving operation of the uploaded files.
hasUploads()
Return (bool)true if one ore more file-uploads are in the current request, (bool)false if not.
process()
Invokes all preprocessors for each uploaded file in the sequence they got registered.
hasBeenProcessed()
Return (bool)true if the current upload has already been processed.
moveOneFileTo(UploadResult $UploadResult, $destination, $location=Location::STORAGE, $file_name='', $override_existing=false)
Moves a single File (the attributes, metadata and upload-status of which are contained in UploadResul...

References Vendor\Package\$e, $result, ILIAS\FileUpload\FileUpload\getResults(), ILIAS\FileUpload\FileUpload\hasBeenProcessed(), ILIAS\FileUpload\FileUpload\hasUploads(), initWebDir(), ILIAS\FileUpload\FileUpload\moveOneFileTo(), ILIAS\FileUpload\FileUpload\process(), and settings().

+ Here is the call graph for this function:

◆ initWebDir()

ilDidacticTemplateIconHandler::initWebDir ( )
private

Init web directory.

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

153 {
154 if (!$this->webDirectory->has(self::WEBDIR_PREFIX)) {
155 try {
156 $this->webDirectory->createDir(self::WEBDIR_PREFIX);
157 } catch (IOException $e) {
158 $this->logger->error('Creating icon directory failed with message: ' . $e->getMessage());
159 } catch (IllegalStateException $e) {
160 $this->logger->warning('Creating icon directory failed with message: ' . $e->getMessage());
161 }
162 }
163 }
Class IOException Indicates general problems with the input or output operations.
Definition: IOException.php:13

References Vendor\Package\$e.

Referenced by handleUpload().

+ Here is the caller graph for this function:

◆ toXml()

ilDidacticTemplateIconHandler::toXml ( ilXmlWriter  $writer)
Parameters
ilXmlWriter$writer
Returns
ilXmlWriter

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

170 {
171 if ($this->settings->getIconIdentifier()) {
172 try {
173 if ($this->webDirectory->has(self::WEBDIR_PREFIX . '/' . $this->settings->getIconIdentifier() . '.svg')) {
174 $writer->xmlElement('icon', [], $this->webDirectory->read(
175 self::WEBDIR_PREFIX . '/' . $this->settings->getIconIdentifier() . '.svg'
176 ));
177 }
178 } catch (Exception $e) {
179 $this->logger->warning('Export xml failed with message: ' . $e->getMessage());
180 }
181 }
182 return $writer;
183 }
xmlElement($tag, $attrs=null, $data=null, $encode=true, $escape=true)
Writes a basic element (no children, just textual content)

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

+ Here is the call graph for this function:

◆ writeSvg()

ilDidacticTemplateIconHandler::writeSvg ( string  $svg)
Parameters
string$svg

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

86 {
87 try {
88 $this->webDirectory->write(
89 self::WEBDIR_PREFIX . '/' . $this->settings->getId() . '.svg',
90 trim($svg)
91 );
92 $this->settings->setIconIdentifier((string) $this->settings->getId());
93 $this->settings->update();
94 } catch (Exception $e) {
95 $this->logger->warning('Error writing svg image from xml: ' . $e->getMessage());
96 }
97 }

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

+ Here is the call graph for this function:

Field Documentation

◆ $logger

ilDidacticTemplateIconHandler::$logger
protected

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

◆ $settings

ilDidacticTemplateIconHandler::$settings
protected

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

◆ $webDirectory

ilDidacticTemplateIconHandler::$webDirectory
protected

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

◆ WEBDIR_PREFIX

const ilDidacticTemplateIconHandler::WEBDIR_PREFIX = 'ilDidacticTemplateIcons'
protected

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


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