ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
class.ilObjectServiceSettingsGUI.php
Go to the documentation of this file.
1 <?php
2 
3 /* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
4 
15 {
16  // unfortunately the following constants are not stored
17  // in a non-GUI class, other classes are currently directly
18  // accessing these, see ilObjectDataSet (changes should be
19  // made there accordingly)
20 
21  const CALENDAR_VISIBILITY = 'cont_show_calendar';
22  const NEWS_VISIBILITY = 'cont_show_news';
23  const USE_NEWS = 'cont_use_news';
24  const AUTO_RATING_NEW_OBJECTS = 'cont_auto_rate_new_obj';
25  const INFO_TAB_VISIBILITY = 'cont_show_info_tab';
26  const TAXONOMIES = 'cont_taxonomies';
27  const TAG_CLOUD = 'cont_tag_cloud';
28  const CUSTOM_METADATA = 'cont_custom_md';
29  const BADGES = 'cont_badges';
30 
31  private $gui = null;
32  private $modes = array();
33  private $obj_id = 0;
34 
39  public function __construct($a_parent_gui, $a_obj_id, $a_modes)
40  {
41  $this->gui = $a_parent_gui;
42  $this->modes = $a_modes;
43  $this->obj_id = $a_obj_id;
44  }
45 
46 
47 
52  public function executeCommand()
53  {
54  global $ilCtrl;
55 
56  $next_class = $ilCtrl->getNextClass($this);
57  $cmd = $ilCtrl->getCmd('editSettings');
58 
59  switch($next_class)
60  {
61  default:
62  $this->$cmd();
63  break;
64  }
65  }
66 
72  public static function initServiceSettingsForm($a_obj_id, ilPropertyFormGUI $form, $services)
73  {
74  global $ilSetting, $ilCtrl;
75 
76  // info tab
77  if(in_array(self::INFO_TAB_VISIBILITY, $services))
78  {
79  $info = new ilCheckboxInputGUI($GLOBALS['lng']->txt('obj_tool_setting_info_tab'), self::INFO_TAB_VISIBILITY);
80  $info->setValue(1);
82  $a_obj_id,
83  self::INFO_TAB_VISIBILITY,
84  true
85  ));
86  //$info->setOptionTitle($GLOBALS['lng']->txt('obj_tool_setting_info_tab'));
87  $info->setInfo($GLOBALS['lng']->txt('obj_tool_setting_info_tab_info'));
88  $form->addItem($info);
89  }
90 
91  // calendar
92  if(in_array(self::CALENDAR_VISIBILITY, $services))
93  {
94  include_once './Services/Calendar/classes/class.ilObjCalendarSettings.php';
95  if(ilCalendarSettings::_getInstance()->isEnabled())
96  {
97  // Container tools (calendar, news, ... activation)
98  $cal = new ilCheckboxInputGUI($GLOBALS['lng']->txt('obj_tool_setting_calendar'), self::CALENDAR_VISIBILITY);
99  $cal->setValue(1);
100  include_once './Services/Calendar/classes/class.ilObjCalendarSettings.php';
101  $cal->setChecked(ilCalendarSettings::lookupCalendarActivated($a_obj_id));
102  //$cal->setOptionTitle($GLOBALS['lng']->txt('obj_tool_setting_calendar'));
103  $cal->setInfo($GLOBALS['lng']->txt('obj_tool_setting_calendar_info'));
104  $form->addItem($cal);
105  }
106  }
107 
108  // news
109  if(in_array(self::USE_NEWS, $services))
110  {
111  $news = new ilCheckboxInputGUI($GLOBALS['lng']->txt('obj_tool_setting_use_news'), self::USE_NEWS);
112  $news->setValue(1);
114  $a_obj_id,
115  self::USE_NEWS,
116  true
117  );
118  $news->setChecked($checked);
119  $info = $GLOBALS['lng']->txt('obj_tool_setting_use_news_info');
120  if ($checked)
121  {
122  $info.=" <a href='".$ilCtrl->getLinkTargetByClass("ilcontainernewssettingsgui", "").
123  "'>ยป ".$GLOBALS['lng']->txt('obj_tool_setting_use_news_open_settings')."</a>";
124  }
125  $news->setInfo($info);
126  $form->addItem($news);
127 
128  }
129  if(in_array(self::NEWS_VISIBILITY, $services))
130  {
131  if($ilSetting->get('block_activated_news'))
132  {
133  // Container tools (calendar, news, ... activation)
134  $news = new ilCheckboxInputGUI($GLOBALS['lng']->txt('obj_tool_setting_news'), self::NEWS_VISIBILITY);
135  $news->setValue(1);
136  $news->setChecked(ilContainer::_lookupContainerSetting(
137  $a_obj_id,
138  self::NEWS_VISIBILITY,
139  $ilSetting->get('block_activated_news',true)
140  ));
141  //$news->setOptionTitle($GLOBALS['lng']->txt('obj_tool_setting_news'));
142  $news->setInfo($GLOBALS['lng']->txt('obj_tool_setting_news_info'));
143  $form->addItem($news);
144 
145  if(in_array(ilObject::_lookupType($a_obj_id), array('crs', 'grp')))
146  {
147  $ref_id = array_pop(ilObject::_getAllReferences($a_obj_id));
148 
149  include_once 'Services/Membership/classes/class.ilMembershipNotifications.php';
151  }
152  }
153  }
154 
155  // (local) custom metadata
156  if(in_array(self::CUSTOM_METADATA, $services))
157  {
158  $md = new ilCheckboxInputGUI($GLOBALS['lng']->txt('obj_tool_setting_custom_metadata'), self::CUSTOM_METADATA);
159  $md->setInfo($GLOBALS['lng']->txt('obj_tool_setting_custom_metadata_info'));
160  $md->setValue(1);
161  $md->setChecked(ilContainer::_lookupContainerSetting(
162  $a_obj_id,
163  self::CUSTOM_METADATA,
164  false
165  ));
166  $form->addItem($md);
167  }
168 
169  // tag cloud
170  if(in_array(self::TAG_CLOUD, $services))
171  {
172  $tags_active = new ilSetting("tags");
173  if($tags_active->get("enable", false))
174  {
175  $tag = new ilCheckboxInputGUI($GLOBALS['lng']->txt('obj_tool_setting_tag_cloud'), self::TAG_CLOUD);
176  $tag->setInfo($GLOBALS['lng']->txt('obj_tool_setting_tag_cloud_info'));
177  $tag->setValue(1);
178  $tag->setChecked(ilContainer::_lookupContainerSetting(
179  $a_obj_id,
180  self::TAG_CLOUD,
181  false
182  ));
183  $form->addItem($tag);
184  }
185  }
186 
187  // taxonomies
188  if(in_array(self::TAXONOMIES, $services))
189  {
190  $tax = new ilCheckboxInputGUI($GLOBALS['lng']->txt('obj_tool_setting_taxonomies'), self::TAXONOMIES);
191  $tax->setValue(1);
192  $tax->setChecked(ilContainer::_lookupContainerSetting(
193  $a_obj_id,
194  self::TAXONOMIES,
195  false
196  ));
197  $form->addItem($tax);
198  }
199 
200  // auto rating
201  if(in_array(self::AUTO_RATING_NEW_OBJECTS, $services))
202  {
203  $GLOBALS['lng']->loadLanguageModule("rating");
204 
205  // auto rating for new objects
206  $rate = new ilCheckboxInputGUI($GLOBALS['lng']->txt('rating_new_objects_auto'), self::AUTO_RATING_NEW_OBJECTS);
207  $rate->setValue(1);
208  //$rate->setOptionTitle($GLOBALS['lng']->txt('rating_new_objects_auto'));
209  $rate->setInfo($GLOBALS['lng']->txt('rating_new_objects_auto_info'));
210  $rate->setChecked(ilContainer::_lookupContainerSetting(
211  $a_obj_id,
212  self::AUTO_RATING_NEW_OBJECTS,
213  false
214  ));
215  $form->addItem($rate);
216  }
217 
218  // badges
219  if(in_array(self::BADGES, $services))
220  {
221  include_once 'Services/Badge/classes/class.ilBadgeHandler.php';
222  if(ilBadgeHandler::getInstance()->isActive())
223  {
224  $bdg = new ilCheckboxInputGUI($GLOBALS['lng']->txt('obj_tool_setting_badges'), self::BADGES);
225  $bdg->setInfo($GLOBALS['lng']->txt('obj_tool_setting_badges_info'));
226  $bdg->setValue(1);
227  $bdg->setChecked(ilContainer::_lookupContainerSetting(
228  $a_obj_id,
229  self::BADGES,
230  false
231  ));
232  $form->addItem($bdg);
233  }
234  }
235 
236  return $form;
237  }
238 
245  public static function updateServiceSettingsForm($a_obj_id, ilPropertyFormGUI $form, $services)
246  {
247  // info
248  if(in_array(self::INFO_TAB_VISIBILITY, $services))
249  {
250  include_once './Services/Container/classes/class.ilContainer.php';
251  ilContainer::_writeContainerSetting($a_obj_id,self::INFO_TAB_VISIBILITY,(int) $form->getInput(self::INFO_TAB_VISIBILITY));
252  }
253 
254  // calendar
255  if(in_array(self::CALENDAR_VISIBILITY, $services))
256  {
257  include_once './Services/Calendar/classes/class.ilCalendarSettings.php';
258  if(ilCalendarSettings::_getInstance()->isEnabled())
259  {
260  include_once './Services/Container/classes/class.ilContainer.php';
261  ilContainer::_writeContainerSetting($a_obj_id,self::CALENDAR_VISIBILITY,(int) $form->getInput(self::CALENDAR_VISIBILITY));
262  }
263  }
264 
265  // news
266  if(in_array(self::USE_NEWS, $services))
267  {
268  include_once './Services/Container/classes/class.ilContainer.php';
269  ilContainer::_writeContainerSetting($a_obj_id,self::USE_NEWS,(int) $form->getInput(self::USE_NEWS));
270  }
271  if(in_array(self::NEWS_VISIBILITY, $services))
272  {
273  include_once './Services/Container/classes/class.ilContainer.php';
274  ilContainer::_writeContainerSetting($a_obj_id,self::NEWS_VISIBILITY,(int) $form->getInput(self::NEWS_VISIBILITY));
275 
276  if(in_array(ilObject::_lookupType($a_obj_id), array('crs', 'grp')))
277  {
278  $ref_id = array_pop(ilObject::_getAllReferences($a_obj_id));
279 
280  include_once "Services/Membership/classes/class.ilMembershipNotifications.php";
282  }
283  }
284 
285  // rating
286  if(in_array(self::AUTO_RATING_NEW_OBJECTS, $services))
287  {
288  include_once './Services/Container/classes/class.ilContainer.php';
289  ilContainer::_writeContainerSetting($a_obj_id,self::AUTO_RATING_NEW_OBJECTS,(int) $form->getInput(self::AUTO_RATING_NEW_OBJECTS));
290  }
291 
292  // taxonomies
293  if(in_array(self::TAXONOMIES, $services))
294  {
295  include_once './Services/Container/classes/class.ilContainer.php';
296  ilContainer::_writeContainerSetting($a_obj_id,self::TAXONOMIES,(int) $form->getInput(self::TAXONOMIES));
297  }
298 
299  // tag cloud
300  if(in_array(self::TAG_CLOUD, $services))
301  {
302  include_once './Services/Container/classes/class.ilContainer.php';
303  ilContainer::_writeContainerSetting($a_obj_id,self::TAG_CLOUD,(int) $form->getInput(self::TAG_CLOUD));
304  }
305 
306  // (local) custom metadata
307  if(in_array(self::CUSTOM_METADATA, $services))
308  {
309  include_once './Services/Container/classes/class.ilContainer.php';
310  ilContainer::_writeContainerSetting($a_obj_id,self::CUSTOM_METADATA,(int) $form->getInput(self::CUSTOM_METADATA));
311  }
312 
313  // badges
314  if(in_array(self::BADGES, $services))
315  {
316  include_once 'Services/Badge/classes/class.ilBadgeHandler.php';
317  if(ilBadgeHandler::getInstance()->isActive())
318  {
319  include_once './Services/Container/classes/class.ilContainer.php';
320  ilContainer::_writeContainerSetting($a_obj_id,self::BADGES,(int) $form->getInput(self::BADGES));
321  }
322  }
323 
324  return true;
325  }
326 
327 
332  public function getModes()
333  {
334  return $this->modes;
335  }
336 
341  public function getObjId()
342  {
343  return $this->obj_id;
344  }
345 
346  protected function cancel()
347  {
348  $GLOBALS['ilCtrl']->returnToParent($this);
349  }
350 
355  protected function editSettings(ilPropertyFormGUI $form = null)
356  {
357  if(!$form instanceof ilPropertyFormGUI)
358  {
359  $form = $this->initSettingsForm();
360  }
361  $GLOBALS['tpl']->setContent($form->getHTML());
362  }
363 
364 
368  protected function updateToolSettings()
369  {
370  $form = $this->initSettingsForm();
371  if($form->checkInput())
372  {
373  include_once './Services/Calendar/classes/class.ilCalendarSettings.php';
374  if(ilCalendarSettings::_getInstance()->isEnabled())
375  {
376  if($this->isModeActive(self::CALENDAR_VISIBILITY))
377  {
378  ilContainer::_writeContainerSetting($this->getObjId(),'show_calendar',(int) $form->getInput('calendar'));
379  }
380  }
381  ilUtil::sendSuccess($GLOBALS['lng']->txt('settings_saved'),true);
382  $GLOBALS['ilCtrl']->redirect($this);
383  }
384 
385  ilUtil::sendFailure($GLOBALS['lng']->txt('err_check_input'));
386  $form->setValuesByPost();
387  $this->editSettings($form);
388  }
389 
395  protected function isModeActive($a_mode)
396  {
397  return in_array($a_mode, $this->getModes());
398  }
399 
400 }
401 ?>
static sendSuccess($a_info="", $a_keep=false)
Send Success Message to Screen.
ILIAS Setting Class.
static _getInstance()
get singleton instance
isModeActive($a_mode)
Check if specific mode is active.
This class represents a property form user interface.
static lookupCalendarActivated($a_obj_id)
$GLOBALS['loaded']
Global hash that tracks already loaded includes.
$cmd
Definition: sahs_server.php:35
This class represents a checkbox property in a property form.
addItem($a_item)
Add Item (Property, SectionHeader).
static _getAllReferences($a_id)
get all reference ids of object
global $ilCtrl
Definition: ilias.php:18
$info
Definition: example_052.php:80
__construct($a_parent_gui, $a_obj_id, $a_modes)
Constructor.
static addToSettingsForm($a_ref_id, ilPropertyFormGUI $a_form=null, ilFormPropertyGUI $a_input=null)
Add notification settings to form.
getInput($a_post_var, $ensureValidation=true)
Returns the value of a HTTP-POST variable, identified by the passed id.
static updateServiceSettingsForm($a_obj_id, ilPropertyFormGUI $form, $services)
Update service settings.
Create styles array
The data for the language used.
static _lookupType($a_id, $a_reference=false)
lookup object type
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
static _lookupContainerSetting($a_id, $a_keyword, $a_default_value=NULL)
Lookup a container setting.
$ref_id
Definition: sahs_server.php:39
global $ilSetting
Definition: privfeed.php:17
static initServiceSettingsForm($a_obj_id, ilPropertyFormGUI $form, $services)
Init service settings form.
static _writeContainerSetting($a_id, $a_keyword, $a_value)
editSettings(ilPropertyFormGUI $form=null)
Edit tool settings (calendar, news, comments, ...)
GUI class for service settings (calendar, notes, comments)
static importFromForm($a_ref_id, ilPropertyFormGUI $a_form=null)
Import notification settings from form.
static getInstance()
Constructor.