19 declare(strict_types=1);
56 $this->db = $DIC->database();
58 if (
$user_id && $post_id && $draft_id) {
82 $draft->
setRCID((
string) ($row[
'rcid']));
90 public function setRCID(
string $rcid): void
237 $res = $this->db->queryF(
238 'SELECT * FROM frm_posts_drafts WHERE post_author_id = %s AND draft_id = %s',
239 [
'integer',
'integer'],
243 if ($row = $this->db->fetchAssoc(
$res)) {
244 self::populateWithDatabaseRecord($this, $row);
251 $ilDB = $DIC->database();
254 'SELECT * FROM frm_posts_drafts WHERE post_author_id = %s',
265 self::populateWithDatabaseRecord($draft, $row);
266 self::$instances[
$user_id][$row[
'thread_id']][$draft->getPostId()][] = $draft;
267 self::$instances[
$user_id][
'draft_ids'][$draft->getDraftId()] = $draft;
280 $ilDB = $DIC->database();
285 $orderDirection =
' ';
288 $orderColumn =
' ORDER BY post_date ';
289 $orderDirection =
'ASC';
291 $orderDirection =
'DESC';
296 'SELECT * FROM frm_posts_drafts WHERE post_author_id = %s AND thread_id = %s' .
297 $orderColumn . $orderDirection,
298 [
'integer',
'integer'],
304 self::populateWithDatabaseRecord($draft, $row);
306 self::$instances[$usrId][$threadId][$draft->getPostId()][] = $draft;
310 return self::$instances[$usrId][$threadId] ?? [];
321 if (!isset(self::$instances[$user_id])) {
322 self::readDrafts($user_id);
325 return self::$instances[
$user_id][
'draft_ids'];
331 $ilDB = $DIC->database();
334 'SELECT * FROM frm_posts_drafts WHERE draft_id = %s',
341 self::populateWithDatabaseRecord($tmp_obj, $row);
348 $draft_id = $this->db->nextId(
'frm_posts_drafts');
349 $post_date = date(
"Y-m-d H:i:s");
351 $this->db->insert(
'frm_posts_drafts', [
352 'draft_id' => [
'integer', $draft_id],
353 'post_id' => [
'integer', $this->
getPostId()],
355 'forum_id' => [
'integer', $this->
getForumId()],
361 'post_date' => [
'timestamp', $post_date],
362 'post_update' => [
'timestamp', $post_date],
383 'post_update' => [
'timestamp', date(
"Y-m-d H:i:s")],
385 'rcid' => [
'text', $this->
getRCID()]
387 [
'draft_id' => [
'integer', $this->
getDraftId()]]
393 $this->db->manipulateF(
394 'DELETE FROM frm_posts_drafts WHERE draft_id = %s',
403 foreach ($oldMediaObjects as $oldMob) {
418 $res = $this->db->query(
'SELECT draft_id FROM frm_posts_drafts WHERE ' . $this->db->in(
424 while ($row = $this->db->fetchAssoc(
$res)) {
425 $draft_ids[] = (
int) $row[
'draft_id'];
428 foreach ($draft_ids as $draft_id) {
429 self::deleteMobsOfDraft($draft_id);
433 $objFileDataForumDrafts->delete($draft_ids);
435 $this->db->manipulate(
'DELETE FROM frm_drafts_history WHERE ' . $this->db->in(
441 $this->db->manipulate(
'DELETE FROM frm_posts_drafts WHERE ' . $this->db->in(
454 foreach ($draft_ids as $draft_id) {
455 self::deleteMobsOfDraft($draft_id);
459 $objFileDataForumDrafts->delete($draft_ids);
461 $this->db->manipulate(
'DELETE FROM frm_drafts_history WHERE ' . $this->db->in(
467 $this->db->manipulate(
'DELETE FROM frm_posts_drafts WHERE ' . $this->db->in(
478 $ilDB = $DIC->database();
481 'SELECT draft_id FROM frm_posts_drafts WHERE post_author_id = %s',
488 $draft_ids[] = (
int) $row[
'draft_id'];
491 foreach ($draft_ids as $draft_id) {
492 self::deleteMobsOfDraft($draft_id);
496 $objFileDataForumDrafts->delete($draft_ids);
498 $ilDB->manipulate(
'DELETE FROM frm_drafts_history WHERE ' .
$ilDB->in(
505 'DELETE FROM frm_posts_drafts WHERE post_author_id = %s',
513 if (!isset(self::$drafts_settings_cache[
'save_post_drafts'])) {
515 self::$drafts_settings_cache[
'save_post_drafts'] = (bool) $DIC->settings()->get(
'save_post_drafts',
'0');
518 return self::$drafts_settings_cache[
'save_post_drafts'];
523 if (!self::isSavePostDraftAllowed()) {
527 if (!isset(self::$drafts_settings_cache[
'autosave_drafts'])) {
530 self::$drafts_settings_cache[
'autosave_drafts'] = (bool) $DIC->settings()->get(
'autosave_drafts',
'0');
531 self::$drafts_settings_cache[
'autosave_drafts_ival'] = (
int) $DIC->settings()->get(
532 'autosave_drafts_ival',
537 return self::$drafts_settings_cache[
'autosave_drafts'];
542 if (self::isAutoSavePostDraftAllowed()) {
543 return (
int) self::$drafts_settings_cache[
'autosave_drafts_ival'];
551 $ilDB = $DIC->database();
552 $ilUser = $DIC->user();
554 if (!isset(self::$forum_statistics_cache[$ref_id][$ilUser->getId()])) {
559 SELECT COUNT(draft_id) num_drafts, thread_id FROM frm_posts_drafts 560 LEFT JOIN frm_posts ON pos_pk = post_id 561 WHERE forum_id = %s AND post_author_id = %s AND (frm_posts.pos_pk IS NOT NULL OR post_id = 0) 563 [
'integer',
'integer'],
564 [$forumId, $ilUser->getId()]
567 $num_drafts_total = 0;
570 $num_drafts_total += $row[
'num_drafts'];
571 self::$forum_statistics_cache[
$ref_id][$ilUser->getId()][(
int) $row[
'thread_id']] = (
int) $row[
'num_drafts'];
574 self::$forum_statistics_cache[
$ref_id][$ilUser->getId()][
'total'] = $num_drafts_total;
576 return self::$forum_statistics_cache[
$ref_id][$ilUser->getId()];
582 $ilDB = $DIC->database();
586 [
'thread_id' => [
'integer', $target_thread_id]],
587 [
'thread_id' => [
'integer', $source_thread_id]]
594 $ilDB = $DIC->database();
597 'SELECT * FROM frm_posts_drafts 598 WHERE post_author_id = %s 602 ORDER BY post_date DESC',
603 [
'integer',
'integer',
'integer',
'integer'],
604 [$post_author_id, $forum_id, 0, 0]
608 $tmp_obj =
new self();
609 self::populateWithDatabaseRecord($tmp_obj, $row);
610 $draft_data[] = [
'subject' => $tmp_obj->getPostSubject(),
611 'post_update' => $tmp_obj->getPostUpdate(),
612 'draft_id' => $tmp_obj->getDraftId()
621 $ilDB = $DIC->database();
624 'SELECT * FROM frm_posts_drafts WHERE draft_id = %s',
629 $tmp_obj =
new self();
631 self::populateWithDatabaseRecord($tmp_obj, $row);
635 $history_obj->deleteHistoryByDraftIds([$draft_id]);
637 $history_obj->setDraftId($draft_id);
638 $history_obj->setPostSubject($tmp_obj->getPostSubject());
639 $history_obj->setPostMessage($tmp_obj->getPostMessage());
640 $history_obj->addDraftToHistory();
643 $tmp_obj->getPostMessage(),
644 self::MEDIAOBJECT_TYPE,
647 $history_obj->getHistoryId()
setThreadId(int $thread_id)
setPostMessage(string $post_message)
setPostSubject(string $post_subject)
setPostUpdate(string $post_update)
static moveMediaObjects(string $post_message, string $source_type, int $source_id, string $target_type, int $target_id, int $direction=0)
setDraftId(int $draft_id)
deleteDraftsByDraftIds(array $draft_ids=[])
readonly ilDBInterface $db
static readDrafts(int $user_id)
setPostDisplayUserId(int $post_display_user_id)
static lookupAutosaveInterval()
static array $drafts_settings_cache
static deleteMobsOfDraft(int $draft_id)
static lookupForumIdByRefId(int $ref_id)
isPostNotificationEnabled()
static createDraftBackup(int $draft_id)
Class ilForumDraftHistory.
static populateWithDatabaseRecord(ilForumPostDraft $draft, array $row)
static isAutoSavePostDraftAllowed()
setUpdateUserId(int $update_user_id)
static getDraftsStatisticsByRefId(int $ref_id)
setNotificationStatus(bool $notify)
static getThreadDraftData(int $post_author_id, int $forum_id)
__construct(int $user_id=0, int $post_id=0, int $draft_id=0)
setPostUserAlias(string $post_user_alias)
setPostDate(string $post_date)
static isSavePostDraftAllowed()
static deleteDraftsByUserId(int $user_id)
setPostNotificationStatus(bool $post_notify)
deleteDraftsByPostIds(array $post_ids=[])
static getSortedDrafts(int $usrId, int $threadId, int $sorting=ilForumProperties::VIEW_DATE_ASC)
int $post_display_user_id
static moveDraftsByMergedThreads(int $source_thread_id, int $target_thread_id)
static array $forum_statistics_cache
static newInstanceByDraftId(int $draft_id)
static getDraftInstancesByUserId(int $user_id)
setPostAuthorId(int $post_author_id)
setForumId(int $forum_id)