ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilForumProperties.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
28{
29 public const VIEW_TREE = 1;
30 public const VIEW_DATE = 2;
31 public const VIEW_DATE_ASC = 2;
32 public const VIEW_DATE_DESC = 3;
34 public const FILE_UPLOAD_INDIVIDUAL = 1;
35 public const PAGE_SIZE_THREAD_OVERVIEW = 10;
36 public const PAGE_NAME_THREAD_OVERVIEW = 'page';
37
39 private static array $instances = [];
40
41 private readonly ilDBInterface $db;
43 private bool $anonymized = false;
44 private bool $statistics_enabled = false;
45 private bool $post_activation_enabled = false;
48 private bool $admin_force_noti = false;
50 private bool $user_toggle_noti = false;
52 private bool $preset_subject = true;
56 private bool $add_re_subject = false;
57 private bool $mark_mod_posts = false;
58 private bool $is_thread_rating_enabled = false;
59 private bool $file_upload_allowed = false;
60 protected int $styleId = 0;
61 private bool $exists = false;
62 private ?int $lp_req_num_postings = null;
64
65 protected function __construct(private int $obj_id = 0)
66 {
67 global $DIC;
68
69 $this->db = $DIC->database();
70 $this->read();
71 }
72
73 private function contentStyle(): \ILIAS\Style\Content\Object\ObjectFacade
74 {
75 global $DIC;
76
77 if ($this->content_style_service === null) {
78 $this->content_style_service = $DIC->contentStyle()->domain()->styleForObjId($this->obj_id);
79 }
80
82 }
83
84 public static function getInstance(int $a_obj_id = 0): self
85 {
86 if (!isset(self::$instances[$a_obj_id])) {
87 self::$instances[$a_obj_id] = new self($a_obj_id);
88 }
89
90 return self::$instances[$a_obj_id];
91 }
92
93 private function read(): void
94 {
95 if ($this->obj_id !== 0) {
96 $res = $this->db->queryF(
97 'SELECT * FROM frm_settings WHERE obj_id = %s',
98 ['integer'],
99 [$this->obj_id]
100 );
101
102 $row = $this->db->fetchObject($res);
103 if (is_object($row)) {
104 $this->exists = true;
105
106 $this->default_view = (int) $row->default_view;
107 $this->anonymized = (bool) $row->anonymized;
108 $this->statistics_enabled = (bool) $row->statistics_enabled;
109 $this->post_activation_enabled = (bool) $row->post_activation;
110 $this->admin_force_noti = (bool) $row->admin_force_noti;
111 $this->user_toggle_noti = (bool) $row->user_toggle_noti;
112 $this->preset_subject = (bool) $row->preset_subject;
113 $this->add_re_subject = (bool) $row->add_re_subject;
114 $this->interested_events = (int) $row->interested_events;
115
116 $this->notification_type =
117 NotificationType::tryFrom($row->notification_type ?? NotificationType::DEFAULT->value) ??
119 $this->mark_mod_posts = (bool) $row->mark_mod_posts;
120 $this->is_thread_rating_enabled = (bool) $row->thread_rating;
121 $this->file_upload_allowed = (bool) $row->file_upload_allowed;
122 if (is_numeric($row->lp_req_num_postings)) {
123 $this->lp_req_num_postings = (int) $row->lp_req_num_postings;
124 }
125 }
126 }
127 }
128
129 public function insert(): void
130 {
131 if ($this->obj_id && !$this->exists) {
132 $this->db->insert(
133 'frm_settings',
134 [
135 'obj_id' => ['integer', $this->obj_id],
136 'default_view' => ['integer', $this->default_view],
137 'anonymized' => ['integer', (int) $this->anonymized],
138 'statistics_enabled' => ['integer', (int) $this->statistics_enabled],
139 'post_activation' => ['integer', (int) $this->post_activation_enabled],
140 'admin_force_noti' => ['integer', (int) $this->admin_force_noti],
141 'user_toggle_noti' => ['integer', (int) $this->user_toggle_noti],
142 'preset_subject' => ['integer', (int) $this->preset_subject],
143 'add_re_subject' => ['integer', (int) $this->add_re_subject],
144 'notification_type' => ['text', $this->notification_type->value],
145 'mark_mod_posts' => ['integer', (int) $this->mark_mod_posts],
146 'thread_rating' => ['integer', (int) $this->is_thread_rating_enabled],
147 'file_upload_allowed' => ['integer', (int) $this->file_upload_allowed],
148 'lp_req_num_postings' => ['integer', $this->lp_req_num_postings],
149 'interested_events' => ['integer', $this->interested_events]
150 ]
151 );
152 $this->exists = true;
153 }
154 }
155
156 public function update(): void
157 {
158 if ($this->obj_id !== 0) {
159 if (!$this->exists) {
160 $this->insert();
161 return;
162 }
163
164 $this->db->update(
165 'frm_settings',
166 [
167 'default_view' => ['integer', $this->default_view],
168 'anonymized' => ['integer', (int) $this->anonymized],
169 'statistics_enabled' => ['integer', (int) $this->statistics_enabled],
170 'post_activation' => ['integer', (int) $this->post_activation_enabled],
171 'admin_force_noti' => ['integer', (int) $this->admin_force_noti],
172 'user_toggle_noti' => ['integer', (int) $this->user_toggle_noti],
173 'preset_subject' => ['integer', (int) $this->preset_subject],
174 'add_re_subject' => ['integer', (int) $this->add_re_subject],
175 'notification_type' => ['text', $this->notification_type->value],
176 'mark_mod_posts' => ['integer', (int) $this->mark_mod_posts],
177 'thread_rating' => ['integer', (int) $this->is_thread_rating_enabled],
178 'file_upload_allowed' => ['integer', (int) $this->file_upload_allowed],
179 'lp_req_num_postings' => ['integer', (int) $this->lp_req_num_postings],
180 'interested_events' => ['integer', $this->interested_events]
181 ],
182 [
183 'obj_id' => ['integer', $this->obj_id]
184 ]
185 );
186 }
187 }
188
189 public function copy(int $a_new_obj_id): bool
190 {
191 if ($a_new_obj_id !== 0) {
192 $this->contentStyle()->cloneTo($a_new_obj_id);
193
194 $this->db->update(
195 'frm_settings',
196 [
197 'default_view' => ['integer', $this->default_view],
198 'anonymized' => ['integer', (int) $this->anonymized],
199 'statistics_enabled' => ['integer', (int) $this->statistics_enabled],
200 'post_activation' => ['integer', (int) $this->post_activation_enabled],
201 'admin_force_noti' => ['integer', (int) $this->admin_force_noti],
202 'user_toggle_noti' => ['integer', (int) $this->user_toggle_noti],
203 'preset_subject' => ['integer', (int) $this->preset_subject],
204 'add_re_subject' => ['integer', (int) $this->add_re_subject],
205 'notification_type' => ['text', $this->notification_type->value],
206 'mark_mod_posts' => ['integer', (int) $this->mark_mod_posts],
207 'thread_rating' => ['integer', (int) $this->is_thread_rating_enabled],
208 'file_upload_allowed' => ['integer', (int) $this->file_upload_allowed],
209 'lp_req_num_postings' => ['integer', $this->lp_req_num_postings],
210 'interested_events' => ['integer', $this->interested_events]
211 ],
212 [
213 'obj_id' => ['integer', $a_new_obj_id]
214 ]
215 );
216
217 return true;
218 }
219
220 return false;
221 }
222
223 public function isIsThreadRatingEnabled(): bool
224 {
226 }
227
229 {
230 $this->is_thread_rating_enabled = $is_thread_rating_enabled;
231 }
232
233 public function setDefaultView(int $a_default_view): void
234 {
235 $this->default_view = $a_default_view;
236 }
237
238 public function getDefaultView(): int
239 {
240 return $this->default_view;
241 }
242
243 public function setStatisticsStatus(bool $a_statistic_status): void
244 {
245 $this->statistics_enabled = $a_statistic_status;
246 }
247
248 public function isStatisticEnabled(): bool
249 {
251 }
252
253 public function setAnonymisation(bool $a_anonymized): void
254 {
255 $this->anonymized = $a_anonymized;
256 }
257
258 public function isAnonymized(): bool
259 {
260 return $this->anonymized;
261 }
262
263 public static function _isAnonymized(int $a_obj_id): bool
264 {
265 global $DIC;
266 $ilDB = $DIC->database();
267
268 $result = $ilDB->queryF(
269 'SELECT anonymized FROM frm_settings WHERE obj_id = %s',
270 ['integer'],
271 [$a_obj_id]
272 );
273
274 while ($record = $ilDB->fetchAssoc($result)) {
275 return (bool) $record['anonymized'];
276 }
277
278 return false;
279 }
280
281 public function setPostActivation(bool $a_post_activation): void
282 {
283 $this->post_activation_enabled = $a_post_activation;
284 }
285
286 public function isPostActivationEnabled(): bool
287 {
289 }
290
291 public function setObjId(int $a_obj_id): void
292 {
293 $this->obj_id = $a_obj_id;
294 $this->read();
295 }
296
297 public function getObjId(): int
298 {
299 return $this->obj_id;
300 }
301
302 public function setAdminForceNoti(bool $a_admin_force): void
303 {
304 $this->admin_force_noti = $a_admin_force;
305 }
306
307 public function isAdminForceNoti(): bool
308 {
310 }
311
312 public function setUserToggleNoti(bool $a_user_toggle): void
313 {
314 $this->user_toggle_noti = $a_user_toggle;
315 }
316
317 public function isUserToggleNoti(): bool
318 {
320 }
321
322 public static function _isAdminForceNoti(int $a_obj_id): bool
323 {
324 global $DIC;
325
326 $ilDB = $DIC->database();
327
328 $res = $ilDB->queryF(
329 'SELECT admin_force_noti FROM frm_settings WHERE obj_id = %s',
330 ['integer'],
331 [$a_obj_id]
332 );
333 if ($record = $ilDB->fetchAssoc($res)) {
334 return (bool) $record['admin_force_noti'];
335 }
336
337 return false;
338 }
339
340 public static function _isUserToggleNoti(int $a_obj_id): bool
341 {
342 global $DIC;
343
344 $ilDB = $DIC->database();
345
346 $res = $ilDB->queryF(
347 'SELECT user_toggle_noti FROM frm_settings WHERE obj_id = %s',
348 ['integer'],
349 [$a_obj_id]
350 );
351 while ($record = $ilDB->fetchAssoc($res)) {
352 return (bool) $record['user_toggle_noti'];
353 }
354
355 return false;
356 }
357
358 public function setPresetSubject(bool $a_preset_subject): void
359 {
360 $this->preset_subject = $a_preset_subject;
361 }
362
363 public function isSubjectPreset(): bool
364 {
366 }
367
368 public function setAddReSubject(bool $a_add_re_subject): void
369 {
370 $this->add_re_subject = $a_add_re_subject;
371 }
372
373 public function isSubjectAdded(): bool
374 {
376 }
377
378 public function setNotificationType(NotificationType $a_notification_type): void
379 {
380 $this->notification_type = $a_notification_type;
381 }
382
384 {
386 }
387
388 public function getSubjectSetting(): string
389 {
390 if (!$this->isSubjectPreset() && !$this->isSubjectAdded()) {
391 return "empty_subject";
392 }
393
394 if ($this->isSubjectPreset()) {
395 return "preset_subject";
396 }
397
398 if ($this->isSubjectAdded()) {
399 return "add_re_to_subject";
400 }
401
402 return "preset_subject";
403 }
404
405 public function setSubjectSetting($a_subject_setting): void
406 {
407 if ($a_subject_setting === 'empty_subject') {
408 $this->setPresetSubject(false);
409 $this->setAddReSubject(false);
410 } elseif ($a_subject_setting === 'preset_subject') {
411 $this->setPresetSubject(true);
412 $this->setAddReSubject(false);
413 } elseif ($a_subject_setting === 'add_re_to_subject') {
414 $this->setPresetSubject(false);
415 $this->setAddReSubject(true);
416 }
417 }
418
419 public function setMarkModeratorPosts(bool $a_mod_post): void
420 {
421 $this->mark_mod_posts = $a_mod_post;
422 }
423
424 public function getMarkModeratorPosts(): bool
425 {
427 }
428
429 public function getUserToggleNoti(): bool
430 {
432 }
433
434 public function getAdminForceNoti(): bool
435 {
437 }
438
439 public function setFileUploadAllowed(bool $allowed): void
440 {
441 $this->file_upload_allowed = $allowed;
442 }
443
444 public function getFileUploadAllowed(): bool
445 {
447 }
448
449 public function isFileUploadAllowed(): bool
450 {
451 if (self::isFileUploadGloballyAllowed()) {
452 return true;
453 }
454
455 return $this->getFileUploadAllowed();
456 }
457
458 public static function isFileUploadGloballyAllowed(): bool
459 {
460 global $DIC;
461
462 return (
463 (int) $DIC->settings()->get('file_upload_allowed_fora') === self::FILE_UPLOAD_GLOBALLY_ALLOWED
464 );
465 }
466
467 public static function isSendAttachmentsByMailEnabled(): bool
468 {
469 global $DIC;
470
471 return (bool) $DIC->settings()->get('send_attachments_by_mail');
472 }
473
474 public function getInterestedEvents(): int
475 {
477 }
478
479 public function setInterestedEvents(int $interested_events): void
480 {
481 $this->interested_events = $interested_events;
482 }
483
484 public function getLpReqNumPostings(): ?int
485 {
487 }
488
489 public function setLpReqNumPostings(?int $lp_req_num_postings): void
490 {
491 $this->lp_req_num_postings = $lp_req_num_postings;
492 }
493}
External facade for object content styles.
static _isAdminForceNoti(int $a_obj_id)
static _isUserToggleNoti(int $a_obj_id)
setUserToggleNoti(bool $a_user_toggle)
setSubjectSetting($a_subject_setting)
int $interested_events
Preset notification events for forced notification.
setNotificationType(NotificationType $a_notification_type)
bool $user_toggle_noti
Activation of allowing members to deactivate (CRS/GRP)forum notification.
setDefaultView(int $a_default_view)
static _isAnonymized(int $a_obj_id)
setMarkModeratorPosts(bool $a_mod_post)
setFileUploadAllowed(bool $allowed)
NotificationType $notification_type
setPostActivation(bool $a_post_activation)
static getInstance(int $a_obj_id=0)
readonly ilDBInterface $db
setAdminForceNoti(bool $a_admin_force)
setAnonymisation(bool $a_anonymized)
setLpReqNumPostings(?int $lp_req_num_postings)
ILIAS Style Content Object ObjectFacade $content_style_service
setPresetSubject(bool $a_preset_subject)
setIsThreadRatingEnabled(bool $is_thread_rating_enabled)
setInterestedEvents(int $interested_events)
bool $preset_subject
If deactivated, user is forced to enter a new subject on repliees.
bool $admin_force_noti
Activation of (CRS/GRP) forum notification by mod/admin.
setAddReSubject(bool $a_add_re_subject)
bool $add_re_subject
Add 'Re: ' to subject on reply.
__construct(private int $obj_id=0)
setStatisticsStatus(bool $a_statistic_status)
Interface ilDBInterface.
$res
Definition: ltiservices.php:69
Interface Observer \BackgroundTasks Contains several chained tasks and infos about them.
if(!file_exists('../ilias.ini.php'))
global $DIC
Definition: shib_login.php:26