ILIAS  Release_4_4_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
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  const CALENDAR_VISIBILITY = 'cont_show_calendar';
17  const NEWS_VISIBILITY = 'cont_show_news';
18  const AUTO_RATING_NEW_OBJECTS = 'cont_auto_rate_new_obj';
19  const INFO_TAB_VISIBILITY = 'cont_show_info_tab';
20 
21  private $gui = null;
22  private $modes = array();
23  private $obj_id = 0;
24 
29  public function __construct($a_parent_gui, $a_obj_id, $a_modes)
30  {
31  $this->gui = $a_parent_gui;
32  $this->modes = $a_modes;
33  $this->obj_id = $a_obj_id;
34  }
35 
36 
37 
42  public function executeCommand()
43  {
44  global $ilCtrl;
45 
46  $next_class = $ilCtrl->getNextClass($this);
47  $cmd = $ilCtrl->getCmd('editSettings');
48 
49  switch($next_class)
50  {
51  default:
52  $this->$cmd();
53  break;
54  }
55  }
56 
62  public static function initServiceSettingsForm($a_obj_id, ilPropertyFormGUI $form, $services)
63  {
64  global $ilSetting;
65 
66  // info tab
67  if(in_array(self::INFO_TAB_VISIBILITY, $services))
68  {
69  $info = new ilCheckboxInputGUI($GLOBALS['lng']->txt('obj_tool_setting_info_tab'), self::INFO_TAB_VISIBILITY);
70  $info->setValue(1);
71  $info->setChecked(ilContainer::_lookupContainerSetting(
72  $a_obj_id,
73  self::INFO_TAB_VISIBILITY,
74  true
75  ));
76  //$info->setOptionTitle($GLOBALS['lng']->txt('obj_tool_setting_info_tab'));
77  $info->setInfo($GLOBALS['lng']->txt('obj_tool_setting_info_tab_info'));
78  $form->addItem($info);
79  }
80 
81  // calendar
82  if(in_array(self::CALENDAR_VISIBILITY, $services))
83  {
84  include_once './Services/Calendar/classes/class.ilObjCalendarSettings.php';
85  if(ilCalendarSettings::_getInstance()->isEnabled())
86  {
87  // Container tools (calendar, news, ... activation)
88  $cal = new ilCheckboxInputGUI($GLOBALS['lng']->txt('obj_tool_setting_calendar'), self::CALENDAR_VISIBILITY);
89  $cal->setValue(1);
90  include_once './Services/Calendar/classes/class.ilObjCalendarSettings.php';
91  $cal->setChecked(ilCalendarSettings::lookupCalendarActivated($a_obj_id));
92  //$cal->setOptionTitle($GLOBALS['lng']->txt('obj_tool_setting_calendar'));
93  $cal->setInfo($GLOBALS['lng']->txt('obj_tool_setting_calendar_info'));
94  $form->addItem($cal);
95  }
96  }
97 
98  // news
99  if(in_array(self::NEWS_VISIBILITY, $services))
100  {
101  if($ilSetting->get('block_activated_news'))
102  {
103  // Container tools (calendar, news, ... activation)
104  $news = new ilCheckboxInputGUI($GLOBALS['lng']->txt('obj_tool_setting_news'), self::NEWS_VISIBILITY);
105  $news->setValue(1);
106  $news->setChecked(ilContainer::_lookupContainerSetting(
107  $a_obj_id,
108  self::NEWS_VISIBILITY,
109  $ilSetting->get('block_activated_news',true)
110  ));
111  //$news->setOptionTitle($GLOBALS['lng']->txt('obj_tool_setting_news'));
112  $news->setInfo($GLOBALS['lng']->txt('obj_tool_setting_news_info'));
113  $form->addItem($news);
114  }
115  }
116 
117  // auto rating
118  if(in_array(self::AUTO_RATING_NEW_OBJECTS, $services))
119  {
120  $GLOBALS['lng']->loadLanguageModule("rating");
121 
122  // auto rating for new objects
123  $rate = new ilCheckboxInputGUI($GLOBALS['lng']->txt('rating_new_objects_auto'), self::AUTO_RATING_NEW_OBJECTS);
124  $rate->setValue(1);
125  //$rate->setOptionTitle($GLOBALS['lng']->txt('rating_new_objects_auto'));
126  $rate->setInfo($GLOBALS['lng']->txt('rating_new_objects_auto_info'));
127  $rate->setChecked(ilContainer::_lookupContainerSetting(
128  $a_obj_id,
129  self::AUTO_RATING_NEW_OBJECTS,
130  false
131  ));
132  $form->addItem($rate);
133  }
134 
135  return $form;
136  }
137 
144  public static function updateServiceSettingsForm($a_obj_id, ilPropertyFormGUI $form, $services)
145  {
146  // info
147  if(in_array(self::INFO_TAB_VISIBILITY, $services))
148  {
149  include_once './Services/Container/classes/class.ilContainer.php';
150  ilContainer::_writeContainerSetting($a_obj_id,self::INFO_TAB_VISIBILITY,(int) $form->getInput(self::INFO_TAB_VISIBILITY));
151  }
152 
153  // calendar
154  if(in_array(self::CALENDAR_VISIBILITY, $services))
155  {
156  include_once './Services/Calendar/classes/class.ilCalendarSettings.php';
157  if(ilCalendarSettings::_getInstance()->isEnabled())
158  {
159  include_once './Services/Container/classes/class.ilContainer.php';
160  ilContainer::_writeContainerSetting($a_obj_id,self::CALENDAR_VISIBILITY,(int) $form->getInput(self::CALENDAR_VISIBILITY));
161  }
162  }
163 
164  // news
165  if(in_array(self::NEWS_VISIBILITY, $services))
166  {
167  include_once './Services/Container/classes/class.ilContainer.php';
168  ilContainer::_writeContainerSetting($a_obj_id,self::NEWS_VISIBILITY,(int) $form->getInput(self::NEWS_VISIBILITY));
169  }
170 
171  // rating
172  if(in_array(self::AUTO_RATING_NEW_OBJECTS, $services))
173  {
174  include_once './Services/Container/classes/class.ilContainer.php';
175  ilContainer::_writeContainerSetting($a_obj_id,self::AUTO_RATING_NEW_OBJECTS,(int) $form->getInput(self::AUTO_RATING_NEW_OBJECTS));
176  }
177 
178  return true;
179  }
180 
181 
186  public function getModes()
187  {
188  return $this->modes;
189  }
190 
195  public function getObjId()
196  {
197  return $this->obj_id;
198  }
199 
200  protected function cancel()
201  {
202  $GLOBALS['ilCtrl']->returnToParent($this);
203  }
204 
209  protected function editSettings(ilPropertyFormGUI $form = null)
210  {
211  if(!$form instanceof ilPropertyFormGUI)
212  {
213  $form = $this->initSettingsForm();
214  }
215  $GLOBALS['tpl']->setContent($form->getHTML());
216  }
217 
218 
222  protected function updateToolSettings()
223  {
224  $form = $this->initSettingsForm();
225  if($form->checkInput())
226  {
227  include_once './Services/Calendar/classes/class.ilCalendarSettings.php';
228  if(ilCalendarSettings::_getInstance()->isEnabled())
229  {
230  if($this->isModeActive(self::CALENDAR_VISIBILITY))
231  {
232  ilContainer::_writeContainerSetting($this->getObjId(),'show_calendar',(int) $form->getInput('calendar'));
233  }
234  }
235  ilUtil::sendSuccess($GLOBALS['lng']->txt('settings_saved'),true);
236  $GLOBALS['ilCtrl']->redirect($this);
237  }
238 
239  ilUtil::sendFailure($GLOBALS['lng']->txt('err_check_input'));
240  $form->setValuesByPost();
241  $this->editSettings($form);
242  }
243 
249  protected function isModeActive($a_mode)
250  {
251  return in_array($a_mode, $this->getModes());
252  }
253 
254 }
255 ?>