ILIAS  trunk Revision v11.0_alpha-1811-gd2d5443e411
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator 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 34 of file class.ilDidacticTemplateIconHandler.php.

Constructor & Destructor Documentation

◆ __construct()

ilDidacticTemplateIconHandler::__construct ( ilDidacticTemplateSetting  $setting)

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

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

43  {
44  global $DIC;
45 
46  $this->settings = $setting;
47  $this->webDirectory = $DIC->filesystem()->web();
48  $this->logger = $DIC->logger()->otpl();
49  }
global $DIC
Definition: shib_login.php:22
+ Here is the call graph for this function:

Member Function Documentation

◆ copy()

ilDidacticTemplateIconHandler::copy ( ilDidacticTemplateSetting  $original)

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

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

99  : void
100  {
101  if ($original->getIconHandler()->getAbsolutePath()) {
102  try {
103  $this->webDirectory->copy(
104  self::WEBDIR_PREFIX . '/' . $original->getIconIdentifier() . '.svg',
105  self::WEBDIR_PREFIX . '/' . $this->settings->getId() . '.svg'
106  );
107  } catch (Exception $e) {
108  $this->logger->warning('Copying icon failed with message: ' . $e->getMessage());
109  }
110  $this->settings->setIconIdentifier((string) $this->settings->getId());
111  } else {
112  $this->settings->setIconIdentifier("0");
113  }
114  $this->settings->update();
115  }
+ Here is the call graph for this function:

◆ delete()

ilDidacticTemplateIconHandler::delete ( )

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

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

117  : void
118  {
119  if ($this->webDirectory->has(self::WEBDIR_PREFIX . '/' . $this->settings->getIconIdentifier() . '.svg')) {
120  try {
121  $this->webDirectory->delete(self::WEBDIR_PREFIX . '/' . $this->settings->getIconIdentifier() . '.svg');
122  $this->settings->setIconIdentifier('');
123  $this->settings->update();
124  } catch (Exception $e) {
125  $this->logger->warning('Deleting icon dfailed with message: ' . $e->getMessage());
126  }
127  }
128  }
+ Here is the call graph for this function:

◆ getAbsolutePath()

ilDidacticTemplateIconHandler::getAbsolutePath ( )

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

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

90  : string
91  {
92  if ($this->webDirectory->has(self::WEBDIR_PREFIX . '/' . $this->settings->getIconIdentifier() . '.svg')) {
93  return ilFileUtils::getWebspaceDir() . '/' . self::WEBDIR_PREFIX . '/' . $this->settings->getIconIdentifier() . '.svg';
94  }
95 
96  return '';
97  }
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 51 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().

51  : void
52  {
53  if ($upload->hasUploads() && !$upload->hasBeenProcessed()) {
54  try {
55  $upload->process();
56  } catch (IllegalStateException $e) {
57  $this->logger->warning('File upload already processed: ' . $e->getMessage());
58  }
59  }
60  $this->initWebDir();
61  $result = $upload->getResults()[$tmpname] ?? false;
62  if ($result instanceof UploadResult && $result->isOK() && $result->getSize()) {
63  $this->delete();
64  $upload->moveOneFileTo(
65  $result,
66  self::WEBDIR_PREFIX,
67  Location::WEB,
68  $this->settings->getId() . '.svg'
69  );
70 
71  $this->settings->setIconIdentifier((string) $this->settings->getId());
72  $this->settings->update();
73  }
74  }
process()
Invokes all preprocessors for each uploaded file in the sequence they got registered.
The IllegalStateException indicates a wrong state of the object.
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 130 of file class.ilDidacticTemplateIconHandler.php.

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

Referenced by handleUpload().

130  : void
131  {
132  if (!$this->webDirectory->has(self::WEBDIR_PREFIX)) {
133  try {
134  $this->webDirectory->createDir(self::WEBDIR_PREFIX);
135  } catch (IOException $e) {
136  $this->logger->error('Creating icon directory failed with message: ' . $e->getMessage());
137  } catch (IllegalStateException $e) {
138  $this->logger->warning('Creating icon directory failed with message: ' . $e->getMessage());
139  }
140  }
141  }
Indicates general problems with the input or output operations.
Definition: IOException.php:27
The IllegalStateException indicates a wrong state of the object.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ toXml()

ilDidacticTemplateIconHandler::toXml ( ilXmlWriter  $writer)

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

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

143  : ilXmlWriter
144  {
145  if ($this->settings->getIconIdentifier()) {
146  try {
147  if ($this->webDirectory->has(self::WEBDIR_PREFIX . '/' . $this->settings->getIconIdentifier() . '.svg')) {
148  $writer->xmlElement('icon', [], $this->webDirectory->read(
149  self::WEBDIR_PREFIX . '/' . $this->settings->getIconIdentifier() . '.svg'
150  ));
151  }
152  } catch (Exception $e) {
153  $this->logger->warning('Export xml failed with message: ' . $e->getMessage());
154  }
155  }
156  return $writer;
157  }
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 76 of file class.ilDidacticTemplateIconHandler.php.

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

76  : void
77  {
78  try {
79  $this->webDirectory->write(
80  self::WEBDIR_PREFIX . '/' . $this->settings->getId() . '.svg',
81  trim($svg)
82  );
83  $this->settings->setIconIdentifier((string) $this->settings->getId());
84  $this->settings->update();
85  } catch (Exception $e) {
86  $this->logger->warning('Error writing svg image from xml: ' . $e->getMessage());
87  }
88  }
+ Here is the call graph for this function:

Field Documentation

◆ $logger

ilLogger ilDidacticTemplateIconHandler::$logger
protected

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

◆ $settings

ilDidacticTemplateSetting ilDidacticTemplateIconHandler::$settings
protected

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

◆ $webDirectory

Filesystem ilDidacticTemplateIconHandler::$webDirectory
protected

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

◆ WEBDIR_PREFIX

const ilDidacticTemplateIconHandler::WEBDIR_PREFIX = 'ilDidacticTemplateIcons'
protected

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


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