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 (!isset(self::$instances[$user_id])) {
446 self::readDrafts($user_id);
449 return self::$instances[$user_id][
'draft_ids'];
462 'SELECT * FROM frm_posts_drafts WHERE draft_id = %s',
469 self::populateWithDatabaseRecord($tmp_obj, $row);
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');
502 $post_date = date(
"Y-m-d H:i:s");
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()),
509 'post_author_id' => array(
'integer', $this->getPostAuthorId()),
510 'post_subject' => array(
'text', $this->getPostSubject()),
511 'post_message' => array(
'clob', $this->getPostMessage()),
512 'notify' => array(
'integer', $this->getNotify()),
513 'post_notify' => array(
'integer', $this->getPostNotify()),
514 'post_date' => array(
'timestamp', $post_date),
515 'post_update' => array(
'timestamp', $post_date),
517 'post_user_alias' => array(
'text', $this->getPostUserAlias()),
518 'pos_display_usr_id' => array(
'integer', $this->getPostDisplayUserId())
520 $this->setDraftId($draft_id);
529 'post_subject' => array(
'text', $this->getPostSubject()),
530 'post_message' => array(
'clob', $this->getPostMessage()),
531 'post_user_alias' => array(
'text', $this->getPostUserAlias()),
532 'post_update' => array(
'timestamp', date(
"Y-m-d H:i:s")),
533 'update_user_id' => array(
'integer', $this->getUpdateUserId()),
535 array(
'draft_id' => array(
'integer', $this->getDraftId()))
541 $this->db->manipulateF(
542 'DELETE FROM frm_posts_drafts WHERE draft_id = %s',
544 array($this->getDraftId())
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'];
575 foreach ($draft_ids as $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'));
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'));
611 'SELECT draft_id FROM frm_posts_drafts WHERE post_author_id = %s',
616 $draft_ids = array();
618 $draft_ids[] = $row[
'draft_id'];
621 foreach ($draft_ids as $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'];
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()];
720 array(
'thread_id' => array(
'integer', $target_thread_id)),
721 array(
'thread_id' => array(
'integer', $source_thread_id))
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)
760 'SELECT * FROM frm_posts_drafts
761 WHERE post_author_id = %s
765 ORDER BY post_date DESC',
766 array(
'integer',
'integer',
'integer',
'integer'),
767 array($post_author_id, $forum_id, 0, 0)
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());
787 'SELECT * FROM frm_posts_drafts WHERE draft_id = %s',
789 array((
int) $draft_id)
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()
An exception for terminatinating execution or to throw for unit testing.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
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 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