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 (!isset(self::$instances[$user_id])) {
446 self::readDrafts($user_id);
449 return self::$instances[$user_id][
'draft_ids'];
459 $ilDB = $DIC->database();
462 'SELECT * FROM frm_posts_drafts WHERE draft_id = %s',
469 self::populateWithDatabaseRecord($tmp_obj, $row);
482 $ilDB = $DIC->database();
485 'SELECT * FROM frm_drafts_history WHERE history_id = %s',
492 self::populateWithDatabaseRecord($tmp_obj, $row);
496 throw new ilException(sprintf(
"Could not find history object for id %s", $history_id));
501 $draft_id = $this->db->nextId(
'frm_posts_drafts');
504 $this->db->insert(
'frm_posts_drafts', array(
505 'draft_id' => array(
'integer',
$draft_id),
506 'post_id' => array(
'integer', $this->
getPostId()),
507 'thread_id' => array(
'integer', $this->
getThreadId()),
508 'forum_id' => array(
'integer', $this->
getForumId()),
512 'notify' => array(
'integer', $this->
getNotify()),
514 'post_date' => array(
'timestamp',
$post_date),
515 'post_update' => array(
'timestamp',
$post_date),
532 'post_update' => array(
'timestamp', date(
"Y-m-d H:i:s")),
535 array(
'draft_id' => array(
'integer', $this->
getDraftId()))
541 $this->db->manipulateF(
542 'DELETE FROM frm_posts_drafts WHERE draft_id = %s',
555 foreach ($oldMediaObjects as $oldMob) {
569 $draft_ids = array();
570 $res = $this->db->query(
'SELECT draft_id FROM frm_posts_drafts WHERE ' . $this->db->in(
'post_id', $post_ids,
false,
'integer'));
571 while ($row = $this->db->fetchAssoc(
$res)) {
572 $draft_ids[] = $row[
'draft_id'];
576 self::deleteMobsOfDraft($draft_id);
580 $objFileDataForumDrafts->delete();
582 $this->db->manipulate(
'DELETE FROM frm_drafts_history WHERE ' . $this->db->in(
'draft_id', $draft_ids,
false,
'integer'));
583 $this->db->manipulate(
'DELETE FROM frm_posts_drafts WHERE ' . $this->db->in(
'draft_id', $draft_ids,
false,
'integer'));
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 $ilDB = $DIC->database();
611 'SELECT draft_id FROM frm_posts_drafts WHERE post_author_id = %s',
616 $draft_ids = array();
618 $draft_ids[] = $row[
'draft_id'];
622 self::deleteMobsOfDraft($draft_id);
626 $objFileDataForumDrafts->delete();
629 $ilDB->manipulate(
'DELETE FROM frm_drafts_history WHERE ' .
$ilDB->in(
'draft_id', $draft_ids,
false,
'integer'));
631 'DELETE FROM frm_posts_drafts WHERE post_author_id = %s',
642 if (!isset(self::$drafts_settings_cache[
'save_post_drafts'])) {
644 self::$drafts_settings_cache[
'save_post_drafts'] = (bool) $DIC->settings()->get(
'save_post_drafts',
false);
646 return self::$drafts_settings_cache[
'save_post_drafts'];
654 if (!self::isSavePostDraftAllowed()) {
658 if (!isset(self::$drafts_settings_cache[
'autosave_drafts'])) {
661 self::$drafts_settings_cache[
'autosave_drafts'] = (bool) $DIC->settings()->get(
'autosave_drafts',
false);
662 self::$drafts_settings_cache[
'autosave_drafts_ival'] = (int) $DIC->settings()->get(
'autosave_drafts_ival', 30);
664 return self::$drafts_settings_cache[
'autosave_drafts'];
669 if (self::isAutoSavePostDraftAllowed()) {
670 return self::$drafts_settings_cache[
'autosave_drafts_ival'];
682 $ilDB = $DIC->database();
685 if (!isset(self::$forum_statistics_cache[$ref_id][
$ilUser->getId()])) {
690 SELECT COUNT(draft_id) num_drafts, thread_id FROM frm_posts_drafts 691 WHERE forum_id = %s AND post_author_id = %s 693 array(
'integer',
'integer'),
694 array($forumId,
$ilUser->getId())
697 $num_drafts_total = 0;
700 $num_drafts_total += $row[
'num_drafts'];
701 self::$forum_statistics_cache[$ref_id][
$ilUser->getId()][$row[
'thread_id']] = $row[
'num_drafts'];
704 self::$forum_statistics_cache[$ref_id][
$ilUser->getId()][
'total'] = $num_drafts_total;
706 return self::$forum_statistics_cache[$ref_id][
$ilUser->getId()];
716 $ilDB = $DIC->database();
720 array(
'thread_id' => array(
'integer', $target_thread_id)),
721 array(
'thread_id' => array(
'integer', $source_thread_id))
733 $ilDB = $DIC->database();
740 UPDATE frm_posts_drafts 743 AND ' .
$ilDB->in(
'thread_id', $thread_ids,
false,
'integer'),
744 array(
'integer',
'integer'),
745 array($target_forum_id, $source_forum_id)
757 $ilDB = $DIC->database();
760 'SELECT * FROM frm_posts_drafts 761 WHERE post_author_id = %s 765 ORDER BY post_date DESC',
766 array(
'integer',
'integer',
'integer',
'integer'),
769 $draft_data = array();
772 self::populateWithDatabaseRecord($tmp_obj, $row);
773 $draft_data[] = array(
'subject' => $tmp_obj->getPostSubject(),
'post_update' => $tmp_obj->getPostUpdate(),
'draft_id' => $tmp_obj->getDraftId());
784 $ilDB = $DIC->database();
787 'SELECT * FROM frm_posts_drafts WHERE draft_id = %s',
794 self::populateWithDatabaseRecord($tmp_obj, $row);
798 $history_obj->deleteHistoryByDraftIds(array($draft_id));
800 $history_obj->setDraftId($draft_id);
801 $history_obj->setPostSubject($tmp_obj->getPostSubject());
802 $history_obj->setPostMessage($tmp_obj->getPostMessage());
803 $history_obj->addDraftToHistory();
806 $tmp_obj->getPostMessage(),
807 self::MEDIAOBJECT_TYPE,
810 $history_obj->getHistoryId()
static getDraftInstancesByUserId($user_id)
static getThreadDraftData($post_author_id, $forum_id)
deleteDraftsByDraftIds(array $draft_ids=array())
setPostUserAlias($post_user_alias)
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)