19declare(strict_types=1);
54 $this->db =
$DIC->database();
224 $res = $this->db->queryF(
225 'SELECT * FROM frm_posts_drafts WHERE post_author_id = %s AND draft_id = %s',
226 [
'integer',
'integer'],
230 if ($row = $this->db->fetchAssoc(
$res)) {
241 'SELECT * FROM frm_posts_drafts WHERE post_author_id = %s',
246 self::$instances[$user_id] = [
253 self::$instances[$user_id][$row[
'thread_id']][$tmp_obj->getPostId()][] = $tmp_obj;
254 self::$instances[$user_id][
'draft_ids'][$tmp_obj->getDraftId()] = $tmp_obj;
272 $orderDirection =
' ';
275 $orderColumn =
' ORDER BY post_date ';
276 $orderDirection =
'ASC';
278 $orderDirection =
'DESC';
283 'SELECT * FROM frm_posts_drafts WHERE post_author_id = %s AND thread_id = %s' .
284 $orderColumn . $orderDirection,
285 [
'integer',
'integer'],
293 self::$instances[$usrId][$threadId][$draft->getPostId()][] = $draft;
297 return self::$instances[$usrId][$threadId] ?? [];
308 if (!isset(self::$instances[$user_id])) {
309 self::readDrafts($user_id);
312 return self::$instances[$user_id][
'draft_ids'];
321 'SELECT * FROM frm_posts_drafts WHERE draft_id = %s',
328 self::populateWithDatabaseRecord($tmp_obj, $row);
335 $draft_id = $this->db->nextId(
'frm_posts_drafts');
336 $post_date = date(
"Y-m-d H:i:s");
338 $this->db->insert(
'frm_posts_drafts', [
339 'draft_id' => [
'integer', $draft_id],
340 'post_id' => [
'integer', $this->getPostId()],
341 'thread_id' => [
'integer', $this->getThreadId()],
342 'forum_id' => [
'integer', $this->getForumId()],
343 'post_author_id' => [
'integer', $this->getPostAuthorId()],
344 'post_subject' => [
'text', $this->getPostSubject()],
345 'post_message' => [
'clob', $this->getPostMessage()],
346 'notify' => [
'integer', (
int) $this->isNotificationEnabled()],
347 'post_notify' => [
'integer', (
int) $this->isPostNotificationEnabled()],
348 'post_date' => [
'timestamp', $post_date],
349 'post_update' => [
'timestamp', $post_date],
350 'post_user_alias' => [
'text', $this->getPostUserAlias()],
351 'pos_display_usr_id' => [
'integer', $this->getPostDisplayUserId()]
353 $this->setDraftId($draft_id);
362 'post_subject' => [
'text', $this->getPostSubject()],
363 'post_message' => [
'clob', $this->getPostMessage()],
364 'post_user_alias' => [
'text', $this->getPostUserAlias()],
365 'post_update' => [
'timestamp', date(
"Y-m-d H:i:s")],
366 'update_user_id' => [
'integer', $this->getUpdateUserId()],
368 [
'draft_id' => [
'integer', $this->getDraftId()]]
374 $this->db->manipulateF(
375 'DELETE FROM frm_posts_drafts WHERE draft_id = %s',
377 [$this->getDraftId()]
384 foreach ($oldMediaObjects as $oldMob) {
399 $res = $this->db->query(
'SELECT draft_id FROM frm_posts_drafts WHERE ' . $this->db->in(
405 while ($row = $this->db->fetchAssoc(
$res)) {
406 $draft_ids[] = (
int) $row[
'draft_id'];
409 foreach ($draft_ids as $draft_id) {
410 self::deleteMobsOfDraft($draft_id);
413 $objFileDataForumDrafts->delete();
415 $this->db->manipulate(
'DELETE FROM frm_drafts_history WHERE ' . $this->db->in(
421 $this->db->manipulate(
'DELETE FROM frm_posts_drafts WHERE ' . $this->db->in(
434 foreach ($draft_ids as $draft_id) {
435 self::deleteMobsOfDraft($draft_id);
438 $objFileDataForumDrafts->delete();
440 $this->db->manipulate(
'DELETE FROM frm_drafts_history WHERE ' . $this->db->in(
446 $this->db->manipulate(
'DELETE FROM frm_posts_drafts WHERE ' . $this->db->in(
460 'SELECT draft_id FROM frm_posts_drafts WHERE post_author_id = %s',
467 $draft_ids[] = (
int) $row[
'draft_id'];
470 foreach ($draft_ids as $draft_id) {
471 self::deleteMobsOfDraft($draft_id);
474 $objFileDataForumDrafts->delete();
477 $ilDB->manipulate(
'DELETE FROM frm_drafts_history WHERE ' .
$ilDB->in(
484 'DELETE FROM frm_posts_drafts WHERE post_author_id = %s',
492 if (!isset(self::$drafts_settings_cache[
'save_post_drafts'])) {
494 self::$drafts_settings_cache[
'save_post_drafts'] = (bool)
$DIC->settings()->get(
'save_post_drafts',
'0');
497 return self::$drafts_settings_cache[
'save_post_drafts'];
502 if (!self::isSavePostDraftAllowed()) {
506 if (!isset(self::$drafts_settings_cache[
'autosave_drafts'])) {
509 self::$drafts_settings_cache[
'autosave_drafts'] = (bool)
$DIC->settings()->get(
'autosave_drafts',
'0');
510 self::$drafts_settings_cache[
'autosave_drafts_ival'] = (
int)
$DIC->settings()->get(
511 'autosave_drafts_ival',
516 return self::$drafts_settings_cache[
'autosave_drafts'];
521 if (self::isAutoSavePostDraftAllowed()) {
522 return (
int) self::$drafts_settings_cache[
'autosave_drafts_ival'];
533 if (!isset(self::$forum_statistics_cache[
$ref_id][
$ilUser->getId()])) {
538 SELECT COUNT(draft_id) num_drafts, thread_id FROM frm_posts_drafts
539 WHERE forum_id = %s AND post_author_id = %s
541 [
'integer',
'integer'],
545 $num_drafts_total = 0;
548 $num_drafts_total += $row[
'num_drafts'];
549 self::$forum_statistics_cache[
$ref_id][
$ilUser->getId()][(
int) $row[
'thread_id']] = (
int) $row[
'num_drafts'];
552 self::$forum_statistics_cache[
$ref_id][
$ilUser->getId()][
'total'] = $num_drafts_total;
564 [
'thread_id' => [
'integer', $target_thread_id]],
565 [
'thread_id' => [
'integer', $source_thread_id]]
575 'SELECT * FROM frm_posts_drafts
576 WHERE post_author_id = %s
580 ORDER BY post_date DESC',
581 [
'integer',
'integer',
'integer',
'integer'],
582 [$post_author_id, $forum_id, 0, 0]
586 $tmp_obj =
new self();
587 self::populateWithDatabaseRecord($tmp_obj, $row);
588 $draft_data[] = [
'subject' => $tmp_obj->getPostSubject(),
589 'post_update' => $tmp_obj->getPostUpdate(),
590 'draft_id' => $tmp_obj->getDraftId()
602 'SELECT * FROM frm_posts_drafts WHERE draft_id = %s',
607 $tmp_obj =
new self();
609 self::populateWithDatabaseRecord($tmp_obj, $row);
613 $history_obj->deleteHistoryByDraftIds([$draft_id]);
615 $history_obj->setDraftId($draft_id);
616 $history_obj->setPostSubject($tmp_obj->getPostSubject());
617 $history_obj->setPostMessage($tmp_obj->getPostMessage());
618 $history_obj->addDraftToHistory();
621 $tmp_obj->getPostMessage(),
622 self::MEDIAOBJECT_TYPE,
625 $history_obj->getHistoryId()
This class handles all operations on files for the drafts of a forum object.
Class ilForumDraftHistory.
static getThreadDraftData(int $post_author_id, int $forum_id)
static getDraftsStatisticsByRefId(int $ref_id)
static deleteMobsOfDraft(int $draft_id)
static lookupAutosaveInterval()
setUpdateUserId(int $update_user_id)
static createDraftBackup(int $draft_id)
setPostAuthorId(int $post_author_id)
static array $forum_statistics_cache
static isAutoSavePostDraftAllowed()
static populateWithDatabaseRecord(ilForumPostDraft $draft, array $row)
__construct(int $user_id=0, int $post_id=0, int $draft_id=0)
static isSavePostDraftAllowed()
int $post_display_user_id
setThreadId(int $thread_id)
static readDrafts(int $user_id)
setPostDisplayUserId(int $post_display_user_id)
setNotificationStatus(bool $notify)
setPostMessage(string $post_message)
static moveDraftsByMergedThreads(int $source_thread_id, int $target_thread_id)
setPostUserAlias(string $post_user_alias)
setDraftId(int $draft_id)
static array $drafts_settings_cache
setPostUpdate(string $post_update)
setForumId(int $forum_id)
static newInstanceByDraftId(int $draft_id)
isPostNotificationEnabled()
static getDraftInstancesByUserId(int $user_id)
deleteDraftsByDraftIds(array $draft_ids=[])
static deleteDraftsByUserId(int $user_id)
setPostNotificationStatus(bool $post_notify)
deleteDraftsByPostIds(array $post_ids=[])
setPostDate(string $post_date)
static getSortedDrafts(int $usrId, int $threadId, int $sorting=ilForumProperties::VIEW_DATE_ASC)
setPostSubject(string $post_subject)
static moveMediaObjects(string $post_message, string $source_type, int $source_id, string $target_type, int $target_id, int $direction=0)
static lookupForumIdByRefId(int $ref_id)