ILIAS  trunk Revision v11.0_alpha-1846-g895b5f47236
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
General.php
Go to the documentation of this file.
1 <?php
2 
20 
22 use ilSetting;
23 
27 class General extends ilSetting implements Setting
28 {
29  public const MODULE_NAME = 'file_access';
30  public const F_BG_LIMIT = 'bg_limit';
31  public const F_INLINE_FILE_EXTENSIONS = 'inline_file_extensions';
32  public const F_SHOW_AMOUNT_OF_DOWNLOADS = 'show_amount_of_downloads';
33  public const F_DOWNLOAD_ASCII_FILENAME = 'download_ascii_filename';
37  private const SEPARATOR = ' ';
38 
39  private array $default_inline_extensions = [
40  'gif',
41  'jpg',
42  'jpeg',
43  'mp3',
44  'pdf',
45  'png',
46  ];
47 
48  public function __construct()
49  {
50  parent::__construct(self::MODULE_NAME, false);
51  }
52 
53  public function isDownloadWithAsciiFileName(): bool
54  {
55  return $this->strToBool($this->get(self::F_DOWNLOAD_ASCII_FILENAME, '1'));
56  }
57 
58  public function setDownloadWithAsciiFileName(bool $value): void
59  {
60  $this->set(self::F_DOWNLOAD_ASCII_FILENAME, $this->boolToStr($value));
61  }
62 
63  public function isShowAmountOfDownloads(): bool
64  {
65  return $this->strToBool($this->get(self::F_SHOW_AMOUNT_OF_DOWNLOADS, '1'));
66  }
67 
68  public function setShowAmountOfDownloads(bool $value): void
69  {
70  $this->set(self::F_SHOW_AMOUNT_OF_DOWNLOADS, $this->boolToStr($value));
71  }
72 
73  public function setInlineFileExtensions(array $extensions): void
74  {
75  $extensions = array_map(fn(string $extension): string => strtolower(trim($extension, " \t\n\r\0\x0B,")), $extensions);
76 
77  $this->set(self::F_INLINE_FILE_EXTENSIONS, $this->arrayToStr($extensions));
78  }
79 
80  public function getInlineFileExtensions(): array
81  {
82  return $this->strToArray(
83  $this->get(
84  self::F_INLINE_FILE_EXTENSIONS,
85  $this->arrayToStr($this->default_inline_extensions)
86  )
87  );
88  }
89 
90  public function getDownloadLimitinMB(): int
91  {
92  return $this->strToInt($this->get(self::F_BG_LIMIT, '200'));
93  }
94 
95  public function setDownloadLimitInMB(int $limit): void
96  {
97  $this->set(self::F_BG_LIMIT, $this->intToStr($limit));
98  }
99 
100  // HELPERS
101 
102  private function strToBool(string $value): bool
103  {
104  return $value === '1';
105  }
106 
107  private function boolToStr(bool $value): string
108  {
109  return $value ? '1' : '0';
110  }
111 
112  private function intToStr(int $int): string
113  {
114  return (string) $int;
115  }
116 
117  private function strToInt(string $str): int
118  {
119  return (int) $str;
120  }
121 
122  private function arrayToStr(array $array): string
123  {
124  return implode(self::SEPARATOR, $array);
125  }
126 
127  private function strToArray(string $str): array
128  {
129  return explode(self::SEPARATOR, $str);
130  }
131 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: Form.php:19
__construct(Container $dic, ilPlugin $plugin)
setInlineFileExtensions(array $extensions)
Definition: General.php:73