ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilMediaCastSettings.php
Go to the documentation of this file.
1<?php
2
20
26{
27 private array $supported_suffixes = ["mp4", "mp3", "webm", "jpg", "jpeg", "png", "gif", "svg"];
28 private array $supported_mime_types = [
29 "video/mp4" => "video/mp4",
30 "video/webm" => "video/webm",
31 "audio/mpeg" => "audio/mpeg",
32 "image/jpeg" => "image/jpeg",
33 "image/png" => "image/png",
34 "image/gif" => "image/gif",
35 "image/svg+xml" => "image/svg+xml"
36 ];
37
38
39 private static ?self $instance = null;
40 private string $defaultAccess = "users";
41 private array $purposeSuffixes = array();
42 private array $mimeTypes = array();
44 protected int $video_threshold = 0;
45
46 private function __construct()
47 {
48 $this->initStorage();
49 $this->read();
50 }
51
52 public static function _getInstance(): self
53 {
54 if (self::$instance) {
55 return self::$instance;
56 }
57 return self::$instance = new ilMediaCastSettings();
58 }
59
60 public function setPurposeSuffixes(array $purpose_filetypes): void
61 {
62 $this->purposeSuffixes = $purpose_filetypes;
63 }
64
65 public function getPurposeSuffixes(): array
66 {
68 }
69
70 public function getDefaultAccess(): string
71 {
73 }
74
75 public function setDefaultAccess(string $value): void
76 {
77 $this->defaultAccess = $value === "users" ? "users" : "public";
78 }
79
80 public function getMimeTypes(): array
81 {
82 return $this->mimeTypes;
83 }
84
85 public function setMimeTypes(array $mimeTypes): void
86 {
87 $this->mimeTypes = $mimeTypes;
88 }
89
90 public function setVideoCompletionThreshold(int $a_val): void
91 {
92 $this->video_threshold = $a_val;
93 }
94
96 {
98 }
99
100 public function save(): void
101 {
102 foreach ($this->purposeSuffixes as $purpose => $filetypes) {
103 $this->storage->set($purpose . "_types", implode(",", $filetypes));
104 }
105 $this->storage->set("defaultaccess", $this->defaultAccess);
106 $this->storage->set("video_threshold", $this->video_threshold);
107 $this->storage->set("mimetypes", implode(",", $this->getMimeTypes()));
108 }
109
110 private function read(): void
111 {
112 foreach ($this->purposeSuffixes as $purpose => $filetypes) {
113 if ($this->storage->get($purpose . "_types") != false) {
114 $sf = explode(",", $this->storage->get($purpose . "_types"));
115 $sf = array_filter($sf, function ($c) {
116 return in_array($c, $this->supported_suffixes);
117 });
118 $this->purposeSuffixes[$purpose] = $sf;
119 }
120 }
121 $this->setDefaultAccess((string) $this->storage->get("defaultaccess"));
122 $this->setVideoCompletionThreshold((int) $this->storage->get("video_threshold"));
123 if ($this->storage->get("mimetypes")) {
124 $mt = explode(",", $this->storage->get("mimetypes"));
125 $mt = array_filter($mt, function ($c) {
126 return in_array($c, $this->supported_mime_types);
127 });
128
129 $this->setMimeTypes($mt);
130 }
131 }
132
133 private function initStorage(): void
134 {
135 $this->storage = new ilSetting('mcst');
136 $this->purposeSuffixes = array_flip(ilObjMediaCast::$purposes);
137
138 $this->purposeSuffixes["Standard"] = $this->supported_suffixes;
139 $this->setDefaultAccess("users");
140 $mimeTypes = array_unique(array_values(MimeType::getExt2MimeMap()));
142 $this->setMimeTypes($this->supported_mime_types);
143 }
144}
Mime type determination.
Definition: MimeType.php:30
Stores all mediacast relevant settings.
setPurposeSuffixes(array $purpose_filetypes)
static array $purposes
ILIAS Setting Class.
$c
Definition: deliver.php:25