ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
ilCertificate Class Reference

Create PDF certificates. More...

+ Collaboration diagram for ilCertificate:

Public Member Functions

 __construct (ilCertificateAdapter $adapter, ilCertificatePlaceholderDescription $placeholderDescriptionObject, ilCertificatePlaceholderValues $placeholderValuesObject, $objectId, $certificatePath, ilCertificateTemplateRepository $templateRepository=null, ilUserCertificateRepository $certificateRepository=null)
 ilCertificate constructor More...
 
 getBackgroundImageDirectory ($asRelative=false, $backgroundImagePath='')
 Returns the filesystem path of the background image. More...
 
 getBackgroundImageName ()
 Returns the filename of the background image. More...
 
 getBackgroundImageThumbPath ()
 Returns the filesystem path of the background image thumbnail. More...
 
 getBackgroundImageTempfilePath ()
 Returns the filesystem path of the background image temp file during upload. More...
 
 getXSLPath ()
 Returns the filesystem path of the XSL-FO file. More...
 
 getXSLName ()
 Returns the filename of the XSL-FO file. More...
 
 getBackgroundImagePathWeb ()
 Returns the web path of the background image. More...
 
 getBackgroundImageThumbPathWeb ()
 Returns the web path of the background image thumbnail. More...
 
 deleteBackgroundImage ($version)
 Deletes the background image of a certificate. More...
 
 createCertificateFile ($xslfo, $filename='')
 Saves the XSL-FO code to a file. More...
 
 hasBackgroundImage ()
 Checks for the background image of the certificate. More...
 
 isComplete ()
 Checks the status of the certificate. More...
 
 getAdapter ()
 Gets the adapter. More...
 
 setAdapter ($adapter)
 Sets the adapter. More...
 
 createArchiveDirectory ()
 
 addPDFtoArchiveDirectory ($pdfdata, $dir, $filename)
 Adds PDF data as a file to a given directory. More...
 
 zipCertificatesInArchiveDirectory ($dir, $deliver=true)
 Create a ZIP file from a directory with certificates. More...
 
 readActive ()
 

Static Public Member Functions

static _getXSLName ()
 Returns the filename of the XSL-FO file. More...
 
static isActive ()
 
static isObjectActive ($a_obj_id)
 

Protected Attributes

 $ctrl
 
 $tree
 
 $ilias
 
 $lng
 
 $adapter
 
 $settings
 
 $log
 
 $db
 

Static Protected Attributes

static $is_active
 

Private Attributes

 $templateRepository
 
 $placeholderDescriptionObject
 
 $objectId
 
 $certificateRepository
 
 $certificatePath
 
 $placeholderValuesObject
 

Detailed Description

Create PDF certificates.

Base class to create PDF certificates using XML-FO XML transformations

Author
Helmut Schottmüller helmu.nosp@m.t.sc.nosp@m.hottm.nosp@m.uell.nosp@m.er@ma.nosp@m.c.co.nosp@m.m
Version
$Id$

Definition at line 15 of file class.ilCertificate.php.

Constructor & Destructor Documentation

◆ __construct()

ilCertificate::__construct ( ilCertificateAdapter  $adapter,
ilCertificatePlaceholderDescription  $placeholderDescriptionObject,
ilCertificatePlaceholderValues  $placeholderValuesObject,
  $objectId,
  $certificatePath,
ilCertificateTemplateRepository  $templateRepository = null,
ilUserCertificateRepository  $certificateRepository = null 
)

ilCertificate constructor

Parameters
ilCertificateAdapter$adapterThe certificate adapter needed to construct the certificate
ilCertificatePlaceholderDescription$placeholderDescriptionObject
ilCertificatePlaceholderValues$placeholderValuesObject
$objectId- Object ID of the current component (e.g. course, test, exercise)
$certificatePath- Path to certificate data like background images etc.
ilCertificateTemplateRepository | null$templateRepository
ilUserCertificateRepository | null$certificateRepository

Definition at line 112 of file class.ilCertificate.php.

