ILIAS  Release_4_2_x_branch Revision 61807
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilChatroomSettingsTask.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 
14 {
15 
16  private $gui;
17 
27  public function __construct(ilDBayObjectGUI $gui)
28  {
29  $this->gui = $gui;
30 
31  require_once 'Modules/Chatroom/classes/class.ilChatroomFormFactory.php';
32  require_once 'Modules/Chatroom/classes/class.ilChatroom.php';
33  require_once 'Modules/Chatroom/classes/class.ilChatroomInstaller.php';
34  //ilChatroomInstaller::install();
35  }
36 
45  public function general(ilPropertyFormGUI $settingsForm = null)
46  {
47  global $lng, $tpl, $ilCtrl;
48 
49  if ( !ilChatroom::checkUserPermissions( array('read', 'write') , $this->gui->ref_id ) )
50  {
51  ilUtil::redirect("repository.php");
52  }
53 
54  $chatSettings = new ilSetting('chatroom');
55  if( !$chatSettings->get('chat_enabled') )
56  {
57  ilUtil::sendInfo($lng->txt('server_disabled'), true);
58  }
59 
60  $this->gui->switchToVisibleMode();
61 
62  $formFactory = new ilChatroomFormFactory();
63 
64  if( !$settingsForm )
65  {
66  $settingsForm = $formFactory->getSettingsForm();
67  }
68 
69  $room = ilChatRoom::byObjectId( $this->gui->object->getId() );
70 
71  $settings = array(
72  'title' => $this->gui->object->getTitle(),
73  'desc' => $this->gui->object->getDescription(),
74  );
75 
76  if( $room )
77  {
78  //$settingsForm->setValuesByArray(array_merge($settings, $room->getSettings()));
80  $settingsForm, array_merge( $settings, $room->getSettings() )
81  );
82  }
83  else
84  {
85  //$settingsForm->setValuesByArray($settings);
86  ilChatroomFormFactory::applyValues( $settingsForm, $settings );
87  }
88 
89  $settingsForm->setTitle( $lng->txt('settings_title') );
90  $settingsForm->addCommandButton( 'settings-saveGeneral', $lng->txt( 'save' ) );
91  $settingsForm->addCommandButton( 'settings-general', $lng->txt( 'cancel' ) );
92  $settingsForm->setFormAction(
93  $ilCtrl->getFormAction( $this->gui, 'settings-saveGeneral' )
94  );
95 
96  $tpl->setVariable( 'ADM_CONTENT', $settingsForm->getHtml() );
97  }
98 
104  public function saveGeneral()
105  {
106  global $ilCtrl, $lng;
107 
108  $formFactory = new ilChatroomFormFactory();
109  $settingsForm = $formFactory->getSettingsForm();
110 
111  if( !$settingsForm->checkInput() )
112  {
113  $this->general( $settingsForm );
114  }
115  else
116  {
117  $this->gui->object->setTitle( $_POST['title'] );
118  $this->gui->object->setDescription( $_POST['desc'] );
119  $this->gui->object->update();
120 
121  $settings = $_POST;
122  $room = ilChatRoom::byObjectId( $this->gui->object->getId() );
123 
124  if( !$room )
125  {
126  $room = new ilChatRoom();
127  $settings['object_id'] = $this->gui->object->getId();
128  }
129 //var_dump($settings);exit;
130  $room->saveSettings( $settings );
131 
132  ilUtil::sendSuccess($lng->txt('saved_successfully'), true);
133 
134  $ilCtrl->redirect( $this->gui, 'settings-general' );
135  }
136  }
137 
143  public function executeDefault($requestedMethod)
144  {
145  $this->general();
146  }
147 
148 }
149 
150 ?>