ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilForumProperties.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2012 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
11 {
12  const VIEW_TREE = 1;
13  const VIEW_DATE = 2;
14  const VIEW_DATE_ASC = 2;
15  const VIEW_DATE_DESC = 3;
16 
19 
22 
27  private $obj_id;
28 
33  private $default_view = self::VIEW_TREE;
34 
39  private $anonymized = 0; //false;
40 
45  private $statistics_enabled = 0; //false;
46 
51  private $post_activation_enabled = 0; //false;
52 
61  private $notification_type = null;
62 
67  private $admin_force_noti = false;
72  private $user_toggle_noti = false;
73 
80  private $preset_subject = 1;
81 
87  private $add_re_subject = 0;
88 
89  private $mark_mod_posts = 0;
90 
98  private $thread_sorting = 0;
99 
103  private $is_thread_rating_enabled = false;
104 
109  private $db = null;
110 
114  private $file_upload_allowed = 0;
115 
119  private static $instances = array();
120 
122  private $exists = false;
123 
124  protected function __construct($a_obj_id = 0)
125  {
126  global $DIC;
127 
128  $this->db = $DIC->database();
129  $this->obj_id = $a_obj_id;
130  $this->read();
131  }
132 
133  private function __clone()
134  {
135  }
136 
141  public static function getInstance($a_obj_id = 0)
142  {
143  if (!self::$instances[$a_obj_id]) {
144  self::$instances[$a_obj_id] = new ilForumProperties($a_obj_id);
145  }
146 
147  return self::$instances[$a_obj_id];
148  }
149 
150  private function read()
151  {
152  if ($this->obj_id) {
153  $res = $this->db->queryf(
154  '
155  SELECT * FROM frm_settings
156  WHERE obj_id = %s',
157  array('integer'),
158  array($this->obj_id)
159  );
160 
161  $row = $this->db->fetchObject($res);
162 
163  if (is_object($row)) {
164  $this->default_view = $row->default_view;
165  $this->anonymized = $row->anonymized ;// == 1 ? true : false;
166  $this->statistics_enabled = $row->statistics_enabled ;// == 1 ? true : false;
167  $this->post_activation_enabled = $row->post_activation ;// == 1 ? true : false;
168  $this->admin_force_noti = $row->admin_force_noti == 1 ? true : false;
169  $this->user_toggle_noti = $row->user_toggle_noti == 1 ? true : false;
170  $this->preset_subject = $row->preset_subject;
171  $this->add_re_subject = $row->add_re_subject;
172 
173  $this->notification_type = $row->notification_type == null ? 'default': $row->notification_type;
174  $this->mark_mod_posts = $row->mark_mod_posts == 1 ? true : false;
175  $this->thread_sorting = $row->thread_sorting == 1? true : false;
176  $this->setIsThreadRatingEnabled((bool) $row->thread_rating);
177  $this->file_upload_allowed = $row->file_upload_allowed == 1 ? true : false;
178 
179  $this->exists = true;
180  return true;
181  }
182 
183  return false;
184  }
185 
186  return false;
187  }
188 
189  public function insert()
190  {
191  if ($this->obj_id && !$this->exists) {
192  $this->db->insert(
193  'frm_settings',
194  array(
195  'obj_id' => array('integer', $this->obj_id),
196  'default_view' => array('integer', $this->default_view),
197  'anonymized' => array('integer', $this->anonymized),
198  'statistics_enabled' => array('integer', $this->statistics_enabled),
199  'post_activation' => array('integer', $this->post_activation_enabled),
200  'admin_force_noti' => array('integer', $this->admin_force_noti),
201  'user_toggle_noti' => array('integer', $this->user_toggle_noti),
202  'preset_subject' => array('integer', $this->preset_subject),
203  'add_re_subject' => array('integer', $this->add_re_subject),
204  'notification_type' => array('text', $this->notification_type),
205  'mark_mod_posts' => array('integer', $this->mark_mod_posts),
206  'thread_sorting' => array('integer', $this->thread_sorting),
207  'thread_rating' => array('integer', $this->isIsThreadRatingEnabled()),
208  'file_upload_allowed' => array('integer', $this->file_upload_allowed)
209  )
210  );
211 
212  $this->exists = true;
213  return true;
214  }
215 
216  return false;
217  }
218 
219  public function update()
220  {
221  if ($this->obj_id) {
222  if (!$this->exists) {
223  return $this->insert();
224  }
225 
226  $this->db->update(
227  'frm_settings',
228  array(
229  'default_view' => array('integer', $this->default_view),
230  'anonymized' => array('integer', $this->anonymized),
231  'statistics_enabled' => array('integer', $this->statistics_enabled),
232  'post_activation' => array('integer', $this->post_activation_enabled),
233  'admin_force_noti' => array('integer', $this->admin_force_noti),
234  'user_toggle_noti' => array('integer', $this->user_toggle_noti),
235  'preset_subject' => array('integer', $this->preset_subject),
236  'add_re_subject' => array('integer', $this->add_re_subject),
237  'notification_type' => array('text', $this->notification_type),
238  'mark_mod_posts' => array('integer', $this->mark_mod_posts),
239  'thread_sorting' => array('integer', $this->thread_sorting),
240  'thread_rating' => array('integer', $this->isIsThreadRatingEnabled()),
241  'file_upload_allowed' => array('integer', $this->file_upload_allowed)
242  ),
243  array(
244  'obj_id' => array('integer', $this->obj_id)
245  )
246  );
247  return true;
248  }
249  return false;
250  }
251 
252  public function copy($a_new_obj_id)
253  {
254  if ($a_new_obj_id) {
255  $this->db->update(
256  'frm_settings',
257  array(
258  'default_view' => array('integer', $this->default_view),
259  'anonymized' => array('integer', $this->anonymized),
260  'statistics_enabled' => array('integer', $this->statistics_enabled),
261  'post_activation' => array('integer', $this->post_activation_enabled),
262  'admin_force_noti' => array('integer', $this->admin_force_noti),
263  'user_toggle_noti' => array('integer', $this->user_toggle_noti),
264  'preset_subject' => array('integer', $this->preset_subject),
265  'add_re_subject' => array('integer', $this->add_re_subject),
266  'notification_type' => array('text', $this->notification_type),
267  'mark_mod_posts' => array('integer', $this->mark_mod_posts),
268  'thread_sorting' => array('integer', $this->thread_sorting),
269  'thread_rating' => array('integer', $this->isIsThreadRatingEnabled()),
270  'file_upload_allowed' => array('integer', $this->file_upload_allowed)
271  ),
272  array(
273  'obj_id' => array('integer', $a_new_obj_id)
274  )
275  );
276  return true;
277  }
278 
279  return false;
280  }
281 
285  public function isIsThreadRatingEnabled()
286  {
287  return (bool) $this->is_thread_rating_enabled;
288  }
289 
294  {
295  $this->is_thread_rating_enabled = (bool) $is_thread_rating_enabled;
296  }
297 
298  public function setDefaultView($a_default_view)
299  {
300  $this->default_view = $a_default_view;
301  }
302  public function getDefaultView()
303  {
304  return $this->default_view;
305  }
306  public function setStatisticsStatus($a_statistic_status)
307  {
308  $this->statistics_enabled = $a_statistic_status;
309  }
310  public function isStatisticEnabled()
311  {
313  }
314  public function setAnonymisation($a_anonymized)
315  {
316  $this->anonymized = $a_anonymized;
317  }
318  public function isAnonymized()
319  {
320  return $this->anonymized;
321  }
322  public static function _isAnonymized($a_obj_id)
323  {
324  global $DIC;
325  $ilDB = $DIC->database();
326 
327  $result = $ilDB->queryf(
328  "SELECT anonymized FROM frm_settings WHERE obj_id = %s",
329  array('integer'),
330  array($a_obj_id)
331  );
332 
333  while ($record = $ilDB->fetchAssoc($result)) {
334  return $record['anonymized'];
335  }
336 
337  return 0;
338  }
339 
340  public function setPostActivation($a_post_activation)
341  {
342  $this->post_activation_enabled = $a_post_activation;
343  }
344  public function isPostActivationEnabled()
345  {
347  }
348  public function setObjId($a_obj_id = 0)
349  {
350  $this->obj_id = $a_obj_id;
351  $this->read();
352  }
353  public function getObjId()
354  {
355  return $this->obj_id;
356  }
357 
358  public function setAdminForceNoti($a_admin_force)
359  {
360  $this->admin_force_noti = $a_admin_force;
361  }
362 
363  public function isAdminForceNoti()
364  {
366  }
367 
368  public function setUserToggleNoti($a_user_toggle)
369  {
370  $this->user_toggle_noti = $a_user_toggle;
371  }
372 
373  public function isUserToggleNoti()
374  {
376  }
377 
378  public static function _isAdminForceNoti($a_obj_id)
379  {
380  global $DIC;
381  $ilDB = $DIC->database();
382 
383  $res = $ilDB->queryF(
384  "SELECT admin_force_noti FROM frm_settings WHERE obj_id = %s",
385  array('integer'),
386  array($a_obj_id)
387  );
388  while ($record = $ilDB->fetchAssoc($res)) {
389  return $record['admin_force_noti'];
390  }
391 
392  return 0;
393  }
394 
395  public static function _isUserToggleNoti($a_obj_id)
396  {
397  global $DIC;
398  $ilDB = $DIC->database();
399 
400  $res = $ilDB->queryF(
401  "SELECT user_toggle_noti FROM frm_settings WHERE obj_id = %s",
402  array('integer'),
403  array($a_obj_id)
404  );
405  while ($record = $ilDB->fetchAssoc($res)) {
406  return $record['user_toggle_noti'];
407  }
408  return 0;
409  }
410 
411  public function setPresetSubject($a_preset_subject)
412  {
413  $this->preset_subject = $a_preset_subject;
414  }
415  public function getPresetSubject()
416  {
417  return $this->preset_subject;
418  }
419  public function setAddReSubject($a_add_re_subject)
420  {
421  $this->add_re_subject = $a_add_re_subject;
422  }
423  public function getAddReSubject()
424  {
425  return $this->add_re_subject;
426  }
427 
428  public function setNotificationType($a_notification_type)
429  {
430  if ($a_notification_type == null) {
431  $this->notification_type = 'default';
432  } else {
433  $this->notification_type = $a_notification_type;
434  }
435  }
436  public function getNotificationType()
437  {
439  }
440 
441  public function getSubjectSetting()
442  {
443  if ($this->getPresetSubject() == 0
444  && $this->getAddReSubject() == 0) {
445  return "empty_subject";
446  } elseif ($this->getPresetSubject() == 1) {
447  return "preset_subject";
448  } elseif ($this->getAddReSubject() == 1) {
449  return "add_re_to_subject";
450  } else {
451  return "preset_subject";
452  }
453  }
454  public function setSubjectSetting($a_subject_setting)
455  {
456  if ($a_subject_setting == 'empty_subject') {
457  $this->setPresetSubject(0);
458  $this->setAddReSubject(0);
459  } elseif ($a_subject_setting == 'preset_subject') {
460  $this->setPresetSubject(1);
461  $this->setAddReSubject(0);
462  } elseif ($a_subject_setting == 'add_re_to_subject') {
463  $this->setPresetSubject(0);
464  $this->setAddReSubject(1);
465  }
466  }
467 
468  public function setMarkModeratorPosts($a_mod_post)
469  {
470  $this->mark_mod_posts = $a_mod_post;
471  }
472 
473  public function getMarkModeratorPosts()
474  {
475  return $this->mark_mod_posts;
476  }
477 
478  public function setThreadSorting($a_thread_sorting)
479  {
480  $this->thread_sorting = $a_thread_sorting;
481  }
482  public function getThreadSorting()
483  {
484  return $this->thread_sorting;
485  }
486 
490  public function getUserToggleNoti()
491  {
493  }
494 
498  public function getAdminForceNoti()
499  {
501  }
502 
507  public function setFileUploadAllowed($allowed)
508  {
509  $this->file_upload_allowed = $allowed;
510  }
511 
515  public function getFileUploadAllowed()
516  {
518  }
519 
523  public function isFileUploadAllowed()
524  {
525  if (self::isFileUploadGloballyAllowed()) {
526  return true;
527  }
528 
529  if ((bool) $this->getFileUploadAllowed()) {
530  return true;
531  }
532 
533  return false;
534  }
535 
539  public static function isFileUploadGloballyAllowed()
540  {
541  global $DIC;
542  return $DIC->settings()->get('file_upload_allowed_fora', self::FILE_UPLOAD_GLOBALLY_ALLOWED) == self::FILE_UPLOAD_GLOBALLY_ALLOWED;
543  }
544 
548  public static function isSendAttachmentsByMailEnabled()
549  {
550  global $DIC;
551  return $DIC->settings()->get('send_attachments_by_mail') == true ? true : false;
552  }
553 }
setThreadSorting($a_thread_sorting)
setPostActivation($a_post_activation)
setUserToggleNoti($a_user_toggle)
$statistics_enabled
Defines if a forum can show ranking statistics private.
$result
setStatisticsStatus($a_statistic_status)
global $DIC
Definition: saml.php:7
setPresetSubject($a_preset_subject)
setAdminForceNoti($a_admin_force)
setDefaultView($a_default_view)
$user_toggle_noti
Activation of allowing members to deactivate (CRS/GRP)forum notification private.
$default_view
Default view ( 1 => &#39;order by answers&#39;, 2 => &#39;order by date ascending&#39;, 3 => &#39;order by date descendin...
$obj_id
Object id of current forum private.
$admin_force_noti
Activation of (CRS/GRP) forum notification by mod/admin private.
$thread_sorting
sorting type for threads (manual sorting) 0 = default 1 = manual
static _isAnonymized($a_obj_id)
static getInstance($a_obj_id=0)
setIsThreadRatingEnabled($is_thread_rating_enabled)
foreach($_POST as $key=> $value) $res
$add_re_subject
Add &#39;Re: &#39; to subject on reply.
static _isUserToggleNoti($a_obj_id)
static _isAdminForceNoti($a_obj_id)
setAddReSubject($a_add_re_subject)
$row
$post_activation_enabled
Activation of new posts private.
global $ilDB
$anonymized
Defines if a forum is anonymized or not private.
$preset_subject
Preset subject on reply.
setSubjectSetting($a_subject_setting)
setNotificationType($a_notification_type)
$notification_type
Global notification-type setting (CRS/GRP) possible values: &#39;all_users&#39;, &#39;per_user&#39;, null (default)