120 {
121 global $DIC;
122
123 $this->lng = $DIC['lng'];
124 $this->ctrl = $DIC['ilCtrl'];
125 $this->ilias = $DIC['ilias'];
126 $this->tree = $DIC['tree'];
127 $this->settings = $DIC['ilSetting'];
128 $this->log = $DIC['ilLog'];
129 $this->db = $DIC['ilDB'];
130
131 $this->adapter = $adapter;
132
133 $this->placeholderDescriptionObject = $placeholderDescriptionObject;
134
135 $this->placeholderValuesObject = $placeholderValuesObject;
136
137 $this->objectId = $objectId;
138
139 $this->certificatePath = $certificatePath;
140
141 $logger = $DIC->logger()->cert();
142
143 if ($templateRepository === null) {
144 $templateRepository = new ilCertificateTemplateRepository($DIC->database(), $logger);
145 }
146 $this->templateRepository = $templateRepository;
147
148 if ($certificateRepository === null) {
149 $certificateRepository = new ilUserCertificateRepository($DIC->database(), $logger);
150 }
151 $this->certificateRepository = $certificateRepository;
152 }
redirection script todo: (a better solution should control the processing via a xml file)
global $DIC
Definition: saml.php:7
settings()
Definition: settings.php:2

References $adapter, $certificatePath, $certificateRepository, $DIC, $objectId, $placeholderDescriptionObject, $placeholderValuesObject, $templateRepository, and settings().

+ Here is the call graph for this function:

Member Function Documentation

◆ _getXSLName()

static ilCertificate::_getXSLName ( )
static

Returns the filename of the XSL-FO file.

Returns
string The filename of the XSL-FO file

Definition at line 227 of file class.ilCertificate.php.

228 {
229 return "certificate.xml";
230 }

◆ addPDFtoArchiveDirectory()

ilCertificate::addPDFtoArchiveDirectory (   $pdfdata,
  $dir,
  $filename 
)

Adds PDF data as a file to a given directory.

Parameters
binary$pdfdataBinary PDF data
string$dirDirectory to contain the PDF data
string$filenameThe filename to save the PDF data

Definition at line 397 of file class.ilCertificate.php.

398 {
399 $fh = fopen($dir . $filename, "wb");
400 fwrite($fh, $pdfdata);
401 fclose($fh);
402 }
$filename
Definition: buildRTE.php:89

◆ createArchiveDirectory()

ilCertificate::createArchiveDirectory ( )

Definition at line 380 of file class.ilCertificate.php.

381 {
382 $type = ilObject::_lookupType($this->objectId);
383 $certificateId = $this->objectId;
384
385 $dir = CLIENT_WEB_DIR . $this->certificatePath . time() . "__" . IL_INST_ID . "__" . $type . "__" . $certificateId . "__certificate/";
387 return $dir;
388 }
static _lookupType($a_id, $a_reference=false)
lookup object type
static makeDirParents($a_dir)
Create a new directory and all parent directories.
$type

◆ createCertificateFile()

ilCertificate::createCertificateFile (   $xslfo,
  $filename = '' 
)

Saves the XSL-FO code to a file.

Parameters
string$xslfoXSL-FO code

Definition at line 293 of file class.ilCertificate.php.

294 {
295 if (!file_exists($this->certificatePath)) {
296 ilUtil::makeDirParents($this->certificatePath);
297 }
298
299 if (strlen($filename) == 0) {
300 $filename = $this->getXSLPath();
301 }
302
303 $fileHandle = fopen($filename, "w");
304 fwrite($fileHandle, $xslfo);
305 fclose($fileHandle);
306 }
getXSLPath()
Returns the filesystem path of the XSL-FO file.

References $filename, getXSLPath(), and ilUtil\makeDirParents().

+ Here is the call graph for this function:

◆ deleteBackgroundImage()

ilCertificate::deleteBackgroundImage (   $version)

Deletes the background image of a certificate.

Returns
boolean TRUE if the process succeeds

Definition at line 269 of file class.ilCertificate.php.

