ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilLearningSequenceFilesystem.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
11 {
12  const IMG_ABSTRACT = 'abstract';
13  const IMG_EXTRO = 'extro';
14  const PATH_PRE = 'LSO';
15  const PATH_POST = 'Images';
16 
17  public function __construct()
18  {
19  parent::__construct(self::STORAGE_WEB, false, 0);
20  if (!is_dir($this->getAbsolutePath())) {
21  $this->create();
22  }
23  }
24 
25  public function moveUploaded(
26  string $which,
27  array $file_info,
30  $target = $this->getStoragePathFor(
31  $which,
32  $settings->getObjId(),
33  $this->getSuffix($file_info['name'])
34  );
35  move_uploaded_file($file_info['tmp_name'], $target);
36 
37  if ($which === self::IMG_ABSTRACT) {
38  $settings = $settings->withAbstractImage($target);
39  }
40  if ($which === self::IMG_EXTRO) {
41  $settings = $settings->withExtroImage($target);
42  }
43  return $settings;
44  }
45 
46 
47  public function delete_image(string $which, ilLearningSequenceSettings $settings)
48  {
49  if ($which === self::IMG_ABSTRACT) {
50  $delete = $settings->getAbstractImage();
51  $settings = $settings->withAbstractImage(null);
52  }
53  if ($which === self::IMG_EXTRO) {
54  $delete = $settings->getExtroImage();
55  $settings = $settings->withExtroImage(null);
56  }
57 
58  $this->deleteFile($delete);
59  return $settings;
60  }
61 
62  public function getStoragePathFor(string $which, int $obj_id, string $suffix)
63  {
64  return $this->getStoragePath()
65  . $which
66  . '_'
67  . (string) $obj_id
68  . '.'
69  . $suffix;
70  }
71 
72  public function getSuffix(string $file_name) : string
73  {
74  return pathinfo($file_name, PATHINFO_EXTENSION);
75  }
76 
80  protected function getStoragePath()
81  {
82  return $this->getAbsolutePath() . '/';
83  }
84 
88  protected function getPathPrefix()
89  {
90  return self::PATH_PRE;
91  }
92 
96  protected function getPathPostfix()
97  {
98  return self::PATH_POST;
99  }
100 }
moveUploaded(string $which, array $file_info, ilLearningSequenceSettings $settings)
delete_image(string $which, ilLearningSequenceSettings $settings)
getStoragePathFor(string $which, int $obj_id, string $suffix)
Settings for an LSO (like abstract, extro)
getAbsolutePath()
Get absolute path of storage directory.
__construct(Container $dic, ilPlugin $plugin)
deleteFile($a_abs_name)
Delete file.