ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
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';
34  private const SEPARATOR = ' ';
35 
36  private array $default_inline_extensions = [
37  'gif',
38  'jpg',
39  'jpeg',
40  'mp3',
41  'pdf',
42  'png',
43  ];
44 
45  public function __construct()
46  {
47  parent::__construct(self::MODULE_NAME, false);
48  }
49 
50  public function isDownloadWithAsciiFileName(): bool
51  {
52  return $this->strToBool($this->get(self::F_DOWNLOAD_ASCII_FILENAME, '1'));
53  }
54 
55  public function setDownloadWithAsciiFileName(bool $value): void
56  {
57  $this->set(self::F_DOWNLOAD_ASCII_FILENAME, $this->boolToStr($value));
58  }
59 
60  public function isShowAmountOfDownloads(): bool
61  {
62  return $this->strToBool($this->get(self::F_SHOW_AMOUNT_OF_DOWNLOADS, '1'));
63  }
64 
65  public function setShowAmountOfDownloads(bool $value): void
66  {
67  $this->set(self::F_SHOW_AMOUNT_OF_DOWNLOADS, $this->boolToStr($value));
68  }
69 
70  public function setInlineFileExtensions(array $extensions): void
71  {
72  $extensions = array_map(function (string $extension): string {
73  return strtolower(trim($extension, " \t\n\r\0\x0B,"));
74  }, $extensions);
75 
76  $this->set(self::F_INLINE_FILE_EXTENSIONS, $this->arrayToStr($extensions));
77  }
78 
79  public function getInlineFileExtensions(): array
80  {
81  return $this->strToArray(
82  $this->get(
83  self::F_INLINE_FILE_EXTENSIONS,
84  $this->arrayToStr($this->default_inline_extensions)
85  )
86  );
87  }
88 
89  public function getDownloadLimitinMB(): int
90  {
91  return $this->strToInt($this->get(self::F_BG_LIMIT, '200'));
92  }
93 
94  public function setDownloadLimitInMB(int $limit): void
95  {
96  $this->set(self::F_BG_LIMIT, $this->intToStr($limit));
97  }
98 
99  // HELPERS
100 
101  private function strToBool(string $value): bool
102  {
103  return $value === '1';
104  }
105 
106  private function boolToStr(bool $value): string
107  {
108  return $value ? '1' : '0';
109  }
110 
111  private function intToStr(int $int): string
112  {
113  return (string) $int;
114  }
115 
116  private function strToInt(string $str): int
117  {
118  return (int) $str;
119  }
120 
121  private function arrayToStr(array $array): string
122  {
123  return implode(self::SEPARATOR, $array);
124  }
125 
126  private function strToArray(string $str): array
127  {
128  return explode(self::SEPARATOR, $str);
129  }
130 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: Form.php:19
setInlineFileExtensions(array $extensions)
Definition: General.php:70
setDownloadWithAsciiFileName(bool $value)
Definition: General.php:55
__construct(VocabulariesInterface $vocabularies)