270 {
271 $result = true;
272 if (file_exists($this->getBackgroundImageThumbPath())) {
273 $result = $result & unlink($this->getBackgroundImageThumbPath());
274 }
275
276 $filename = $this->getBackgroundImageDirectory() . 'background_' . $version . '.jpg';
277 if (file_exists($filename)) {
278 $result = $result & unlink($filename);
279 }
280
281 if (file_exists($this->getBackgroundImageTempfilePath())) {
283 }
284
285 return $result;
286 }
$result
$version
Definition: build.php:27
getBackgroundImageTempfilePath()
Returns the filesystem path of the background image temp file during upload.
getBackgroundImageDirectory($asRelative=false, $backgroundImagePath='')
Returns the filesystem path of the background image.
getBackgroundImageThumbPath()
Returns the filesystem path of the background image thumbnail.

References $filename, $result, $version, getBackgroundImageDirectory(), getBackgroundImageTempfilePath(), and getBackgroundImageThumbPath().

+ Here is the call graph for this function:

◆ getAdapter()

ilCertificate::getAdapter ( )

Gets the adapter.

Returns
ilCertificateAdapter Adapter

Definition at line 356 of file class.ilCertificate.php.

357 {
358 return $this->adapter;
359 }

References $adapter.

Referenced by ilCertificateSettingsFormRepository\createForm().

+ Here is the caller graph for this function:

◆ getBackgroundImageDirectory()

ilCertificate::getBackgroundImageDirectory (   $asRelative = false,
  $backgroundImagePath = '' 
)

Returns the filesystem path of the background image.

Parameters
bool$asRelative
Returns
string The filesystem path of the background image

Definition at line 159 of file class.ilCertificate.php.

160 {
161 if ($asRelative) {
162 return str_replace(
163 array(CLIENT_WEB_DIR, '//'),
164 array('[CLIENT_WEB_DIR]', '/'),
165 $backgroundImagePath
166 );
167 }
168
170 }

References $certificatePath.

Referenced by deleteBackgroundImage().

+ Here is the caller graph for this function:

◆ getBackgroundImageName()

ilCertificate::getBackgroundImageName ( )

Returns the filename of the background image.

Returns
string The filename of the background image

Definition at line 177 of file class.ilCertificate.php.

178 {
179 return "background.jpg";
180 }

Referenced by getBackgroundImagePathWeb(), and getBackgroundImageThumbPath().

+ Here is the caller graph for this function:

◆ getBackgroundImagePathWeb()

ilCertificate::getBackgroundImagePathWeb ( )

Returns the web path of the background image.

Returns
string The web path of the background image

Definition at line 237 of file class.ilCertificate.php.

238 {
239 // TODO: this is generic now -> provide better solution
240 $webdir = $this->certificatePath . $this->getBackgroundImageName();
241
242 return str_replace(
243 ilUtil::removeTrailingPathSeparators(ILIAS_ABSOLUTE_PATH),
245 $webdir
246 );
247 }
getBackgroundImageName()
Returns the filename of the background image.
static removeTrailingPathSeparators($path)

References getBackgroundImageName(), and ilUtil\removeTrailingPathSeparators().

+ Here is the call graph for this function:

◆ getBackgroundImageTempfilePath()

ilCertificate::getBackgroundImageTempfilePath ( )

Returns the filesystem path of the background image temp file during upload.

Returns
string The filesystem path of the background image temp file

Definition at line 197 of file class.ilCertificate.php.

198 {
199 return CLIENT_WEB_DIR . $this->certificatePath . "background_upload.tmp";
200 }

Referenced by deleteBackgroundImage().

+ Here is the caller graph for this function:

◆ getBackgroundImageThumbPath()

ilCertificate::getBackgroundImageThumbPath ( )

Returns the filesystem path of the background image thumbnail.

Returns
string The filesystem path of the background image thumbnail

Definition at line 187 of file class.ilCertificate.php.

188 {
189 return CLIENT_WEB_DIR . $this->certificatePath . $this->getBackgroundImageName() . ".thumb.jpg";
190 }

References getBackgroundImageName().

Referenced by ilCertificateSettingsFormRepository\createForm(), deleteBackgroundImage(), and getBackgroundImageThumbPathWeb().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getBackgroundImageThumbPathWeb()

ilCertificate::getBackgroundImageThumbPathWeb ( )

