ILIAS  trunk Revision v11.0_alpha-1731-gff9cd7e2bd3
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
ilFSStoragePRG.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
25 {
26  protected const MEMBER_EXPORT_DIR = 'assingmentsExport';
27 
28  public function __construct(int $a_container_id = 0)
29  {
31  }
32 
36  protected function getPathPostfix(): string
37  {
38  return 'prg';
39  }
40 
44  protected function getPathPrefix(): string
45  {
46  return 'StudyProgramme';
47  }
48 
49  public function getMemberExportDirectory(): string
50  {
51  return $this->getAbsolutePath() . '/' . self::MEMBER_EXPORT_DIR;
52  }
53 
54  public function initMemberExportDirectory(): void
55  {
57  }
58 
59  public function getMemberExportFiles(): array
60  {
61  if (!is_dir($this->getMemberExportDirectory())) {
62  return array();
63  }
64  $dp = opendir($this->getMemberExportDirectory());
65 
66  $files = [];
67  while ($file = readdir($dp)) {
68  if (is_dir($file)) {
69  continue;
70  }
71  if (
72  preg_match(
73  "/^([0-9]{10})_[a-zA-Z]*_export_([a-z]+)_([0-9]+)\.[a-z]+$/",
74  $file,
75  $matches
76  )
77  && $matches[3] == $this->getContainerId()
78  ) {
79  $timest = $matches[1];
80  $file_info['name'] = $matches[0];
81  $file_info['timest'] = $matches[1];
82  $file_info['type'] = $matches[2];
83  $file_info['id'] = $matches[3];
84  $file_info['size'] = filesize($this->getMemberExportDirectory() . '/' . $file);
85 
86  $files[$timest] = $file_info;
87  }
88  }
89  closedir($dp);
90  return $files;
91  }
92 
93  public function getMemberExportFile(string $filename): string
94  {
95  $file_name = $this->getMemberExportDirectory() . '/' . $filename;
96 
97  if (file_exists($file_name)) {
98  return file_get_contents($file_name);
99  } else {
100  throw new \Exception('file not found:' . $filename);
101  }
102  return '';
103  }
104 
105  public function addMemberExportFile($a_data, $a_rel_name): bool
106  {
107  $this->initMemberExportDirectory();
108  if (!$this->writeToFile($a_data, $this->getMemberExportDirectory() . '/' . $a_rel_name)) {
109  $this->logger->write('Cannot write to file: ' . $this->getMemberExportDirectory() . '/' . $a_rel_name);
110  return false;
111  }
112 
113  return true;
114  }
115 
116  public function deleteMemberExportFile(string $filename): bool
117  {
118  return $this->deleteFile($this->getMemberExportDirectory() . '/' . $filename);
119  }
120 
121  public function hasMemberExportFile(string $filename): bool
122  {
123  return $this->fileExists($this->getMemberExportDirectory() . '/' . $filename);
124  }
125 }
store prg-files
static makeDirParents(string $a_dir)
Create a new directory and all parent directories.
deleteMemberExportFile(string $filename)
__construct(int $a_container_id=0)
addMemberExportFile($a_data, $a_rel_name)
$filename
Definition: buildRTE.php:78
getAbsolutePath()
Calculates the full path on the filesystem.
getMemberExportFile(string $filename)
__construct(Container $dic, ilPlugin $plugin)
hasMemberExportFile(string $filename)