ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
class.ilTestExportFilename.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
27 {
31  protected $test;
32 
36  protected $timestamp = 0;
37 
41  public function __construct(ilObjTest $test)
42  {
43  $this->test = $test;
44  $this->timestamp = time();
45  }
46 
50  public function getTimestamp(): int
51  {
52  return $this->timestamp;
53  }
54 
61  public function getPathname($extension, $additional = ''): string
62  {
63  if (!is_string($extension) || !strlen($extension)) {
64  throw new ilException('Missing file extension! Please pass a file extension of type string.');
65  } elseif (substr_count($extension, '.') > 1 || (strpos($extension, '.') !== false && strpos($extension, '.') !== 0)) {
66  throw new ilException('Please use at most one dot in your file extension.');
67  } elseif (strpos($extension, '.') === 0) {
68  $extension = substr($extension, 1);
69  }
70 
71  if (!is_string($additional)) {
72  } elseif (strlen($additional)) {
73  if (strpos($additional, '__') === 0) {
74  throw new ilException('The additional file part may not contain __ at the beginning!');
75  }
76 
77  $additional = '__' . $additional . '_';
78  } else {
79  $additional = '_';
80  }
81 
82  return $this->test->getExportDirectory() . DIRECTORY_SEPARATOR . $this->getTimestamp() . '__' . IL_INST_ID . '__' . $this->test->getType() . $additional . $this->test->getId() . '.' . $extension;
83  }
84 }
const IL_INST_ID
Definition: constants.php:40
getPathname($extension, $additional='')