ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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 */
3 include_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  {
71  $ilAccess = $this->access;
72 
73  $next_class = $this->ctrl->getNextClass($this);
74  $cmd = $this->ctrl->getCmd();
75 
76  $this->prepareOutput();
77 
78  if (!$ilAccess->checkAccess('read', '', $this->object->getRefId())) {
79  $ilErr->raiseError($this->lng->txt('no_permission'), $ilErr->WARNING);
80  }
81 
82  switch ($next_class) {
83  case 'ilpermissiongui':
84  $this->tabs_gui->setTabActive('perm_settings');
85  include_once("Services/AccessControl/classes/class.ilPermissionGUI.php");
86  $perm_gui = new ilPermissionGUI($this);
87  $ret = $this->ctrl->forwardCommand($perm_gui);
88  break;
89 
90  default:
91  if (!$cmd || $cmd == 'view') {
92  $cmd = "editSettings";
93  }
94 
95  $this->$cmd();
96  break;
97  }
98  return true;
99  }
100 
107  public function getAdminTabs()
108  {
110  $ilAccess = $this->access;
111 
112  if ($rbacsystem->checkAccess("visible,read", $this->object->getRefId())) {
113  $this->tabs_gui->addTarget(
114  "news_edit_news_settings",
115  $this->ctrl->getLinkTarget($this, "editSettings"),
116  array("editSettings", "view")
117  );
118  }
119 
120  if ($rbacsystem->checkAccess('edit_permission', $this->object->getRefId())) {
121  $this->tabs_gui->addTarget(
122  "perm_settings",
123  $this->ctrl->getLinkTargetByClass('ilpermissiongui', "perm"),
124  array(),
125  'ilpermissiongui'
126  );
127  }
128  }
129 
133  public function editSettings()
134  {
136  $lng = $this->lng;
138  $ilAccess = $this->access;
139 
140  $news_set = new ilSetting("news");
141  $feed_set = new ilSetting("feed");
142 
143  $enable_internal_news = $ilSetting->get("block_activated_news");
144  $enable_internal_rss = $news_set->get("enable_rss_for_internal");
145  $rss_title_format = $news_set->get("rss_title_format");
146  $enable_private_feed = $news_set->get("enable_private_feed");
147  $news_default_visibility = ($news_set->get("default_visibility") != "")
148  ? $news_set->get("default_visibility")
149  : "users";
150  $disable_repository_feeds = $feed_set->get("disable_rep_feeds");
151  $nr_personal_desktop_feeds = $ilSetting->get("block_limit_pdfeed");
152 
153  $allow_shorter_periods = $news_set->get("allow_shorter_periods");
154  $allow_longer_periods = $news_set->get("allow_longer_periods");
155 
156  include_once("./Services/News/classes/class.ilNewsItem.php");
157  $rss_period = ilNewsItem::_lookupRSSPeriod();
158 
159  include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
160  $form = new ilPropertyFormGUI();
161  $form->setFormAction($ilCtrl->getFormAction($this));
162  $form->setTitle($lng->txt("news_settings"));
163 
164  // Enable internal news
165  $cb_prop = new ilCheckboxInputGUI(
166  $lng->txt("news_enable_internal_news"),
167  "enable_internal_news"
168  );
169  $cb_prop->setValue("1");
170  $cb_prop->setInfo($lng->txt("news_enable_internal_news_info"));
171  $cb_prop->setChecked($enable_internal_news);
172  $form->addItem($cb_prop);
173 
174  // Default Visibility
175  $radio_group = new ilRadioGroupInputGUI($lng->txt("news_default_visibility"), "news_default_visibility");
176  $radio_option = new ilRadioOption($lng->txt("news_visibility_users"), "users");
177  $radio_group->addOption($radio_option);
178  $radio_option = new ilRadioOption($lng->txt("news_visibility_public"), "public");
179  $radio_group->addOption($radio_option);
180  $radio_group->setInfo($lng->txt("news_news_item_visibility_info"));
181  $radio_group->setRequired(false);
182  $radio_group->setValue($news_default_visibility);
183  $form->addItem($radio_group);
184 
185  // Number of news items per object
186  $nr_opts = array(50 => 50, 100 => 100, 200 => 200);
187  $nr_sel = new ilSelectInputGUI(
188  $lng->txt("news_nr_of_items"),
189  "news_max_items"
190  );
191  $nr_sel->setInfo($lng->txt("news_nr_of_items_info"));
192  $nr_sel->setOptions($nr_opts);
193  $nr_sel->setValue($news_set->get("max_items"));
194  $form->addItem($nr_sel);
195 
196  // Access Cache
197  $min_opts = array(0 => 0, 1 => 1, 2 => 2, 5 => 5, 10 => 10, 20 => 20, 30 => 30, 60 => 60);
198  $min_sel = new ilSelectInputGUI(
199  $lng->txt("news_cache"),
200  "news_acc_cache_mins"
201  );
202  $min_sel->setInfo($lng->txt("news_cache_info"));
203  $min_sel->setOptions($min_opts);
204  $min_sel->setValue($news_set->get("acc_cache_mins"));
205  $form->addItem($min_sel);
206 
207  // PD News Period
208  $per_opts = array(
209  2 => "2 " . $lng->txt("days"),
210  3 => "3 " . $lng->txt("days"),
211  5 => "5 " . $lng->txt("days"),
212  7 => "1 " . $lng->txt("week"),
213  14 => "2 " . $lng->txt("weeks"),
214  30 => "1 " . $lng->txt("month"),
215  60 => "2 " . $lng->txt("months"),
216  120 => "4 " . $lng->txt("months"),
217  180 => "6 " . $lng->txt("months"),
218  366 => "1 " . $lng->txt("year"));
219  $per_sel = new ilSelectInputGUI(
220  $lng->txt("news_pd_period"),
221  "news_pd_period"
222  );
223  $per_sel->setInfo($lng->txt("news_pd_period_info"));
224  $per_sel->setOptions($per_opts);
225  $per_sel->setValue((int) ilNewsItem::_lookupDefaultPDPeriod());
226  $form->addItem($per_sel);
227 
228  // Allow user to choose lower values
229  $sp_prop = new ilCheckboxInputGUI(
230  $lng->txt("news_allow_shorter_periods"),
231  "allow_shorter_periods"
232  );
233  $sp_prop->setValue("1");
234  $sp_prop->setInfo($lng->txt("news_allow_shorter_periods_info"));
235  $sp_prop->setChecked($allow_shorter_periods);
236  $form->addItem($sp_prop);
237 
238  // Allow user to choose higher values
239  $lp_prop = new ilCheckboxInputGUI(
240  $lng->txt("news_allow_longer_periods"),
241  "allow_longer_periods"
242  );
243  $lp_prop->setValue("1");
244  $lp_prop->setInfo($lng->txt("news_allow_longer_periods_info"));
245  $lp_prop->setChecked($allow_longer_periods);
246  $form->addItem($lp_prop);
247 
248  // Enable rss for internal news
249  $cb_prop = new ilCheckboxInputGUI(
250  $lng->txt("news_enable_internal_rss"),
251  "enable_internal_rss"
252  );
253  $cb_prop->setValue("1");
254  $cb_prop->setInfo($lng->txt("news_enable_internal_rss_info"));
255  $cb_prop->setChecked($enable_internal_rss);
256 
257  // RSS News Period
258  $rssp_opts = array(
259  2 => "2 " . $lng->txt("days"),
260  3 => "3 " . $lng->txt("days"),
261  5 => "5 " . $lng->txt("days"),
262  7 => "1 " . $lng->txt("week"),
263  14 => "2 " . $lng->txt("weeks"),
264  30 => "1 " . $lng->txt("month"),
265  60 => "2 " . $lng->txt("months"),
266  120 => "4 " . $lng->txt("months"),
267  180 => "6 " . $lng->txt("months"),
268  365 => "1 " . $lng->txt("year")
269  );
270  $rssp_sel = new ilSelectInputGUI(
271  $lng->txt("news_rss_period"),
272  "news_rss_period"
273  );
274  $rssp_sel->setOptions($rssp_opts);
275  $rssp_sel->setValue((int) $rss_period);
276  $cb_prop->addSubItem($rssp_sel);
277 
278  // Section Header: RSS
279  $sh = new ilFormSectionHeaderGUI();
280  $sh->setTitle($lng->txt("news_rss"));
281  $form->addItem($sh);
282 
283  // title format for rss entries
284  $options = array(
285  "" => $lng->txt("news_rss_title_format_obj_news"),
286  "news_obj" => $lng->txt("news_rss_title_format_news_obj"),
287  );
288  $si = new ilSelectInputGUI($lng->txt("news_rss_title_format"), "rss_title_format");
289  $si->setOptions($options);
290  $si->setValue($rss_title_format);
291  $cb_prop->addSubItem($si);
292 
293  $form->addItem($cb_prop);
294 
295  // Enable private news feed
296  $cb_prop = new ilCheckboxInputGUI(
297  $lng->txt("news_enable_private_feed"),
298  "enable_private_feed"
299  );
300  $cb_prop->setValue("1");
301  $cb_prop->setInfo($lng->txt("news_enable_private_feed_info"));
302  $cb_prop->setChecked($enable_private_feed);
303  $form->addItem($cb_prop);
304 
305 
306  // Section Header: External Web Feeds Settings
307  $sh = new ilFormSectionHeaderGUI();
308  $sh->setTitle($lng->txt("feed_settings"));
309  $form->addItem($sh);
310 
311  // Number of External Feeds on personal desktop
312  $sel = new ilSelectInputGUI($lng->txt("feed_nr_pd_feeds"), "nr_pd_feeds");
313  $sel->setInfo($lng->txt("feed_nr_pd_feeds_info"));
314  $sel->setOptions(array(0 => "0",
315  1 => "1",
316  2 => "2",
317  3 => "3",
318  4 => "4",
319  5 => "5"));
320  $sel->setValue($nr_personal_desktop_feeds);
321  $form->addItem($sel);
322 
323  // Disable External Web Feeds in catetegories
324  $cb_prop = new ilCheckboxInputGUI(
325  $lng->txt("feed_disable_rep_feeds"),
326  "disable_repository_feeds"
327  );
328  $cb_prop->setValue("1");
329  $cb_prop->setInfo($lng->txt("feed_disable_rep_feeds_info"));
330  $cb_prop->setChecked($disable_repository_feeds);
331  $form->addItem($cb_prop);
332 
333  if ($ilAccess->checkAccess('write', '', $this->object->getRefId())) {
334  // command buttons
335  $form->addCommandButton("saveSettings", $lng->txt("save"));
336  $form->addCommandButton("view", $lng->txt("cancel"));
337  }
338 
339  $this->tpl->setContent($form->getHTML());
340  }
341 
345  public function saveSettings()
346  {
349  $ilAccess = $this->access;
350 
351  if (!$ilAccess->checkAccess('write', '', $this->object->getRefId())) {
352  $ilCtrl->redirect($this, "view");
353  }
354 
355  // empty news cache
356  include_once("./Services/News/classes/class.ilNewsCache.php");
357  $this->acache = new ilNewsCache();
358  $this->acache->deleteAllEntries();
359 
360  $news_set = new ilSetting("news");
361  $feed_set = new ilSetting("feed");
362 
363 
364 
365  $ilSetting->set("block_activated_news", $_POST["enable_internal_news"]);
366  $ilSetting->set("block_activated_pdnews", $_POST["enable_internal_news"]);
367  $news_set->set("enable_rss_for_internal", $_POST["enable_internal_rss"]);
368  $news_set->set("max_items", $_POST["news_max_items"]);
369  $news_set->set("acc_cache_mins", $_POST["news_acc_cache_mins"]);
370  $news_set->set("pd_period", $_POST["news_pd_period"]);
371  $news_set->set("default_visibility", $_POST["news_default_visibility"]);
372  $news_set->set("allow_shorter_periods", $_POST["allow_shorter_periods"]);
373  $news_set->set("allow_longer_periods", $_POST["allow_longer_periods"]);
374  $news_set->set("rss_period", $_POST["news_rss_period"]);
375  $news_set->set("rss_title_format", $_POST["rss_title_format"]);
376 
377  $feed_set->set("disable_rep_feeds", $_POST["disable_repository_feeds"]);
378  $ilSetting->set("block_limit_pdfeed", $_POST["nr_pd_feeds"]);
379  if ($_POST["nr_pd_feeds"] > 0) {
380  $ilSetting->set("block_activated_pdfeed", 1);
381  } else {
382  $ilSetting->set("block_activated_pdfeed", 0);
383  }
384 
385  if ($_POST["enable_internal_rss"] != 0) {
386  $news_set->set("enable_private_feed", $_POST["enable_private_feed"]);
387  } else {
388  $news_set->set("enable_private_feed", 0);
389  }
390 
391  ilUtil::sendSuccess($this->lng->txt("settings_saved"), true);
392 
393  $ilCtrl->redirect($this, "view");
394  }
395 }
This class represents an option in a radio group.
settings()
Definition: settings.php:2
static _lookupRSSPeriod()
This class represents a selection list property in a property form.
This class represents a property form user interface.
global $DIC
Definition: saml.php:7
This class represents a section header in a property form.
This class represents a checkbox property in a property form.
setInfo($a_info)
Set Info.
News cache.
global $ilCtrl
Definition: ilias.php:18
setInfo($a_info)
Set Information Text.
prepareOutput($a_show_subobjects=true)
prepare output
This class represents a property in a property form.
if(isset($_POST['submit'])) $form
Class ilObjectGUI Basic methods of all Output classes.
setValue($a_value)
Set Value.
$feed_set
Definition: privfeed.php:19
setOptions($a_options)
Set Options.
global $ilSetting
Definition: privfeed.php:17
$ret
Definition: parser.php:6
saveSettings()
Save news and external webfeeds settings.
New PermissionGUI (extends from old ilPermission2GUI) RBAC related output.
__construct($a_data, $a_id, $a_call_by_reference=true, $a_prepare_output=true)
Contructor.
editSettings()
Edit news settings.
$_POST["username"]
static _lookupDefaultPDPeriod()