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