ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilLearningSequenceFilesystem.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
25 {
26  public const IMG_ABSTRACT = 'abstract';
27  public const IMG_EXTRO = 'extro';
28  public const PATH_PRE = 'LSO';
29  public const PATH_POST = 'Images';
30 
31  public function __construct()
32  {
33  parent::__construct(self::STORAGE_WEB, false, 0);
34  if (!is_dir($this->getAbsolutePath())) {
35  $this->create();
36  }
37  }
38 
39  public function moveUploaded(
40  string $which,
41  array $file_info,
44  $target = $this->getStoragePathFor(
45  $which,
46  $settings->getObjId(),
47  $this->getSuffix($file_info['name'])
48  );
49  move_uploaded_file($file_info['tmp_name'], $target);
50 
51  if ($which === self::IMG_ABSTRACT) {
52  $settings = $settings->withAbstractImage($target);
53  }
54  if ($which === self::IMG_EXTRO) {
55  $settings = $settings->withExtroImage($target);
56  }
57  return $settings;
58  }
59 
60 
62  {
63  $delete = '';
64  if ($which === self::IMG_ABSTRACT) {
65  $delete = $settings->getAbstractImage();
66  $settings = $settings->withAbstractImage();
67  }
68  if ($which === self::IMG_EXTRO) {
69  $delete = $settings->getExtroImage();
70  $settings = $settings->withExtroImage();
71  }
72  if ($delete !== '' && str_starts_with($delete, $this->getStoragePath())) {
73  $this->deleteFile($delete);
74  }
75  return $settings;
76  }
77 
78  public function getStoragePathFor(string $which, int $obj_id, string $suffix): string
79  {
80  return $this->getStoragePath()
81  . $which
82  . '_'
83  . $obj_id
84  . '.'
85  . $suffix;
86  }
87 
88  public function getSuffix(string $file_name): string
89  {
90  return pathinfo($file_name, PATHINFO_EXTENSION);
91  }
92 
93  protected function getStoragePath(): string
94  {
95  return $this->getAbsolutePath() . '/';
96  }
97 
101  protected function getPathPrefix(): string
102  {
103  return self::PATH_PRE;
104  }
105 
109  protected function getPathPostfix(): string
110  {
111  return self::PATH_POST;
112  }
113 }
moveUploaded(string $which, array $file_info, ilLearningSequenceSettings $settings)
array $settings
Setting values (LTI parameters, custom parameters and local parameters).
Definition: System.php:200
delete_image(string $which, ilLearningSequenceSettings $settings)
getStoragePathFor(string $which, int $obj_id, string $suffix)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
getAbsolutePath()
Calculates the full path on the filesystem.
__construct(Container $dic, ilPlugin $plugin)