ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
ilCertificateTemplatePreviewAction Class Reference
+ Collaboration diagram for ilCertificateTemplatePreviewAction:

Public Member Functions

 __construct (ilCertificateTemplateRepository $templateRepository, ilCertificatePlaceholderValues $placeholderValuesObject, ilLogger $logger=null, ilObjUser $user=null, ilCertificateUtilHelper $utilHelper=null, ilCertificateMathJaxHelper $mathJaxHelper=null, ilCertificateUserDefinedFieldsHelper $userDefinedFieldsHelper=null, ilCertificateRpcClientFactoryHelper $rpcClientFactoryHelper=null, string $rootDirectory=CLIENT_WEB_DIR)
 
 createPreviewPdf (int $objectId)
 

Private Member Functions

 exchangeCertificateVariables (string $certificate_text, ilCertificateTemplate $template, int $objectId)
 Exchanges the variables in the certificate text with given values. More...
 
 getCustomCertificateFields ()
 Get custom certificate fields. More...
 

Private Attributes

 $templateRepository
 
 $placeholderValuesObject
 
 $logger
 
 $user
 
 $utilHelper
 
 $mathJaxHelper
 
 $userDefinedFieldsHelper
 
 $rpcClientFactoryHelper
 
 $rootDirectory
 

Detailed Description

Constructor & Destructor Documentation

◆ __construct()

ilCertificateTemplatePreviewAction::__construct ( ilCertificateTemplateRepository  $templateRepository,
ilCertificatePlaceholderValues  $placeholderValuesObject,
ilLogger  $logger = null,
ilObjUser  $user = null,
ilCertificateUtilHelper  $utilHelper = null,
ilCertificateMathJaxHelper  $mathJaxHelper = null,
ilCertificateUserDefinedFieldsHelper  $userDefinedFieldsHelper = null,
ilCertificateRpcClientFactoryHelper  $rpcClientFactoryHelper = null,
string  $rootDirectory = CLIENT_WEB_DIR 
)
Parameters
ilCertificateTemplateRepository$templateRepository
ilCertificatePlaceholderValues$placeholderValuesObject
ilLogger | null$logger
ilObjUser | null$user
ilCertificateUtilHelper | null$utilHelper
ilCertificateMathJaxHelper | null$mathJaxHelper
ilCertificateUserDefinedFieldsHelper | null$userDefinedFieldsHelper
ilCertificateRpcClientFactoryHelper | null$rpcClientFactoryHelper
string$rootDirectory

Definition at line 65 of file ilCertificateTemplatePreviewAction.php.

References $DIC, $logger, $mathJaxHelper, $placeholderValuesObject, $rootDirectory, $rpcClientFactoryHelper, $templateRepository, $user, $userDefinedFieldsHelper, $utilHelper, and user().

75  {
76  $this->templateRepository = $templateRepository;
77  $this->placeholderValuesObject = $placeholderValuesObject;
78 
79  if (null === $logger) {
80  global $DIC;
81  $logger = $DIC->logger()->cert();
82  }
83  $this->logger = $logger;
84 
85  if (null === $user) {
86  global $DIC;
87  $user = $DIC->user();
88  }
89  $this->user = $user;
90 
91  if (null === $utilHelper) {
92  $utilHelper = new ilCertificateUtilHelper();
93  }
94  $this->utilHelper = $utilHelper;
95 
96  if (null === $mathJaxHelper) {
97  $mathJaxHelper = new ilCertificateMathJaxHelper();
98  }
99  $this->mathJaxHelper = $mathJaxHelper;
100 
101  if (null === $userDefinedFieldsHelper) {
102  $userDefinedFieldsHelper = new ilCertificateUserDefinedFieldsHelper();
103  }
104  $this->userDefinedFieldsHelper = $userDefinedFieldsHelper;
105 
106  if (null === $rpcClientFactoryHelper) {
107  $rpcClientFactoryHelper = new ilCertificateRpcClientFactoryHelper();
108  }
109  $this->rpcClientFactoryHelper = $rpcClientFactoryHelper;
110 
111  $this->rootDirectory = $rootDirectory;
112  }
global $DIC
Definition: saml.php:7
user()
Definition: user.php:4
Just a wrapper class to create Unit Test for other classes.
+ Here is the call graph for this function:

Member Function Documentation

◆ createPreviewPdf()

ilCertificateTemplatePreviewAction::createPreviewPdf ( int  $objectId)
Parameters
int$objectId
Returns
bool
Exceptions
ilException
Exception

Definition at line 120 of file ilCertificateTemplatePreviewAction.php.

References $template, and exchangeCertificateVariables().

