ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
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 if (is_array($hide_news_date)) {
152 $dt_prop->setDate(new ilDateTime($hide_news_date[0] . ' ' . ($hide_news_date[1] ?? "12:00:00"), IL_CAL_DATETIME));
153 }
154
155 $dt_prop->setShowTime(true);
156
157 $hnpd->addSubItem($dt_prop);
158
159 $form->addItem($hnpd);
160 }
161
162 // public notifications (forums)
163 if ($this->has_public_notification) {
164 $public = ilBlockSetting::_lookup("news", "public_notifications", 0, $block_id);
165
166 $ch = new ilCheckboxInputGUI(
167 $this->lng->txt("news_notifications_public"),
168 "public_notifications"
169 );
170 $ch->setInfo($this->lng->txt("news_notifications_public_info"));
171 $ch->setChecked((bool) $public);
172 $form->addItem($ch);
173 }
174
175 $form->setTitle($this->lng->txt("cont_news_settings"));
176 $form->setFormAction($this->ctrl->getFormAction($this));
177 $form->addCommandButton("save", $this->lng->txt("save"));
178
179 return $form;
180 }
181
182 public function save(): void
183 {
184 $form = $this->initForm();
185 if ($form->checkInput()) {
186 //non container objects force this news block (forums etc.)
187 if (!$this->has_block_forced) {
188 $this->object->setNewsBlockActivated($form->getInput(ilObjectServiceSettingsGUI::NEWS_VISIBILITY));
189 }
190 if ($this->has_timeline) {
191 $this->object->setNewsTimeline($form->getInput("news_timeline"));
192 $this->object->setNewsTimelineAutoEntries($form->getInput("news_timeline_auto_entries"));
193 $this->object->setNewsTimelineLandingPage($form->getInput("news_timeline_landing_page"));
194 }
195 if ($this->setting->get('block_activated_news')) {
196 //save contextblock settings
197 $context_block_settings = [
198 "public_feed" => $form->getInput("notifications_public_feed") ?? "",
199 "default_visibility" => $form->getInput("default_visibility"),
200 "hide_news_per_date" => $form->getInput("hide_news_per_date"),
201 "hide_news_date" => $form->getInput("hide_news_date")
202 ];
203 if ($this->has_public_notification) {
204 $context_block_settings["public_notifications"] =
205 $form->getInput('public_notifications');
206 }
207
208 ilNewsForContextBlockGUI::writeSettings($context_block_settings);
209
210 if (in_array(ilObject::_lookupType($this->object->getId()), ['crs', 'grp'])) {
211 $ref_ids = ilObject::_getAllReferences($this->object->getId());
212 $ref_id = array_pop($ref_ids);
213
215 }
216 }
217
218 $this->object->update();
219 $this->tpl->setOnScreenMessage('success', $this->lng->txt("msg_obj_modified"), true);
220 $this->ctrl->redirect($this, "");
221 } else {
222 $form->setValuesByPost();
223 $this->tpl->setContent($form->getHTML());
224 }
225 }
226
227 // Set all possible news options as false;
228 public function initDefaultOptions(): void
229 {
230 $this->has_timeline = false;
231 $this->has_cron_notifications = false;
232 $this->has_hide_by_date = false;
233 $this->has_block_forced = false;
234 }
235
236 public function setTimeline(bool $a_value): void
237 {
238 $this->has_timeline = $a_value;
239 }
240
241 public function getTimeline(): bool
242 {
243 return $this->has_timeline;
244 }
245
246 public function setCronNotifications(bool $a_value): void
247 {
248 $this->has_cron_notifications = $a_value;
249 }
250
251 public function getCronNotifications(): bool
252 {
254 }
255
256 public function setHideByDate(bool $a_value): void
257 {
258 $this->has_hide_by_date = $a_value;
259 }
260
261 public function getHideByDate(): bool
262 {
264 }
265
266 public function setPublicNotification(bool $a_value): void
267 {
268 $this->has_public_notification = $a_value;
269 }
270
271 public function getPublicNotification(): bool
272 {
274 }
275
276 // Set if the repository object has the news block forced
277 public function setNewsBlockForced(bool $a_value): void
278 {
279 $this->has_block_forced = $a_value;
280 }
281
282 public function getNewsBlockForced(): bool
283 {
285 }
286}
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.
$ref_id
Definition: ltiauth.php:66
global $DIC
Definition: shib_login.php:26