ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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 
4 require_once 'Services/Block/classes/class.ilBlockGUI.php';
5 require_once './Modules/Forum/classes/class.ilForum.php';
6 
14 {
18  public static $block_type = 'pdfrmpostdraft';
19 
23  private $settings;
24 
28  public function __construct()
29  {
30  global $DIC;
31 
32  parent::__construct();
33 
34  $this->settings = $DIC->settings();
35 
36  $this->lng->loadLanguageModule('forum');
37 
38  $this->setLimit(5);
39  $this->setImage(ilUtil::getImagePath('icon_frm.svg'));
40  $this->setTitle($this->lng->txt('frm_my_posting_drafts'));
41  $this->setAvailableDetailLevels(3);
42  $this->allow_moving = true;
43  }
44 
48  public function executeCommand()
49  {
50  $cmd = $this->ctrl->getCmd('getHTML');
51  return $this->$cmd();
52  }
53 
57  public static function getBlockType()
58  {
59  return self::$block_type;
60  }
61 
65  public static function isRepositoryObject()
66  {
67  return false;
68  }
69 
73  public function getHTML()
74  {
75  if ($this->getCurrentDetailLevel() == 0 || !$this->settings->get('save_post_drafts', 0) || !$this->settings->get('block_activated_pdfrmpostdraft', 0)) {
76  return '';
77  } else {
78  return parent::getHTML();
79  }
80  }
81 
85  public function fillRow($draft)
86  {
87  $this->tpl->setVariable('SUBJECT', $draft['subject']);
88  $this->tpl->setVariable('SOURCE', $draft['source']);
89  $this->tpl->setVariable("HREF", $draft['href']);
90  if ($this->getCurrentDetailLevel() > 2) {
91  $this->tpl->setVariable('CREATE_DATE', ilDatePresentation::formatDate(new ilDateTime($draft['create_date'], IL_CAL_DATETIME)));
92  }
93  }
94 
98  public function fillDataSection()
99  {
100  require_once './Modules/Forum/classes/class.ilForumPostDraft.php';
101  require_once './Modules/Forum/classes/class.ilForumUtil.php';
102  require_once './Services/Link/classes/class.ilLink.php';
103 
104  $drafts_instances = ilForumPostDraft::getDraftInstancesByUserId($this->user->getId());
105 
106  $draft_as_array = array();
107  $data = array();
108  if (is_array($drafts_instances) && count($drafts_instances) > 0) {
109  foreach ($drafts_instances as $draft) {
110  $is_thread = false;
111  if ((int) $draft->getThreadId() == 0) {
112  $is_thread = true;
113  }
114 
115  $draft_as_array['subject'] = $draft->getPostSubject();
116  $draft_as_array['draft_id'] = $draft->getDraftId();
117 
118  $information = ilForumUtil::collectPostInformationByPostId($draft->getPostId());
119  $draft_as_array['source'] = implode('/', $information);
120  $draft_as_array['create_date'] = $draft->getPostDate();
121 
122  $obj_id = ilForum::_lookupObjIdForForumId($draft->getForumId());
123  $ref_id = end(ilObject::_getAllReferences($obj_id));
124 
125  if ($is_thread) {
126  $params['cmd'] = 'editThreadDraft';
127  $params['draft_id'] = $draft->getDraftId();
128  $draft_as_array['href'] = ilLink::_getLink($ref_id, 'frm', $params);
129  } else {
130  $params['thr_pk'] = $draft->getThreadId();
131  $params['pos_pk'] = $draft->getPostId();
132  $params['cmd'] = 'viewThread';
133  $draft_as_array['href'] = ilLink::_getLink($ref_id, 'frm', $params) . '#draft_' . $draft->getDraftId();
134  }
135 
136  $data[] = $draft_as_array;
137  }
138  }
139  $this->setData($data);
140 
141  if ($this->getCurrentDetailLevel() > 1 && count($this->data) > 0) {
142  $this->setRowTemplate('tpl.pd_frm_posting_drafts_row.html', 'Modules/Forum');
143  if ($this->getCurrentDetailLevel() > 2) {
144  $this->setColSpan(2);
145  }
146  parent::fillDataSection();
147  } else {
148  $this->setEnableNumInfo(false);
149  if (count($this->data) == 0) {
150  $this->setEnableDetailRow(false);
151  }
152  $this->setDataSection($this->getOverview());
153  }
154  }
155 
159  protected function getOverview()
160  {
161  $tpl = new ilTemplate('tpl.pd_frm_posting_drafts_row.html', true, true, 'Modules/Forum');
162  $tpl->setCurrentBlock('overview');
163  $tpl->setVariable('NUM_FRM_POSTING_DRAFTS', count($this->data));
164  if (count($this->data) == 1) {
165  $tpl->setVariable('TXT_FRM_POSTING_DRAFTS', $this->lng->txt('frm_posting_draft'));
166  } else {
167  $tpl->setVariable('TXT_FRM_POSTING_DRAFTS', $this->lng->txt('frm_posting_drafts'));
168  }
169  $tpl->parseCurrentBlock();
170 
171  return $tpl->get();
172  }
173 }
static getDraftInstancesByUserId($user_id)
$params
Definition: disable.php:11
Add some data
static _lookupObjIdForForumId($a_for_id)
const IL_CAL_DATETIME
global $DIC
Definition: saml.php:7
setDataSection($a_content)
Call this from overwritten fillDataSection(), if standard row based data is not used.
static formatDate(ilDateTime $date, $a_skip_day=false, $a_include_wd=false)
Format a date public.
setEnableNumInfo($a_enablenuminfo)
Set Enable Item Number Info.
user()
Definition: user.php:4
static _getAllReferences($a_id)
get all reference ids of object
setColSpan($a_colspan)
Set Columns Span.
static collectPostInformationByPostId($post_id)
setImage($a_image)
Set Image.
setTitle($a_title)
Set Title.
static getImagePath($img, $module_path="", $mode="output", $offline=false)
get image path (for images located in a template directory)
setData($a_data)
Set Data.
special template class to simplify handling of ITX/PEAR
setAvailableDetailLevels($a_max, $a_min=0)
Set Available Detail Levels.
Date and time handling
Create styles array
The data for the language used.
setLimit($a_limit)
Set Limit.
settings()
Definition: settings.php:2
This class represents a block method of a block.
Class ilForumPostingDraftsBlockGUI.
setRowTemplate($a_rowtemplatename, $a_rowtemplatedir="")
Set Row Template Name.
setEnableDetailRow($a_enabledetailrow)
Set EnableDetailRow.
getCurrentDetailLevel()
Get Current Detail Level.