ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilPortfolioPageGUI.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 include_once("./Services/COPage/classes/class.ilPageObjectGUI.php");
5 include_once("./Services/Portfolio/classes/class.ilPortfolioPage.php");
6 
19 {
20  protected $js_onload_code = array();
21  protected $additional = array();
22 
26  function __construct($a_portfolio_id, $a_id = 0, $a_old_nr = 0, $a_enable_comments = true)
27  {
28  global $tpl, $ilSetting;
29 
30  $this->portfolio_id = (int)$a_portfolio_id;
31  $this->enable_comments = (bool)$a_enable_comments;
32 
33  parent::__construct("prtf", $a_id, $a_old_nr);
34 
35  // content style
36  include_once("./Services/Style/classes/class.ilObjStyleSheet.php");
37 
38  $tpl->setCurrentBlock("SyntaxStyle");
39  $tpl->setVariable("LOCATION_SYNTAX_STYLESHEET",
41  $tpl->parseCurrentBlock();
42 
43  $tpl->setCurrentBlock("ContentStyle");
44  $tpl->setVariable("LOCATION_CONTENT_STYLESHEET",
46  $tpl->parseCurrentBlock();
47 
48  // #11190
49  $prfa_set = new ilSetting("prfa");
50  $this->setPreventHTMLUnmasking(!(bool)$prfa_set->get("mask", false));
51 
52  // $this->setEnabledMaps(true);
53  $this->setEnabledInternalLinks(false);
54  $this->setEnabledPCTabs(true);
55  $this->setEnabledProfile(true);
56 
57  if(!$ilSetting->get('disable_wsp_certificates'))
58  {
59  $this->setEnabledVerification(true);
60  }
61 
62  /* embedding blog postings currently disabled
63  if(!$ilSetting->get('disable_wsp_blogs'))
64  {
65  $this->setEnabledBlog(true);
66  }
67  */
68 
69  $skmg_set = new ilSetting("skmg");
70  if($skmg_set->get("enable_skmg"))
71  {
72  $this->setEnabledSkills(true);
73  }
74  }
75 
83  function initPageObject($a_parent_type, $a_id, $a_old_nr)
84  {
85  $page = new ilPortfolioPage($this->portfolio_id, $a_id, $a_old_nr);
86  $this->setPageObject($page);
87  }
88 
92  function &executeCommand()
93  {
94  global $ilCtrl, $ilTabs, $ilUser;
95 
96  $next_class = $this->ctrl->getNextClass($this);
97  $cmd = $this->ctrl->getCmd();
98 
99  switch($next_class)
100  {
101  case "ilobjbloggui":
102  // #12879 - we need the wsp-id for the keywords
103  include_once "Services/PersonalWorkspace/classes/class.ilWorkspaceTree.php";
104  $wsp_tree = new ilWorkspaceTree($ilUser->getId());
105  $blog_obj_id = (int)$this->getPageObject()->getTitle();
106  $blog_node_id = $wsp_tree->lookupNodeId($blog_obj_id);
107 
108  include_once "Modules/Blog/classes/class.ilObjBlogGUI.php";
109  $blog_gui = new ilObjBlogGUI($blog_node_id, ilObjBlogGUI::WORKSPACE_NODE_ID);
110  $blog_gui->disableNotes(!$this->enable_comments);
111  return $ilCtrl->forwardCommand($blog_gui);
112 
113  case "ilpageobjectgui":
114  $page_gui = new ilPageObjectGUI("prtf",
115  $this->getPageObject()->getId(), $this->getPageObject()->old_nr);
116  $page_gui->setPresentationTitle($this->getPageObject()->getTitle());
117  return $ilCtrl->forwardCommand($page_gui);
118 
119  default:
120  $this->setPresentationTitle($this->getPageObject()->getTitle());
121  return parent::executeCommand();
122  }
123  }
124 
130  function showPage()
131  {
132  global $tpl, $ilCtrl, $ilUser;
133 
134  if(!$this->getPageObject())
135  {
136  return;
137  }
138 
139  // render blog directly
140  if($this->getPageObject()->getType() == ilPortfolioPage::TYPE_BLOG)
141  {
142  return $this->renderBlog($ilUser->getId(), (int)$this->getPageObject()->getTitle());
143  }
144 
145  $this->setTemplateOutput(false);
146  // $this->setPresentationTitle($this->getPageObject()->getTitle());
147  $output = parent::showPage();
148 
149  return $output;
150  }
151 
158  function getTabs($a_activate = "")
159  {
160  global $ilTabs, $ilCtrl;
161 
162  if(!$this->embedded)
163  {
164  parent::getTabs($a_activate);
165  }
166  }
167 
173  function setEmbedded($a_value)
174  {
175  $this->embedded = (bool)$a_value;
176  }
177 
183  function setAdditional($a_additional)
184  {
185  $this->additional = $a_additional;
186  }
187 
193  function getAdditional()
194  {
195  return $this->additional;
196  }
197 
198  function postOutputProcessing($a_output)
199  {
200  $parts = array(
201  "Profile" => array("0-9", "a-z", "a-z_;\W"), // user, mode, fields
202  "Verification" => array("0-9", "a-z", "0-9"), // user, type, id
203  "Blog" => array("0-9", "0-9", "0-9;\W"), // user, blog id, posting ids
204  "BlogTeaser" => array("0-9", "0-9", "0-9;\W"), // user, blog id, posting ids
205  "Skills" => array("0-9", "0-9"), // user, skill id
206  "SkillsTeaser" => array("0-9", "0-9") // user, skill id
207  );
208 
209  foreach($parts as $type => $def)
210  {
211  $def = implode("]+)#([", $def);
212  if(preg_match_all("/".$this->pl_start.$type."#([".$def.
213  "]+)".$this->pl_end."/", $a_output, $blocks))
214  {
215  foreach($blocks[0] as $idx => $block)
216  {
217  switch($type)
218  {
219  case "Profile":
220  case "Blog":
221  case "BlogTeaser":
222  case "Skills":
223  case "SkillsTeaser":
224  $subs = null;
225  if(trim($blocks[3][$idx]))
226  {
227  foreach(explode(";", $blocks[3][$idx]) as $sub)
228  {
229  if(trim($sub))
230  {
231  $subs[] = trim($sub);
232  }
233  }
234  }
235  $snippet = $this->{"render".$type}($blocks[1][$idx],
236  $blocks[2][$idx], $subs);
237  break;
238 
239  default:
240  $snippet = $this->{"render".$type}($blocks[1][$idx],
241  $blocks[2][$idx], $blocks[3][$idx]);
242  break;
243  }
244 
245  $a_output = str_replace($block, $snippet, $a_output);
246  }
247  }
248  }
249 
250  return $a_output;
251  }
252 
253  protected function renderProfile($a_user_id, $a_type, array $a_fields = null)
254  {
255  global $ilCtrl;
256 
257  include_once("./Services/User/classes/class.ilPublicUserProfileGUI.php");
258  $pub_profile = new ilPublicUserProfileGUI($a_user_id);
259  $pub_profile->setEmbedded(true, ($this->getOutputMode() == "offline"));
260 
261  // full circle: additional was set in the original public user profile call
262  $pub_profile->setAdditional($this->getAdditional());
263 
264  if($a_type == "manual" && sizeof($a_fields))
265  {
266  foreach($a_fields as $field)
267  {
268  $field = trim($field);
269  if($field)
270  {
271  $prefs["public_".$field] = "y";
272  }
273  }
274 
275  $pub_profile->setCustomPrefs($prefs);
276  }
277 
278  if($this->getOutputMode() != "offline")
279  {
280  return $ilCtrl->getHTML($pub_profile);
281  }
282  else
283  {
284  return $pub_profile->getEmbeddable();
285  }
286  }
287 
288  protected function renderVerification($a_user_id, $a_type, $a_id)
289  {
290  global $objDefinition;
291 
292  $class = "ilObj".$objDefinition->getClassName($a_type)."GUI";
293  include_once $objDefinition->getLocation($a_type)."/class.".$class.".php";
294  $verification = new $class($a_id, ilObject2GUI::WORKSPACE_OBJECT_ID);
295 
296  // direct download link
297  $this->ctrl->setParameter($this, "dlid", $a_id);
298  $url = $this->ctrl->getLinkTarget($this, "dl".$a_type);
299  $this->ctrl->setParameter($this, "dlid", "");
300 
301  return $verification->render(true, $url);
302  }
303 
304  protected function dltstv()
305  {
306  $id = $_GET["dlid"];
307  if($id)
308  {
309  include_once "Modules/Test/classes/class.ilObjTestVerificationGUI.php";
311  $verification->downloadFromPortfolioPage($this->getPageObject());
312  }
313  }
314 
315  protected function dlexcv()
316  {
317  $id = $_GET["dlid"];
318  if($id)
319  {
320  include_once "Modules/Exercise/classes/class.ilObjExerciseVerificationGUI.php";
322  $verification->downloadFromPortfolioPage($this->getPageObject());
323  }
324  }
325 
326  protected function renderBlog($a_user_id, $a_blog_id, array $a_posting_ids = null)
327  {
328  global $ilCtrl;
329 
330  // :TODO: what about user?
331 
332  // full blog (separate tab/page)
333  if(!$a_posting_ids)
334  {
335  include_once "Modules/Blog/classes/class.ilObjBlogGUI.php";
336  $blog = new ilObjBlogGUI($a_blog_id, ilObject2GUI::WORKSPACE_OBJECT_ID);
337  $blog->disableNotes(!$this->enable_comments);
338 
339  if($this->getOutputMode() != "offline")
340  {
341  return $ilCtrl->getHTML($blog);
342  }
343  else
344  {
345 
346  }
347  }
348  // embedded postings
349  else
350  {
351  $html = array();
352 
353  include_once "Modules/Blog/classes/class.ilObjBlog.php";
354  $html[] = ilObjBlog::_lookupTitle($a_blog_id);
355 
356  include_once "Modules/Blog/classes/class.ilBlogPostingGUI.php";
357  foreach($a_posting_ids as $post)
358  {
359  $page = new ilBlogPostingGUI(0, null, $post);
360  if($this->getOutputMode() != "offline")
361  {
362  $page->setOutputMode(IL_PAGE_PREVIEW);
363  }
364  else
365  {
366  $page->setOutputMode("offline");
367  }
368  $html[] = $page->showPage();
369  }
370 
371  return implode("\n", $html);
372  }
373  }
374 
375  protected function renderBlogTeaser($a_user_id, $a_blog_id, array $a_posting_ids = null)
376  {
377  global $lng;
378 
379  $postings = "";
380  if($a_posting_ids)
381  {
382  $postings = array("<ul>");
383  include_once "Modules/Blog/classes/class.ilBlogPosting.php";
384  foreach($a_posting_ids as $post)
385  {
386  $post = new ilBlogPosting($post);
387  $postings[] = "<li>".$post->getTitle()." - ".
388  ilDatePresentation::formatDate($post->getCreated())."</li>";
389  }
390  $postings[] = "</ul>";
391  $postings = implode("\n", $postings);
392  }
393 
394  return "<div style=\"margin:5px\">".$lng->txt("obj_blog").": \"".
395  ilObject::_lookupTitle($a_blog_id)."\"".$postings."</div>";
396  }
397 
398  protected function renderSkills($a_user_id, $a_skills_id)
399  {
400  include_once "Services/Skill/classes/class.ilPersonalSkillsGUI.php";
401  $gui = new ilPersonalSkillsGUI();
402  if($this->getOutputMode() == "offline")
403  {
404  $gui->setOfflineMode("./files/");
405  }
406  $html = $gui->getSkillHTML($a_skills_id, $a_user_id);
407 
408  if($this->getOutputMode() == "offline")
409  {
410  $js = $gui->getTooltipsJs();
411  if(sizeof($js))
412  {
413  $this->js_onload_code = array_merge($this->js_onload_code, $js);
414  }
415  }
416 
417  return $html;
418  }
419 
420  protected function renderSkillsTeaser($a_user_id, $a_skills_id)
421  {
422  global $lng;
423 
424  include_once "Services/Skill/classes/class.ilSkillTreeNode.php";
425 
426  return "<div style=\"margin:5px\">".$lng->txt("skills").": \"".
427  ilSkillTreeNode::_lookupTitle($a_skills_id)."\"</div>";
428  }
429 
430  function getJsOnloadCode()
431  {
432  return $this->js_onload_code;
433  }
434 }
435 ?>