ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
class.ilXlsFoParser.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 {
23  private readonly ilXMLChecker $xmlChecker;
26  private readonly ilLanguage $language;
28 
29  public function __construct(
30  private readonly ilSetting $settings,
31  private readonly ilPageFormats $pageFormats,
32  ?ilXMLChecker $xmlChecker = null,
33  ?ilCertificateUtilHelper $utilHelper = null,
34  ?ilCertificateXlstProcess $xlstProcess = null,
35  ?ilLanguage $language = null,
36  ?ilCertificateXlsFileLoader $certificateXlsFileLoader = null
37  ) {
38  if (null === $xmlChecker) {
39  $xmlChecker = new ilXMLChecker(new ILIAS\Data\Factory());
40  }
41  $this->xmlChecker = $xmlChecker;
42 
43  if (null === $utilHelper) {
44  $utilHelper = new ilCertificateUtilHelper();
45  }
46  $this->utilHelper = $utilHelper;
47 
48  if (null === $xlstProcess) {
49  $xlstProcess = new ilCertificateXlstProcess();
50  }
51  $this->xlstProcess = $xlstProcess;
52 
53  if (null === $language) {
54  global $DIC;
55  $language = $DIC->language();
56  }
57  $this->language = $language;
58 
59  if (null === $certificateXlsFileLoader) {
60  $certificateXlsFileLoader = new ilCertificateXlsFileLoader();
61  }
62  $this->certificateXlsFileLoader = $certificateXlsFileLoader;
63  }
64 
68  public function parse(array $formData): string
69  {
70  $content = "<html><body>" . $formData['certificate_text'] . "</body></html>";
71  $content = preg_replace("/<p>(&nbsp;){1,}<\\/p>/", "<p></p>", $content);
72  $content = preg_replace("/<p>(\\s)*?<\\/p>/", "<p></p>", $content);
73  $content = str_replace("<p></p>", "<p class=\"emptyrow\"></p>", $content);
74  $content = str_replace("&nbsp;", "&#160;", $content);
75  $content = preg_replace("//", "", $content);
76 
77  $this->xmlChecker->parse($content);
78  if ($this->xmlChecker->result()->isError()) {
79  throw new Exception($this->language->txt("certificate_not_well_formed"));
80  }
81 
82  $xsl = $this->certificateXlsFileLoader->getXlsCertificateContent();
83 
84  // additional font support
85  $xsl = str_replace(
86  'font-family="Helvetica, unifont"',
87  'font-family="' . $this->settings->get('rpc_pdf_font', 'Helvetica, unifont') . '"',
88  $xsl
89  );
90 
91  $args = [
92  '/_xml' => $content,
93  '/_xsl' => $xsl
94  ];
95 
96  if (strcmp($formData['pageformat'], 'custom') === 0) {
97  $pageheight = $formData['pageheight'] ?? '';
98  $pagewidth = $formData['pagewidth'] ?? '';
99  } else {
100  $pageformats = $this->pageFormats->fetchPageFormats();
101  $pageheight = $pageformats[$formData['pageformat']]['height'];
102  $pagewidth = $pageformats[$formData['pageformat']]['width'];
103  }
104 
105  $params = [
106  'pageheight' => $this->formatNumberString($this->utilHelper->stripSlashes($pageheight)),
107  'pagewidth' => $this->formatNumberString($this->utilHelper->stripSlashes($pagewidth)),
108  'backgroundimage' => '[BACKGROUND_IMAGE]',
109  'marginbody' => implode(
110  ' ',
111  [
112  $this->formatNumberString($this->utilHelper->stripSlashes($formData['margin_body']['top'])),
113  $this->formatNumberString($this->utilHelper->stripSlashes($formData['margin_body']['right'])),
114  $this->formatNumberString($this->utilHelper->stripSlashes($formData['margin_body']['bottom'])),
115  $this->formatNumberString($this->utilHelper->stripSlashes($formData['margin_body']['left']))
116  ]
117  )
118  ];
119 
120  return $this->xlstProcess->process($args, $params);
121  }
122 
123  private function formatNumberString(string $a_number): string
124  {
125  return str_replace(',', '.', $a_number);
126  }
127 }
readonly ilCertificateXlsFileLoader $certificateXlsFileLoader
formatNumberString(string $a_number)
array $settings
Setting values (LTI parameters, custom parameters and local parameters).
Definition: System.php:200
readonly ilCertificateUtilHelper $utilHelper
__construct(private readonly ilSetting $settings, private readonly ilPageFormats $pageFormats, ?ilXMLChecker $xmlChecker=null, ?ilCertificateUtilHelper $utilHelper=null, ?ilCertificateXlstProcess $xlstProcess=null, ?ilLanguage $language=null, ?ilCertificateXlsFileLoader $certificateXlsFileLoader=null)
if(! $DIC->user() ->getId()||!ilLTIConsumerAccess::hasCustomProviderCreationAccess()) $params
Definition: ltiregstart.php:33
Class ChatMainBarProvider .
global $DIC
Definition: feed.php:28
readonly ilCertificateXlstProcess $xlstProcess
Just a wrapper class to create Unit Test for other classes.
readonly ilXMLChecker $xmlChecker
readonly ilLanguage $language
parse(array $formData)