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