ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilContainerNewsSettingsGUI.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (c) 1998-2016 ILIAS open source, Extended GPL, see docs/LICENSE */
4
13{
17 protected $ctrl;
18
22 protected $tpl;
23
27 protected $lng;
28
32 protected $setting;
33
37 protected $parent_gui;
38
42 protected $object;
43
47 protected $has_timeline;
48
53
58
63
68
72 public function __construct(ilObjectGUI $a_parent_gui)
73 {
74 global $DIC;
75
76 $this->ctrl = $DIC->ctrl();
77 $this->lng = $DIC->language();
78 $this->lng->loadLanguageModule("news");
79 $this->tpl = $DIC["tpl"];
80 $this->setting = $DIC["ilSetting"];
81 $this->parent_gui = $a_parent_gui;
82 $this->object = $this->parent_gui->object;
83
84 $this->initDefaultOptions();
85 }
86
90 public function executeCommand()
91 {
92 $next_class = $this->ctrl->getNextClass($this);
93 $cmd = $this->ctrl->getCmd("show");
94
95 switch ($next_class) {
96 default:
97 if (in_array($cmd, array("show", "save"))) {
98 $this->$cmd();
99 }
100 }
101 }
102
109 public function show()
110 {
111 $form = $this->initForm();
112 $this->tpl->setContent($form->getHTML());
113 }
114
118 public function initForm()
119 {
120 $form = new ilPropertyFormGUI();
121 //from crs/grp/cat settings - additional feature - news
122
123 if ($this->setting->get('block_activated_news')) {
124 $news = new ilCheckboxInputGUI($this->lng->txt('news_news_block'), ilObjectServiceSettingsGUI::NEWS_VISIBILITY);
125 $news->setValue(1);
126 if ($this->has_block_forced) {
127 $news->setChecked(true);
128 $news->setDisabled(true);
129 } else {
130 $news->setChecked($this->object->getNewsBlockActivated());
131 }
132 $news->setInfo($this->lng->txt('obj_tool_setting_news_info'));
134 $form->addItem($news);
135 }
136
137 // Timeline (courses and groups)
138 if ($this->has_timeline) {
139 // timeline
140 $cb = new ilCheckboxInputGUI($this->lng->txt("cont_news_timeline"), "news_timeline");
141 $cb->setInfo($this->lng->txt("cont_news_timeline_info"));
142 $cb->setChecked($this->object->getNewsTimeline());
143 $form->addItem($cb);
144
145 // ...timeline: auto entries
146 $cb2 = new ilCheckboxInputGUI($this->lng->txt("cont_news_timeline_auto_entries"), "news_timeline_auto_entries");
147 $cb2->setInfo($this->lng->txt("cont_news_timeline_auto_entries_info"));
148 $cb2->setChecked($this->object->getNewsTimelineAutoEntries());
149 $cb->addSubItem($cb2);
150
151 // ...timeline: landing page
152 $cb2 = new ilCheckboxInputGUI($this->lng->txt("cont_news_timeline_landing_page"), "news_timeline_landing_page");
153 $cb2->setInfo($this->lng->txt("cont_news_timeline_landing_page_info"));
154 $cb2->setChecked($this->object->getNewsTimelineLandingPage());
155 $cb->addSubItem($cb2);
156 }
157
158 // Cron Notifications (courses and groups)
159 if ($this->has_cron_notifications) {
160 if (in_array(ilObject::_lookupType($this->object->getId()), array('crs', 'grp'))) {
161 $ref_id = array_pop(ilObject::_getAllReferences($this->object->getId()));
162 include_once 'Services/Membership/classes/class.ilMembershipNotifications.php';
164 }
165 }
166
167 $block_id = $this->ctrl->getContextObjId();
168
169 // Visibility by date
170 $hide_news_per_date = ilBlockSetting::_lookup(
172 "hide_news_per_date",
173 0,
174 $block_id
175 );
176 $hide_news_date = ilBlockSetting::_lookup(
178 "hide_news_date",
179 0,
180 $block_id
181 );
182
183 if ($hide_news_date != "") {
184 $hide_news_date = explode(" ", $hide_news_date);
185 }
186
187 // Hide news before a date (courses, groups and categories)
188 if ($this->has_hide_by_date) {
189 //Hide news per date
190 $hnpd = new ilCheckboxInputGUI(
191 $this->lng->txt("news_hide_news_per_date"),
192 "hide_news_per_date"
193 );
194 $hnpd->setInfo($this->lng->txt("news_hide_news_per_date_info"));
195 $hnpd->setChecked($hide_news_per_date);
196
197 $dt_prop = new ilDateTimeInputGUI($this->lng->txt("news_hide_news_date"), "hide_news_date");
198 $dt_prop->setRequired(true);
199
200 if ($hide_news_date != "") {
201 $dt_prop->setDate(new ilDateTime($hide_news_date[0] . ' ' . $hide_news_date[1], IL_CAL_DATETIME));
202 }
203
204 $dt_prop->setShowTime(true);
205
206 $hnpd->addSubItem($dt_prop);
207
208 $form->addItem($hnpd);
209 }
210
211 // public notifications (forums)
212 if ($this->has_public_notification) {
213 $public = ilBlockSetting::_lookup("news", "public_notifications", 0, $block_id);
214
215 $ch = new ilCheckboxInputGUI(
216 $this->lng->txt("news_notifications_public"),
217 "public_notifications"
218 );
219 $ch->setInfo($this->lng->txt("news_notifications_public_info"));
220 $ch->setChecked($public);
221 $form->addItem($ch);
222 }
223
224 $form->setTitle($this->lng->txt("cont_news_settings"));
225 $form->setFormAction($this->ctrl->getFormAction($this));
226 $form->addCommandButton("save", $this->lng->txt("save"));
227
228 return $form;
229 }
230
234 public function save()
235 {
236 $form = $this->initForm();
237 if ($form->checkInput()) {
238 include_once("./Services/Object/classes/class.ilObjectServiceSettingsGUI.php");
239 //non container objects force this news block (forums etc.)
240 if (!$this->has_block_forced) {
241 $this->object->setNewsBlockActivated($form->getInput(ilObjectServiceSettingsGUI::NEWS_VISIBILITY));
242 }
243 if ($this->has_timeline) {
244 $this->object->setNewsTimeline($form->getInput("news_timeline"));
245 $this->object->setNewsTimelineAutoEntries($form->getInput("news_timeline_auto_entries"));
246 $this->object->setNewsTimelineLandingPage($form->getInput("news_timeline_landing_page"));
247 }
248 if ($this->setting->get('block_activated_news')) {
249 //save contextblock settings
250 $context_block_settings = array(
251 "public_feed" => $_POST["notifications_public_feed"],
252 "default_visibility" => $_POST["default_visibility"],
253 "hide_news_per_date" => $_POST["hide_news_per_date"],
254 "hide_news_date" => $_POST["hide_news_date"]
255 );
256 if ($this->has_public_notification) {
257 $context_block_settings["public_notifications"] = $_POST['public_notifications'];
258 }
259
260 ilNewsForContextBlockGUI::writeSettings($context_block_settings);
261
262 if (in_array(ilObject::_lookupType($this->object->getId()), array('crs', 'grp'))) {
263 $ref_id = array_pop(ilObject::_getAllReferences($this->object->getId()));
264
265 include_once "Services/Membership/classes/class.ilMembershipNotifications.php";
267 }
268 }
269
270 $this->object->update();
271 ilUtil::sendSuccess($this->lng->txt("msg_obj_modified"), true);
272 $this->ctrl->redirect($this, "");
273 } else {
274 $form->setValuesByPost();
275 $this->tpl->setContent($form->getHtml());
276 }
277 }
278
282 public function initDefaultOptions()
283 {
284 $this->has_timeline = false;
285 $this->has_cron_notifications = false;
286 $this->has_hide_by_date = false;
287 $this->has_block_forced = false;
288 }
289
294 public function setTimeline(bool $a_value)
295 {
296 $this->has_timeline = $a_value;
297 }
298
303 public function getTimeline() : bool
304 {
305 return $this->has_timeline;
306 }
307
312 public function setCronNotifications(bool $a_value)
313 {
314 $this->has_cron_notifications = $a_value;
315 }
316
321 public function getCronNotifications() : bool
322 {
323 return $this->getCronNotifications();
324 }
325
330 public function setHideByDate(bool $a_value)
331 {
332 $this->has_hide_by_date = $a_value;
333 }
334
339 public function getHideByDate() : bool
340 {
342 }
343
348 public function setPublicNotification(bool $a_value)
349 {
350 $this->has_public_notification = $a_value;
351 }
352
357 public function getPublicNotification()
358 {
360 }
361
366 public function setNewsBlockForced(bool $a_value)
367 {
368 $this->has_block_forced = $a_value;
369 }
370
375 public function getNewsBlockForced() : bool
376 {
378 }
379}
$_POST["username"]
An exception for terminatinating execution or to throw for unit testing.
const IL_CAL_DATETIME
static _lookup($a_type, $a_setting, $a_user=0, $a_block_id=0)
Lookup setting from database.
This class represents a checkbox property in a property form.
getPublicNotification()
Get if this repository object has public notifications available.
getHideByDate()
Get if the container can hide news created before a date.
getTimeline()
Get if the container has timeline or not.
getCronNotifications()
Get if the container has a configurable cron job to send notifications.
setHideByDate(bool $a_value)
Set if the container can hide news created before a date.
initDefaultOptions()
Set all possible news options as false;.
setNewsBlockForced(bool $a_value)
Set if the News block is forced.
getNewsBlockForced()
Get if the repository object has the news block forced.
setPublicNotification(bool $a_value)
Set if this repository object has public notifications.
setCronNotifications(bool $a_value)
Set if the container has a configurable cron job to send notifications.
__construct(ilObjectGUI $a_parent_gui)
Constructor.
setTimeline(bool $a_value)
Set if the container has timeline or not.
This class represents a date/time property in a property form.
@classDescription Date and time handling
static importFromForm($a_ref_id, ilPropertyFormGUI $a_form=null)
Import notification settings from form.
static addToSettingsForm($a_ref_id, ilPropertyFormGUI $a_form=null, ilFormPropertyGUI $a_input=null)
Add notification settings to form.
static addToSettingsForm(ilFormPropertyGUI $a_input)
Add inputs to the container news settings form to configure also the contextBlock options.
Class ilObjectGUI Basic methods of all Output classes.
static _getAllReferences($a_id)
get all reference ids of object
static _lookupType($a_id, $a_reference=false)
lookup object type
This class represents a property form user interface.
if(isset($_POST['submit'])) $form
global $DIC
Definition: saml.php:7