ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
class.ilForumPostDraft.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2016 ILIAS open source, Extended GPL, see docs/LICENSE */
3require_once './Modules/Forum/classes/class.ilFileDataForumDrafts.php';
9{
10 const MEDIAOBJECT_TYPE = 'frm~d:html';
14 protected $draft_id = 0;
18 protected $post_id = 0;
22 protected $forum_id = 0;
26 protected $thread_id = 0;
30 protected $post_subject = '';
34 protected $post_message = '';
38 protected $post_date = '0000-00-00 00:00:00';
42 protected $post_update = '0000-00-00 00:00:00';
46 protected $update_user_id = 0;
50 protected $post_user_alias = '';
54 protected $post_author_id = 0;
58 protected $post_display_user_id = 0;
59
63 protected $notify = 0;
64 protected $post_notify = 0;
65
69 static private $instances = array();
70
75 protected static $forum_statistics_cache = array();
76
80 protected static $drafts_settings_cache = array();
81
86 protected static function populateWithDatabaseRecord(ilForumPostDraft $draft, array $row)
87 {
88 $draft->setDraftId($row['draft_id']);
89 $draft->setForumId($row['forum_id']);
90 $draft->setPostAuthorId($row['post_author_id']);
91 $draft->setPostDate($row['post_date']);
92 $draft->setPostDisplayUserId($row['pos_display_usr_id']);
93 $draft->setPostId($row['post_id']);
94 $draft->setPostMessage($row['post_message']);
95 $draft->setPostSubject($row['post_subject']);
96 $draft->setPostUpdate($row['post_update']);
97 $draft->setPostUserAlias($row['post_user_alias']);
98 $draft->setThreadId($row['thread_id']);
99 $draft->setUpdateUserId($row['update_user_id']);
100 $draft->setNotify($row['notify']);
101 $draft->setPostNotify($row['post_notify']);
102 }
103
107 public function getPostNotify()
108 {
109 return $this->post_notify;
110 }
111
116 {
117 $this->post_notify = $post_notify;
118 }
119
123 public function getDraftId()
124 {
125 return $this->draft_id;
126 }
127
131 public function setDraftId($draft_id)
132 {
133 $this->draft_id = $draft_id;
134 }
135
139 public function getPostId()
140 {
141 return $this->post_id;
142 }
143
147 public function setPostId($post_id)
148 {
149 $this->post_id = $post_id;
150 }
151
155 public function getForumId()
156 {
157 return $this->forum_id;
158 }
159
163 public function setForumId($forum_id)
164 {
165 $this->forum_id = $forum_id;
166 }
167
171 public function getThreadId()
172 {
173 return $this->thread_id;
174 }
175
179 public function setThreadId($thread_id)
180 {
181 $this->thread_id = $thread_id;
182 }
183
187 public function getPostSubject()
188 {
189 return $this->post_subject;
190 }
191
196 {
197 $this->post_subject = $post_subject;
198 }
199
203 public function getPostMessage()
204 {
205 return $this->post_message;
206 }
207
212 {
213 $this->post_message = $post_message;
214 }
215
219 public function getPostDate()
220 {
221 return $this->post_date;
222 }
223
227 public function setPostDate($post_date)
228 {
229 $this->post_date = $post_date;
230 }
231
235 public function getPostUpdate()
236 {
237 return $this->post_update;
238 }
239
244 {
245 $this->post_update = $post_update;
246 }
247
251 public function getUpdateUserId()
252 {
254 }
255
260 {
261 $this->update_user_id = $update_user_id;
262 }
263
267 public function getPostUserAlias()
268 {
270 }
271
276 {
277 $this->post_user_alias = $post_user_alias;
278 }
279
283 public function getPostAuthorId()
284 {
286 }
287
292 {
293 $this->post_author_id = $post_author_id;
294 }
295
299 public function getPostDisplayUserId()
300 {
302 }
303
308 {
309 $this->post_display_user_id = $post_display_user_id;
310 }
311
315 public function getNotify()
316 {
317 return $this->notify;
318 }
319
323 public function setNotify($notify)
324 {
325 $this->notify = $notify;
326 }
327
333 public function __construct($user_id = 0, $post_id = 0, $draft_id = 0)
334 {
335 if($user_id && $post_id && $draft_id)
336 {
337 $this->setPostAuthorId($user_id);
338 $this->setPostId($post_id);
339 $this->setDraftId($draft_id);
340 $this->readDraft();
341 }
342 }
343
347 protected function readDraft()
348 {
349 global $ilDB;
350
351 $res = $ilDB->queryF(
352 'SELECT * FROM frm_posts_drafts WHERE post_author_id = %s AND post_id = %s AND draft_id = %s',
353 array('integer', 'integer','integer'),
354 array($this->getPostAuthorId(), $this->getPostId(), $this->getDraftId())
355 );
356
357 while($row = $ilDB->fetchAssoc($res))
358 {
360 }
361 }
362
366 protected static function readDrafts($user_id)
367 {
368 global $ilDB;
369
370 $res = $ilDB->queryF('SELECT * FROM frm_posts_drafts WHERE post_author_id = %s',
371 array('integer'), array($user_id));
372
373 self::$instances[$user_id] = array();
374 while($row = $ilDB->fetchAssoc($res))
375 {
376 $tmp_obj = new ilForumPostDraft();
378 self::$instances[$user_id][$row['thread_id']][$tmp_obj->getPostId()][] = $tmp_obj;
379 self::$instances[$user_id]['draft_ids'][$tmp_obj->getDraftId()] = $tmp_obj;
380 }
381 unset($tmp_obj);
382 }
383
388 public static function getDraftInstancesByUserId($user_id)
389 {
390 if(!self::$instances[$user_id])
391 {
392 self::readDrafts($user_id);
393 }
394
395 return self::$instances[$user_id]['draft_ids'];
396 }
397
403 public static function getInstancesByUserIdAndThreadId($user_id, $thread_id)
404 {
405 if(!self::$instances[$user_id])
406 {
407 self::readDrafts($user_id);
408 }
409
410 if(self::$instances[$user_id][$thread_id])
411 {
412 return self::$instances[$user_id][$thread_id];
413 }
414 }
415
420 public static function newInstanceByDraftId($draft_id)
421 {
425 global $ilDB;
426
427 $res = $ilDB->queryF(
428 'SELECT * FROM frm_posts_drafts WHERE draft_id = %s',
429 array('integer'),
430 array($draft_id)
431 );
432
433 while($row = $ilDB->fetchAssoc($res))
434 {
435 $tmp_obj = new ilForumPostDraft();
437 return $tmp_obj;
438 }
439 }
440
446 public static function newInstanceByHistorytId($history_id)
447 {
451 global $ilDB;
452
453 $res = $ilDB->queryF(
454 'SELECT * FROM frm_drafts_history WHERE history_id = %s',
455 array('integer'),
456 array($history_id)
457 );
458
459 while($row = $ilDB->fetchAssoc($res))
460 {
461 $tmp_obj = new ilForumPostDraft();
463 return $tmp_obj;
464 }
465
466 throw new ilException(sprintf("Could not find history object for id %s", $history_id));
467 }
468
469 public function saveDraft()
470 {
471 global $ilDB;
472
473 $draft_id = $ilDB->nextId('frm_posts_drafts');
474 $post_date = date("Y-m-d H:i:s");
475
476 $ilDB->insert('frm_posts_drafts', array(
477 'draft_id' => array('integer', $draft_id),
478 'post_id' => array('integer', $this->getPostId()),
479 'thread_id' => array('integer', $this->getThreadId()),
480 'forum_id' => array('integer', $this->getForumId()),
481 'post_author_id' => array('integer', $this->getPostAuthorId()),
482 'post_subject' => array('text', $this->getPostSubject()),
483 'post_message' => array('clob', $this->getPostMessage()),
484 'notify' => array('integer', $this->getNotify()),
485 'post_notify' => array('integer', $this->getPostNotify()),
486 'post_date' => array('timestamp', $post_date),
487 'post_update' => array('timestamp', $post_date),
488// 'update_user_id' => array('integer', $this->getUpdateUserId()),
489 'post_user_alias' => array('text', $this->getPostUserAlias()),
490 'pos_display_usr_id' => array('integer', $this->getPostDisplayUserId())
491 ));
492 $this->setDraftId($draft_id);
493 return $draft_id;
494 }
495
496 public function updateDraft()
497 {
498 global $ilDB;
499
500 $ilDB->update('frm_posts_drafts', array(
501 'post_subject' => array('text', $this->getPostSubject()),
502 'post_message' => array('clob', $this->getPostMessage()),
503 'notify' => array('integer', $this->getNotify()),
504 'post_notify' => array('integer', $this->getPostNotify()),
505 'post_update' => array('timestamp', date("Y-m-d H:i:s")),
506 'update_user_id' => array('integer', $this->getUpdateUserId()),
507 'post_user_alias' => array('text', $this->getPostUserAlias()),
508 'pos_display_usr_id' => array('integer', $this->getPostDisplayUserId())
509 ),
510 array('draft_id' => array('integer', $this->getDraftId())));
511 }
512
513 public function deleteDraft()
514 {
515 global $ilDB;
516
517 $ilDB->manipulateF('DELETE FROM frm_posts_drafts WHERE draft_id = %s',
518 array('integer'), array($this->getDraftId()));
519 }
520
524 public static function deleteMobsOfDraft($draft_id)
525 {
526 require_once 'Services/MediaObjects/classes/class.ilObjMediaObject.php';
527 // delete mobs of draft
528 $oldMediaObjects = ilObjMediaObject::_getMobsOfObject('frm~d:html', $draft_id);
529 foreach($oldMediaObjects as $oldMob)
530 {
531 if(ilObjMediaObject::_exists($oldMob))
532 {
533 ilObjMediaObject::_removeUsage($oldMob, 'frm~d:html', $draft_id);
534 $mob_obj = new ilObjMediaObject($oldMob);
535 $mob_obj->delete();
536 }
537 }
538 }
539
543 public function deleteDraftsByDraftIds(array $draft_ids = array())
544 {
545 global $ilDB;
546
547 foreach($draft_ids as $draft_id)
548 {
550
551 // delete attachments of draft
552 $objFileDataForumDrafts = new ilFileDataForumDrafts(0, $draft_id);
553 $objFileDataForumDrafts->delete();
554 }
555 $ilDB->manipulate('DELETE FROM frm_drafts_history WHERE ' . $ilDB->in('draft_id', $draft_ids, false, 'integer'));
556 $ilDB->manipulate('DELETE FROM frm_posts_drafts WHERE ' . $ilDB->in('draft_id', $draft_ids, false, 'integer'));
557 }
558
562 public static function deleteDraftsByUserId($user_id)
563 {
564 global $ilDB;
565
566 $res = $ilDB->queryF('SELECT draft_id FROM frm_posts_drafts WHERE post_author_id = %s',
567 array('integer'), array($user_id));
568
569 $draft_ids = array();
570 while($row = $ilDB->fetchAssoc($res))
571 {
572 $draft_ids[] = $row['draft_id'];
573 }
574
575 foreach($draft_ids as $draft_id)
576 {
578
579 // delete attachments of draft
580 $objFileDataForumDrafts = new ilFileDataForumDrafts(0, $draft_id);
581 $objFileDataForumDrafts->delete();
582 }
583
584 $ilDB->manipulate('DELETE FROM frm_drafts_history WHERE ' . $ilDB->in('draft_id', $draft_ids, false, 'integer'));
585 $ilDB->manipulateF('DELETE FROM frm_posts_drafts WHERE post_author_id = %s',
586 array('integer'), array($user_id));
587 }
588
592 public static function isSavePostDraftAllowed()
593 {
594 if(!isset(self::$drafts_settings_cache['save_post_drafts']))
595 {
596 global $ilSetting;
597 self::$drafts_settings_cache['save_post_drafts'] = (bool)$ilSetting->get('save_post_drafts', false);
598 }
599 return self::$drafts_settings_cache['save_post_drafts'];
600 }
601
605 public static function isAutoSavePostDraftAllowed()
606 {
607 if(!self::isSavePostDraftAllowed())
608 {
609 // feature is globally deactivated
610 return false;
611 }
612 if(!isset(self::$drafts_settings_cache['autosave_drafts']))
613 {
614 global $ilSetting;
615
616 self::$drafts_settings_cache['autosave_drafts'] = (bool)$ilSetting->get('autosave_drafts', false);
617 self::$drafts_settings_cache['autosave_drafts_ival'] = (int)$ilSetting->get('autosave_drafts_ival', 30);
618 }
619 return self::$drafts_settings_cache['autosave_drafts'];
620 }
621
622 public static function lookupAutosaveInterval()
623 {
624 if(self::isAutoSavePostDraftAllowed())
625 {
626 return self::$drafts_settings_cache['autosave_drafts_ival'];
627 }
628 return 0;
629 }
630
635 public static function getDraftsStatisticsByRefId($ref_id)
636 {
637 global $ilUser, $ilDB;
638
639 if(!isset(self::$forum_statistics_cache[$ref_id][$ilUser->getId()]))
640 {
642
643 $res = $ilDB->queryF('
644 SELECT COUNT(draft_id) num_drafts, thread_id FROM frm_posts_drafts
645 WHERE forum_id = %s AND post_author_id = %s
646 GROUP BY thread_id',
647 array('integer', 'integer'), array($forumId, $ilUser->getId()));
648
649 $num_drafts_total = 0;
650
651 while($row = $ilDB->fetchAssoc($res))
652 {
653 $num_drafts_total += $row['num_drafts'];
654 self::$forum_statistics_cache[$ref_id][$ilUser->getId()][$row['thread_id']] = $row['num_drafts'];
655 }
656
657 self::$forum_statistics_cache[$ref_id][$ilUser->getId()]['total'] = $num_drafts_total;
658 }
659 return self::$forum_statistics_cache[$ref_id][$ilUser->getId()];
660 }
661
666 public static function moveDraftsByMergedThreads($source_thread_id, $target_thread_id)
667 {
668 global $ilDB;
669
670 $ilDB->update('frm_posts_drafts',
671 array('thread_id' => array('integer', $target_thread_id)),
672 array('thread_id' => array('integer', $source_thread_id))
673 );
674 }
675
681 public static function moveDraftsByMovedThread($thread_ids, $source_ref_id, $target_ref_id)
682 {
683 global $ilDB;
684
685 $source_forum_id = ilObjForum::lookupForumIdByRefId($source_ref_id);
686 $target_forum_id = ilObjForum::lookupForumIdByRefId($target_ref_id);
687
688 $ilDB->manipulateF('
689 UPDATE frm_posts_drafts
690 SET forum_id = %s
691 WHERE forum_id = %s
692 AND '. $ilDB->in('thread_id', $thread_ids, false, 'integer'),
693 array('integer', 'integer'),
694 array($target_forum_id, $source_forum_id)
695 );
696 }
697
704 {
705 global $ilDB;
706
707 $res = $ilDB->queryF('SELECT * FROM frm_posts_drafts
708 WHERE post_author_id = %s
709 AND forum_id = %s
710 AND thread_id = %s
711 AND post_id = %s
712 ORDER BY post_date DESC',
713 array('integer', 'integer', 'integer', 'integer'),
714 array($post_author_id, $forum_id, 0, 0));
715 $draft_data = array();
716 while($row = $ilDB->fetchAssoc($res))
717 {
718 $tmp_obj = new self;
720 $draft_data[] = array('subject'=> $tmp_obj->getPostSubject(), 'post_update' => $tmp_obj->getPostUpdate(), 'draft_id' => $tmp_obj->getDraftId());
721 }
722 return $draft_data;
723 }
724
728 public static function createDraftBackup($draft_id)
729 {
730 global $ilDB;
731
732 $res = $ilDB->queryF('SELECT * FROM frm_posts_drafts WHERE draft_id = %s',
733 array('integer'), array((int)$draft_id));
734
735 while($row = $ilDB->fetchAssoc($res))
736 {
737 $tmp_obj = new self;
739 }
740
741 $history_obj = new ilForumDraftsHistory();
742 $history_obj->deleteHistoryByDraftIds(array($draft_id));
743
744 $history_obj->setDraftId($draft_id);
745 $history_obj->setPostSubject($tmp_obj->getPostSubject());
746 $history_obj->setPostMessage($tmp_obj->getPostMessage());
747 $history_obj->addDraftToHistory();
748
749 ilForumUtil::moveMediaObjects($tmp_obj->getPostMessage(),
750 self::MEDIAOBJECT_TYPE, $draft_id,
751 ilForumDraftsHistory::MEDIAOBJECT_TYPE, $history_obj->getHistoryId());
752 }
753}
sprintf('%.4f', $callTime)
date( 'd-M-Y', $objPHPExcel->getProperties() ->getCreated())
An exception for terminatinating execution or to throw for unit testing.
Base class for ILIAS Exception handling.
This class handles all operations on files for the drafts of a forum object.
Class ilForumDraftHistory.
Class ilForumPostDraft.
setPostUserAlias($post_user_alias)
static moveDraftsByMergedThreads($source_thread_id, $target_thread_id)
deleteDraftsByDraftIds(array $draft_ids=array())
__construct($user_id=0, $post_id=0, $draft_id=0)
ilForumPostDraft constructor.
static populateWithDatabaseRecord(ilForumPostDraft $draft, array $row)
static getInstancesByUserIdAndThreadId($user_id, $thread_id)
static readDrafts($user_id)
setPostMessage($post_message)
static moveDraftsByMovedThread($thread_ids, $source_ref_id, $target_ref_id)
static deleteDraftsByUserId($user_id)
static getDraftInstancesByUserId($user_id)
static createDraftBackup($draft_id)
static getThreadDraftData($post_author_id, $forum_id)
setPostSubject($post_subject)
setPostAuthorId($post_author_id)
setPostDisplayUserId($post_display_user_id)
static deleteMobsOfDraft($draft_id)
static getDraftsStatisticsByRefId($ref_id)
setUpdateUserId($update_user_id)
static moveMediaObjects($post_message, $source_type, $source_id, $target_type, $target_id, $direction=0)
static lookupForumIdByRefId($ref_id)
Class ilObjMediaObject.
static _getMobsOfObject($a_type, $a_id, $a_usage_hist_nr=0, $a_lang="-")
get mobs of object
static _removeUsage($a_mob_id, $a_type, $a_id, $a_usage_hist_nr=0, $a_lang="-")
Remove usage of mob in another container.
static _exists($a_id, $a_reference=false, $a_type=NULL)
checks wether a lm content object with specified id exists or not
global $ilSetting
Definition: privfeed.php:17
$ref_id
Definition: sahs_server.php:39
global $ilDB
$ilUser
Definition: imgupload.php:18