ILIAS  release_4-4 Revision
class.ilTestExportFilename.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 require_once 'Services/Component/classes/class.ilPlugin.php';
5 
12 {
16  protected $test;
17 
21  protected $timestamp = 0;
22 
26  public function __construct(ilObjTest $test)
27  {
28  $this->test = $test;
29  $this->timestamp = time();
30  }
31 
35  public function getTimestamp()
36  {
37  return $this->timestamp;
38  }
39 
46  public function getPathname($extension, $additional = '')
47  {
48  if(!is_string($extension) || !strlen($extension))
49  {
50  throw new ilException('Missing file extension! Please pass a file extension of type string.');
51  }
52  else if(substr_count($extension, '.') > 1 || (strpos($extension, '.') !== false && strpos($extension, '.') !== 0))
53  {
54  throw new ilException('Please use at most one dot in your file extension.');
55  }
56  else if(strpos($extension, '.') === 0)
57  {
58  $extension = substr($extension, 1);
59  }
60 
61  if(!is_string($additional))
62  {
63 
64  }
65  else if(strlen($additional))
66  {
67  if(strpos($additional, '__') === 0)
68  {
69  throw new ilException('The additional file part may not contain __ at the beginning!');
70  }
71 
72  $additional = '__' . $additional . '_';
73  }
74  else
75  {
76  $additional = '_';
77  }
78 
79  return $this->test->getExportDirectory() . DIRECTORY_SEPARATOR . $this->getTimestamp() . '__' . IL_INST_ID . '__' . $this->test->getType() . $additional . $this->test->getId() . '.' . $extension;
80  }
81 }
Base class for ILIAS Exception handling.
$additional
Definition: goto.php:89
getPathname($extension, $additional='')