ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilCertificate.php
Go to the documentation of this file.
1 <?php
2 
3 /* Copyright (c) 1998-2011 ILIAS open source, Extended GPL, see docs/LICENSE */
4 
5 
16 {
22  protected $ctrl;
23 
29  protected $tree;
30 
36  protected $ilias;
37 
43  protected $lng;
44 
50  protected $adapter;
51 
55  protected $settings;
56 
60  protected $log;
61 
65  protected $db;
66 
70  protected static $is_active;
71 
76 
81 
85  private $objectId;
86 
91 
96 
101 
112  public function __construct(
116  $objectId,
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  }
153 
159  public function getBackgroundImageDirectory($asRelative = false, $backgroundImagePath = '')
160  {
161  if ($asRelative) {
162  return str_replace(
163  array(CLIENT_WEB_DIR, '//'),
164  array('[CLIENT_WEB_DIR]', '/'),
165  $backgroundImagePath
166  );
167  }
168 
169  return $this->certificatePath;
170  }
171 
177  public function getBackgroundImageName()
178  {
179  return "background.jpg";
180  }
181 
187  public function getBackgroundImageThumbPath()
188  {
189  return CLIENT_WEB_DIR . $this->certificatePath . $this->getBackgroundImageName() . ".thumb.jpg";
190  }
191 
198  {
199  return CLIENT_WEB_DIR . $this->certificatePath . "background_upload.tmp";
200  }
201 
207  public function getXSLPath()
208  {
209  return CLIENT_WEB_DIR . $this->certificatePath . $this->getXSLName();
210  }
211 
217  public function getXSLName()
218  {
219  return "certificate.xml";
220  }
221 
227  public static function _getXSLName()
228  {
229  return "certificate.xml";
230  }
231 
237  public function getBackgroundImagePathWeb()
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),
244  ilUtil::removeTrailingPathSeparators(ILIAS_HTTP_PATH),
245  $webdir
246  );
247  }
248 
255  {
256  // TODO: this is generic now -> provide better solution
257  return str_replace(
258  ilUtil::removeTrailingPathSeparators(ILIAS_ABSOLUTE_PATH),
259  ilUtil::removeTrailingPathSeparators(ILIAS_HTTP_PATH),
261  );
262  }
263 
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())) {
282  $result = $result & unlink($this->getBackgroundImageTempfilePath());
283  }
284 
285  return $result;
286  }
287 
293  public function createCertificateFile($xslfo, $filename = '')
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  }
307 
314  public function hasBackgroundImage()
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  }
332 
338  public function isComplete()
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  }
350 
356  public function getAdapter()
357  {
358  return $this->adapter;
359  }
360 
366  public function setAdapter($adapter)
367  {
368  $this->adapter = &$adapter;
369  }
370 
371  /***************************************
372  /* BULK CERTIFICATE PROCESSING METHODS *
373  /***************************************
374 
380  public function createArchiveDirectory()
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/";
386  ilUtil::makeDirParents($dir);
387  return $dir;
388  }
389 
397  public function addPDFtoArchiveDirectory($pdfdata, $dir, $filename)
398  {
399  $fh = fopen($dir . $filename, "wb");
400  fwrite($fh, $pdfdata);
401  fclose($fh);
402  }
403 
411  public function zipCertificatesInArchiveDirectory($dir, $deliver = true)
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  }
422 
423  public static function isActive()
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  }
441 
446  public static function isObjectActive($a_obj_id)
447  {
448  $chk = self::areObjectsActive(array($a_obj_id));
449  return $chk[$a_obj_id];
450  }
451 
456  public static function areObjectsActive(array $a_obj_ids)
457  {
461  global $DIC;
462 
463  $ilDB = $DIC['ilDB'];
464 
465  $all = array();
466  foreach ($a_obj_ids as $id) {
467  $all[$id] = false;
468  }
469 
470  $set = $ilDB->query("SELECT obj_id FROM il_certificate WHERE " . $ilDB->in("obj_id", $a_obj_ids, "", "integer"));
471  while ($row = $ilDB->fetchAssoc($set)) {
472  $all[$row["obj_id"]] = true;
473  }
474 
475  return $all;
476  }
477 
481  public function readActive()
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  }
486 }
static makeDirParents($a_dir)
Create a new directory and all parent directories.
settings()
Definition: settings.php:2
$result
$template
global $DIC
Definition: saml.php:7
deleteBackgroundImage($version)
Deletes the background image of a certificate.
getBackgroundImagePathWeb()
Returns the web path of the background image.
createCertificateFile($xslfo, $filename='')
Saves the XSL-FO code to a file.
hasBackgroundImage()
Checks for the background image of the certificate.
getBackgroundImageThumbPath()
Returns the filesystem path of the background image thumbnail.
$version
Definition: build.php:27
__construct(ilCertificateAdapter $adapter, ilCertificatePlaceholderDescription $placeholderDescriptionObject, ilCertificatePlaceholderValues $placeholderValuesObject, $objectId, $certificatePath, ilCertificateTemplateRepository $templateRepository=null, ilUserCertificateRepository $certificateRepository=null)
ilCertificate constructor
getBackgroundImageDirectory($asRelative=false, $backgroundImagePath='')
Returns the filesystem path of the background image.
getAdapter()
Gets the adapter.
getXSLPath()
Returns the filesystem path of the XSL-FO file.
getBackgroundImageTempfilePath()
Returns the filesystem path of the background image temp file during upload.
redirection script todo: (a better solution should control the processing via a xml file) ...
static removeTrailingPathSeparators($path)
$filename
Definition: buildRTE.php:89
isComplete()
Checks the status of the certificate.
setAdapter($adapter)
Sets the adapter.
getBackgroundImageName()
Returns the filename of the background image.
Adapter class to provide certificate data for the certificate generator.
getBackgroundImageThumbPathWeb()
Returns the web path of the background image thumbnail.
Create PDF certificates.
static _getXSLName()
Returns the filename of the XSL-FO file.
getXSLName()
Returns the filename of the XSL-FO file.