Returns the web path of the background image thumbnail.

Returns
string The web path of the background image thumbnail

Definition at line 254 of file class.ilCertificate.php.

255 {
256 // TODO: this is generic now -> provide better solution
257 return str_replace(
258 ilUtil::removeTrailingPathSeparators(ILIAS_ABSOLUTE_PATH),
261 );
262 }

References getBackgroundImageThumbPath(), and ilUtil\removeTrailingPathSeparators().

+ Here is the call graph for this function:

◆ getXSLName()

ilCertificate::getXSLName ( )

Returns the filename of the XSL-FO file.

Returns
string The filename of the XSL-FO file

Definition at line 217 of file class.ilCertificate.php.

218 {
219 return "certificate.xml";
220 }

Referenced by getXSLPath().

+ Here is the caller graph for this function:

◆ getXSLPath()

ilCertificate::getXSLPath ( )

Returns the filesystem path of the XSL-FO file.

Returns
string The filesystem path of the XSL-FO file

Definition at line 207 of file class.ilCertificate.php.

208 {
209 return CLIENT_WEB_DIR . $this->certificatePath . $this->getXSLName();
210 }
getXSLName()
Returns the filename of the XSL-FO file.

References getXSLName().

Referenced by createCertificateFile().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ hasBackgroundImage()

ilCertificate::hasBackgroundImage ( )

Checks for the background image of the certificate.

Returns
boolean Returns TRUE if the certificate has a background image, FALSE otherwise
Exceptions
ilException

Definition at line 314 of file class.ilCertificate.php.

315 {
316 $template = $this->templateRepository->fetchCurrentlyUsedCertificate($this->objectId);
317
318 $backgroundImagePath = $template->getBackgroundImagePath();
319 if ($backgroundImagePath === '') {
320 return false;
321 }
322
323 $absolutePath = CLIENT_WEB_DIR . $backgroundImagePath;
324
325 if (file_exists($absolutePath)
326 && (filesize($absolutePath) > 0)
327 ) {
328 return true;
329 }
330 return false;
331 }
$template

References $template.

Referenced by ilCertificateSettingsFormRepository\createForm().

+ Here is the caller graph for this function:

◆ isActive()

static ilCertificate::isActive ( )
static

Definition at line 423 of file class.ilCertificate.php.

424 {
425 if (self::$is_active === null) {
426 // basic admin setting active?
427 $certificate_active = new ilSetting("certificate");
428 $certificate_active = (bool) $certificate_active->get("active");
429
430 // java/rtpc-server active?
431 if ($certificate_active) {
432 include_once './Services/WebServices/RPC/classes/class.ilRPCServerSettings.php';
433 $certificate_active = ilRPCServerSettings::getInstance()->isEnabled();
434 }
435
436 self::$is_active = (bool) $certificate_active;
437 }
438
439 return self::$is_active;
440 }
static getInstance()
Get singelton instance.
ILIAS Setting Class.

Referenced by ilCourseCertificateAdapter\_preloadListData(), ilPCPlaceHolderGUI\getAvailableTypes(), ilCertificateMigrationJob\getScormCertificates(), ilTestTabsManager\getSettingsSubTabs(), ilExerciseCertificateAdapter\hasUserCertificate(), ilAchievements\isActive(), ilObjExerciseGUI\setSettingsSubTabs(), ilObjSAHSLearningModuleGUI\setSettingsSubTabs(), and ilObjCourseGUI\setSubTabs().

+ Here is the caller graph for this function:

◆ isComplete()

ilCertificate::isComplete ( )

Checks the status of the certificate.

Returns
boolean Returns TRUE if the certificate is complete, FALSE otherwise

Definition at line 338 of file class.ilCertificate.php.

339 {
340 if (self::isActive()) {
341 if ($this->objectId && !self::isObjectActive($this->objectId)) {
342 return false;
343 }
344
345 return true;
346 }
347
348 return false;
349 }

◆ isObjectActive()

static ilCertificate::isObjectActive (   $a_obj_id)
static
Parameters
int$a_obj_id
Returns
bool

Definition at line 446 of file class.ilCertificate.php.

