ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilObjNewsSettingsGUI.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3include_once("./Services/Object/classes/class.ilObjectGUI.php");
4
5
17{
21 protected $rbacsystem;
22
26 protected $error;
27
31 protected $access;
32
36 protected $settings;
37
38 private static $ERROR_MESSAGE;
44 public function __construct($a_data, $a_id, $a_call_by_reference = true, $a_prepare_output = true)
45 {
46 global $DIC;
47
48 $this->rbacsystem = $DIC->rbac()->system();
49 $this->error = $DIC["ilErr"];
50 $this->access = $DIC->access();
51 $this->ctrl = $DIC->ctrl();
52 $this->lng = $DIC->language();
53 $this->settings = $DIC->settings();
54 $this->type = 'nwss';
55 parent::__construct($a_data, $a_id, $a_call_by_reference, $a_prepare_output);
56
57 $this->lng->loadLanguageModule('news');
58 $this->lng->loadLanguageModule('feed');
59 }
60
67 public function executeCommand()
68 {
69 $next_class = $this->ctrl->getNextClass($this);
70 $cmd = $this->ctrl->getCmd();
71
72 $this->prepareOutput();
73
74 if (!$this->rbacsystem->checkAccess("visible,read", $this->object->getRefId())) {
75 $this->error->raiseError($this->lng->txt('no_permission'), $this->error->WARNING);
76 }
77
78 switch ($next_class) {
79 case 'ilpermissiongui':
80 $this->tabs_gui->setTabActive('perm_settings');
81 include_once("Services/AccessControl/classes/class.ilPermissionGUI.php");
82 $perm_gui = new ilPermissionGUI($this);
83 $ret = $this->ctrl->forwardCommand($perm_gui);
84 break;
85
86 default:
87 if (!$cmd || $cmd == 'view') {
88 $cmd = "editSettings";
89 }
90
91 $this->$cmd();
92 break;
93 }
94 return true;
95 }
96
103 public function getAdminTabs()
104 {
106 $ilAccess = $this->access;
107
108 if ($rbacsystem->checkAccess("visible,read", $this->object->getRefId())) {
109 $this->tabs_gui->addTarget(
110 "news_edit_news_settings",
111 $this->ctrl->getLinkTarget($this, "editSettings"),
112 array("editSettings", "view")
113 );
114 }
115
116 if ($rbacsystem->checkAccess('edit_permission', $this->object->getRefId())) {
117 $this->tabs_gui->addTarget(
118 "perm_settings",
119 $this->ctrl->getLinkTargetByClass('ilpermissiongui', "perm"),
120 array(),
121 'ilpermissiongui'
122 );
123 }
124 }
125
129 public function editSettings()
130 {
131 $ilCtrl = $this->ctrl;
134 $ilAccess = $this->access;
135
136 $news_set = new ilSetting("news");
137 $feed_set = new ilSetting("feed");
138
139 $enable_internal_news = $ilSetting->get("block_activated_news");
140 $enable_internal_rss = $news_set->get("enable_rss_for_internal");
141 $rss_title_format = $news_set->get("rss_title_format");
142 $enable_private_feed = $news_set->get("enable_private_feed");
143 $news_default_visibility = ($news_set->get("default_visibility") != "")
144 ? $news_set->get("default_visibility")
145 : "users";
146 $disable_repository_feeds = $feed_set->get("disable_rep_feeds");
147 $nr_personal_desktop_feeds = $ilSetting->get("block_limit_pdfeed");
148
149 $allow_shorter_periods = $news_set->get("allow_shorter_periods");
150 $allow_longer_periods = $news_set->get("allow_longer_periods");
151
152 include_once("./Services/News/classes/class.ilNewsItem.php");
153 $rss_period = ilNewsItem::_lookupRSSPeriod();
154
155 include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
156 $form = new ilPropertyFormGUI();
157 $form->setFormAction($ilCtrl->getFormAction($this));
158 $form->setTitle($lng->txt("news_settings"));
159
160 // Enable internal news
161 $cb_prop = new ilCheckboxInputGUI(
162 $lng->txt("news_enable_internal_news"),
163 "enable_internal_news"
164 );
165 $cb_prop->setValue("1");
166 $cb_prop->setInfo($lng->txt("news_enable_internal_news_info"));
167 $cb_prop->setChecked($enable_internal_news);
168 $form->addItem($cb_prop);
169
170 // Default Visibility
171 $radio_group = new ilRadioGroupInputGUI($lng->txt("news_default_visibility"), "news_default_visibility");
172 $radio_option = new ilRadioOption($lng->txt("news_visibility_users"), "users");
173 $radio_group->addOption($radio_option);
174 $radio_option = new ilRadioOption($lng->txt("news_visibility_public"), "public");
175 $radio_group->addOption($radio_option);
176 $radio_group->setInfo($lng->txt("news_news_item_visibility_info"));
177 $radio_group->setRequired(false);
178 $radio_group->setValue($news_default_visibility);
179 $form->addItem($radio_group);
180
181 // Number of news items per object
182 $nr_opts = array(50 => 50, 100 => 100, 200 => 200);
183 $nr_sel = new ilSelectInputGUI(
184 $lng->txt("news_nr_of_items"),
185 "news_max_items"
186 );
187 $nr_sel->setInfo($lng->txt("news_nr_of_items_info"));
188 $nr_sel->setOptions($nr_opts);
189 $nr_sel->setValue($news_set->get("max_items"));
190 $form->addItem($nr_sel);
191
192 // Access Cache
193 $min_opts = array(0 => 0, 1 => 1, 2 => 2, 5 => 5, 10 => 10, 20 => 20, 30 => 30, 60 => 60);
194 $min_sel = new ilSelectInputGUI(
195 $lng->txt("news_cache"),
196 "news_acc_cache_mins"
197 );
198 $min_sel->setInfo($lng->txt("news_cache_info"));
199 $min_sel->setOptions($min_opts);
200 $min_sel->setValue($news_set->get("acc_cache_mins"));
201 $form->addItem($min_sel);
202
203 // PD News Period
204 $per_opts = array(
205 7 => "1 " . $lng->txt("week"),
206 30 => "1 " . $lng->txt("month"),
207 366 => "1 " . $lng->txt("year"));
208 $per_sel = new ilSelectInputGUI(
209 $lng->txt("news_pd_period"),
210 "news_pd_period"
211 );
212 $per_sel->setInfo($lng->txt("news_pd_period_info"));
213 $per_sel->setOptions($per_opts);
214 $per_sel->setValue((int) ilNewsItem::_lookupDefaultPDPeriod());
215 $form->addItem($per_sel);
216
217 // Allow user to choose lower values
218 $sp_prop = new ilCheckboxInputGUI(
219 $lng->txt("news_allow_shorter_periods"),
220 "allow_shorter_periods"
221 );
222 $sp_prop->setValue("1");
223 $sp_prop->setInfo($lng->txt("news_allow_shorter_periods_info"));
224 $sp_prop->setChecked($allow_shorter_periods);
225 $form->addItem($sp_prop);
226
227 // Allow user to choose higher values
228 $lp_prop = new ilCheckboxInputGUI(
229 $lng->txt("news_allow_longer_periods"),
230 "allow_longer_periods"
231 );
232 $lp_prop->setValue("1");
233 $lp_prop->setInfo($lng->txt("news_allow_longer_periods_info"));
234 $lp_prop->setChecked($allow_longer_periods);
235 $form->addItem($lp_prop);
236
237 // Enable rss for internal news
238 $cb_prop = new ilCheckboxInputGUI(
239 $lng->txt("news_enable_internal_rss"),
240 "enable_internal_rss"
241 );
242 $cb_prop->setValue("1");
243 $cb_prop->setInfo($lng->txt("news_enable_internal_rss_info"));
244 $cb_prop->setChecked($enable_internal_rss);
245
246 // RSS News Period
247 $rssp_opts = array(
248 2 => "2 " . $lng->txt("days"),
249 3 => "3 " . $lng->txt("days"),
250 5 => "5 " . $lng->txt("days"),
251 7 => "1 " . $lng->txt("week"),
252 14 => "2 " . $lng->txt("weeks"),
253 30 => "1 " . $lng->txt("month"),
254 60 => "2 " . $lng->txt("months"),
255 120 => "4 " . $lng->txt("months"),
256 180 => "6 " . $lng->txt("months"),
257 365 => "1 " . $lng->txt("year")
258 );
259 $rssp_sel = new ilSelectInputGUI(
260 $lng->txt("news_rss_period"),
261 "news_rss_period"
262 );
263 $rssp_sel->setOptions($rssp_opts);
264 $rssp_sel->setValue((int) $rss_period);
265 $cb_prop->addSubItem($rssp_sel);
266
267 // Section Header: RSS
268 $sh = new ilFormSectionHeaderGUI();
269 $sh->setTitle($lng->txt("news_rss"));
270 $form->addItem($sh);
271
272 // title format for rss entries
273 $options = array(
274 "" => $lng->txt("news_rss_title_format_obj_news"),
275 "news_obj" => $lng->txt("news_rss_title_format_news_obj"),
276 );
277 $si = new ilSelectInputGUI($lng->txt("news_rss_title_format"), "rss_title_format");
278 $si->setOptions($options);
279 $si->setValue($rss_title_format);
280 $cb_prop->addSubItem($si);
281
282 $form->addItem($cb_prop);
283
284 // Enable private news feed
285 $cb_prop = new ilCheckboxInputGUI(
286 $lng->txt("news_enable_private_feed"),
287 "enable_private_feed"
288 );
289 $cb_prop->setValue("1");
290 $cb_prop->setInfo($lng->txt("news_enable_private_feed_info"));
291 $cb_prop->setChecked($enable_private_feed);
292 $form->addItem($cb_prop);
293
294
295 // Section Header: External Web Feeds Settings
296 $sh = new ilFormSectionHeaderGUI();
297 $sh->setTitle($lng->txt("feed_settings"));
298 $form->addItem($sh);
299
300 // Disable External Web Feeds in catetegories
301 $cb_prop = new ilCheckboxInputGUI(
302 $lng->txt("feed_disable_rep_feeds"),
303 "disable_repository_feeds"
304 );
305 $cb_prop->setValue("1");
306 $cb_prop->setInfo($lng->txt("feed_disable_rep_feeds_info"));
307 $cb_prop->setChecked($disable_repository_feeds);
308 $form->addItem($cb_prop);
309
310 if ($ilAccess->checkAccess('write', '', $this->object->getRefId())) {
311 // command buttons
312 $form->addCommandButton("saveSettings", $lng->txt("save"));
313 $form->addCommandButton("view", $lng->txt("cancel"));
314 }
315
316 $this->tpl->setContent($form->getHTML());
317 }
318
322 public function saveSettings()
323 {
324 $ilCtrl = $this->ctrl;
326 $ilAccess = $this->access;
327
328 if (!$ilAccess->checkAccess('write', '', $this->object->getRefId())) {
329 $ilCtrl->redirect($this, "view");
330 }
331
332 // empty news cache
333 include_once("./Services/News/classes/class.ilNewsCache.php");
334 $this->acache = new ilNewsCache();
335 $this->acache->deleteAllEntries();
336
337 $news_set = new ilSetting("news");
338 $feed_set = new ilSetting("feed");
339
340
341
342 $ilSetting->set("block_activated_news", $_POST["enable_internal_news"]);
343 $ilSetting->set("block_activated_pdnews", $_POST["enable_internal_news"]);
344 $news_set->set("enable_rss_for_internal", $_POST["enable_internal_rss"]);
345 $news_set->set("max_items", $_POST["news_max_items"]);
346 $news_set->set("acc_cache_mins", $_POST["news_acc_cache_mins"]);
347 $news_set->set("pd_period", $_POST["news_pd_period"]);
348 $news_set->set("default_visibility", $_POST["news_default_visibility"]);
349 $news_set->set("allow_shorter_periods", $_POST["allow_shorter_periods"]);
350 $news_set->set("allow_longer_periods", $_POST["allow_longer_periods"]);
351 $news_set->set("rss_period", $_POST["news_rss_period"]);
352 $news_set->set("rss_title_format", $_POST["rss_title_format"]);
353
354 $feed_set->set("disable_rep_feeds", $_POST["disable_repository_feeds"]);
355
356 if ($_POST["enable_internal_rss"] != 0) {
357 $news_set->set("enable_private_feed", $_POST["enable_private_feed"]);
358 } else {
359 $news_set->set("enable_private_feed", 0);
360 }
361
362 ilUtil::sendSuccess($this->lng->txt("settings_saved"), true);
363
364 $ilCtrl->redirect($this, "view");
365 }
366}
$_POST["username"]
An exception for terminatinating execution or to throw for unit testing.
error($a_errmsg)
set error message @access public
This class represents a checkbox property in a property form.
This class represents a section header in a property form.
static _lookupRSSPeriod()
static _lookupDefaultPDPeriod()
editSettings()
Edit news settings.
saveSettings()
Save news and external webfeeds settings.
__construct($a_data, $a_id, $a_call_by_reference=true, $a_prepare_output=true)
Contructor.
Class ilObjectGUI Basic methods of all Output classes.
prepareOutput($a_show_subobjects=true)
prepare output
New PermissionGUI (extends from old ilPermission2GUI) RBAC related output.
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.
global $DIC
Definition: goto.php:24
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
$ret
Definition: parser.php:6
global $ilSetting
Definition: privfeed.php:17
$feed_set
Definition: privfeed.php:19
settings()
Definition: settings.php:2