ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilForumPostingDraftsBlockGUI.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2016 ILIAS open source, Extended GPL, see docs/LICENSE */
3
11{
15 public static $block_type = 'pdfrmpostdraft';
16
20 private $settings;
21
25 public function __construct()
26 {
27 global $DIC;
28
29 parent::__construct();
30
31 $this->settings = $DIC->settings();
32
33 $this->lng->loadLanguageModule('forum');
34
35 $this->setLimit(5);
36 $this->setImage(ilUtil::getImagePath('icon_frm.svg'));
37 $this->setTitle($this->lng->txt('frm_my_posting_drafts'));
39 $this->allow_moving = true;
40 }
41
45 public function executeCommand()
46 {
47 $cmd = $this->ctrl->getCmd('getHTML');
48 return $this->$cmd();
49 }
50
54 public function getBlockType() : string
55 {
56 return self::$block_type;
57 }
58
62 protected function isRepositoryObject() : bool
63 {
64 return false;
65 }
66
70 public function getHTML()
71 {
72 if ($this->getCurrentDetailLevel() == 0 || !$this->settings->get('save_post_drafts', 0) || !$this->settings->get('block_activated_pdfrmpostdraft', 0)) {
73 return '';
74 } else {
75 return parent::getHTML();
76 }
77 }
78
82 public function fillRow($draft)
83 {
84 $this->tpl->setVariable('SUBJECT', $draft['subject']);
85 $this->tpl->setVariable('SOURCE', $draft['source']);
86 $this->tpl->setVariable("HREF", $draft['href']);
87 if ($this->getCurrentDetailLevel() > 2) {
88 $this->tpl->setVariable('CREATE_DATE', ilDatePresentation::formatDate(new ilDateTime($draft['create_date'], IL_CAL_DATETIME)));
89 }
90 }
91
95 public function fillDataSection()
96 {
97 $drafts_instances = ilForumPostDraft::getDraftInstancesByUserId($this->user->getId());
98
99 $draft_as_array = array();
100 $data = array();
101 if (is_array($drafts_instances) && count($drafts_instances) > 0) {
102 foreach ($drafts_instances as $draft) {
103 $is_thread = false;
104 if ((int) $draft->getThreadId() == 0) {
105 $is_thread = true;
106 }
107
108 $draft_as_array['subject'] = $draft->getPostSubject();
109 $draft_as_array['draft_id'] = $draft->getDraftId();
110
111 $information = ilForumUtil::collectPostInformationByPostId($draft->getPostId());
112 $draft_as_array['source'] = implode('/', $information);
113 $draft_as_array['create_date'] = $draft->getPostDate();
114
115 $obj_id = ilForum::_lookupObjIdForForumId($draft->getForumId());
116 $ref_id = end(ilObject::_getAllReferences($obj_id));
117
118 if ($is_thread) {
119 $params['cmd'] = 'editThreadDraft';
120 $params['draft_id'] = $draft->getDraftId();
121 $draft_as_array['href'] = ilLink::_getLink($ref_id, 'frm', $params);
122 } else {
123 $params['thr_pk'] = $draft->getThreadId();
124 $params['pos_pk'] = $draft->getPostId();
125 $params['cmd'] = 'viewThread';
126 $draft_as_array['href'] = ilLink::_getLink($ref_id, 'frm', $params) . '#draft_' . $draft->getDraftId();
127 }
128
129 $data[] = $draft_as_array;
130 }
131 }
132 $this->setData($data);
133
134 if ($this->getCurrentDetailLevel() > 1 && count($this->data) > 0) {
135 $this->setRowTemplate('tpl.pd_frm_posting_drafts_row.html', 'Modules/Forum');
136 if ($this->getCurrentDetailLevel() > 2) {
137 $this->setColSpan(2);
138 }
139 parent::fillDataSection();
140 } else {
141 $this->setEnableNumInfo(false);
142 if (count($this->data) == 0) {
143 $this->setEnableDetailRow(false);
144 }
145 $this->setDataSection($this->getOverview());
146 }
147 }
148
152 protected function getOverview()
153 {
154 $tpl = new ilTemplate('tpl.pd_frm_posting_drafts_row.html', true, true, 'Modules/Forum');
155 $tpl->setCurrentBlock('overview');
156 $tpl->setVariable('NUM_FRM_POSTING_DRAFTS', count($this->data));
157 if (count($this->data) == 1) {
158 $tpl->setVariable('TXT_FRM_POSTING_DRAFTS', $this->lng->txt('frm_posting_draft'));
159 } else {
160 $tpl->setVariable('TXT_FRM_POSTING_DRAFTS', $this->lng->txt('frm_posting_drafts'));
161 }
162 $tpl->parseCurrentBlock();
163
164 return $tpl->get();
165 }
166}
user()
Definition: user.php:4
An exception for terminatinating execution or to throw for unit testing.
const IL_CAL_DATETIME
This class represents a block method of a block.
setRowTemplate($a_rowtemplatename, $a_rowtemplatedir="")
Set Row Template Name.
setLimit($a_limit)
Set Limit.
setImage($a_image)
Set Image.
getCurrentDetailLevel()
Get Current Detail Level.
setAvailableDetailLevels($a_max, $a_min=0)
Set Available Detail Levels.
setEnableDetailRow($a_enabledetailrow)
Set EnableDetailRow.
setData($a_data)
Set Data.
setDataSection($a_content)
Call this from overwritten fillDataSection(), if standard row based data is not used.
setColSpan($a_colspan)
Set Columns Span.
setTitle($a_title)
Set Title.
setEnableNumInfo($a_enablenuminfo)
Set Enable Item Number Info.
static formatDate(ilDateTime $date, $a_skip_day=false, $a_include_wd=false, $include_seconds=false)
Format a date @access public.
@classDescription Date and time handling
static getDraftInstancesByUserId($user_id)
Class ilForumPostingDraftsBlockGUI.
getHTML()
{Handle config status.Get HTML.}
isRepositoryObject()
Returns whether block has a corresponding repository object.bool
fillDataSection()
{Standard implementation for row based data.Overwrite this and call setContent for other data....
static collectPostInformationByPostId($post_id)
static _lookupObjIdForForumId($a_for_id)
static _getAllReferences($a_id)
get all reference ids of object
special template class to simplify handling of ITX/PEAR
static getImagePath($img, $module_path="", $mode="output", $offline=false)
get image path (for images located in a template directory)
global $DIC
Definition: saml.php:7
settings()
Definition: settings.php:2
$this data['403_header']