339 $this->db = $DIC->database();
354 $res = $this->db->queryF(
355 'SELECT * FROM frm_posts_drafts WHERE post_author_id = %s AND post_id = %s AND draft_id = %s',
356 array(
'integer',
'integer',
'integer'),
360 while ($row = $this->db->fetchAssoc(
$res)) {
361 self::populateWithDatabaseRecord($this, $row);
371 $ilDB = $DIC->database();
374 'SELECT * FROM frm_posts_drafts WHERE post_author_id = %s',
379 self::$instances[$user_id] = [
385 self::populateWithDatabaseRecord($tmp_obj, $row);
386 self::$instances[$user_id][$row[
'thread_id']][$tmp_obj->getPostId()][] = $tmp_obj;
387 self::$instances[$user_id][
'draft_ids'][$tmp_obj->getDraftId()] = $tmp_obj;
403 $ilDB = $DIC->database();
408 $orderDirection =
' ';
411 $orderColumn =
' ORDER BY post_date ';
412 $orderDirection =
'ASC';
414 $orderDirection =
'DESC';
419 'SELECT * FROM frm_posts_drafts WHERE post_author_id = %s AND thread_id = %s' .
420 $orderColumn . $orderDirection,
421 [
'integer',
'integer'],
427 self::populateWithDatabaseRecord($draft, $row);
429 self::$instances[$usrId][$threadId][$draft->getPostId()][] = $draft;
433 return self::$instances[$usrId][$threadId] ?? [];
445 if (!self::$instances[$user_id]) {
446 self::readDrafts($user_id);
449 return self::$instances[$user_id][
'draft_ids'];
459 if (!self::$instances[$user_id]) {
460 self::readDrafts($user_id);
463 if (isset(self::$instances[$user_id][
$thread_id])) {
464 return self::$instances[$user_id][
$thread_id];
477 $ilDB = $DIC->database();
480 'SELECT * FROM frm_posts_drafts WHERE draft_id = %s',
487 self::populateWithDatabaseRecord($tmp_obj, $row);
500 $ilDB = $DIC->database();
503 'SELECT * FROM frm_drafts_history WHERE history_id = %s',
510 self::populateWithDatabaseRecord($tmp_obj, $row);
514 throw new ilException(sprintf(
"Could not find history object for id %s", $history_id));
519 $draft_id = $this->db->nextId(
'frm_posts_drafts');
522 $this->db->insert(
'frm_posts_drafts', array(
523 'draft_id' => array(
'integer',
$draft_id),
524 'post_id' => array(
'integer', $this->
getPostId()),
525 'thread_id' => array(
'integer', $this->
getThreadId()),
526 'forum_id' => array(
'integer', $this->
getForumId()),
530 'notify' => array(
'integer', $this->
getNotify()),
532 'post_date' => array(
'timestamp',
$post_date),
533 'post_update' => array(
'timestamp',
$post_date),
551 array(
'draft_id' => array(
'integer', $this->
getDraftId()))
557 $this->db->manipulateF(
558 'DELETE FROM frm_posts_drafts WHERE draft_id = %s',
571 foreach ($oldMediaObjects as $oldMob) {
585 $draft_ids = array();
586 $res = $this->db->query(
'SELECT draft_id FROM frm_posts_drafts WHERE ' . $this->db->in(
'post_id', $post_ids,
false,
'integer'));
587 while ($row = $this->db->fetchAssoc(
$res)) {
588 $draft_ids[] = $row[
'draft_id'];
592 self::deleteMobsOfDraft($draft_id);
596 $objFileDataForumDrafts->delete();
598 $this->db->manipulate(
'DELETE FROM frm_drafts_history WHERE ' . $this->db->in(
'draft_id', $draft_ids,
false,
'integer'));
599 $this->db->manipulate(
'DELETE FROM frm_posts_drafts WHERE ' . $this->db->in(
'draft_id', $draft_ids,
false,
'integer'));
608 self::deleteMobsOfDraft($draft_id);
612 $objFileDataForumDrafts->delete();
614 $this->db->manipulate(
'DELETE FROM frm_drafts_history WHERE ' . $this->db->in(
'draft_id', $draft_ids,
false,
'integer'));
615 $this->db->manipulate(
'DELETE FROM frm_posts_drafts WHERE ' . $this->db->in(
'draft_id', $draft_ids,
false,
'integer'));
624 $ilDB = $DIC->database();
627 'SELECT draft_id FROM frm_posts_drafts WHERE post_author_id = %s',
632 $draft_ids = array();
634 $draft_ids[] = $row[
'draft_id'];
638 self::deleteMobsOfDraft($draft_id);
642 $objFileDataForumDrafts->delete();
645 $ilDB->manipulate(
'DELETE FROM frm_drafts_history WHERE ' .
$ilDB->in(
'draft_id', $draft_ids,
false,
'integer'));
647 'DELETE FROM frm_posts_drafts WHERE post_author_id = %s',
658 if (!isset(self::$drafts_settings_cache[
'save_post_drafts'])) {
660 self::$drafts_settings_cache[
'save_post_drafts'] = (bool) $DIC->settings()->get(
'save_post_drafts',
false);
662 return self::$drafts_settings_cache[
'save_post_drafts'];
670 if (!self::isSavePostDraftAllowed()) {
674 if (!isset(self::$drafts_settings_cache[
'autosave_drafts'])) {
677 self::$drafts_settings_cache[
'autosave_drafts'] = (bool) $DIC->settings()->get(
'autosave_drafts',
false);
678 self::$drafts_settings_cache[
'autosave_drafts_ival'] = (int) $DIC->settings()->get(
'autosave_drafts_ival', 30);
680 return self::$drafts_settings_cache[
'autosave_drafts'];
685 if (self::isAutoSavePostDraftAllowed()) {
686 return self::$drafts_settings_cache[
'autosave_drafts_ival'];
698 $ilDB = $DIC->database();
701 if (!isset(self::$forum_statistics_cache[$ref_id][
$ilUser->getId()])) {
706 SELECT COUNT(draft_id) num_drafts, thread_id FROM frm_posts_drafts 707 WHERE forum_id = %s AND post_author_id = %s 709 array(
'integer',
'integer'),
710 array($forumId,
$ilUser->getId())
713 $num_drafts_total = 0;
716 $num_drafts_total += $row[
'num_drafts'];
717 self::$forum_statistics_cache[$ref_id][
$ilUser->getId()][$row[
'thread_id']] = $row[
'num_drafts'];
720 self::$forum_statistics_cache[$ref_id][
$ilUser->getId()][
'total'] = $num_drafts_total;
722 return self::$forum_statistics_cache[$ref_id][
$ilUser->getId()];
732 $ilDB = $DIC->database();
736 array(
'thread_id' => array(
'integer', $target_thread_id)),
737 array(
'thread_id' => array(
'integer', $source_thread_id))
749 $ilDB = $DIC->database();
756 UPDATE frm_posts_drafts 759 AND ' .
$ilDB->in(
'thread_id', $thread_ids,
false,
'integer'),
760 array(
'integer',
'integer'),
761 array($target_forum_id, $source_forum_id)
773 $ilDB = $DIC->database();
776 'SELECT * FROM frm_posts_drafts 777 WHERE post_author_id = %s 781 ORDER BY post_date DESC',
782 array(
'integer',
'integer',
'integer',
'integer'),
785 $draft_data = array();
788 self::populateWithDatabaseRecord($tmp_obj, $row);
789 $draft_data[] = array(
'subject' => $tmp_obj->getPostSubject(),
'post_update' => $tmp_obj->getPostUpdate(),
'draft_id' => $tmp_obj->getDraftId());
800 $ilDB = $DIC->database();
803 'SELECT * FROM frm_posts_drafts WHERE draft_id = %s',
810 self::populateWithDatabaseRecord($tmp_obj, $row);
814 $history_obj->deleteHistoryByDraftIds(array($draft_id));
816 $history_obj->setDraftId($draft_id);
817 $history_obj->setPostSubject($tmp_obj->getPostSubject());
818 $history_obj->setPostMessage($tmp_obj->getPostMessage());
819 $history_obj->addDraftToHistory();
822 $tmp_obj->getPostMessage(),
823 self::MEDIAOBJECT_TYPE,
826 $history_obj->getHistoryId()
static getDraftInstancesByUserId($user_id)
static getThreadDraftData($post_author_id, $forum_id)
deleteDraftsByDraftIds(array $draft_ids=array())
setPostUserAlias($post_user_alias)
static getInstancesByUserIdAndThreadId($user_id, $thread_id)
static lookupForumIdByRefId($ref_id)
setPostDisplayUserId($post_display_user_id)
__construct($user_id=0, $post_id=0, $draft_id=0)
ilForumPostDraft constructor.
static lookupAutosaveInterval()
static moveMediaObjects($post_message, $source_type, $source_id, $target_type, $target_id, $direction=0)
This class handles all operations on files for the drafts of a forum object.
setPostNotify($post_notify)
static readDrafts($user_id)
Class ilForumDraftHistory.
static populateWithDatabaseRecord(ilForumPostDraft $draft, array $row)
static createDraftBackup($draft_id)
static moveDraftsByMergedThreads($source_thread_id, $target_thread_id)
foreach($_POST as $key=> $value) $res
static isAutoSavePostDraftAllowed()
static deleteMobsOfDraft($draft_id)
deleteDraftsByPostIds(array $post_ids=array())
setUpdateUserId($update_user_id)
setPostMessage($post_message)
static newInstanceByDraftId($draft_id)
static $drafts_settings_cache
setPostSubject($post_subject)
setPostAuthorId($post_author_id)
static moveDraftsByMovedThread($thread_ids, $source_ref_id, $target_ref_id)
static newInstanceByHistorytId($history_id)
static isSavePostDraftAllowed()
static getSortedDrafts(int $usrId, int $threadId, int $sorting=ilForumProperties::VIEW_DATE_ASC)
static deleteDraftsByUserId($user_id)
static $forum_statistics_cache
setPostUpdate($post_update)
static getDraftsStatisticsByRefId($ref_id)