ILIAS  release_7 Revision v7.30-3-g800a261c036
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilObjCommentsSettingsGUI.php
Go to the documentation of this file.
1 <?php
2 
3 /* Copyright (c) 1998-2019 ILIAS open source, Extended GPL, see docs/LICENSE */
4 
14 {
18  protected $rbacsystem;
19 
23  protected $error;
24 
28  protected $request;
29 
33  protected $tabs;
34 
38  protected $ui;
39 
40 
44  protected $setting;
45 
49  protected $main_tpl;
50 
51 
57  public function __construct($a_data, $a_id, $a_call_by_reference = true, $a_prepare_output = true)
58  {
59  global $DIC;
60 
61  $this->lng = $DIC->language();
62  $this->rbacsystem = $DIC->rbac()->system();
63  $this->error = $DIC["ilErr"];
64  $this->ctrl = $DIC->ctrl();
65  $this->request = $DIC->http()->request();
66  $this->tabs = $DIC->tabs();
67  $this->ui = $DIC->ui();
68  $this->setting = $DIC->settings();
69  $this->main_tpl = $DIC->ui()->mainTemplate();
70 
71  $this->type = 'coms';
72 
73  parent::__construct($a_data, $a_id, $a_call_by_reference, $a_prepare_output);
74 
75  $this->lng->loadLanguageModule("note");
76  }
77 
82  public function executeCommand()
83  {
87 
88  $next_class = $ctrl->getNextClass($this);
89  $cmd = $ctrl->getCmd("editSettings");
90 
91  if (!$rbacsystem->checkAccess("visible,read", $this->object->getRefId())) {
92  $this->error->raiseError($this->lng->txt('no_permission'), $this->error->WARNING);
93  }
94 
95  $this->prepareOutput();
96 
97  switch ($next_class) {
98  case 'ilpermissiongui':
99  $tabs->activateTab('perm_settings');
100  $perm_gui = new ilPermissionGUI($this);
101  $ctrl->forwardCommand($perm_gui);
102  break;
103 
104  default:
105  if ($cmd == "view") {
106  $cmd = "editSettings";
107  }
108  if (in_array($cmd, ["editSettings", "saveSettings"])) {
109  $this->$cmd();
110  }
111  break;
112  }
113  }
114 
118  public function getAdminTabs()
119  {
121  $lng = $this->lng;
122  $tabs = $this->tabs;
123  $ctrl = $this->ctrl;
124 
125  if ($rbacsystem->checkAccess("visible,read", $this->object->getRefId())) {
126  $tabs->addTab(
127  "settings",
128  $lng->txt("settings"),
129  $ctrl->getLinkTarget($this, "editSettings")
130  );
131  }
132 
133  if ($rbacsystem->checkAccess('edit_permission', $this->object->getRefId())) {
134  $tabs->addTab(
135  "perm_settings",
136  $lng->txt("perm_settings"),
137  $ctrl->getLinkTargetByClass('ilpermissiongui', "perm")
138  );
139  }
140  }
141 
145  public function editSettings()
146  {
148  $ui = $this->ui;
149  $tabs = $this->tabs;
150 
151  $tabs->activateTab("settings");
152 
153  $form = $this->initForm();
154  $main_tpl->setContent($ui->renderer()->render($form));
155  }
156 
161  public function initForm()
162  {
163  $ui = $this->ui;
164  $f = $ui->factory();
165  $ctrl = $this->ctrl;
166  $lng = $this->lng;
168 
169  $subfields["comm_del_user"] = $f->input()->field()->checkbox(
170  $lng->txt("note_enable_comments_del_user")
171  )
172  ->withValue((bool) $setting->get("comments_del_user", 0));
173  $subfields["comm_del_tutor"] = $f->input()->field()->checkbox(
174  $lng->txt("note_enable_comments_del_tutor"),
175  $lng->txt("note_enable_comments_del_tutor_info")
176  )
177  ->withValue((bool) $setting->get("comments_del_tutor", 1));
178  $subfields["comments_noti_recip"] = $f->input()->field()->text(
179  $lng->txt("note_comments_notification"),
180  $lng->txt("note_comments_notification_info")
181  )
182  ->withValue((string) $setting->get("comments_noti_recip"));
183 
184  $privacy = ilPrivacySettings::_getInstance();
185  $subfields["enable_comments_export"] = $f->input()->field()->checkbox(
186  $lng->txt("enable_comments_export"),
187  $lng->txt("note_enable_comments_export_info")
188  )
189  ->withValue((bool) $privacy->enabledCommentsExport());
190 
191 
192  $fields["enable_comments"] = $f->input()->field()->optionalGroup(
193  $subfields,
194  $lng->txt("note_enable_comments"),
195  $lng->txt("")
196  );
197  if ($setting->get("disable_comments")) {
198  $fields["enable_comments"] = $fields["enable_comments"]->withValue(null);
199  }
200 
201  // section
202  $section1 = $f->input()->field()->section($fields, $lng->txt("settings"));
203 
204  $form_action = $ctrl->getLinkTarget($this, "saveSettings");
205  return $f->input()->container()->form()->standard($form_action, ["sec" => $section1]);
206  }
207 
211  public function saveSettings()
212  {
214  $form = $this->initForm();
215  $lng = $this->lng;
216  $ctrl = $this->ctrl;
218 
219  if ($request->getMethod() == "POST") {
220  $form = $form->withRequest($request);
221  $data = $form->getData();
222  if (is_array($data["sec"])) {
223  $data = $data["sec"]["enable_comments"];
224  $setting->set("disable_comments", (is_array($data) ? 0 : 1));
225  $setting->set("comments_del_user", ($data["comm_del_user"] ? 1 : 0));
226  $setting->set("comments_del_tutor", ($data["comm_del_tutor"] ? 1 : 0));
227  $setting->set("comments_noti_recip", $data["comments_noti_recip"]);
228 
229  $privacy = ilPrivacySettings::_getInstance();
230  $privacy->enableCommentsExport((bool) $data['enable_comments_export']);
231  $privacy->save();
232 
233  ilUtil::sendInfo($lng->txt("msg_obj_modified"), true);
234  }
235  }
236  $ctrl->redirect($this, "editSettings");
237  }
238 
239  public function addToExternalSettingsForm($a_form_id)
240  {
241  switch ($a_form_id) {
243 
244  $privacy = ilPrivacySettings::_getInstance();
245 
246  $fields = array('enable_comments_export' => array($privacy->enabledCommentsExport(), ilAdministrationSettingsFormHandler::VALUE_BOOL));
247 
248  return array(array("editSettings", $fields));
249  }
250  }
251 }
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
prepareOutput($a_show_subobjects=true)
prepare output
Class ilObjectGUI Basic methods of all Output classes.
global $DIC
Definition: goto.php:24
ui()
Definition: ui.php:5
__construct(Container $dic, ilPlugin $plugin)
__construct($a_data, $a_id, $a_call_by_reference=true, $a_prepare_output=true)
Contructor.
New PermissionGUI (extends from old ilPermission2GUI) RBAC related output.
static _getInstance()
Get instance of ilPrivacySettings.