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)) {
374 'SELECT * FROM frm_posts_drafts WHERE post_author_id = %s',
379 self::$instances[$user_id] = [
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;
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'],
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];
480 'SELECT * FROM frm_posts_drafts WHERE draft_id = %s',
487 self::populateWithDatabaseRecord($tmp_obj, $row);
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');
520 $post_date = date(
"Y-m-d H:i:s");
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()),
527 'post_author_id' => array(
'integer', $this->getPostAuthorId()),
528 'post_subject' => array(
'text', $this->getPostSubject()),
529 'post_message' => array(
'clob', $this->getPostMessage()),
530 'notify' => array(
'integer', $this->getNotify()),
531 'post_notify' => array(
'integer', $this->getPostNotify()),
532 'post_date' => array(
'timestamp', $post_date),
533 'post_update' => array(
'timestamp', $post_date),
535 'post_user_alias' => array(
'text', $this->getPostUserAlias()),
536 'pos_display_usr_id' => array(
'integer', $this->getPostDisplayUserId())
538 $this->setDraftId($draft_id);
547 'post_subject' => array(
'text', $this->getPostSubject()),
548 'post_message' => array(
'clob', $this->getPostMessage()),
549 'post_user_alias' => array(
'text', $this->getPostUserAlias())
551 array(
'draft_id' => array(
'integer', $this->getDraftId()))
557 $this->db->manipulateF(
558 'DELETE FROM frm_posts_drafts WHERE draft_id = %s',
560 array($this->getDraftId())
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'];
591 foreach ($draft_ids as $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'));
607 foreach ($draft_ids as $draft_id) {
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'));
627 'SELECT draft_id FROM frm_posts_drafts WHERE post_author_id = %s',
632 $draft_ids = array();
634 $draft_ids[] = $row[
'draft_id'];
637 foreach ($draft_ids as $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'];
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()];
736 array(
'thread_id' => array(
'integer', $target_thread_id)),
737 array(
'thread_id' => array(
'integer', $source_thread_id))
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)
776 'SELECT * FROM frm_posts_drafts
777 WHERE post_author_id = %s
781 ORDER BY post_date DESC',
782 array(
'integer',
'integer',
'integer',
'integer'),
783 array($post_author_id, $forum_id, 0, 0)
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());
803 'SELECT * FROM frm_posts_drafts WHERE draft_id = %s',
805 array((
int) $draft_id)
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()
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.
setPostUserAlias($post_user_alias)
static moveDraftsByMergedThreads($source_thread_id, $target_thread_id)
static lookupAutosaveInterval()
deleteDraftsByDraftIds(array $draft_ids=array())
__construct($user_id=0, $post_id=0, $draft_id=0)
ilForumPostDraft constructor.
static isAutoSavePostDraftAllowed()
static newInstanceByDraftId($draft_id)
static populateWithDatabaseRecord(ilForumPostDraft $draft, array $row)
static isSavePostDraftAllowed()
static getInstancesByUserIdAndThreadId($user_id, $thread_id)
static newInstanceByHistorytId($history_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)
setPostUpdate($post_update)
setPostNotify($post_notify)
setPostSubject($post_subject)
setPostAuthorId($post_author_id)
static $drafts_settings_cache
static $forum_statistics_cache
deleteDraftsByPostIds(array $post_ids=array())
setPostDisplayUserId($post_display_user_id)
static deleteMobsOfDraft($draft_id)
static getSortedDrafts(int $usrId, int $threadId, int $sorting=ilForumProperties::VIEW_DATE_ASC)
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)
foreach($_POST as $key=> $value) $res