ILIAS  trunk Revision v12.0_alpha-1329-g1094ddb0c33
class.ilContainerNewsSettingsGUI.php
Go to the documentation of this file.
1<?php
2
25{
26 protected ilCtrl $ctrl;
28 protected ilLanguage $lng;
31 protected ilTree $tree;
33 protected ilObject $object;
34 protected bool $has_timeline = false;
35 protected bool $has_cron_notifications = false;
36 protected bool $has_hide_by_date = false;
37 protected bool $has_public_notification = false;
38 protected bool $has_block_forced = false;
39
40 public function __construct(ilObjectGUI $a_parent_gui)
41 {
42 global $DIC;
43
44 $this->ctrl = $DIC->ctrl();
45 $this->lng = $DIC->language();
46 $this->lng->loadLanguageModule("news");
47 $this->tpl = $DIC["tpl"];
48 $this->setting = $DIC["ilSetting"];
49 $this->access = $DIC->access();
50 $this->tree = $DIC->repositoryTree();
51 $this->parent_gui = $a_parent_gui;
52 $this->object = $this->parent_gui->getObject();
53
54 $this->initDefaultOptions();
55 }
56
57 public function executeCommand(): void
58 {
59 $next_class = $this->ctrl->getNextClass($this);
60 $cmd = $this->ctrl->getCmd("show");
61
62 switch ($next_class) {
63 default:
64 if (in_array($cmd, ["show", "save"])) {
65 $this->checkPermission('write');
66 $this->$cmd();
67 }
68 }
69 }
70
71 protected function checkPermission(string $perm): void
72 {
73 if ($this->access->checkAccess($perm, '', $this->object->getRefId())) {
74 return;
75 }
76
77 $this->tpl->setOnScreenMessage(
79 $this->lng->txt('msg_no_perm_read'),
80 true
81 );
82 $parent_ref_id = $this->tree->getParentId($this->object->getRefId());
83 $this->ctrl->redirectToURL($parent_ref_id > 0 ? ilLink::_getLink($parent_ref_id) : 'login.php?cmd=force_login');
84 }
85
86 public function show(): void
87 {
88 $form = $this->initForm();
89 $this->tpl->setContent($form->getHTML());
90 }
91
92 public function initForm(): ilPropertyFormGUI
93 {
94 $form = new ilPropertyFormGUI();
95 //from crs/grp/cat settings - additional feature - news
96
97 if ($this->setting->get('block_activated_news')) {
98 $news = new ilCheckboxInputGUI($this->lng->txt('news_news_block'), ilObjectServiceSettingsGUI::NEWS_VISIBILITY);
99 $news->setValue('1');
100 if ($this->has_block_forced) {
101 $news->setChecked(true);
102 $news->setDisabled(true);
103 } else {
104 $news->setChecked($this->object->getNewsBlockActivated());
105 }
106 $news->setInfo($this->lng->txt('obj_tool_setting_news_info'));
108 $form->addItem($news);
109 }
110
111 // Timeline (courses and groups)
112 if ($this->has_timeline) {
113 // timeline
114 $cb = new ilCheckboxInputGUI($this->lng->txt("cont_news_timeline"), "news_timeline");
115 $cb->setInfo($this->lng->txt("cont_news_timeline_info"));
116 $cb->setChecked($this->object->getNewsTimeline());
117 $form->addItem($cb);
118
119 // ...timeline: auto entries
120 $cb2 = new ilCheckboxInputGUI($this->lng->txt("cont_news_timeline_auto_entries"), "news_timeline_auto_entries");
121 $cb2->setInfo($this->lng->txt("cont_news_timeline_auto_entries_info"));
122 $cb2->setChecked($this->object->getNewsTimelineAutoEntries());
123 $cb->addSubItem($cb2);
124
125 // ...timeline: landing page
126 $cb2 = new ilCheckboxInputGUI($this->lng->txt("cont_news_timeline_landing_page"), "news_timeline_landing_page");
127 $cb2->setInfo($this->lng->txt("cont_news_timeline_landing_page_info"));
128 $cb2->setChecked($this->object->getNewsTimelineLandingPage());
129 $cb->addSubItem($cb2);
130 }
131
132 // Cron Notifications (courses and groups)
133 if ($this->has_cron_notifications && in_array(ilObject::_lookupType($this->object->getId()), ['crs', 'grp'])) {
134 $ref_ids = ilObject::_getAllReferences($this->object->getId());
135 $ref_id = array_pop($ref_ids);
137 }
138
139 $block_id = $this->ctrl->getContextObjId();
140
141 // Visibility by date
142 $hide_news_per_date = ilBlockSetting::_lookup(
144 "hide_news_per_date",
145 0,
146 $block_id
147 );
148 $hide_news_date = ilBlockSetting::_lookup(
150 "hide_news_date",
151 0,
152 $block_id
153 );
154
155 if ($hide_news_date != "") {
156 $hide_news_date = explode(" ", $hide_news_date);
157 }
158
159 // Hide news before a date (courses, groups and categories)
160 if ($this->has_hide_by_date) {
161 //Hide news per date
162 $hnpd = new ilCheckboxInputGUI(
163 $this->lng->txt("news_hide_news_per_date"),
164 "hide_news_per_date"
165 );
166 $hnpd->setInfo($this->lng->txt("news_hide_news_per_date_info"));
167 $hnpd->setChecked((bool) $hide_news_per_date);
168
169 $dt_prop = new ilDateTimeInputGUI($this->lng->txt("news_hide_news_date"), "hide_news_date");
170 $dt_prop->setRequired(true);
171 if (is_array($hide_news_date)) {
172 $dt_prop->setDate(new ilDateTime($hide_news_date[0] . ' ' . ($hide_news_date[1] ?? "12:00:00"), IL_CAL_DATETIME));
173 }
174
175 $dt_prop->setShowTime(true);
176
177 $hnpd->addSubItem($dt_prop);
178
179 $form->addItem($hnpd);
180 }
181
182 // public notifications (forums)
183 if ($this->has_public_notification) {
184 $public = ilBlockSetting::_lookup("news", "public_notifications", 0, $block_id);
185
186 $ch = new ilCheckboxInputGUI(
187 $this->lng->txt("news_notifications_public"),
188 "public_notifications"
189 );
190 $ch->setInfo($this->lng->txt("news_notifications_public_info"));
191 $ch->setChecked((bool) $public);
192 $form->addItem($ch);
193 }
194
195 $form->setTitle($this->lng->txt("cont_news_settings"));
196 $form->setFormAction($this->ctrl->getFormAction($this));
197 $form->addCommandButton("save", $this->lng->txt("save"));
198
199 return $form;
200 }
201
202 public function save(): void
203 {
204 $form = $this->initForm();
205 if ($form->checkInput()) {
206 //non container objects force this news block (forums etc.)
207 if (!$this->has_block_forced) {
208 $this->object->setNewsBlockActivated($form->getInput(ilObjectServiceSettingsGUI::NEWS_VISIBILITY));
209 }
210 if ($this->has_timeline) {
211 $this->object->setNewsTimeline($form->getInput("news_timeline"));
212 $this->object->setNewsTimelineAutoEntries($form->getInput("news_timeline_auto_entries"));
213 $this->object->setNewsTimelineLandingPage($form->getInput("news_timeline_landing_page"));
214 }
215 if ($this->setting->get('block_activated_news')) {
216 //save contextblock settings
217 $context_block_settings = [
218 "public_feed" => $form->getInput("notifications_public_feed") ?? "",
219 "default_visibility" => $form->getInput("default_visibility"),
220 "hide_news_per_date" => $form->getInput("hide_news_per_date"),
221 "hide_news_date" => $form->getInput("hide_news_date")
222 ];
223 if ($this->has_public_notification) {
224 $context_block_settings["public_notifications"] =
225 $form->getInput('public_notifications');
226 }
227
228 ilNewsForContextBlockGUI::writeSettings($context_block_settings);
229
230 if (in_array(ilObject::_lookupType($this->object->getId()), ['crs', 'grp'])) {
231 $ref_ids = ilObject::_getAllReferences($this->object->getId());
232 $ref_id = array_pop($ref_ids);
233
235 }
236 }
237
238 $this->object->update();
239 $this->tpl->setOnScreenMessage('success', $this->lng->txt("msg_obj_modified"), true);
240 $this->ctrl->redirect($this, "");
241 } else {
242 $form->setValuesByPost();
243 $this->tpl->setContent($form->getHTML());
244 }
245 }
246
247 // Set all possible news options as false;
248 public function initDefaultOptions(): void
249 {
250 $this->has_timeline = false;
251 $this->has_cron_notifications = false;
252 $this->has_hide_by_date = false;
253 $this->has_block_forced = false;
254 }
255
256 public function setTimeline(bool $a_value): void
257 {
258 $this->has_timeline = $a_value;
259 }
260
261 public function getTimeline(): bool
262 {
263 return $this->has_timeline;
264 }
265
266 public function setCronNotifications(bool $a_value): void
267 {
268 $this->has_cron_notifications = $a_value;
269 }
270
271 public function getCronNotifications(): bool
272 {
274 }
275
276 public function setHideByDate(bool $a_value): void
277 {
278 $this->has_hide_by_date = $a_value;
279 }
280
281 public function getHideByDate(): bool
282 {
284 }
285
286 public function setPublicNotification(bool $a_value): void
287 {
288 $this->has_public_notification = $a_value;
289 }
290
291 public function getPublicNotification(): bool
292 {
294 }
295
296 // Set if the repository object has the news block forced
297 public function setNewsBlockForced(bool $a_value): void
298 {
299 $this->has_block_forced = $a_value;
300 }
301
302 public function getNewsBlockForced(): bool
303 {
305 }
306}
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 class represents a date/time property in a property form.
@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.
Class ilObject Basic functions for all objects.
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.
ILIAS Setting Class.
Tree class data representation in hierachical trees using the Nested Set Model with Gaps by Joe Celco...
Interface ilAccessHandler This interface combines all available interfaces which can be called via gl...
$ref_id
Definition: ltiauth.php:66
global $DIC
Definition: shib_login.php:26