447 {
448 $chk = self::areObjectsActive(array($a_obj_id));
449 return $chk[$a_obj_id];
450 }

Referenced by ilExerciseCertificateAdapter\hasUserCertificate(), and ilCertificateMigrationJob\run().

+ Here is the caller graph for this function:

◆ readActive()

ilCertificate::readActive ( )
Returns
int

Definition at line 481 of file class.ilCertificate.php.

482 {
483 $set = $this->db->query("SELECT obj_id FROM il_certificate WHERE obj_id = " . $this->db->quote($this->objectId, "integer"));
484 return $this->db->numRows($set);
485 }

◆ setAdapter()

ilCertificate::setAdapter (   $adapter)

Sets the adapter.

Parameters
object$adapterAdapter

Definition at line 366 of file class.ilCertificate.php.

367 {
368 $this->adapter = &$adapter;
369 }

References $adapter.

◆ zipCertificatesInArchiveDirectory()

ilCertificate::zipCertificatesInArchiveDirectory (   $dir,
  $deliver = true 
)

Create a ZIP file from a directory with certificates.

Parameters
string$dirDirectory containing the certificates
boolean$deliverTRUE to deliver the ZIP file, FALSE to return the filename only
Returns
string The created ZIP archive path

Definition at line 411 of file class.ilCertificate.php.

412 {
413 $zipfile = time() . "__" . IL_INST_ID . "__" . $this->getAdapter()->getAdapterType() . "__" . $this->getAdapter()->getCertificateId() . "__certificates.zip";
414 $zipfilePath = CLIENT_WEB_DIR . $this->certificatePath . $zipfile;
415 ilUtil::zip($dir, $zipfilePath);
416 ilUtil::delDir($dir);
417 if ($deliver) {
418 ilUtil::deliverFile($zipfilePath, $zipfile, "application/zip", false, true);
419 }
420 return $zipfilePath;
421 }
getAdapter()
Gets the adapter.
static delDir($a_dir, $a_clean_only=false)
removes a dir and all its content (subdirs and files) recursively
static zip($a_dir, $a_file, $compress_content=false)
zips given directory/file into given zip.file
static deliverFile( $a_file, $a_filename, $a_mime='', $isInline=false, $removeAfterDelivery=false, $a_exit_after=true)
deliver file for download via browser.

Field Documentation

◆ $adapter

ilCertificate::$adapter
protected

Definition at line 50 of file class.ilCertificate.php.

Referenced by __construct(), getAdapter(), and setAdapter().

◆ $certificatePath

ilCertificate::$certificatePath
private

Definition at line 95 of file class.ilCertificate.php.

Referenced by __construct(), and getBackgroundImageDirectory().

◆ $certificateRepository

ilCertificate::$certificateRepository
private

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

Referenced by __construct().

◆ $ctrl

ilCertificate::$ctrl
protected

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

◆ $db

ilCertificate::$db
protected

Definition at line 65 of file class.ilCertificate.php.

◆ $ilias

ilCertificate::$ilias
protected

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

◆ $is_active

ilCertificate::$is_active
staticprotected

Definition at line 70 of file class.ilCertificate.php.

◆ $lng

ilCertificate::$lng
protected

Definition at line 43 of file class.ilCertificate.php.

◆ $log

ilCertificate::$log
protected

Definition at line 60 of file class.ilCertificate.php.

◆ $objectId

ilCertificate::$objectId
private

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

Referenced by __construct().

◆ $placeholderDescriptionObject

ilCertificate::$placeholderDescriptionObject
private

Definition at line 80 of file class.ilCertificate.php.

Referenced by __construct().

◆ $placeholderValuesObject

ilCertificate::$placeholderValuesObject
private

Definition at line 100 of file class.ilCertificate.php.

Referenced by __construct().

◆ $settings

ilCertificate::$settings
protected

Definition at line 55 of file class.ilCertificate.php.

◆ $templateRepository

ilCertificate::$templateRepository
private

Definition at line 75 of file class.ilCertificate.php.

Referenced by __construct().

◆ $tree

ilCertificate::$tree
protected

Definition at line 29 of file class.ilCertificate.php.


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