ILIAS  release_8 Revision v8.24
class.ilContainerNewsSettingsGUI.php
Go to the documentation of this file.
1<?php
2
25{
26 protected ilCtrl $ctrl;
28 protected ilLanguage $lng;
31 protected ilObject $object;
32 protected bool $has_timeline = false;
33 protected bool $has_cron_notifications = false;
34 protected bool $has_hide_by_date = false;
35 protected bool $has_public_notification = false;
36 protected bool $has_block_forced = false;
37
38 public function __construct(ilObjectGUI $a_parent_gui)
39 {
40 global $DIC;
41
42 $this->ctrl = $DIC->ctrl();
43 $this->lng = $DIC->language();
44 $this->lng->loadLanguageModule("news");
45 $this->tpl = $DIC["tpl"];
46 $this->setting = $DIC["ilSetting"];
47 $this->parent_gui = $a_parent_gui;
48 $this->object = $this->parent_gui->getObject();
49
50 $this->initDefaultOptions();
51 }
52
53 public function executeCommand(): void
54 {
55 $next_class = $this->ctrl->getNextClass($this);
56 $cmd = $this->ctrl->getCmd("show");
57
58 switch ($next_class) {
59 default:
60 if (in_array($cmd, ["show", "save"])) {
61 $this->$cmd();
62 }
63 }
64 }
65
66 public function show(): void
67 {
68 $form = $this->initForm();
69 $this->tpl->setContent($form->getHTML());
70 }
71
72 public function initForm(): ilPropertyFormGUI
73 {
74 $form = new ilPropertyFormGUI();
75 //from crs/grp/cat settings - additional feature - news
76
77 if ($this->setting->get('block_activated_news')) {
78 $news = new ilCheckboxInputGUI($this->lng->txt('news_news_block'), ilObjectServiceSettingsGUI::NEWS_VISIBILITY);
79 $news->setValue('1');
80 if ($this->has_block_forced) {
81 $news->setChecked(true);
82 $news->setDisabled(true);
83 } else {
84 $news->setChecked($this->object->getNewsBlockActivated());
85 }
86 $news->setInfo($this->lng->txt('obj_tool_setting_news_info'));
88 $form->addItem($news);
89 }
90
91 // Timeline (courses and groups)
92 if ($this->has_timeline) {
93 // timeline
94 $cb = new ilCheckboxInputGUI($this->lng->txt("cont_news_timeline"), "news_timeline");
95 $cb->setInfo($this->lng->txt("cont_news_timeline_info"));
96 $cb->setChecked($this->object->getNewsTimeline());
97 $form->addItem($cb);
98
99 // ...timeline: auto entries
100 $cb2 = new ilCheckboxInputGUI($this->lng->txt("cont_news_timeline_auto_entries"), "news_timeline_auto_entries");
101 $cb2->setInfo($this->lng->txt("cont_news_timeline_auto_entries_info"));
102 $cb2->setChecked($this->object->getNewsTimelineAutoEntries());
103 $cb->addSubItem($cb2);
104
105 // ...timeline: landing page
106 $cb2 = new ilCheckboxInputGUI($this->lng->txt("cont_news_timeline_landing_page"), "news_timeline_landing_page");
107 $cb2->setInfo($this->lng->txt("cont_news_timeline_landing_page_info"));
108 $cb2->setChecked($this->object->getNewsTimelineLandingPage());
109 $cb->addSubItem($cb2);
110 }
111
112 // Cron Notifications (courses and groups)
113 if ($this->has_cron_notifications && in_array(ilObject::_lookupType($this->object->getId()), ['crs', 'grp'])) {
114 $ref_ids = ilObject::_getAllReferences($this->object->getId());
115 $ref_id = array_pop($ref_ids);
117 }
118
119 $block_id = $this->ctrl->getContextObjId();
120
121 // Visibility by date
122 $hide_news_per_date = ilBlockSetting::_lookup(
124 "hide_news_per_date",
125 0,
126 $block_id
127 );
128 $hide_news_date = ilBlockSetting::_lookup(
130 "hide_news_date",
131 0,
132 $block_id
133 );
134
135 if ($hide_news_date != "") {
136 $hide_news_date = explode(" ", $hide_news_date);
137 }
138
139 // Hide news before a date (courses, groups and categories)
140 if ($this->has_hide_by_date) {
141 //Hide news per date
142 $hnpd = new ilCheckboxInputGUI(
143 $this->lng->txt("news_hide_news_per_date"),
144 "hide_news_per_date"
145 );
146 $hnpd->setInfo($this->lng->txt("news_hide_news_per_date_info"));
147 $hnpd->setChecked((bool) $hide_news_per_date);
148
149 $dt_prop = new ilDateTimeInputGUI($this->lng->txt("news_hide_news_date"), "hide_news_date");
150 $dt_prop->setRequired(true);
151
152 if ($hide_news_date != "") {
153 $dt_prop->setDate(new ilDateTime($hide_news_date[0] . ' ' . $hide_news_date[1], IL_CAL_DATETIME));
154 }
155
156 $dt_prop->setShowTime(true);
157
158 $hnpd->addSubItem($dt_prop);
159
160 $form->addItem($hnpd);
161 }
162
163 // public notifications (forums)
164 if ($this->has_public_notification) {
165 $public = ilBlockSetting::_lookup("news", "public_notifications", 0, $block_id);
166
167 $ch = new ilCheckboxInputGUI(
168 $this->lng->txt("news_notifications_public"),
169 "public_notifications"
170 );
171 $ch->setInfo($this->lng->txt("news_notifications_public_info"));
172 $ch->setChecked((bool) $public);
173 $form->addItem($ch);
174 }
175
176 $form->setTitle($this->lng->txt("cont_news_settings"));
177 $form->setFormAction($this->ctrl->getFormAction($this));
178 $form->addCommandButton("save", $this->lng->txt("save"));
179
180 return $form;
181 }
182
183 public function save(): void
184 {
185 $form = $this->initForm();
186 if ($form->checkInput()) {
187 //non container objects force this news block (forums etc.)
188 if (!$this->has_block_forced) {
189 $this->object->setNewsBlockActivated($form->getInput(ilObjectServiceSettingsGUI::NEWS_VISIBILITY));
190 }
191 if ($this->has_timeline) {
192 $this->object->setNewsTimeline($form->getInput("news_timeline"));
193 $this->object->setNewsTimelineAutoEntries($form->getInput("news_timeline_auto_entries"));
194 $this->object->setNewsTimelineLandingPage($form->getInput("news_timeline_landing_page"));
195 }
196 if ($this->setting->get('block_activated_news')) {
197 //save contextblock settings
198 $context_block_settings = [
199 "public_feed" => $form->getInput("notifications_public_feed") ?? "",
200 "default_visibility" => $form->getInput("default_visibility"),
201 "hide_news_per_date" => $form->getInput("hide_news_per_date"),
202 "hide_news_date" => $form->getInput("hide_news_date")
203 ];
204 if ($this->has_public_notification) {
205 $context_block_settings["public_notifications"] =
206 $form->getInput('public_notifications');
207 }
208
209 ilNewsForContextBlockGUI::writeSettings($context_block_settings);
210
211 if (in_array(ilObject::_lookupType($this->object->getId()), ['crs', 'grp'])) {
212 $ref_ids = ilObject::_getAllReferences($this->object->getId());
213 $ref_id = array_pop($ref_ids);
214
216 }
217 }
218
219 $this->object->update();
220 $this->tpl->setOnScreenMessage('success', $this->lng->txt("msg_obj_modified"), true);
221 $this->ctrl->redirect($this, "");
222 } else {
223 $form->setValuesByPost();
224 $this->tpl->setContent($form->getHTML());
225 }
226 }
227
228 // Set all possible news options as false;
229 public function initDefaultOptions(): void
230 {
231 $this->has_timeline = false;
232 $this->has_cron_notifications = false;
233 $this->has_hide_by_date = false;
234 $this->has_block_forced = false;
235 }
236
237 public function setTimeline(bool $a_value): void
238 {
239 $this->has_timeline = $a_value;
240 }
241
242 public function getTimeline(): bool
243 {
244 return $this->has_timeline;
245 }
246
247 public function setCronNotifications(bool $a_value): void
248 {
249 $this->has_cron_notifications = $a_value;
250 }
251
252 public function getCronNotifications(): bool
253 {
255 }
256
257 public function setHideByDate(bool $a_value): void
258 {
259 $this->has_hide_by_date = $a_value;
260 }
261
262 public function getHideByDate(): bool
263 {
265 }
266
267 public function setPublicNotification(bool $a_value): void
268 {
269 $this->has_public_notification = $a_value;
270 }
271
272 public function getPublicNotification(): bool
273 {
275 }
276
277 // Set if the repository object has the news block forced
278 public function setNewsBlockForced(bool $a_value): void
279 {
280 $this->has_block_forced = $a_value;
281 }
282
283 public function getNewsBlockForced(): bool
284 {
286 }
287}
const IL_CAL_DATETIME
static _lookup(string $a_type, string $a_setting, int $a_user=0, int $a_block_id=0)
Lookup setting from database.
This class represents a checkbox property in a property form.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Class ilCtrl provides processing control methods.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
@classDescription Date and time handling
language handling
static importFromForm(int $a_ref_id, ?ilPropertyFormGUI $a_form=null)
static addToSettingsForm(int $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.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static _lookupType(int $id, bool $reference=false)
static _getAllReferences(int $id)
get all reference ids for object ID
This class represents a property form user interface.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
global $DIC
Definition: feed.php:28
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$ref_id
Definition: ltiauth.php:67