121  {
122  $template = $this->templateRepository->fetchCurrentlyUsedCertificate($objectId);
123 
124  $xslfo = $template->getCertificateContent();
125 
126  $xslfo = $this->exchangeCertificateVariables($xslfo, $template, $objectId);
127 
128  try {
129  // render tex as fo graphics
130  $xlsfo = $this->mathJaxHelper->fillXlsFoContent($xslfo);
131 
132  $pdf_base64 = $this->rpcClientFactoryHelper
133  ->ilFO2PDF('RPCTransformationHandler', $xlsfo);
134 
135  $this->utilHelper->deliverData(
136  $pdf_base64->scalar,
137  'Certificate.pdf',
138  'application/pdf'
139  );
140  } catch (Exception $e) {
141  throw $e;
142  }
143  }
$template
exchangeCertificateVariables(string $certificate_text, ilCertificateTemplate $template, int $objectId)
Exchanges the variables in the certificate text with given values.
+ Here is the call graph for this function:

◆ exchangeCertificateVariables()

ilCertificateTemplatePreviewAction::exchangeCertificateVariables ( string  $certificate_text,
ilCertificateTemplate  $template,
int  $objectId 
)
private

Exchanges the variables in the certificate text with given values.

Parameters
string$certificate_textThe XSL-FO certificate text
ilCertificateTemplate$template
int$objectId
Returns
string XSL-FO code

Definition at line 153 of file ilCertificateTemplatePreviewAction.php.

References $key, ilCertificateTemplate\getBackgroundImagePath(), getCustomCertificateFields(), and user().

Referenced by createPreviewPdf().

157  {
158  $insert_tags = $this->placeholderValuesObject->getPlaceholderValuesForPreview($this->user->getId(), $objectId);
159 
160  foreach ($this->getCustomCertificateFields() as $key => $value) {
161  $insert_tags[$value['ph']] = $this->utilHelper->prepareFormOutput($value['name']);
162  }
163 
164  foreach ($insert_tags as $placeholderVariable => $value) {
165  $certificate_text = str_replace('[' . $placeholderVariable . ']', $value, $certificate_text);
166  }
167 
168  $certificate_text = str_replace(
169  '[CLIENT_WEB_DIR]',
170  $this->rootDirectory,
171  $certificate_text
172  );
173 
174  $backgroundImagePath = $template->getBackgroundImagePath();
175 
176  $certificate_text = str_replace(
177  '[BACKGROUND_IMAGE]',
178  $this->rootDirectory . $backgroundImagePath,
179  $certificate_text
180  );
181 
182  return $certificate_text;
183  }
getCustomCertificateFields()
Get custom certificate fields.
user()
Definition: user.php:4
$key
Definition: croninfo.php:18
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getCustomCertificateFields()

ilCertificateTemplatePreviewAction::getCustomCertificateFields ( )
private

Get custom certificate fields.

Returns
array

Definition at line 190 of file ilCertificateTemplatePreviewAction.php.

References $f.

Referenced by exchangeCertificateVariables().

191  {
192  $user_field_definitions = $this->userDefinedFieldsHelper->createInstance();
193  $fds = $user_field_definitions->getDefinitions();
194 
195  $fields = array();
196  foreach ($fds as $f) {
197  if ($f['certificate']) {
198  $fields[$f['field_id']] = array(
199  'name' => $f['field_name'],
200  'ph' => '[#' . str_replace(' ', '_', strtoupper($f['field_name'])) . ']');
201  }
202  }
203 
204  return $fields;
205  }
+ Here is the caller graph for this function:

Field Documentation

◆ $logger

ilCertificateTemplatePreviewAction::$logger
private

Definition at line 22 of file ilCertificateTemplatePreviewAction.php.

Referenced by __construct().

◆ $mathJaxHelper

ilCertificateTemplatePreviewAction::$mathJaxHelper
private

Definition at line 37 of file ilCertificateTemplatePreviewAction.php.

Referenced by __construct().

◆ $placeholderValuesObject

ilCertificateTemplatePreviewAction::$placeholderValuesObject
private

Definition at line 17 of file ilCertificateTemplatePreviewAction.php.

Referenced by __construct().

◆ $rootDirectory

ilCertificateTemplatePreviewAction::$rootDirectory
private

Definition at line 52 of file ilCertificateTemplatePreviewAction.php.

Referenced by __construct().

◆ $rpcClientFactoryHelper

ilCertificateTemplatePreviewAction::$rpcClientFactoryHelper
private

Definition at line 47 of file ilCertificateTemplatePreviewAction.php.

Referenced by __construct().

◆ $templateRepository

ilCertificateTemplatePreviewAction::$templateRepository
private

Definition at line 12 of file ilCertificateTemplatePreviewAction.php.

Referenced by __construct().

◆ $user

ilCertificateTemplatePreviewAction::$user
private

Definition at line 27 of file ilCertificateTemplatePreviewAction.php.

Referenced by __construct().

◆ $userDefinedFieldsHelper

ilCertificateTemplatePreviewAction::$userDefinedFieldsHelper
private

Definition at line 42 of file ilCertificateTemplatePreviewAction.php.

Referenced by __construct().

◆ $utilHelper

ilCertificateTemplatePreviewAction::$utilHelper
private

Definition at line 32 of file ilCertificateTemplatePreviewAction.php.

Referenced by __construct().


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