ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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  public function __construct()
24  {
28  global $lng;
29 
30  parent::__construct();
31 
32  $lng->loadLanguageModule('forum');
33 
34  $this->setLimit(5);
35  $this->setImage(ilUtil::getImagePath('icon_frm.svg'));
36  $this->setTitle($lng->txt('frm_my_posting_drafts'));
37  $this->setAvailableDetailLevels(3);
38  $this->allow_moving = true;
39  }
40 
44  public function executeCommand()
45  {
49  global $ilCtrl;
50 
51  $cmd = $ilCtrl->getCmd('getHTML');
52 
53  return $this->$cmd();
54  }
55 
59  public static function getBlockType()
60  {
61  return self::$block_type;
62  }
63 
67  public static function isRepositoryObject()
68  {
69  return false;
70  }
71 
75  public function getHTML()
76  {
80  global $ilSetting;
81 
82  if($this->getCurrentDetailLevel() == 0 || !$ilSetting->get('save_post_drafts', 0) || !$ilSetting->get('block_activated_pdfrmpostdraft', 0))
83  {
84  return '';
85  }
86  else
87  {
88  return parent::getHTML();
89  }
90  }
91 
95  public function fillRow($draft)
96  {
97  $this->tpl->setVariable('SUBJECT', $draft['subject']);
98  $this->tpl->setVariable('SOURCE', $draft['source']);
99  $this->tpl->setVariable("HREF", $draft['href']);
100  if($this->getCurrentDetailLevel() > 2)
101  {
102  $this->tpl->setVariable('CREATE_DATE', ilDatePresentation::formatDate(new ilDateTime($draft['create_date'], IL_CAL_DATETIME)));
103  }
104  }
105 
109  public function fillDataSection()
110  {
111  global $ilUser;
112 
113  require_once './Modules/Forum/classes/class.ilForumPostDraft.php';
114  require_once './Modules/Forum/classes/class.ilForumUtil.php';
115  require_once './Services/Link/classes/class.ilLink.php';
116 
117  $drafts_instances = ilForumPostDraft::getDraftInstancesByUserId($ilUser->getId());
118 
119  $draft_as_array = array();
120  $data = array();
121  if(is_array($drafts_instances) || count($drafts_instances) > 0 )
122  {
123  foreach($drafts_instances as $draft)
124  {
125  $is_thread = false;
126  if((int)$draft->getThreadId() == 0)
127  {
128  $is_thread = true;
129  }
130 
131  $draft_as_array['subject'] = $draft->getPostSubject();
132  $draft_as_array['draft_id'] = $draft->getDraftId();
133 
134  $information = ilForumUtil::collectPostInformationByPostId($draft->getPostId());
135  $draft_as_array['source'] = implode('/', $information);
136  $draft_as_array['create_date'] = $draft->getPostDate();
137 
138  $obj_id = ilForum::_lookupObjIdForForumId($draft->getForumId());
139  $ref_id = end(ilObject::_getAllReferences($obj_id));
140 
141  if($is_thread)
142  {
143  $params['cmd'] = 'editThreadDraft';
144  $params['draft_id'] = $draft->getDraftId();
145  $draft_as_array['href'] = ilLink::_getLink($ref_id, 'frm', $params);
146  }
147  else
148  {
149  $params['thr_pk'] = $draft->getThreadId();
150  $params['pos_pk'] = $draft->getPostId();
151  $params['cmd'] = 'viewThread';
152  $draft_as_array['href'] = ilLink::_getLink($ref_id, 'frm', $params) . '#draft_' . $draft->getDraftId();
153  }
154 
155  $data[] = $draft_as_array;
156  }
157  }
158  $this->setData($data);
159 
160  if($this->getCurrentDetailLevel() > 1 && count($this->data) > 0)
161  {
162  $this->setRowTemplate('tpl.pd_frm_posting_drafts_row.html', 'Modules/Forum');
163  if($this->getCurrentDetailLevel() > 2)
164  {
165  $this->setColSpan(2);
166  }
167  parent::fillDataSection();
168  }
169  else
170  {
171  $this->setEnableNumInfo(false);
172  if(count($this->data) == 0)
173  {
174  $this->setEnableDetailRow(false);
175  }
176  $this->setDataSection($this->getOverview());
177  }
178  }
179 
183  protected function getOverview()
184  {
188  global $lng;
189 
190  $tpl = new ilTemplate('tpl.pd_frm_posting_drafts_row.html', true, true, 'Modules/Forum');
191  $tpl->setCurrentBlock('overview');
192  $tpl->setVariable('NUM_FRM_POSTING_DRAFTS', count($this->data));
193  if(count($this->data) == 1)
194  {
195  $tpl->setVariable('TXT_FRM_POSTING_DRAFTS', $lng->txt('frm_posting_draft'));
196  }
197  else
198  {
199  $tpl->setVariable('TXT_FRM_POSTING_DRAFTS', $lng->txt('frm_posting_drafts'));
200  }
201  $tpl->parseCurrentBlock();
202 
203  return $tpl->get();
204  }
205 }
static getDraftInstancesByUserId($user_id)
Add some data
static _lookupObjIdForForumId($a_for_id)
const IL_CAL_DATETIME
setDataSection($a_content)
Call this from overwritten fillDataSection(), if standard row based data is not used.
$cmd
Definition: sahs_server.php:35
setEnableNumInfo($a_enablenuminfo)
Set Enable Item Number Info.
static _getAllReferences($a_id)
get all reference ids of object
global $tpl
Definition: ilias.php:8
global $ilCtrl
Definition: ilias.php:18
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.
static formatDate(ilDateTime $date)
Format a date public.
Date and time handling
$ilUser
Definition: imgupload.php:18
Create styles array
The data for the language used.
__construct()
Constructor.
getHTML()
Handle config status.
setLimit($a_limit)
Set Limit.
$ref_id
Definition: sahs_server.php:39
global $ilSetting
Definition: privfeed.php:17
global $lng
Definition: privfeed.php:17
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.
$params
Definition: example_049.php:96
getCurrentDetailLevel()
Get Current Detail Level.