ILIAS  trunk Revision v12.0_alpha-1227-g7ff6d300864
class.ilObjNewsSettingsGUI.php
Go to the documentation of this file.
1<?php
2
20
28{
29 protected readonly NewsCache $cache;
30
31 public function __construct($a_data, $a_id, $a_call_by_reference = true, $a_prepare_output = true)
32 {
33 global $DIC;
34 $this->cache = $DIC->news()->internal()->repo()->cache();
35
36 $this->type = 'nwss';
37 parent::__construct($a_data, $a_id, $a_call_by_reference, $a_prepare_output);
38
39 $this->lng->loadLanguageModule('news');
40 $this->lng->loadLanguageModule('feed');
41 }
42
43 public function executeCommand(): void
44 {
45 $next_class = $this->ctrl->getNextClass($this);
46 $cmd = $this->ctrl->getCmd();
47
48 $this->prepareOutput();
49
50 if (!$this->rbac_system->checkAccess("read", $this->object->getRefId())) {
51 throw new ilPermissionException($this->lng->txt('no_permission'));
52 }
53
54 switch ($next_class) {
55 case 'ilpermissiongui':
56 $this->tabs_gui->setTabActive('perm_settings');
57 $perm_gui = new ilPermissionGUI($this);
58 $this->ctrl->forwardCommand($perm_gui);
59 break;
60
61 default:
62 if ($cmd === null || $cmd === '' || $cmd === 'view') {
63 $cmd = "editSettings";
64 }
65
66 $this->$cmd();
67 break;
68 }
69 }
70
71 public function getAdminTabs(): void
72 {
73 $rbacsystem = $this->rbac_system;
74
75 if ($rbacsystem->checkAccess("read", $this->object->getRefId())) {
76 $this->tabs_gui->addTarget(
77 "news_edit_news_settings",
78 $this->ctrl->getLinkTarget($this, "editSettings"),
79 ["editSettings", "view"]
80 );
81 }
82
83 if ($rbacsystem->checkAccess('edit_permission', $this->object->getRefId())) {
84 $this->tabs_gui->addTarget(
85 "perm_settings",
86 $this->ctrl->getLinkTargetByClass(ilPermissionGUI::class, "perm"),
87 [],
88 ilPermissionGUI::class
89 );
90 }
91 }
92
93 public function editSettings(): void
94 {
95 $form = $this->getSettingsForm();
96 $this->tpl->setContent($form->getHTML());
97 }
98
100 {
101 $ilCtrl = $this->ctrl;
104 $ilAccess = $this->access;
105
106 $news_set = new ilSetting("news");
107 $feed_set = new ilSetting("feed");
108
109 $enable_internal_news = $ilSetting->get("block_activated_news");
110 $enable_internal_rss = $news_set->get("enable_rss_for_internal");
111 $rss_title_format = $news_set->get("rss_title_format");
112 $enable_private_feed = $news_set->get("enable_private_feed");
113 $news_default_visibility = ($news_set->get("default_visibility") != "")
114 ? $news_set->get("default_visibility")
115 : "users";
116
117 $allow_shorter_periods = $news_set->get("allow_shorter_periods");
118 $allow_longer_periods = $news_set->get("allow_longer_periods");
119
120 $rss_period = ilNewsItem::_lookupRSSPeriod();
121
122 $form = new ilPropertyFormGUI();
123 $form->setFormAction($ilCtrl->getFormAction($this));
124 $form->setTitle($lng->txt("news_settings"));
125
126 // Enable internal news
127 $cb_prop = new ilCheckboxInputGUI(
128 $lng->txt("news_enable_internal_news"),
129 "enable_internal_news"
130 );
131 $cb_prop->setValue("1");
132 $cb_prop->setInfo($lng->txt("news_enable_internal_news_info"));
133 $cb_prop->setChecked((bool) $enable_internal_news);
134 $form->addItem($cb_prop);
135
136 // Default Visibility
137 $radio_group = new ilRadioGroupInputGUI($lng->txt("news_default_visibility"), "news_default_visibility");
138 $radio_option = new ilRadioOption($lng->txt("news_visibility_users"), "users");
139 $radio_group->addOption($radio_option);
140 $radio_option = new ilRadioOption($lng->txt("news_visibility_public"), "public");
141 $radio_group->addOption($radio_option);
142 $radio_group->setInfo($lng->txt("news_news_item_visibility_info"));
143 $radio_group->setRequired(false);
144 $radio_group->setValue($news_default_visibility);
145 $form->addItem($radio_group);
146
147 // Number of news items per object
148 $nr_opts = [50 => 50, 100 => 100, 200 => 200];
149 $nr_sel = new ilSelectInputGUI(
150 $lng->txt("news_nr_of_items"),
151 "news_max_items"
152 );
153 $nr_sel->setInfo($lng->txt("news_nr_of_items_info"));
154 $nr_sel->setOptions($nr_opts);
155 $nr_sel->setValue((string) $news_set->get("max_items"));
156 $form->addItem($nr_sel);
157
158 // Access Cache
159 $min_opts = [0 => 0, 1 => 1, 2 => 2, 5 => 5, 10 => 10, 20 => 20, 30 => 30, 60 => 60];
160 $min_sel = new ilSelectInputGUI(
161 $lng->txt("news_cache"),
162 "news_acc_cache_mins"
163 );
164 $min_sel->setInfo($lng->txt("news_cache_info"));
165 $min_sel->setOptions($min_opts);
166 $min_sel->setValue((string) $news_set->get("acc_cache_mins"));
167 $form->addItem($min_sel);
168
169 // PD News Period
170 $per_opts = [
171 7 => "1 " . $lng->txt("week"),
172 30 => "1 " . $lng->txt("month"),
173 366 => "1 " . $lng->txt("year")
174 ];
175 $per_sel = new ilSelectInputGUI(
176 $lng->txt("news_pd_period"),
177 "news_pd_period"
178 );
179 $per_sel->setInfo($lng->txt("news_pd_period_info"));
180 $per_sel->setOptions($per_opts);
181 $per_sel->setValue((string) ilNewsItem::_lookupDefaultPDPeriod());
182 $form->addItem($per_sel);
183
184 // Allow user to choose lower values
185 $sp_prop = new ilCheckboxInputGUI(
186 $lng->txt("news_allow_shorter_periods"),
187 "allow_shorter_periods"
188 );
189 $sp_prop->setValue("1");
190 $sp_prop->setInfo($lng->txt("news_allow_shorter_periods_info"));
191 $sp_prop->setChecked((bool) $allow_shorter_periods);
192 $form->addItem($sp_prop);
193
194 // Allow user to choose higher values
195 $lp_prop = new ilCheckboxInputGUI(
196 $lng->txt("news_allow_longer_periods"),
197 "allow_longer_periods"
198 );
199 $lp_prop->setValue("1");
200 $lp_prop->setInfo($lng->txt("news_allow_longer_periods_info"));
201 $lp_prop->setChecked((bool) $allow_longer_periods);
202 $form->addItem($lp_prop);
203
204 // Enable rss for internal news
205 $cb_prop = new ilCheckboxInputGUI(
206 $lng->txt("news_enable_internal_rss"),
207 "enable_internal_rss"
208 );
209 $cb_prop->setValue("1");
210 $cb_prop->setInfo($lng->txt("news_enable_internal_rss_info"));
211 $cb_prop->setChecked((bool) $enable_internal_rss);
212
213 // RSS News Period
214 $rssp_opts = [
215 2 => "2 " . $lng->txt("days"),
216 3 => "3 " . $lng->txt("days"),
217 5 => "5 " . $lng->txt("days"),
218 7 => "1 " . $lng->txt("week"),
219 14 => "2 " . $lng->txt("weeks"),
220 30 => "1 " . $lng->txt("month"),
221 60 => "2 " . $lng->txt("months"),
222 120 => "4 " . $lng->txt("months"),
223 180 => "6 " . $lng->txt("months"),
224 365 => "1 " . $lng->txt("year")
225 ];
226 $rssp_sel = new ilSelectInputGUI(
227 $lng->txt("news_rss_period"),
228 "news_rss_period"
229 );
230 $rssp_sel->setOptions($rssp_opts);
231 $rssp_sel->setValue($rss_period);
232 $cb_prop->addSubItem($rssp_sel);
233
234 // Section Header: RSS
235 $sh = new ilFormSectionHeaderGUI();
236 $sh->setTitle($lng->txt("news_rss"));
237 $form->addItem($sh);
238
239 // title format for rss entries
240 $options = [
241 "" => $lng->txt("news_rss_title_format_obj_news"),
242 "news_obj" => $lng->txt("news_rss_title_format_news_obj"),
243 ];
244 $si = new ilSelectInputGUI($lng->txt("news_rss_title_format"), "rss_title_format");
245 $si->setOptions($options);
246 $si->setValue($rss_title_format);
247 $cb_prop->addSubItem($si);
248
249 $form->addItem($cb_prop);
250
251 // Enable private news feed
252 $cb_prop = new ilCheckboxInputGUI(
253 $lng->txt("news_enable_private_feed"),
254 "enable_private_feed"
255 );
256 $cb_prop->setValue("1");
257 $cb_prop->setInfo($lng->txt("news_enable_private_feed_info"));
258 $cb_prop->setChecked((bool) $enable_private_feed);
259 $form->addItem($cb_prop);
260
261 if ($ilAccess->checkAccess('write', '', $this->object->getRefId())) {
262 // command buttons
263 $form->addCommandButton("saveSettings", $lng->txt("save"));
264 $form->addCommandButton("view", $lng->txt("cancel"));
265 }
266 return $form;
267 }
268
269 public function saveSettings(): void
270 {
271 $ilCtrl = $this->ctrl;
273 $ilAccess = $this->access;
274
275 if (!$ilAccess->checkAccess('write', '', $this->object->getRefId())) {
276 $ilCtrl->redirect($this, "view");
277 }
278
279 // empty news cache
280 $this->cache->flush();
281
282 $news_set = new ilSetting("news");
283 $feed_set = new ilSetting("feed");
284
285 $form = $this->getSettingsForm();
286
287 if ($form->checkInput()) {
288 $ilSetting->set("block_activated_news", $form->getInput("enable_internal_news"));
289 $ilSetting->set("block_activated_pdnews", $form->getInput("enable_internal_news"));
290 $news_set->set("enable_rss_for_internal", $form->getInput("enable_internal_rss"));
291 $news_set->set("max_items", $form->getInput("news_max_items"));
292 $news_set->set("acc_cache_mins", $form->getInput("news_acc_cache_mins"));
293 $news_set->set("pd_period", $form->getInput("news_pd_period"));
294 $news_set->set("default_visibility", $form->getInput("news_default_visibility"));
295 $news_set->set("allow_shorter_periods", $form->getInput("allow_shorter_periods"));
296 $news_set->set("allow_longer_periods", $form->getInput("allow_longer_periods"));
297 $news_set->set("rss_period", $form->getInput("news_rss_period"));
298 $news_set->set("rss_title_format", $form->getInput("rss_title_format"));
299
300 if ($form->getInput("enable_internal_rss")) {
301 $news_set->set("enable_private_feed", $form->getInput("enable_private_feed"));
302 } else {
303 $news_set->set("enable_private_feed", '0');
304 }
305
306 $this->tpl->setOnScreenMessage('success', $this->lng->txt("settings_saved"), true);
307 }
308
309 $ilCtrl->redirect($this, "view");
310 }
311}
Multi-Level News Cache Implementation:
Definition: NewsCache.php:36
This class represents a checkbox property in a property form.
This class represents a section header in a property form.
txt(string $a_topic, string $a_default_lang_fallback_mod="")
gets the text for a given topic if the topic is not in the list, the topic itself with "-" will be re...
static _lookupRSSPeriod()
static _lookupDefaultPDPeriod()
__construct($a_data, $a_id, $a_call_by_reference=true, $a_prepare_output=true)
getAdminTabs()
administration tabs show only permissions and trash folder
Class ilObjectGUI Basic methods of all Output classes.
ilAccessHandler $access
ilRbacSystem $rbac_system
ilSetting $settings
prepareOutput(bool $show_sub_objects=true)
ilLanguage $lng
This class represents a property form user interface.
This class represents a property in a property form.
This class represents an option in a radio group.
This class represents a selection list property in a property form.
ILIAS Setting Class.
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
global $ilSetting
Definition: privfeed.php:31
$feed_set
Definition: privfeed.php:33
global $DIC
Definition: shib_login.php:26