ILIAS  trunk Revision v11.0_alpha-1769-g99a433fe2dc
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
class.ilForumProperties.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
26 {
27  public const VIEW_TREE = 1;
28  public const VIEW_DATE = 2;
29  public const VIEW_DATE_ASC = 2;
30  public const VIEW_DATE_DESC = 3;
31  public const FILE_UPLOAD_GLOBALLY_ALLOWED = 0;
32  public const FILE_UPLOAD_INDIVIDUAL = 1;
33  public const PAGE_SIZE_THREAD_OVERVIEW = 10;
34  public const PAGE_NAME_THREAD_OVERVIEW = 'page';
35 
37  private static array $instances = [];
38 
39  private readonly ilDBInterface $db;
40  private int $default_view = self::VIEW_DATE_ASC;
41  private bool $anonymized = false;
42  private bool $statistics_enabled = false;
43  private bool $post_activation_enabled = false;
48  private string $notification_type = 'default';
50  private bool $admin_force_noti = false;
52  private bool $user_toggle_noti = false;
54  private bool $preset_subject = true;
58  private bool $add_re_subject = false;
59  private bool $mark_mod_posts = false;
60  private bool $is_thread_rating_enabled = false;
61  private bool $file_upload_allowed = false;
62  protected int $styleId = 0;
63  private bool $exists = false;
64  private ?int $lp_req_num_postings = null;
65  protected \ILIAS\Style\Content\Object\ObjectFacade $content_style_service;
66 
67  protected function __construct(private int $obj_id = 0)
68  {
69  global $DIC;
70 
71  $this->db = $DIC->database();
72  $this->read();
73  $this->content_style_service = $DIC
74  ->contentStyle()
75  ->domain()
76  ->styleForObjId($obj_id);
77  }
78 
79  public static function getInstance(int $a_obj_id = 0): self
80  {
81  if (!isset(self::$instances[$a_obj_id])) {
82  self::$instances[$a_obj_id] = new self($a_obj_id);
83  }
84 
85  return self::$instances[$a_obj_id];
86  }
87 
88  private function read(): void
89  {
90  if ($this->obj_id !== 0) {
91  $res = $this->db->queryF(
92  'SELECT * FROM frm_settings WHERE obj_id = %s',
93  ['integer'],
94  [$this->obj_id]
95  );
96 
97  $row = $this->db->fetchObject($res);
98  if (is_object($row)) {
99  $this->exists = true;
100 
101  $this->default_view = (int) $row->default_view;
102  $this->anonymized = (bool) $row->anonymized;
103  $this->statistics_enabled = (bool) $row->statistics_enabled;
104  $this->post_activation_enabled = (bool) $row->post_activation;
105  $this->admin_force_noti = (bool) $row->admin_force_noti;
106  $this->user_toggle_noti = (bool) $row->user_toggle_noti;
107  $this->preset_subject = (bool) $row->preset_subject;
108  $this->add_re_subject = (bool) $row->add_re_subject;
109  $this->interested_events = (int) $row->interested_events;
110 
111  $this->notification_type = $row->notification_type ?? 'default';
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],
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],
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],
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(?string $a_notification_type): void
372  {
373  if ($a_notification_type === null) {
374  $this->notification_type = 'default';
375  } else {
376  $this->notification_type = $a_notification_type;
377  }
378  }
379 
380  public function getNotificationType(): string
381  {
383  }
384 
385  public function getSubjectSetting(): string
386  {
387  if (!$this->isSubjectPreset() && !$this->isSubjectAdded()) {
388  return "empty_subject";
389  }
390 
391  if ($this->isSubjectPreset()) {
392  return "preset_subject";
393  }
394 
395  if ($this->isSubjectAdded()) {
396  return "add_re_to_subject";
397  }
398 
399  return "preset_subject";
400  }
401 
402  public function setSubjectSetting($a_subject_setting): void
403  {
404  if ($a_subject_setting === 'empty_subject') {
405  $this->setPresetSubject(false);
406  $this->setAddReSubject(false);
407  } elseif ($a_subject_setting === 'preset_subject') {
408  $this->setPresetSubject(true);
409  $this->setAddReSubject(false);
410  } elseif ($a_subject_setting === 'add_re_to_subject') {
411  $this->setPresetSubject(false);
412  $this->setAddReSubject(true);
413  }
414  }
415 
416  public function setMarkModeratorPosts(bool $a_mod_post): void
417  {
418  $this->mark_mod_posts = $a_mod_post;
419  }
420 
421  public function getMarkModeratorPosts(): bool
422  {
423  return $this->mark_mod_posts;
424  }
425 
426  public function getUserToggleNoti(): bool
427  {
429  }
430 
431  public function getAdminForceNoti(): bool
432  {
434  }
435 
436  public function setFileUploadAllowed(bool $allowed): void
437  {
438  $this->file_upload_allowed = $allowed;
439  }
440 
441  public function getFileUploadAllowed(): bool
442  {
444  }
445 
446  public function isFileUploadAllowed(): bool
447  {
448  if (self::isFileUploadGloballyAllowed()) {
449  return true;
450  }
451 
452  return $this->getFileUploadAllowed();
453  }
454 
455  public static function isFileUploadGloballyAllowed(): bool
456  {
457  global $DIC;
458 
459  return (
460  (int) $DIC->settings()->get('file_upload_allowed_fora') === self::FILE_UPLOAD_GLOBALLY_ALLOWED
461  );
462  }
463 
464  public static function isSendAttachmentsByMailEnabled(): bool
465  {
466  global $DIC;
467 
468  return (bool) $DIC->settings()->get('send_attachments_by_mail');
469  }
470 
471  public function getInterestedEvents(): int
472  {
474  }
475 
476  public function setInterestedEvents(int $interested_events): void
477  {
478  $this->interested_events = $interested_events;
479  }
480 
481  public function getLpReqNumPostings(): ?int
482  {
484  }
485 
486  public function setLpReqNumPostings(?int $lp_req_num_postings): void
487  {
488  $this->lp_req_num_postings = $lp_req_num_postings;
489  }
490 }
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)
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)
static getInstance(int $a_obj_id=0)
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
static _isAnonymized(int $a_obj_id)
static _isAdminForceNoti(int $a_obj_id)
string $notification_type
Global notification-type setting (CRS/GRP) possible values: &#39;all_users&#39;, &#39;per_user&#39;, null (default)
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:22
setLpReqNumPostings(?int $lp_req_num_postings)
setNotificationType(?string $a_notification_type)
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)