ILIAS  trunk Revision v12.0_alpha-1227-g7ff6d300864
class.SettingsGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
27
29{
30 protected \ilSetting $global_settings;
31
32 public function __construct(
33 protected InternalDataService $data,
34 protected InternalDomainService $domain,
35 protected InternalGUIService $gui,
36 protected int $obj_id,
37 protected int $ref_id
38 ) {
39 $this->global_settings = $this->domain->settings();
40 }
41
42 public function executeCommand(): void
43 {
44 $ctrl = $this->gui->ctrl();
45 $next_class = $ctrl->getNextClass($this);
46 $cmd = $ctrl->getCmd("edit");
47
48 switch ($next_class) {
49 default:
50 if (in_array($cmd, ["edit", "save"])) {
51 $this->$cmd();
52 }
53 }
54 }
55
56 protected function edit(): void
57 {
58 $mt = $this->gui->ui()->mainTemplate();
59 $form = $this->getEditForm();
60 $mt->setContent($form->render());
61 }
62
63 protected function getEditForm(): FormAdapterGUI
64 {
65 $settings = $this->domain->mediacastSettings()->getById($this->obj_id);
66 $lng = $this->domain->lng();
67
68 $form = $this->gui
69 ->form([self::class], "save")
70 ->section("general", $lng->txt("mcst_settings"))
71 ->addStdTitleAndDescription($this->obj_id, "mcst")
72 ->section("avail", $lng->txt("rep_activation_availability"))
73 ->addOnline($this->obj_id, "mcst")
74 ->section("presentation", $lng->txt("obj_presentation"))
75 ->addStdTile($this->obj_id, "mcst")
76 ->switch(
77 "order",
78 $lng->txt("mcst_ordering"),
79 "",
80 (string) $settings->getSortMode()
81 )
82 ->group((string) \ilObjMediaCast::ORDER_TITLE, $lng->txt("mcst_ordering_title"))
83 ->group((string) \ilObjMediaCast::ORDER_CREATION_DATE_ASC, $lng->txt("mcst_ordering_creation_date_asc"))
84 ->group((string) \ilObjMediaCast::ORDER_CREATION_DATE_DESC, $lng->txt("mcst_ordering_creation_date_desc"))
85 ->group((string) \ilObjMediaCast::ORDER_MANUAL, $lng->txt("mcst_ordering_manual"))
86 ->end()
87 ->switch(
88 "viewmode",
89 $lng->txt("mcst_viewmode"),
90 "",
91 $settings->getViewMode()
92 )
93 ->group(\ilObjMediaCast::VIEW_IMG_GALLERY, $lng->txt("mcst_img_gallery"))
94 ->group(\ilObjMediaCast::VIEW_PODCAST, $lng->txt("mcst_podcast"))
95 ->group(\ilObjMediaCast::VIEW_VCAST, $lng->txt("mcst_video_cast"))
96 ->number(
97 "nr_videos",
98 $lng->txt("mcst_nr_videos"),
99 "",
100 max(1, $settings->getNumberInitialVideos()),
101 1
102 )
103 ->end()
104 ->checkbox(
105 "downloadable",
106 $lng->txt("mcst_downloadable"),
107 $lng->txt("mcst_downloadable_info"),
108 $settings->getDownloadable()
109 );
110
111 // Webfeed Section
112 $news_set = new \ilSetting("news");
113 if ($news_set->get("enable_rss_for_internal")) {
114 $form = $form
115 ->section("webfeed", $lng->txt("mcst_webfeed"))
116 ->switch(
117 "defaultaccess",
118 $lng->txt("news_default_visibility"),
119 "",
120 (string) $settings->getDefaultAccess()
121 )
122 ->group(
123 "0",
124 $lng->txt("news_visibility_users"),
125 $lng->txt("news_news_item_def_visibility_users_info")
126 )
127 ->group(
128 "1",
129 $lng->txt("news_visibility_public"),
130 $lng->txt("news_news_item_def_visibility_public_info")
131 )
132 ->end();
133
134 // Extra Feed
135 $public_feed = \ilBlockSetting::_lookup("news", "public_feed", 0, $this->obj_id);
136 $form = $form
137 ->optional(
138 "extra_feed",
139 $lng->txt("news_public_feed"),
140 $lng->txt("news_public_feed_info"),
141 (bool) $public_feed
142 )
143 ->number(
144 "keep_rss_min",
145 $lng->txt("news_keep_minimal_x_items"),
146 $lng->txt("news_keep_minimal_x_items_info") . " (" . \ilNewsItem::_lookupRSSPeriod() . " " . ($lng->txt(\ilNewsItem::_lookupRSSPeriod() == 1 ? "day" : "days")) . ")",
148 "news",
149 "keep_rss_min",
150 0,
151 $this->obj_id
152 ),
153 0,
154 100
155 )->end();
156
157 // Include Files in RSS
158 $form = $form->checkbox(
159 "public_files",
160 $lng->txt("mcst_incl_files_in_rss"),
161 $lng->txt("mcst_incl_files_in_rss_info"),
162 $settings->getPublicFiles()
163 );
164 }
165
166 // Learning Progress Section
167 if (\ilLearningProgressAccess::checkAccess($this->ref_id)) {
168 $form = $form->section("learning_progress", $lng->txt("learning_progress"))
169 ->checkbox(
170 "auto_det_lp",
171 $lng->txt("mcst_new_items_det_lp"),
172 $lng->txt("mcst_new_items_det_lp_info"),
173 $settings->getNewItemsInLearningProgress()
174 );
175 }
176
177 if (!$this->global_settings->get('disable_comments')) {
178 $lng->loadLanguageModule("notes");
179 // Features Section
180 $form = $form->section("features", $lng->txt('obj_features'));
181 $form = $form->checkbox(
182 "comments",
183 $lng->txt("notes_comments"),
184 "",
185 $this->domain->notes()->commentsActive($this->obj_id)
186 );
187 }
188 return $form;
189 }
190
191 protected function save(): void
192 {
193 $mt = $this->gui->ui()->mainTemplate();
194 $form = $this->getEditForm();
195 $ctrl = $this->gui->ctrl();
196 $lng = $this->domain->lng();
197
198 $old_settings = $this->domain->mediacastSettings()->getById($this->obj_id);
199
200 if ($form->isValid()) {
201
202 $form->saveStdTitleAndDescription($this->obj_id, "mcst");
203 $form->saveStdTile($this->obj_id, "mcst");
204 $form->saveOnline($this->obj_id, "mcst");
205
206 $settings = $this->data->settings(
207 $this->obj_id,
208 (bool) $form->getData("public_files"),
209 (bool) $form->getData("downloadable"),
210 (int) $form->getData("defaultaccess"),
211 (int) $form->getData("order"),
212 (string) $form->getData("viewmode"),
213 (int) $form->getData("nr_videos"),
214 \ilLearningProgressAccess::checkAccess($this->ref_id) && (bool) $form->getData("auto_det_lp")
215 );
216 $this->domain->mediacastSettings()->update($settings);
217
218 if (!$this->global_settings->get('disable_comments')) {
219 $this->domain->notes()->activateComments(
220 $this->obj_id,
221 $form->getData("comments")
222 );
223 }
224
225 $news_set = new \ilSetting("news");
226 $enable_internal_rss = $news_set->get("enable_rss_for_internal");
227
228 if ($enable_internal_rss) {
230 "news",
231 "public_feed",
232 (string) $form->getData("extra_feed"),
233 0,
234 $this->obj_id
235 );
236
238 "news",
239 "keep_rss_min",
240 (string) $form->getData("keep_rss_min"),
241 0,
242 $this->obj_id
243 );
244 }
245
246 $mt->setOnScreenMessage("success", $lng->txt("msg_obj_modified"), true);
247 $ctrl->redirectByClass(self::class, "edit");
248 } else {
249 $mt = $this->gui->ui()->mainTemplate();
250 $mt->setContent($form->render());
251 }
252 }
253}
__construct(protected InternalDataService $data, protected InternalDomainService $domain, protected InternalGUIService $gui, protected int $obj_id, protected int $ref_id)
static _write(string $a_type, string $a_setting, string $a_value, int $a_user=0, int $a_block_id=0)
Write setting to database.
static _lookup(string $a_type, string $a_setting, int $a_user=0, int $a_block_id=0)
Lookup setting from database.
static checkAccess(int $a_ref_id, bool $a_allow_only_read=true)
check access to learning progress
static _lookupRSSPeriod()
$ref_id
Definition: ltiauth.php:66
global $lng
Definition: privfeed.php:31