ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilPDSelectedItemsBlockGUI.php
Go to the documentation of this file.
1 <?php
2 
3 /* Copyright (c) 1998-2011 ILIAS open source, Extended GPL, see docs/LICENSE */
4 
5 include_once("Services/Block/classes/class.ilBlockGUI.php");
6 include_once './Services/PersonalDesktop/interfaces/interface.ilDesktopItemHandling.php';
7 
18 {
19  const VIEW_MY_OFFERS = 0;
21 
22  static $block_type = "pditems";
23 
25  private $allowed_views = array();
26 
31  {
32  global $ilCtrl, $lng, $ilUser;
33 
35 
36  $lng->loadLanguageModule('pd');
37 
38  //$this->setImage(ilUtil::getImagePath("icon_bm_s.png"));
39  $this->setEnableNumInfo(false);
40  $this->setLimit(99999);
41 // $this->setColSpan(2);
42  $this->setAvailableDetailLevels(3, 1);
43  $this->setBigMode(true);
44  $this->lng = $lng;
45  $this->allow_moving = false;
46 
47  $this->determineViewSettings();
48  }
49 
53  public function addToDeskObject()
54  {
55  global $ilCtrl;
56 
57  include_once './Services/PersonalDesktop/classes/class.ilDesktopItemGUI.php';
59  $ilCtrl->redirectByClass('ilpersonaldesktopgui', 'show');
60  }
61 
65  public function removeFromDeskObject()
66  {
67  global $ilCtrl;
68 
69  include_once './Services/PersonalDesktop/classes/class.ilDesktopItemGUI.php';
71  $ilCtrl->redirectByClass('ilpersonaldesktopgui', 'show');
72  }
73 
74 
80  public function changeView()
81  {
82  global $ilUser, $ilCtrl;
83 
84  if(in_array((int)$_GET['view'], $this->allowed_views))
85  {
86  $ilUser->writePref('pd_view', (int)$_GET['view']);
87  }
88  else
89  {
90  @reset($this->allowed_views);
91  $view = (int)@current($this->allowed_views);
92  $ilUser->writePref('pd_view', $view);
93  }
94 
95  $ilCtrl->redirectByClass('ilpersonaldesktopgui', 'show');
96  }
97 
103  protected function determineViewSettings()
104  {
105  global $ilSetting, $ilUser;
106 
107  $this->allowed_views = array();
108 
109  // determine view
110  if($ilSetting->get('disable_my_offers') == 1 &&
111  $ilSetting->get('disable_my_memberships') == 1)
112  {
113  // if both views are disabled set default view (should not occur but we should prevent it)
114  $ilSetting->set('personal_items_default_view', self::VIEW_MY_OFFERS);
115  $this->allowed_views[] = self::VIEW_MY_OFFERS;
116  }
117  // both views are enabled, get default view
118  else if($ilSetting->get('disable_my_offers') == 0 &&
119  $ilSetting->get('disable_my_memberships') == 0)
120  {
121  $this->allowed_views[] = self::VIEW_MY_OFFERS;
122  $this->allowed_views[] = self::VIEW_MY_MEMBERSHIPS;
123  }
124  else if($ilSetting->get('disable_my_offers') == 0 &&
125  $ilSetting->get('disable_my_memberships') == 1)
126  {
127  $this->allowed_views[] = self::VIEW_MY_OFFERS;
128  }
129  else
130  {
131  $this->allowed_views[] = self::VIEW_MY_MEMBERSHIPS;
132  }
133 
134  $this->view = $ilUser->getPref('pd_view');
135  if($this->view === false || !in_array((int)$this->view, $this->allowed_views))
136  {
137  $ilUser->writePref('pd_view', (int)$ilSetting->get('personal_items_default_view'));
138  $this->view = (int)$ilSetting->get('personal_items_default_view');
139  }
140  }
141 
147  static function getBlockType()
148  {
149  return self::$block_type;
150  }
151 
157  static function isRepositoryObject()
158  {
159  return false;
160  }
161 
162 
163  function getHTML()
164  {
165  global $ilCtrl, $ilSetting, $tpl, $lng, $ilHelp;
166 
167  // both views are activated (show buttons)
168  if($ilSetting->get('disable_my_offers') == 0 &&
169  $ilSetting->get('disable_my_memberships') == 0)
170  {
171 /* $ilCtrl->setParameter($this, 'block_type', $this->getBlockType());
172  $ilCtrl->setParameter($this, 'view', self::VIEW_MY_OFFERS);
173  $this->addHeaderLink($ilCtrl->getLinkTarget($this, 'changeView'), $this->lng->txt('pd_my_offers'),
174  ($this->view == self::VIEW_MY_OFFERS ? false : true)
175  );
176  $ilCtrl->setParameter($this, 'view', self::VIEW_MY_MEMBERSHIPS);
177  $this->addHeaderLink($ilCtrl->getLinkTarget($this, 'changeView'), $this->lng->txt('pd_my_memberships'),
178  ($this->view == self::VIEW_MY_MEMBERSHIPS ? false : true)
179  );
180  $ilCtrl->clearParameters($this);*/
181  }
182 
183  // workaround to show details row
184  $this->setData(array("dummy"));
185 
186  include_once "Services/Object/classes/class.ilObjectListGUI.php";
187  ilObjectListGUI::prepareJSLinks("",
188  $ilCtrl->getLinkTargetByClass(array("ilcommonactiondispatchergui", "ilnotegui"), "", "", true, false),
189  $ilCtrl->getLinkTargetByClass(array("ilcommonactiondispatchergui", "iltagginggui"), "", "", true, false));
190 
191  switch((int)$this->view)
192  {
193  case self::VIEW_MY_MEMBERSHIPS:
194  $ilHelp->setDefaultScreenId(ilHelpGUI::ID_PART_SCREEN, "crs_grp");
195  if ($ilSetting->get('disable_my_offers') == 0)
196  {
197  $tpl->setTitle($lng->txt("my_courses_groups"));
198  }
199  $this->setTitle($this->lng->txt('pd_my_memberships'));
200  $this->setContent($this->getMembershipItemsBlockHTML());
201  break;
202 
203  case self::VIEW_MY_OFFERS:
204  default:
205  $ilHelp->setDefaultScreenId(ilHelpGUI::ID_PART_SCREEN, "sel_items");
206  if(!in_array(self::VIEW_MY_MEMBERSHIPS, $this->allowed_views))
207  {
208  $this->setTitle($this->lng->txt('selected_items'));
209  }
210  else
211  {
212  $this->setTitle($this->lng->txt('pd_my_offers'));
213  }
214 
215  $this->setContent($this->getSelectedItemsBlockHTML());
216  break;
217  }
218 
219  if ($this->getContent() == "")
220  {
221  $this->setEnableDetailRow(false);
222  }
223  $ilCtrl->clearParametersByClass("ilpersonaldesktopgui");
224  $ilCtrl->clearParameters($this);
225  return parent::getHTML();
226  }
227 
231  function &executeCommand()
232  {
233  global $ilCtrl;
234 
235  $next_class = $ilCtrl->getNextClass();
236  $cmd = $ilCtrl->getCmd("getHTML");
237 
238  switch($next_class)
239  {
240  case "ilcommonactiondispatchergui":
241  include_once("Services/Object/classes/class.ilCommonActionDispatcherGUI.php");
243  $ilCtrl->forwardCommand($gui);
244  break;
245 
246  default:
247  if(method_exists($this, $cmd))
248  {
249  return $this->$cmd();
250  }
251  else
252  {
253  $cmd .= 'Object';
254  return $this->$cmd();
255  }
256  }
257  }
258 
259  function getContent()
260  {
261  return $this->content;
262  }
263 
264  function setContent($a_content)
265  {
266  $this->content = $a_content;
267  }
268 
272  function fillDataSection()
273  {
274  global $ilUser;
275 
276  if ($this->getContent() != "")
277  {
278  $this->tpl->setVariable("BLOCK_ROW", $this->getContent());
279  }
280  else
281  {
282  $this->setDataSection($this->getIntroduction());
283  }
284  }
285 
286 
290  function fillFooter()
291  {
292  global $ilCtrl, $lng, $ilUser;
293 
294  $this->setFooterLinks();
295  $this->fillFooterLinks();
296  $this->tpl->setVariable("FCOLSPAN", $this->getColSpan());
297  if ($this->tpl->blockExists("block_footer"))
298  {
299  $this->tpl->setCurrentBlock("block_footer");
300  $this->tpl->parseCurrentBlock();
301  }
302  }
303 
307  function setFooterLinks()
308  {
309  global $ilUser, $ilCtrl, $lng;
310 
311  if ($this->getContent() == "")
312  {
313  $this->setEnableNumInfo(false);
314  return "";
315  }
316 
317  // by type
318 // if ($ilUser->getPref("pd_order_items") == 'location')
319 // {
320  $this->addFooterLink( $lng->txt("by_type"),
321  $ilCtrl->getLinkTarget($this,
322  "orderPDItemsByType"),
323  $ilCtrl->getLinkTarget($this,
324  "orderPDItemsByType", "", true),
325  "block_".$this->getBlockType()."_".$this->block_id,
326  false, false, ($ilUser->getPref("pd_order_items") != 'location')
327  );
328 // }
329 // else
330 // {
331 // $this->addFooterLink($lng->txt("by_type"));
332 // }
333 
334 // // by location
335 // if ($ilUser->getPref("pd_order_items") == 'location')
336 // {
337 // $this->addFooterLink($lng->txt("by_location"));
338 // }
339 // else
340 // {
341  $this->addFooterLink( $lng->txt("by_location"),
342  $ilCtrl->getLinkTarget($this,
343  "orderPDItemsByLocation"),
344  $ilCtrl->getLinkTarget($this,
345  "orderPDItemsByLocation", "", true),
346  "block_".$this->getBlockType()."_".$this->block_id,
347  false, false, ($ilUser->getPref("pd_order_items") == 'location')
348  );
349 // }
350  }
351 
358  protected function getObjectsByMembership($types = array())
359  {
360  global $tree, $ilUser, $ilObjDataCache;
361 
362  include_once 'Services/Membership/classes/class.ilParticipants.php';
363  $items = array();
364 
365  if(is_array($types) && count($types))
366  {
367  foreach($types as $type)
368  {
369  switch($type)
370  {
371  case 'grp':
372  $items = array_merge(ilParticipants::_getMembershipByType($ilUser->getId(), 'grp'), $items);
373  break;
374  case 'crs':
375  $items = array_merge(ilParticipants::_getMembershipByType($ilUser->getId(), 'crs'), $items);
376  break;
377  default:
378  break;
379  }
380  }
381  }
382  else
383  {
384  $crs_mbs = ilParticipants::_getMembershipByType($ilUser->getId(), 'crs');
385  $grp_mbs = ilParticipants::_getMembershipByType($ilUser->getId(), 'grp');
386  $items = array_merge($crs_mbs, $grp_mbs);
387  }
388 
389  $references = array();
390  foreach($items as $key => $obj_id)
391  {
392  $item_references = ilObject::_getAllReferences($obj_id);
393  foreach($item_references as $ref_id)
394  {
395  if($tree->isInTree($ref_id))
396  {
397  $title = $ilObjDataCache->lookupTitle($obj_id);
398  $type = $ilObjDataCache->lookupType($obj_id);
399 
400  $parent_ref_id = $tree->getParentId($ref_id);
401  $par_left = $tree->getLeftValue($parent_ref_id);
402  $par_left = sprintf("%010d", $par_left);
403 
404  $references[$par_left . $title . $ref_id] = array(
405  'ref_id' => $ref_id,
406  'obj_id' => $obj_id,
407  'type' => $type,
408  'title' => $title,
409  'description' => $ilObjDataCache->lookupDescription($obj_id),
410  'parent_ref' => $parent_ref_id
411  );
412  }
413  }
414  }
415  ksort($references);
416  return is_array($references) ? $references : array();
417  }
418 
426  {
427  global $ilUser, $rbacsystem, $objDefinition, $ilBench, $ilSetting, $ilObjDataCache, $rbacreview;
428 
429  $output = false;
430  $items = $this->getObjectsByMembership();
431  $item_html = array();
432  if(count($items) > 0)
433  {
434  // preload object data cache
435  $ref_ids = array();
436  foreach($items as $item)
437  {
438  $ref_ids[] = $item['ref_id'];
439  }
440  reset($items);
441  $ilObjDataCache->preloadReferenceCache($ref_ids);
442 
443  include_once "Services/Object/classes/class.ilObjectActivation.php";
445 
446  foreach($items as $item)
447  {
448  //echo "1";
449  // get list gui class for each object type
450  if ($cur_obj_type != $item["type"])
451  {
452  $item_list_gui =& $this->getItemListGUI($item["type"]);
453  if(!$item_list_gui)
454  {
455  continue;
456  }
457 
458  ilObjectActivation::addListGUIActivationProperty($item_list_gui, $item);
459 
460  // notes, comment currently do not work properly on desktop
461  $item_list_gui->enableNotes(false);
462  $item_list_gui->enableComments(false);
463  $item_list_gui->enableTags(false);
464 
465  $item_list_gui->enableIcon(true);
466  $item_list_gui->enableDelete(false);
467  $item_list_gui->enableCut(false);
468  $item_list_gui->enableCopy(false);
469  $item_list_gui->enablePayment(false);
470  $item_list_gui->enableLink(false);
471  $item_list_gui->enableInfoScreen(true);
472  $item_list_gui->enableSubscribe(false);
473  if ($this->getCurrentDetailLevel() < 3)
474  {
475  //echo "3";
476  $item_list_gui->enableDescription(false);
477  $item_list_gui->enableProperties(false);
478  $item_list_gui->enablePreconditions(false);
479  }
480  if ($this->getCurrentDetailLevel() < 2)
481  {
482  $item_list_gui->enableCommands(true, true);
483  }
484  }
485  // render item row
486  $ilBench->start("ilPersonalDesktopGUI", "getListHTML");
487 
488  if (is_object($item_list_gui))
489  {
490  $html = $item_list_gui->getListItemHTML($item["ref_id"],
491  $item["obj_id"], $item["title"], $item["description"]);
492  $ilBench->stop("ilPersonalDesktopGUI", "getListHTML");
493  if ($html != "")
494  {
495  // BEGIN WebDAV: Use $item_list_gui to determine icon image type
496  $item_html[] = array(
497  "html" => $html,
498  "item_ref_id" => $item["ref_id"],
499  "item_obj_id" => $item["obj_id"],
500  "parent_ref" => $item["parent_ref"],
501  "type" => $item["type"],
502  'item_icon_image_type' => $item_list_gui->getIconImageType()
503  );
504  // END WebDAV: Use $item_list_gui to determine icon image type
505  }
506  }
507  }
508 
509  // output block for resource type
510  if (count($item_html) > 0)
511  {
512  $cur_parent_ref = 0;
513 
514  // content row
515  foreach($item_html as $item)
516  {
517  // add a parent header row for each new parent
518  if ($cur_parent_ref != $item["parent_ref"])
519  {
520  if ($ilSetting->get("icon_position_in_lists") == "item_rows")
521  {
522  $this->addParentRow($tpl, $item["parent_ref"], false);
523  }
524  else
525  {
526  $this->addParentRow($tpl, $item["parent_ref"]);
527  }
528  $this->resetRowType();
529  $cur_parent_ref = $item["parent_ref"];
530  }
531 
532  // BEGIN WebDAV: Use $item_list_gui to determine icon image type.
533  $this->addStandardRow($tpl, $item["html"], $item["item_ref_id"], $item["item_obj_id"],
534  $item['item_icon_image_type'],
535  "th_".$cur_parent_ref);
536  // END WebDAV: Use $item_list_gui to determine icon image type.
537  $output = true;
538  }
539  }
540  }
541 
542  return $output;
543  }
544 
552  {
553  global $ilUser, $rbacsystem, $objDefinition, $ilBench, $ilSetting, $ilObjDataCache;
554 
555  $output = false;
556 
557  $objtype_groups = $objDefinition->getGroupedRepositoryObjectTypes(
558  array("cat", "crs", "grp", "fold"));
559 
560  $types = array();
561  foreach($objtype_groups as $grp => $grpdata)
562  {
563  $types[] = array(
564  "grp" => $grp,
565  "title" => $this->lng->txt("objs_".$grp),
566  "types" => $grpdata["objs"]);
567  }
568 
569  foreach ($types as $t)
570  {
571  $type = $t["types"];
572  $title = $t["title"];
573  $grp = $t["grp"];
574 
575  $items = $this->getObjectsByMembership($type);
576 //var_dump($items);
577  // preload object data cache
578  $ref_ids = array();
579  foreach($items as $item)
580  {
581  $ref_ids[] = $item['ref_id'];
582  }
583  reset($items);
584  $ilObjDataCache->preloadReferenceCache($ref_ids);
585 
586  include_once "Services/Object/classes/class.ilObjectActivation.php";
588 
589  $item_html = array();
590 
591  if ($this->getCurrentDetailLevel() == 3)
592  {
593  $rel_header = "th_".$grp;
594  }
595 
596  if (count($items) > 0)
597  {
598  $tstCount = 0;
599  $unsetCount = 0;
600  $progressCount = 0;
601  $unsetFlag = 0;
602  $progressFlag = 0;
603  $completedFlag = 0;
604  if (strcmp($a_type, "tst") == 0) {
605  $items = $this->multiarray_sort($items, "used_tries; title");
606  foreach ($items as $tst_item) {
607  if (!isset($tst_item["used_tries"])) {
608  $unsetCount++;
609  }
610  elseif ($tst_item["used_tries"] == 0) {
611  $progressCount++;
612  }
613  }
614  }
615 
616  foreach($items as $item)
617  {
618  // get list gui class for each object type
619  if ($cur_obj_type != $item["type"])
620  {
621  $class = $objDefinition->getClassName($item["type"]);
622  $location = $objDefinition->getLocation($item["type"]);
623  $full_class = "ilObj".$class."ListGUI";
624  include_once($location."/class.".$full_class.".php");
625  $item_list_gui = new $full_class();
626 
627  ilObjectActivation::addListGUIActivationProperty($item_list_gui, $item);
628 
629  // notes, comment currently do not work properly on desktop
630  $item_list_gui->enableNotes(false);
631  $item_list_gui->enableComments(false);
632  $item_list_gui->enableTags(false);
633 
634  $item_list_gui->enableIcon(true);
635  $item_list_gui->enableDelete(false);
636  $item_list_gui->enableCut(false);
637  $item_list_gui->enableCopy(false);
638  $item_list_gui->enablePayment(false);
639  $item_list_gui->enableLink(false);
640  $item_list_gui->enableInfoScreen(true);
641  $item_list_gui->enableSubscribe(false);
642  if ($this->getCurrentDetailLevel() < 3)
643  {
644  $item_list_gui->enableDescription(false);
645  $item_list_gui->enableProperties(false);
646  $item_list_gui->enablePreconditions(false);
647  $item_list_gui->enableNoticeProperties(false);
648  }
649  if ($this->getCurrentDetailLevel() < 2)
650  {
651  $item_list_gui->enableCommands(true, true);
652  }
653  }
654  // render item row
655  $ilBench->start("ilPersonalDesktopGUI", "getListHTML");
656 
657  $html = $item_list_gui->getListItemHTML($item["ref_id"],
658  $item["obj_id"], $item["title"], $item["description"]);
659  $ilBench->stop("ilPersonalDesktopGUI", "getListHTML");
660  if ($html != "")
661  {
662  // BEGIN WebDAV: Use $item_list_gui to determine icon image type
663  $item_html[] = array(
664  "html" => $html,
665  "item_ref_id" => $item["ref_id"],
666  "item_obj_id" => $item["obj_id"],
667  'item_icon_image_type' => (method_exists($item_list_gui, 'getIconImageType')) ?
668  $item_list_gui->getIconImageType() :
669  $item['type']
670  );
671  // END WebDAV: Use $item_list_gui to determine icon image type
672  }
673  }
674 
675  // output block for resource type
676  if (count($item_html) > 0)
677  {
678  // add a header for each resource type
679  if ($this->getCurrentDetailLevel() == 3)
680  {
681  if ($ilSetting->get("icon_position_in_lists") == "item_rows")
682  {
683  $this->addHeaderRow($tpl, $grp, false);
684  }
685  else
686  {
687  $this->addHeaderRow($tpl, $grp);
688  }
689  $this->resetRowType();
690  }
691 
692  // content row
693  foreach($item_html as $item)
694  {
695  if ($this->getCurrentDetailLevel() < 3 ||
696  $ilSetting->get("icon_position_in_lists") == "item_rows")
697  {
698  // BEGIN WebDAV: Use $item_list_gui to determine icon image type
699  $this->addStandardRow($tpl, $item["html"], $item["item_ref_id"], $item["item_obj_id"],
700  $item['item_icon_image_type'],
701  $rel_header);
702  // END WebDAV: Use $item_list_gui to determine icon image type
703  }
704  else
705  {
706  $this->addStandardRow($tpl, $item["html"], $item["item_ref_id"], $item["item_obj_id"], "", $rel_header);
707  }
708  $output = true;
709  }
710  }
711  }
712  }
713 
714  return $output;
715  }
716 
723  public function getMembershipItemsBlockHTML()
724  {
725  global $ilUser;
726 
727  $tpl = $this->newBlockTemplate();
728 
729  switch($ilUser->getPref('pd_order_items'))
730  {
731  case 'location':
733  break;
734 
735  default:
737  break;
738  }
739 
740  return $tpl->get();
741  }
742 
747  {
748  global $ilUser, $rbacsystem, $objDefinition, $ilBench;
749 
750  $tpl =& $this->newBlockTemplate();
751 
752  switch ($ilUser->getPref("pd_order_items"))
753  {
754  case "location":
756  break;
757 
758  default:
759  $ok = $this->getSelectedItemsPerType($tpl);
760  break;
761  }
762 
763  return $tpl->get();
764  }
765 
770  {
771  global $ilUser, $rbacsystem, $objDefinition, $ilBench, $ilSetting, $ilObjDataCache, $tree;
772 
773  $items = $ilUser->getDesktopItems();
774  if (count($items) > 0)
775  {
776  // preload object data cache
777  $ref_ids = array();
778  foreach($items as $item)
779  {
780  $ref_ids[] = $item["ref_id"];
781  }
782  $tree->preloadDeleted($ref_ids);
783  $tree->preloadDepthParent($ref_ids);
784  $ilObjDataCache->preloadReferenceCache($ref_ids, true);
785 
786  include_once "Services/Object/classes/class.ilObjectActivation.php";
788  }
789 
790  $output = false;
791 
792  $objtype_groups = $objDefinition->getGroupedRepositoryObjectTypes(
793  array("cat", "crs", "grp", "fold"));
794 
795  $types = array();
796  foreach($objtype_groups as $grp => $grpdata)
797  {
798  $types[] = array(
799  "grp" => $grp,
800  "title" => $this->lng->txt("objs_".$grp),
801  "types" => $grpdata["objs"]);
802  }
803 
804  foreach ($types as $t)
805  {
806 
807  $type = $t["types"];
808  $title = $t["title"];
809  $grp = $t["grp"];
810 
811  $items = $ilUser->getDesktopItems($type);
812  $item_html = array();
813 
814  if ($this->getCurrentDetailLevel() == 3)
815  {
816  $rel_header = "th_".$grp;
817  }
818 
819  if (count($items) > 0)
820  {
821  $tstCount = 0;
822  $unsetCount = 0;
823  $progressCount = 0;
824  $unsetFlag = 0;
825  $progressFlag = 0;
826  $completedFlag = 0;
827  if (strcmp($a_type, "tst") == 0) {
828  $items = $this->multiarray_sort($items, "used_tries; title");
829  foreach ($items as $tst_item) {
830  if (!isset($tst_item["used_tries"])) {
831  $unsetCount++;
832  }
833  elseif ($tst_item["used_tries"] == 0) {
834  $progressCount++;
835  }
836  }
837  }
838 
839  foreach($items as $item)
840  {
841  // get list gui class for each object type
842  if ($cur_obj_type != $item["type"])
843  {
844  $class = $objDefinition->getClassName($item["type"]);
845  $location = $objDefinition->getLocation($item["type"]);
846  $full_class = "ilObj".$class."ListGUI";
847  include_once($location."/class.".$full_class.".php");
848  $item_list_gui = new $full_class();
849 
850  ilObjectActivation::addListGUIActivationProperty($item_list_gui, $item);
851 
852  // notes, comment currently do not work properly on desktop
853  $item_list_gui->enableNotes(false);
854  $item_list_gui->enableComments(false);
855  $item_list_gui->enableTags(false);
856 
857  $item_list_gui->enableIcon(true);
858  $item_list_gui->enableDelete(false);
859  $item_list_gui->enableCut(false);
860  $item_list_gui->enableCopy(false);
861  $item_list_gui->enablePayment(false);
862  $item_list_gui->enableLink(false);
863  $item_list_gui->enableInfoScreen(true);
864  $item_list_gui->setContainerObject($this);
865  if ($this->getCurrentDetailLevel() < 3)
866  {
867  $item_list_gui->enableDescription(false);
868  $item_list_gui->enableProperties(false);
869  $item_list_gui->enablePreconditions(false);
870  $item_list_gui->enableNoticeProperties(false);
871  }
872  if ($this->getCurrentDetailLevel() < 2)
873  {
874  $item_list_gui->enableCommands(true, true);
875  }
876  }
877  // render item row
878  $ilBench->start("ilPersonalDesktopGUI", "getListHTML");
879 
880  $html = $item_list_gui->getListItemHTML($item["ref_id"],
881  $item["obj_id"], $item["title"], $item["description"]);
882  $ilBench->stop("ilPersonalDesktopGUI", "getListHTML");
883  if ($html != "")
884  {
885  // BEGIN WebDAV: Use $item_list_gui to determine icon image type
886  $item_html[] = array(
887  "html" => $html,
888  "item_ref_id" => $item["ref_id"],
889  "item_obj_id" => $item["obj_id"],
890  'item_icon_image_type' => (method_exists($item_list_gui, 'getIconImageType')) ?
891  $item_list_gui->getIconImageType() :
892  $item['type']
893  );
894  // END WebDAV: Use $item_list_gui to determine icon image type
895  }
896  }
897 
898  // output block for resource type
899  if (count($item_html) > 0)
900  {
901  // add a header for each resource type
902  if ($this->getCurrentDetailLevel() == 3)
903  {
904  if ($ilSetting->get("icon_position_in_lists") == "item_rows")
905  {
906  $this->addHeaderRow($tpl, $grp, false);
907  }
908  else
909  {
910  $this->addHeaderRow($tpl, $grp);
911  }
912  $this->resetRowType();
913  }
914 
915  // content row
916  foreach($item_html as $item)
917  {
918  if ($this->getCurrentDetailLevel() < 3 ||
919  $ilSetting->get("icon_position_in_lists") == "item_rows")
920  {
921  // BEGIN WebDAV: Use $item_list_gui to determine icon image type
922  $this->addStandardRow($tpl, $item["html"], $item["item_ref_id"], $item["item_obj_id"],
923  $item['item_icon_image_type'],
924  $rel_header);
925  // END WebDAV: Use $item_list_gui to determine icon image type
926  }
927  else
928  {
929  $this->addStandardRow($tpl, $item["html"], $item["item_ref_id"], $item["item_obj_id"], "", $rel_header);
930  }
931  $output = true;
932  }
933  }
934  }
935  }
936 
937  return $output;
938  }
939 
944  {
945  global $ilUser, $rbacsystem, $objDefinition, $ilBench, $ilSetting, $ilObjDataCache, $tree;
946 
947  $output = false;
948 
949  $items = $ilUser->getDesktopItems();
950  $item_html = array();
951  $cur_obj_type = "";
952 
953  if (count($items) > 0)
954  {
955  // preload object data cache
956  $ref_ids = array();
957  foreach($items as $item)
958  {
959  $ref_ids[] = $item["ref_id"];
960  }
961  reset($items);
962  $tree->preloadDeleted($ref_ids);
963  $tree->preloadDepthParent($ref_ids);
964  $ilObjDataCache->preloadReferenceCache($ref_ids);
965 
966  include_once "Services/Object/classes/class.ilObjectActivation.php";
968 
969  foreach($items as $item)
970  {
971  //echo "1";
972  // get list gui class for each object type
973  if ($cur_obj_type != $item["type"])
974  {
975  $item_list_gui =& $this->getItemListGUI($item["type"]);
976  if(!$item_list_gui)
977  {
978  continue;
979  }
980 
981  ilObjectActivation::addListGUIActivationProperty($item_list_gui, $item);
982 
983  // notes, comment currently do not work properly on desktop
984  $item_list_gui->enableNotes(false);
985  $item_list_gui->enableComments(false);
986  $item_list_gui->enableTags(false);
987 
988  $item_list_gui->enableIcon(true);
989  $item_list_gui->enableDelete(false);
990  $item_list_gui->enableCut(false);
991  $item_list_gui->enableCopy(false);
992  $item_list_gui->enablePayment(false);
993  $item_list_gui->enableLink(false);
994  $item_list_gui->enableInfoScreen(true);
995  if ($this->getCurrentDetailLevel() < 3)
996  {
997  //echo "3";
998  $item_list_gui->enableDescription(false);
999  $item_list_gui->enableProperties(false);
1000  $item_list_gui->enablePreconditions(false);
1001  }
1002  if ($this->getCurrentDetailLevel() < 2)
1003  {
1004  $item_list_gui->enableCommands(true, true);
1005  }
1006  }
1007  // render item row
1008  $ilBench->start("ilPersonalDesktopGUI", "getListHTML");
1009  $item_list_gui->setContainerObject($this);
1010  $html = $item_list_gui->getListItemHTML($item["ref_id"],
1011  $item["obj_id"], $item["title"], $item["description"]);
1012  $ilBench->stop("ilPersonalDesktopGUI", "getListHTML");
1013  if ($html != "")
1014  {
1015  // BEGIN WebDAV: Use $item_list_gui to determine icon image type
1016  $item_html[] = array(
1017  "html" => $html,
1018  "item_ref_id" => $item["ref_id"],
1019  "item_obj_id" => $item["obj_id"],
1020  "parent_ref" => $item["parent_ref"],
1021  "type" => $item["type"],
1022  'item_icon_image_type' => $item_list_gui->getIconImageType()
1023  );
1024  // END WebDAV: Use $item_list_gui to determine icon image type
1025  }
1026  }
1027 
1028  // output block for resource type
1029  if (count($item_html) > 0)
1030  {
1031  $cur_parent_ref = 0;
1032 
1033  // content row
1034  foreach($item_html as $item)
1035  {
1036  // add a parent header row for each new parent
1037  if ($cur_parent_ref != $item["parent_ref"])
1038  {
1039  if ($ilSetting->get("icon_position_in_lists") == "item_rows")
1040  {
1041  $this->addParentRow($tpl, $item["parent_ref"], false);
1042  }
1043  else
1044  {
1045  $this->addParentRow($tpl, $item["parent_ref"]);
1046  }
1047  $this->resetRowType();
1048  $cur_parent_ref = $item["parent_ref"];
1049  }
1050 
1051  // BEGIN WebDAV: Use $item_list_gui to determine icon image type.
1052  $this->addStandardRow($tpl, $item["html"], $item["item_ref_id"], $item["item_obj_id"],
1053  $item['item_icon_image_type'],
1054  "th_".$cur_parent_ref);
1055  // END WebDAV: Use $item_list_gui to determine icon image type.
1056  $output = true;
1057  }
1058  }
1059  }
1060 
1061  return $output;
1062  }
1063 
1064  function resetRowType()
1065  {
1066  $this->cur_row_type = "";
1067  }
1068 
1075  function &newBlockTemplate()
1076  {
1077  $tpl = new ilTemplate("tpl.pd_list_block.html", true, true, "Services/PersonalDesktop");
1078  $this->cur_row_type = "";
1079  return $tpl;
1080  }
1081 
1085  function &getItemListGUI($a_type)
1086  {
1087  global $objDefinition;
1088  //echo "<br>+$a_type+";
1089  if (!isset($this->item_list_guis[$a_type]))
1090  {
1091  $class = $objDefinition->getClassName($a_type);
1092  // Fixed problem with deactivated plugins and existing repo. object plugin objects on the user's desktop
1093  if(!$class)
1094  {
1095  return NULL;
1096  }
1097  // Fixed problem with deactivated plugins and existing repo. object plugin objects on the user's desktop
1098  $location = $objDefinition->getLocation($a_type);
1099  if(!$location)
1100  {
1101  return NULL;
1102  }
1103 
1104  $full_class = "ilObj".$class."ListGUI";
1105  //echo "<br>-".$location."/class.".$full_class.".php"."-";
1106  include_once($location."/class.".$full_class.".php");
1107  $item_list_gui = new $full_class();
1108  $this->item_list_guis[$a_type] =& $item_list_gui;
1109  }
1110  else
1111  {
1112  $item_list_gui =& $this->item_list_guis[$a_type];
1113  }
1114  return $item_list_gui;
1115  }
1116 
1124  function addHeaderRow(&$a_tpl, $a_type, $a_show_image = true)
1125  {
1126  global $objDefinition;
1127 
1128  $icon = ilUtil::getImagePath("icon_".$a_type.".png");
1129  if (!$objDefinition->isPlugin($a_type))
1130  {
1131  $title = $this->lng->txt("objs_".$a_type);
1132  }
1133  else
1134  {
1135  include_once("./Services/Component/classes/class.ilPlugin.php");
1136  $title =
1137  ilPlugin::lookupTxt("rep_robj", $a_type, "objs_".$a_type);
1138 
1139  }
1140  $header_id = "th_".$a_type;
1141 
1142  if ($a_show_image)
1143  {
1144  $a_tpl->setCurrentBlock("container_header_row_image");
1145  $a_tpl->setVariable("HEADER_IMG", $icon);
1146  $a_tpl->setVariable("HEADER_ALT", $title);
1147  }
1148  else
1149  {
1150  $a_tpl->setCurrentBlock("container_header_row");
1151  }
1152 
1153  $a_tpl->setVariable("BLOCK_HEADER_CONTENT", $title);
1154  $a_tpl->setVariable("BLOCK_HEADER_ID", $header_id);
1155  $a_tpl->parseCurrentBlock();
1156  $a_tpl->touchBlock("container_row");
1157  }
1158 
1166  function addParentRow(&$a_tpl, $a_ref_id, $a_show_image = true)
1167  {
1168  global $tree, $ilSetting;
1169 
1170  $par_id = ilObject::_lookupObjId($a_ref_id);
1171  $type = ilObject::_lookupType($par_id);
1172  if (!in_array($type, array("lm", "dbk", "sahs", "htlm")))
1173  {
1174  $icon = ilUtil::getImagePath("icon_".$type.".png");
1175  }
1176  else
1177  {
1178  $icon = ilUtil::getImagePath("icon_lm.png");
1179  }
1180 
1181  // custom icon
1182  if ($ilSetting->get("custom_icons") &&
1183  in_array($type, array("cat","grp","crs", "root")))
1184  {
1185  require_once("./Services/Container/classes/class.ilContainer.php");
1186  if (($path = ilContainer::_lookupIconPath($par_id, "small")) != "")
1187  {
1188  $icon = $path;
1189  }
1190  }
1191 
1192  if ($tree->getRootId() != $par_id)
1193  {
1194  $title = ilObject::_lookupTitle($par_id);
1195  }
1196  else
1197  {
1198  $nd = $tree->getNodeData(ROOT_FOLDER_ID);
1199  $title = $nd["title"];
1200  if ($title == "ILIAS")
1201  {
1202  $title = $this->lng->txt("repository");
1203  }
1204  }
1205 
1206 /*
1207  $item_list_gui =& $this->getItemListGUI($type);
1208 
1209  $item_list_gui->enableIcon(false);
1210  $item_list_gui->enableDelete(false);
1211  $item_list_gui->enableCut(false);
1212  $item_list_gui->enablePayment(false);
1213  $item_list_gui->enableLink(false);
1214  $item_list_gui->enableDescription(false);
1215  $item_list_gui->enableProperties(false);
1216  $item_list_gui->enablePreconditions(false);
1217  $item_list_gui->enablePath(true);
1218  $item_list_gui->enableCommands(false);
1219  $html = $item_list_gui->getListItemHTML($a_ref_id,
1220  $par_id, $title, "");
1221 
1222  if ($a_show_image)
1223  {
1224  $a_tpl->setCurrentBlock("container_header_row_image");
1225  $a_tpl->setVariable("HEADER_IMG", $icon);
1226  $a_tpl->setVariable("HEADER_ALT", $title);
1227  }
1228 */
1229 // else
1230 // {
1231  $a_tpl->setCurrentBlock("container_header_row");
1232 // }
1233 
1234  $a_tpl->setVariable("BLOCK_HEADER_CONTENT", $title);
1235 /* $a_tpl->setVariable("BLOCK_HEADER_CONTENT", $html);
1236  $a_tpl->setVariable("BLOCK_HEADER_ID", "th_".$a_ref_id);*/
1237  $a_tpl->parseCurrentBlock();
1238  $a_tpl->touchBlock("container_row");
1239  }
1240 
1248  function addStandardRow(&$a_tpl, $a_html, $a_item_ref_id = "", $a_item_obj_id = "",
1249  $a_image_type = "", $a_related_header = "")
1250  {
1251  global $ilSetting;
1252 
1253  $this->cur_row_type = ($this->cur_row_type == "row_type_1")
1254  ? "row_type_2"
1255  : "row_type_1";
1256  $a_tpl->touchBlock($this->cur_row_type);
1257 
1258  if ($a_image_type != "")
1259  {
1260  if (!is_array($a_image_type) && !in_array($a_image_type, array("lm", "dbk", "htlm", "sahs")))
1261  {
1262  $icon = ilUtil::getImagePath("icon_".$a_image_type.".png");
1263  $title = $this->lng->txt("obj_".$a_image_type);
1264  }
1265  else
1266  {
1267  $icon = ilUtil::getImagePath("icon_lm.png");
1268  $title = $this->lng->txt("learning_resource");
1269  }
1270 
1271  // custom icon
1272  if ($ilSetting->get("custom_icons") &&
1273  in_array($a_image_type, array("cat","grp","crs")))
1274  {
1275  require_once("./Services/Container/classes/class.ilContainer.php");
1276  if (($path = ilContainer::_lookupIconPath($a_item_obj_id, "small")) != "")
1277  {
1278  $icon = $path;
1279  }
1280  }
1281 
1282  $a_tpl->setCurrentBlock("block_row_image");
1283  $a_tpl->setVariable("ROW_IMG", $icon);
1284  $a_tpl->setVariable("ROW_ALT", $title);
1285  $a_tpl->parseCurrentBlock();
1286  }
1287  else
1288  {
1289  $a_tpl->setVariable("ROW_NBSP", "&nbsp;");
1290  }
1291  $a_tpl->setCurrentBlock("container_standard_row");
1292  $a_tpl->setVariable("BLOCK_ROW_CONTENT", $a_html);
1293  $rel_headers = ($a_related_header != "")
1294  ? "th_selected_items ".$a_related_header
1295  : "th_selected_items";
1296  $a_tpl->setVariable("BLOCK_ROW_HEADERS", $rel_headers);
1297  $a_tpl->parseCurrentBlock();
1298  $a_tpl->touchBlock("container_row");
1299  }
1300 
1304  function getIntroduction()
1305  {
1306  global $ilUser, $lng, $ilCtrl, $tree;
1307 
1308  switch((int)$this->view)
1309  {
1310  case self::VIEW_MY_MEMBERSHIPS:
1311  $tpl = new ilTemplate('tpl.pd_my_memberships_intro.html', true, true, 'Services/PersonalDesktop');
1312  $tpl->setVariable('IMG_PD_LARGE', ilUtil::getImagePath('icon_pd_xxl.png'));
1313  $tpl->setVariable('TXT_WELCOME', $lng->txt('pd_my_memberships_intro'));
1314  $tpl->setVariable('TXT_INTRO_1', $lng->txt('pd_my_memberships_intro2'));
1315  break;
1316 
1317  case self::VIEW_MY_OFFERS:
1318  default:
1319  // get repository link
1320  $nd = $tree->getNodeData(ROOT_FOLDER_ID);
1321  $title = $nd["title"];
1322  if ($title == "ILIAS")
1323  {
1324  $title = $lng->txt("repository");
1325  }
1326 
1327  $tpl = new ilTemplate("tpl.pd_intro.html", true, true, "Services/PersonalDesktop");
1328  $tpl->setVariable("IMG_PD_LARGE", ilUtil::getImagePath("icon_pd_xxl.png"));
1329  $tpl->setVariable("TXT_WELCOME", $lng->txt("pdesk_intro"));
1330  $tpl->setVariable("TXT_INTRO_1", sprintf($lng->txt("pdesk_intro2"), $lng->txt("to_desktop")));
1331  include_once("./Services/Link/classes/class.ilLink.php");
1332  $tpl->setVariable("TXT_INTRO_2", sprintf($lng->txt("pdesk_intro3"),
1333  '<a href="'.ilLink::_getStaticLink(1,'root',true).'">'.$title.'</a>'));
1334  $tpl->setVariable("TXT_INTRO_3", $lng->txt("pdesk_intro4"));
1335  break;
1336  }
1337 
1338  return $tpl->get();
1339  }
1340 
1345  {
1346  global $ilUser, $ilCtrl;
1347 
1348  $ilUser->writePref("pd_order_items", "location");
1349 
1350  if ($ilCtrl->isAsynch())
1351  {
1352  echo $this->getHTML();
1353  exit;
1354  }
1355  else
1356  {
1357  $ilCtrl->redirectByClass("ilpersonaldesktopgui", "show");
1358  }
1359  }
1360 
1365  {
1366  global $ilUser, $ilCtrl;
1367 
1368  $ilUser->writePref("pd_order_items", "type");
1369 
1370  if ($ilCtrl->isAsynch())
1371  {
1372  echo $this->getHTML();
1373  exit;
1374  }
1375  else
1376  {
1377  $ilCtrl->redirectByClass("ilpersonaldesktopgui", "show");
1378  }
1379  }
1380 
1381 }
1382 
1383 ?>