ILIAS  eassessment Revision 61809
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilPDSelectedItemsBlockGUI.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2006 ILIAS open source, University of Cologne |
7  | |
8  | This program is free software; you can redistribute it and/or |
9  | modify it under the terms of the GNU General Public License |
10  | as published by the Free Software Foundation; either version 2 |
11  | of the License, or (at your option) any later version. |
12  | |
13  | This program is distributed in the hope that it will be useful, |
14  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16  | GNU General Public License for more details. |
17  | |
18  | You should have received a copy of the GNU General Public License |
19  | along with this program; if not, write to the Free Software |
20  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21  +-----------------------------------------------------------------------------+
22 */
23 
24 include_once("Services/Block/classes/class.ilBlockGUI.php");
25 include_once './Services/PersonalDesktop/interfaces/interface.ilDesktopItemHandling.php';
26 
36 {
37  const VIEW_MY_OFFERS = 0;
39 
40  static $block_type = "pditems";
41 
43  private $allowed_views = array();
44 
49  {
50  global $ilCtrl, $lng, $ilUser;
51 
53 
54  $lng->loadLanguageModule('pd');
55 
56  //$this->setImage(ilUtil::getImagePath("icon_bm_s.gif"));
57  $this->setEnableNumInfo(false);
58  $this->setLimit(99999);
59  $this->setColSpan(2);
60  $this->setAvailableDetailLevels(3, 1);
61  $this->setBigMode(true);
62  $this->lng = $lng;
63  $this->allow_moving = false;
64 
65  $this->determineViewSettings();
66  }
67 
71  public function addToDeskObject()
72  {
73  global $ilCtrl;
74 
75  include_once './Services/PersonalDesktop/classes/class.ilDesktopItemGUI.php';
77  $ilCtrl->redirectByClass('ilpersonaldesktopgui', 'show');
78  }
79 
83  public function removeFromDeskObject()
84  {
85  global $ilCtrl;
86 
87  include_once './Services/PersonalDesktop/classes/class.ilDesktopItemGUI.php';
89  $ilCtrl->redirectByClass('ilpersonaldesktopgui', 'show');
90  }
91 
92 
98  public function changeView()
99  {
100  global $ilUser, $ilCtrl;
101 
102  if(in_array((int)$_GET['view'], $this->allowed_views))
103  {
104  $ilUser->writePref('pd_view', (int)$_GET['view']);
105  }
106  else
107  {
108  @reset($this->allowed_views);
109  $view = (int)@current($this->allowed_views);
110  $ilUser->writePref('pd_view', $view);
111  }
112 
113  $ilCtrl->redirectByClass('ilpersonaldesktopgui', 'show');
114  }
115 
121  protected function determineViewSettings()
122  {
123  global $ilSetting, $ilUser;
124 
125  $this->allowed_views = array();
126 
127  // determine view
128  if($ilSetting->get('disable_my_offers') == 1 &&
129  $ilSetting->get('disable_my_memberships') == 1)
130  {
131  // if both views are disabled set default view (should not occur but we should prevent it)
132  $ilSetting->set('personal_items_default_view', self::VIEW_MY_OFFERS);
133  $this->allowed_views[] = self::VIEW_MY_OFFERS;
134  }
135  // both views are enabled, get default view
136  else if($ilSetting->get('disable_my_offers') == 0 &&
137  $ilSetting->get('disable_my_memberships') == 0)
138  {
139  $this->allowed_views[] = self::VIEW_MY_OFFERS;
140  $this->allowed_views[] = self::VIEW_MY_MEMBERSHIPS;
141  }
142  else if($ilSetting->get('disable_my_offers') == 0 &&
143  $ilSetting->get('disable_my_memberships') == 1)
144  {
145  $this->allowed_views[] = self::VIEW_MY_OFFERS;
146  }
147  else
148  {
149  $this->allowed_views[] = self::VIEW_MY_MEMBERSHIPS;
150  }
151 
152  $this->view = $ilUser->getPref('pd_view');
153  if($this->view === false || !in_array((int)$this->view, $this->allowed_views))
154  {
155  $ilUser->writePref('pd_view', (int)$ilSetting->get('personal_items_default_view'));
156  $this->view = (int)$ilSetting->get('personal_items_default_view');
157  }
158  }
159 
165  static function getBlockType()
166  {
167  return self::$block_type;
168  }
169 
175  static function isRepositoryObject()
176  {
177  return false;
178  }
179 
180 
181  function getHTML()
182  {
183  global $ilCtrl, $ilSetting;
184 
185  // both views are activated (show buttons)
186  if($ilSetting->get('disable_my_offers') == 0 &&
187  $ilSetting->get('disable_my_memberships') == 0)
188  {
189  $ilCtrl->setParameter($this, 'block_type', $this->getBlockType());
190  $ilCtrl->setParameter($this, 'view', self::VIEW_MY_OFFERS);
191  $this->addHeaderLink($ilCtrl->getLinkTarget($this, 'changeView'), $this->lng->txt('pd_my_offers'),
192  ($this->view == self::VIEW_MY_OFFERS ? false : true)
193  );
194  $ilCtrl->setParameter($this, 'view', self::VIEW_MY_MEMBERSHIPS);
195  $this->addHeaderLink($ilCtrl->getLinkTarget($this, 'changeView'), $this->lng->txt('pd_my_memberships'),
196  ($this->view == self::VIEW_MY_MEMBERSHIPS ? false : true)
197  );
198  $ilCtrl->clearParameters($this);
199  }
200 
201  // workaround to show details row
202  $this->setData(array("dummy"));
203 
204  switch((int)$this->view)
205  {
206  case self::VIEW_MY_MEMBERSHIPS:
207  $this->setTitle($this->lng->txt('pd_my_memberships'));
208  $this->setContent($this->getMembershipItemsBlockHTML());
209  break;
210 
211  case self::VIEW_MY_OFFERS:
212  default:
213  if(!in_array(self::VIEW_MY_MEMBERSHIPS, $this->allowed_views))
214  {
215  $this->setTitle($this->lng->txt('selected_items'));
216  }
217  else
218  {
219  $this->setTitle($this->lng->txt('pd_my_offers'));
220  }
221 
222  $this->setContent($this->getSelectedItemsBlockHTML());
223  break;
224  }
225 
226  if ($this->getContent() == "")
227  {
228  $this->setEnableDetailRow(false);
229  }
230  $ilCtrl->clearParametersByClass("ilpersonaldesktopgui");
231  $ilCtrl->clearParameters($this);
232  return parent::getHTML();
233  }
234 
238  function &executeCommand()
239  {
240  global $ilCtrl;
241 
242  $next_class = $ilCtrl->getNextClass();
243  $cmd = $ilCtrl->getCmd("getHTML");
244 
245  if(method_exists($this, $cmd))
246  {
247  return $this->$cmd();
248  }
249  else
250  {
251  $cmd .= 'Object';
252  return $this->$cmd();
253  }
254  }
255 
256  function getContent()
257  {
258  return $this->content;
259  }
260 
261  function setContent($a_content)
262  {
263  $this->content = $a_content;
264  }
265 
269  function fillDataSection()
270  {
271  global $ilUser;
272 
273  if ($this->getContent() != "")
274  {
275  $this->tpl->setVariable("BLOCK_ROW", $this->getContent());
276  }
277  else
278  {
279  $this->setDataSection($this->getIntroduction());
280  }
281  }
282 
283 
287  function fillFooter()
288  {
289  global $ilCtrl, $lng, $ilUser;
290 
291  $this->setFooterLinks();
292  $this->fillFooterLinks();
293  $this->tpl->setVariable("FCOLSPAN", $this->getColSpan());
294  if ($this->tpl->blockExists("block_footer"))
295  {
296  $this->tpl->setCurrentBlock("block_footer");
297  $this->tpl->parseCurrentBlock();
298  }
299  }
300 
304  function setFooterLinks()
305  {
306  global $ilUser, $ilCtrl, $lng;
307 
308  if ($this->getContent() == "")
309  {
310  $this->setEnableNumInfo(false);
311  return "";
312  }
313 
314  // by type
315  if ($ilUser->getPref("pd_order_items") == 'location')
316  {
317  $this->addFooterLink( $lng->txt("by_type"),
318  $ilCtrl->getLinkTarget($this,
319  "orderPDItemsByType"),
320  $ilCtrl->getLinkTarget($this,
321  "orderPDItemsByType", "", true),
322  "block_".$this->getBlockType()."_".$this->block_id
323  );
324  }
325  else
326  {
327  $this->addFooterLink($lng->txt("by_type"));
328  }
329 
330  // by location
331  if ($ilUser->getPref("pd_order_items") == 'location')
332  {
333  $this->addFooterLink($lng->txt("by_location"));
334  }
335  else
336  {
337  $this->addFooterLink( $lng->txt("by_location"),
338  $ilCtrl->getLinkTarget($this,
339  "orderPDItemsByLocation"),
340  $ilCtrl->getLinkTarget($this,
341  "orderPDItemsByLocation", "", true),
342  "block_".$this->getBlockType()."_".$this->block_id
343  );
344  }
345  }
346 
353  protected function getObjectsByMembership($types = array())
354  {
355  global $tree, $ilUser, $ilObjDataCache;
356 
357  include_once 'Services/Membership/classes/class.ilParticipants.php';
358  $items = array();
359 
360  if(is_array($types) && count($types))
361  {
362  foreach($types as $type)
363  {
364  switch($type)
365  {
366  case 'grp':
367  $items = array_merge(ilParticipants::_getMembershipByType($ilUser->getId(), 'grp'), $items);
368  break;
369  case 'crs':
370  $items = array_merge(ilParticipants::_getMembershipByType($ilUser->getId(), 'crs'), $items);
371  break;
372  default:
373  break;
374  }
375  }
376  }
377  else
378  {
379  $crs_mbs = ilParticipants::_getMembershipByType($ilUser->getId(), 'crs');
380  $grp_mbs = ilParticipants::_getMembershipByType($ilUser->getId(), 'grp');
381  $items = array_merge($crs_mbs, $grp_mbs);
382  }
383 
384  $references = array();
385  foreach($items as $key => $obj_id)
386  {
387  $item_references = ilObject::_getAllReferences($obj_id);
388  if(is_array($item_references) && count($item_references))
389  {
390  foreach($item_references as $ref_id)
391  {
392  $title = $ilObjDataCache->lookupTitle($obj_id);
393  $type = $ilObjDataCache->lookupType($obj_id);
394 
395  $references[$title.$ref_id] =
396  array('ref_id' => $ref_id,
397  'obj_id' => $obj_id,
398  'type' => $type,
399  'title' => $title,
400  'description' => $ilObjDataCache->lookupDescription($obj_id),
401  'parent_ref' => $tree->getParentId($ref_id));
402  }
403  }
404  }
405  ksort($references);
406  return is_array($references) ? $references : array();
407  }
408 
416  {
417  global $ilUser, $rbacsystem, $objDefinition, $ilBench, $ilSetting, $ilObjDataCache, $rbacreview;
418 
419  $output = false;
420  $items = $this->getObjectsByMembership();
421  $item_html = array();
422  if(count($items) > 0)
423  {
424  // preload object data cache
425  $ref_ids = array();
426  foreach($items as $item)
427  {
428  $ref_ids[] = $item['ref_id'];
429  }
430  reset($items);
431  $ilObjDataCache->preloadReferenceCache($ref_ids);
432 
433  foreach($items as $item)
434  {
435  //echo "1";
436  // get list gui class for each object type
437  if ($cur_obj_type != $item["type"])
438  {
439  $item_list_gui =& $this->getItemListGUI($item["type"]);
440 
441  $item_list_gui->enableIcon(true);
442  $item_list_gui->enableDelete(false);
443  $item_list_gui->enableCut(false);
444  $item_list_gui->enableCopy(false);
445  $item_list_gui->enablePayment(false);
446  $item_list_gui->enableLink(false);
447  $item_list_gui->enableInfoScreen(false);
448  $item_list_gui->enableSubscribe(false);
449  if ($this->getCurrentDetailLevel() < 3)
450  {
451  //echo "3";
452  $item_list_gui->enableDescription(false);
453  $item_list_gui->enableProperties(false);
454  $item_list_gui->enablePreconditions(false);
455  }
456  if ($this->getCurrentDetailLevel() < 2)
457  {
458  $item_list_gui->enableCommands(true, true);
459  }
460  }
461  // render item row
462  $ilBench->start("ilPersonalDesktopGUI", "getListHTML");
463 
464  if (is_object($item_list_gui))
465  {
466  $html = $item_list_gui->getListItemHTML($item["ref_id"],
467  $item["obj_id"], $item["title"], $item["description"]);
468  $ilBench->stop("ilPersonalDesktopGUI", "getListHTML");
469  if ($html != "")
470  {
471  // BEGIN WebDAV: Use $item_list_gui to determine icon image type
472  $item_html[] = array(
473  "html" => $html,
474  "item_ref_id" => $item["ref_id"],
475  "item_obj_id" => $item["obj_id"],
476  "parent_ref" => $item["parent_ref"],
477  "type" => $item["type"],
478  'item_icon_image_type' => $item_list_gui->getIconImageType()
479  );
480  // END WebDAV: Use $item_list_gui to determine icon image type
481  }
482  }
483  }
484 
485  // output block for resource type
486  if (count($item_html) > 0)
487  {
488  $cur_parent_ref = 0;
489 
490  // content row
491  foreach($item_html as $item)
492  {
493  // add a parent header row for each new parent
494  if ($cur_parent_ref != $item["parent_ref"])
495  {
496  if ($ilSetting->get("icon_position_in_lists") == "item_rows")
497  {
498  $this->addParentRow($tpl, $item["parent_ref"], false);
499  }
500  else
501  {
502  $this->addParentRow($tpl, $item["parent_ref"]);
503  }
504  $this->resetRowType();
505  $cur_parent_ref = $item["parent_ref"];
506  }
507 
508  // BEGIN WebDAV: Use $item_list_gui to determine icon image type.
509  $this->addStandardRow($tpl, $item["html"], $item["item_ref_id"], $item["item_obj_id"],
510  $item['item_icon_image_type'],
511  "th_".$cur_parent_ref);
512  // END WebDAV: Use $item_list_gui to determine icon image type.
513  $output = true;
514  }
515  }
516  }
517 
518  return $output;
519  }
520 
528  {
529  global $ilUser, $rbacsystem, $objDefinition, $ilBench, $ilSetting, $ilObjDataCache;
530 
531  $output = false;
532 
533  $objtype_groups = $objDefinition->getGroupedRepositoryObjectTypes(
534  array("cat", "crs", "grp", "fold"));
535 
536  $types = array();
537  foreach($objtype_groups as $grp => $grpdata)
538  {
539  $types[] = array(
540  "grp" => $grp,
541  "title" => $this->lng->txt("objs_".$grp),
542  "types" => $grpdata["objs"]);
543  }
544 
545  foreach ($types as $t)
546  {
547  $type = $t["types"];
548  $title = $t["title"];
549  $grp = $t["grp"];
550 
551  $items = $this->getObjectsByMembership($type);
552 //var_dump($items);
553  // preload object data cache
554  $ref_ids = array();
555  foreach($items as $item)
556  {
557  $ref_ids[] = $item['ref_id'];
558  }
559  reset($items);
560  $ilObjDataCache->preloadReferenceCache($ref_ids);
561  $item_html = array();
562 
563  if ($this->getCurrentDetailLevel() == 3)
564  {
565  $rel_header = "th_".$grp;
566  }
567 
568  if (count($items) > 0)
569  {
570  $tstCount = 0;
571  $unsetCount = 0;
572  $progressCount = 0;
573  $unsetFlag = 0;
574  $progressFlag = 0;
575  $completedFlag = 0;
576  if (strcmp($a_type, "tst") == 0) {
577  $items = $this->multiarray_sort($items, "used_tries; title");
578  foreach ($items as $tst_item) {
579  if (!isset($tst_item["used_tries"])) {
580  $unsetCount++;
581  }
582  elseif ($tst_item["used_tries"] == 0) {
583  $progressCount++;
584  }
585  }
586  }
587 
588  foreach($items as $item)
589  {
590  // get list gui class for each object type
591  if ($cur_obj_type != $item["type"])
592  {
593  $class = $objDefinition->getClassName($item["type"]);
594  $location = $objDefinition->getLocation($item["type"]);
595  $full_class = "ilObj".$class."ListGUI";
596  include_once($location."/class.".$full_class.".php");
597  $item_list_gui = new $full_class();
598  $item_list_gui->enableIcon(true);
599  $item_list_gui->enableDelete(false);
600  $item_list_gui->enableCut(false);
601  $item_list_gui->enableCopy(false);
602  $item_list_gui->enablePayment(false);
603  $item_list_gui->enableLink(false);
604  $item_list_gui->enableInfoScreen(false);
605  $item_list_gui->enableSubscribe(false);
606  if ($this->getCurrentDetailLevel() < 3)
607  {
608  $item_list_gui->enableDescription(false);
609  $item_list_gui->enableProperties(false);
610  $item_list_gui->enablePreconditions(false);
611  $item_list_gui->enableNoticeProperties(false);
612  }
613  if ($this->getCurrentDetailLevel() < 2)
614  {
615  $item_list_gui->enableCommands(true, true);
616  }
617  }
618  // render item row
619  $ilBench->start("ilPersonalDesktopGUI", "getListHTML");
620 
621  $html = $item_list_gui->getListItemHTML($item["ref_id"],
622  $item["obj_id"], $item["title"], $item["description"]);
623  $ilBench->stop("ilPersonalDesktopGUI", "getListHTML");
624  if ($html != "")
625  {
626  // BEGIN WebDAV: Use $item_list_gui to determine icon image type
627  $item_html[] = array(
628  "html" => $html,
629  "item_ref_id" => $item["ref_id"],
630  "item_obj_id" => $item["obj_id"],
631  'item_icon_image_type' => (method_exists($item_list_gui, 'getIconImageType')) ?
632  $item_list_gui->getIconImageType() :
633  $item['type']
634  );
635  // END WebDAV: Use $item_list_gui to determine icon image type
636  }
637  }
638 
639  // output block for resource type
640  if (count($item_html) > 0)
641  {
642  // add a header for each resource type
643  if ($this->getCurrentDetailLevel() == 3)
644  {
645  if ($ilSetting->get("icon_position_in_lists") == "item_rows")
646  {
647  $this->addHeaderRow($tpl, $grp, false);
648  }
649  else
650  {
651  $this->addHeaderRow($tpl, $grp);
652  }
653  $this->resetRowType();
654  }
655 
656  // content row
657  foreach($item_html as $item)
658  {
659  if ($this->getCurrentDetailLevel() < 3 ||
660  $ilSetting->get("icon_position_in_lists") == "item_rows")
661  {
662  // BEGIN WebDAV: Use $item_list_gui to determine icon image type
663  $this->addStandardRow($tpl, $item["html"], $item["item_ref_id"], $item["item_obj_id"],
664  $item['item_icon_image_type'],
665  $rel_header);
666  // END WebDAV: Use $item_list_gui to determine icon image type
667  }
668  else
669  {
670  $this->addStandardRow($tpl, $item["html"], $item["item_ref_id"], $item["item_obj_id"], "", $rel_header);
671  }
672  $output = true;
673  }
674  }
675  }
676  }
677 
678  return $output;
679  }
680 
687  public function getMembershipItemsBlockHTML()
688  {
689  global $ilUser;
690 
691  $tpl = $this->newBlockTemplate();
692 
693  switch($ilUser->getPref('pd_order_items'))
694  {
695  case 'location':
697  break;
698 
699  default:
701  break;
702  }
703 
704  return $tpl->get();
705  }
706 
711  {
712  global $ilUser, $rbacsystem, $objDefinition, $ilBench;
713 
714  $tpl =& $this->newBlockTemplate();
715 
716  switch ($ilUser->getPref("pd_order_items"))
717  {
718  case "location":
720  break;
721 
722  default:
723  $ok = $this->getSelectedItemsPerType($tpl);
724  break;
725  }
726 
727  return $tpl->get();
728  }
729 
734  {
735  global $ilUser, $rbacsystem, $objDefinition, $ilBench, $ilSetting, $ilObjDataCache, $tree;
736 
737  $items = $ilUser->getDesktopItems();
738  if (count($items) > 0)
739  {
740  // preload object data cache
741  $ref_ids = array();
742  foreach($items as $item)
743  {
744  $ref_ids[] = $item["ref_id"];
745  }
746  $tree->preloadDeleted($ref_ids);
747  $tree->preloadDepthParent($ref_ids);
748  $ilObjDataCache->preloadReferenceCache($ref_ids, true);
749  }
750 
751  $output = false;
752 
753  $objtype_groups = $objDefinition->getGroupedRepositoryObjectTypes(
754  array("cat", "crs", "grp", "fold"));
755 
756  $types = array();
757  foreach($objtype_groups as $grp => $grpdata)
758  {
759  $types[] = array(
760  "grp" => $grp,
761  "title" => $this->lng->txt("objs_".$grp),
762  "types" => $grpdata["objs"]);
763  }
764 
765  foreach ($types as $t)
766  {
767 
768  $type = $t["types"];
769  $title = $t["title"];
770  $grp = $t["grp"];
771 
772  $items = $ilUser->getDesktopItems($type);
773  $item_html = array();
774 
775  if ($this->getCurrentDetailLevel() == 3)
776  {
777  $rel_header = "th_".$grp;
778  }
779 
780  if (count($items) > 0)
781  {
782  $tstCount = 0;
783  $unsetCount = 0;
784  $progressCount = 0;
785  $unsetFlag = 0;
786  $progressFlag = 0;
787  $completedFlag = 0;
788  if (strcmp($a_type, "tst") == 0) {
789  $items = $this->multiarray_sort($items, "used_tries; title");
790  foreach ($items as $tst_item) {
791  if (!isset($tst_item["used_tries"])) {
792  $unsetCount++;
793  }
794  elseif ($tst_item["used_tries"] == 0) {
795  $progressCount++;
796  }
797  }
798  }
799 
800  foreach($items as $item)
801  {
802  // get list gui class for each object type
803  if ($cur_obj_type != $item["type"])
804  {
805  $class = $objDefinition->getClassName($item["type"]);
806  $location = $objDefinition->getLocation($item["type"]);
807  $full_class = "ilObj".$class."ListGUI";
808  include_once($location."/class.".$full_class.".php");
809  $item_list_gui = new $full_class();
810  $item_list_gui->enableIcon(true);
811  $item_list_gui->enableDelete(false);
812  $item_list_gui->enableCut(false);
813  $item_list_gui->enableCopy(false);
814  $item_list_gui->enablePayment(false);
815  $item_list_gui->enableLink(false);
816  $item_list_gui->enableInfoScreen(false);
817  $item_list_gui->setContainerObject($this);
818  if ($this->getCurrentDetailLevel() < 3)
819  {
820  $item_list_gui->enableDescription(false);
821  $item_list_gui->enableProperties(false);
822  $item_list_gui->enablePreconditions(false);
823  $item_list_gui->enableNoticeProperties(false);
824  }
825  if ($this->getCurrentDetailLevel() < 2)
826  {
827  $item_list_gui->enableCommands(true, true);
828  }
829  }
830  // render item row
831  $ilBench->start("ilPersonalDesktopGUI", "getListHTML");
832 
833  $html = $item_list_gui->getListItemHTML($item["ref_id"],
834  $item["obj_id"], $item["title"], $item["description"]);
835  $ilBench->stop("ilPersonalDesktopGUI", "getListHTML");
836  if ($html != "")
837  {
838  // BEGIN WebDAV: Use $item_list_gui to determine icon image type
839  $item_html[] = array(
840  "html" => $html,
841  "item_ref_id" => $item["ref_id"],
842  "item_obj_id" => $item["obj_id"],
843  'item_icon_image_type' => (method_exists($item_list_gui, 'getIconImageType')) ?
844  $item_list_gui->getIconImageType() :
845  $item['type']
846  );
847  // END WebDAV: Use $item_list_gui to determine icon image type
848  }
849  }
850 
851  // output block for resource type
852  if (count($item_html) > 0)
853  {
854  // add a header for each resource type
855  if ($this->getCurrentDetailLevel() == 3)
856  {
857  if ($ilSetting->get("icon_position_in_lists") == "item_rows")
858  {
859  $this->addHeaderRow($tpl, $grp, false);
860  }
861  else
862  {
863  $this->addHeaderRow($tpl, $grp);
864  }
865  $this->resetRowType();
866  }
867 
868  // content row
869  foreach($item_html as $item)
870  {
871  if ($this->getCurrentDetailLevel() < 3 ||
872  $ilSetting->get("icon_position_in_lists") == "item_rows")
873  {
874  // BEGIN WebDAV: Use $item_list_gui to determine icon image type
875  $this->addStandardRow($tpl, $item["html"], $item["item_ref_id"], $item["item_obj_id"],
876  $item['item_icon_image_type'],
877  $rel_header);
878  // END WebDAV: Use $item_list_gui to determine icon image type
879  }
880  else
881  {
882  $this->addStandardRow($tpl, $item["html"], $item["item_ref_id"], $item["item_obj_id"], "", $rel_header);
883  }
884  $output = true;
885  }
886  }
887  }
888  }
889 
890  return $output;
891  }
892 
897  {
898  global $ilUser, $rbacsystem, $objDefinition, $ilBench, $ilSetting, $ilObjDataCache, $tree;
899 
900  $output = false;
901 
902  $items = $ilUser->getDesktopItems();
903  $item_html = array();
904  $cur_obj_type = "";
905 
906  if (count($items) > 0)
907  {
908  // preload object data cache
909  $ref_ids = array();
910  foreach($items as $item)
911  {
912  $ref_ids[] = $item["ref_id"];
913  }
914  reset($items);
915  $tree->preloadDeleted($ref_ids);
916  $tree->preloadDepthParent($ref_ids);
917  $ilObjDataCache->preloadReferenceCache($ref_ids);
918 
919  foreach($items as $item)
920  {
921  //echo "1";
922  // get list gui class for each object type
923  if ($cur_obj_type != $item["type"])
924  {
925  $item_list_gui =& $this->getItemListGUI($item["type"]);
926 
927  $item_list_gui->enableIcon(true);
928  $item_list_gui->enableDelete(false);
929  $item_list_gui->enableCut(false);
930  $item_list_gui->enableCopy(false);
931  $item_list_gui->enablePayment(false);
932  $item_list_gui->enableLink(false);
933  $item_list_gui->enableInfoScreen(false);
934  if ($this->getCurrentDetailLevel() < 3)
935  {
936  //echo "3";
937  $item_list_gui->enableDescription(false);
938  $item_list_gui->enableProperties(false);
939  $item_list_gui->enablePreconditions(false);
940  }
941  if ($this->getCurrentDetailLevel() < 2)
942  {
943  $item_list_gui->enableCommands(true, true);
944  }
945  }
946  // render item row
947  $ilBench->start("ilPersonalDesktopGUI", "getListHTML");
948  $item_list_gui->setContainerObject($this);
949  $html = $item_list_gui->getListItemHTML($item["ref_id"],
950  $item["obj_id"], $item["title"], $item["description"]);
951  $ilBench->stop("ilPersonalDesktopGUI", "getListHTML");
952  if ($html != "")
953  {
954  // BEGIN WebDAV: Use $item_list_gui to determine icon image type
955  $item_html[] = array(
956  "html" => $html,
957  "item_ref_id" => $item["ref_id"],
958  "item_obj_id" => $item["obj_id"],
959  "parent_ref" => $item["parent_ref"],
960  "type" => $item["type"],
961  'item_icon_image_type' => $item_list_gui->getIconImageType()
962  );
963  // END WebDAV: Use $item_list_gui to determine icon image type
964  }
965  }
966 
967  // output block for resource type
968  if (count($item_html) > 0)
969  {
970  $cur_parent_ref = 0;
971 
972  // content row
973  foreach($item_html as $item)
974  {
975  // add a parent header row for each new parent
976  if ($cur_parent_ref != $item["parent_ref"])
977  {
978  if ($ilSetting->get("icon_position_in_lists") == "item_rows")
979  {
980  $this->addParentRow($tpl, $item["parent_ref"], false);
981  }
982  else
983  {
984  $this->addParentRow($tpl, $item["parent_ref"]);
985  }
986  $this->resetRowType();
987  $cur_parent_ref = $item["parent_ref"];
988  }
989 
990  // BEGIN WebDAV: Use $item_list_gui to determine icon image type.
991  $this->addStandardRow($tpl, $item["html"], $item["item_ref_id"], $item["item_obj_id"],
992  $item['item_icon_image_type'],
993  "th_".$cur_parent_ref);
994  // END WebDAV: Use $item_list_gui to determine icon image type.
995  $output = true;
996  }
997  }
998  }
999 
1000  return $output;
1001  }
1002 
1003  function resetRowType()
1004  {
1005  $this->cur_row_type = "";
1006  }
1007 
1014  function &newBlockTemplate()
1015  {
1016  $tpl = new ilTemplate ("tpl.pd_list_block.html", true, true, "Services/PersonalDesktop");
1017  $this->cur_row_type = "";
1018  return $tpl;
1019  }
1020 
1024  function &getItemListGUI($a_type)
1025  {
1026  global $objDefinition;
1027  //echo "<br>+$a_type+";
1028  if (!isset($this->item_list_guis[$a_type]))
1029  {
1030  $class = $objDefinition->getClassName($a_type);
1031  $location = $objDefinition->getLocation($a_type);
1032  $full_class = "ilObj".$class."ListGUI";
1033  //echo "<br>-".$location."/class.".$full_class.".php"."-";
1034  include_once($location."/class.".$full_class.".php");
1035  $item_list_gui = new $full_class();
1036  $this->item_list_guis[$a_type] =& $item_list_gui;
1037  }
1038  else
1039  {
1040  $item_list_gui =& $this->item_list_guis[$a_type];
1041  }
1042  return $item_list_gui;
1043  }
1044 
1052  function addHeaderRow(&$a_tpl, $a_type, $a_show_image = true)
1053  {
1054  global $objDefinition;
1055 
1056  $icon = ilUtil::getImagePath("icon_".$a_type.".gif");
1057  if (!$objDefinition->isPlugin($a_type))
1058  {
1059  $title = $this->lng->txt("objs_".$a_type);
1060  }
1061  else
1062  {
1063  include_once("./Services/Component/classes/class.ilPlugin.php");
1064  $title =
1065  ilPlugin::lookupTxt("rep_robj", $a_type, "objs_".$a_type);
1066 
1067  }
1068  $header_id = "th_".$a_type;
1069 
1070  if ($a_show_image)
1071  {
1072  $a_tpl->setCurrentBlock("container_header_row_image");
1073  $a_tpl->setVariable("HEADER_IMG", $icon);
1074  $a_tpl->setVariable("HEADER_ALT", $title);
1075  }
1076  else
1077  {
1078  $a_tpl->setCurrentBlock("container_header_row");
1079  }
1080 
1081  $a_tpl->setVariable("BLOCK_HEADER_CONTENT", $title);
1082  $a_tpl->setVariable("BLOCK_HEADER_ID", $header_id);
1083  $a_tpl->parseCurrentBlock();
1084  $a_tpl->touchBlock("container_row");
1085  }
1086 
1094  function addParentRow(&$a_tpl, $a_ref_id, $a_show_image = true)
1095  {
1096  global $tree, $ilSetting;
1097 
1098  $par_id = ilObject::_lookupObjId($a_ref_id);
1099  $type = ilObject::_lookupType($par_id);
1100  if (!in_array($type, array("lm", "dbk", "sahs", "htlm")))
1101  {
1102  $icon = ilUtil::getImagePath("icon_".$type.".gif");
1103  }
1104  else
1105  {
1106  $icon = ilUtil::getImagePath("icon_lm.gif");
1107  }
1108 
1109  // custom icon
1110  if ($ilSetting->get("custom_icons") &&
1111  in_array($type, array("cat","grp","crs", "root")))
1112  {
1113  require_once("./Services/Container/classes/class.ilContainer.php");
1114  if (($path = ilContainer::_lookupIconPath($par_id, "small")) != "")
1115  {
1116  $icon = $path;
1117  }
1118  }
1119 
1120  if ($tree->getRootId() != $par_id)
1121  {
1122  $title = ilObject::_lookupTitle($par_id);
1123  }
1124  else
1125  {
1126  $nd = $tree->getNodeData(ROOT_FOLDER_ID);
1127  $title = $nd["title"];
1128  if ($title == "ILIAS")
1129  {
1130  $title = $this->lng->txt("repository");
1131  }
1132  }
1133 
1134 /*
1135  $item_list_gui =& $this->getItemListGUI($type);
1136 
1137  $item_list_gui->enableIcon(false);
1138  $item_list_gui->enableDelete(false);
1139  $item_list_gui->enableCut(false);
1140  $item_list_gui->enablePayment(false);
1141  $item_list_gui->enableLink(false);
1142  $item_list_gui->enableDescription(false);
1143  $item_list_gui->enableProperties(false);
1144  $item_list_gui->enablePreconditions(false);
1145  $item_list_gui->enablePath(true);
1146  $item_list_gui->enableCommands(false);
1147  $html = $item_list_gui->getListItemHTML($a_ref_id,
1148  $par_id, $title, "");
1149 
1150  if ($a_show_image)
1151  {
1152  $a_tpl->setCurrentBlock("container_header_row_image");
1153  $a_tpl->setVariable("HEADER_IMG", $icon);
1154  $a_tpl->setVariable("HEADER_ALT", $title);
1155  }
1156 */
1157 // else
1158 // {
1159  $a_tpl->setCurrentBlock("container_header_row");
1160 // }
1161 
1162  $a_tpl->setVariable("BLOCK_HEADER_CONTENT", $title);
1163 /* $a_tpl->setVariable("BLOCK_HEADER_CONTENT", $html);
1164  $a_tpl->setVariable("BLOCK_HEADER_ID", "th_".$a_ref_id);*/
1165  $a_tpl->parseCurrentBlock();
1166  $a_tpl->touchBlock("container_row");
1167  }
1168 
1176  function addStandardRow(&$a_tpl, $a_html, $a_item_ref_id = "", $a_item_obj_id = "",
1177  $a_image_type = "", $a_related_header = "")
1178  {
1179  global $ilSetting;
1180 
1181  $this->cur_row_type = ($this->cur_row_type == "row_type_1")
1182  ? "row_type_2"
1183  : "row_type_1";
1184  $a_tpl->touchBlock($this->cur_row_type);
1185 
1186  if ($a_image_type != "")
1187  {
1188  if (!is_array($a_image_type) && !in_array($a_image_type, array("lm", "dbk", "htlm", "sahs")))
1189  {
1190  $icon = ilUtil::getImagePath("icon_".$a_image_type.".gif");
1191  $title = $this->lng->txt("obj_".$a_image_type);
1192  }
1193  else
1194  {
1195  $icon = ilUtil::getImagePath("icon_lm.gif");
1196  $title = $this->lng->txt("learning_resource");
1197  }
1198 
1199  // custom icon
1200  if ($ilSetting->get("custom_icons") &&
1201  in_array($a_image_type, array("cat","grp","crs")))
1202  {
1203  require_once("./Services/Container/classes/class.ilContainer.php");
1204  if (($path = ilContainer::_lookupIconPath($a_item_obj_id, "small")) != "")
1205  {
1206  $icon = $path;
1207  }
1208  }
1209 
1210  $a_tpl->setCurrentBlock("block_row_image");
1211  $a_tpl->setVariable("ROW_IMG", $icon);
1212  $a_tpl->setVariable("ROW_ALT", $title);
1213  $a_tpl->parseCurrentBlock();
1214  }
1215  else
1216  {
1217  $a_tpl->setVariable("ROW_NBSP", "&nbsp;");
1218  }
1219  $a_tpl->setCurrentBlock("container_standard_row");
1220  $a_tpl->setVariable("BLOCK_ROW_CONTENT", $a_html);
1221  $rel_headers = ($a_related_header != "")
1222  ? "th_selected_items ".$a_related_header
1223  : "th_selected_items";
1224  $a_tpl->setVariable("BLOCK_ROW_HEADERS", $rel_headers);
1225  $a_tpl->parseCurrentBlock();
1226  $a_tpl->touchBlock("container_row");
1227  }
1228 
1232  function getIntroduction()
1233  {
1234  global $ilUser, $lng, $ilCtrl, $tree;
1235 
1236  switch((int)$this->view)
1237  {
1238  case self::VIEW_MY_MEMBERSHIPS:
1239  $tpl = new ilTemplate('tpl.pd_my_memberships_intro.html', true, true, 'Services/PersonalDesktop');
1240  $tpl->setVariable('IMG_PD_LARGE', ilUtil::getImagePath('icon_pd_xxl.gif'));
1241  $tpl->setVariable('TXT_WELCOME', $lng->txt('pd_my_memberships_intro'));
1242  $tpl->setVariable('TXT_INTRO_1', $lng->txt('pd_my_memberships_intro2'));
1243  break;
1244 
1245  case self::VIEW_MY_OFFERS:
1246  default:
1247  // get repository link
1248  $nd = $tree->getNodeData(ROOT_FOLDER_ID);
1249  $title = $nd["title"];
1250  if ($title == "ILIAS")
1251  {
1252  $title = $lng->txt("repository");
1253  }
1254 
1255  $tpl = new ilTemplate("tpl.pd_intro.html", true, true, "Services/PersonalDesktop");
1256  $tpl->setVariable("IMG_PD_LARGE", ilUtil::getImagePath("icon_pd_xxl.gif"));
1257  $tpl->setVariable("TXT_WELCOME", $lng->txt("pdesk_intro"));
1258  $tpl->setVariable("TXT_INTRO_1", sprintf($lng->txt("pdesk_intro2"), $lng->txt("to_desktop")));
1259  $tpl->setVariable("TXT_INTRO_2", sprintf($lng->txt("pdesk_intro3"),
1260  '<a href="repository.php?cmd=frameset&getlast=true">'.$title.'</a>'));
1261  $tpl->setVariable("TXT_INTRO_3", $lng->txt("pdesk_intro4"));
1262  break;
1263  }
1264 
1265  return $tpl->get();
1266  }
1267 
1272  {
1273  global $ilUser, $ilCtrl;
1274 
1275  $ilUser->writePref("pd_order_items", "location");
1276 
1277  if ($ilCtrl->isAsynch())
1278  {
1279  echo $this->getHTML();
1280  exit;
1281  }
1282  else
1283  {
1284  $ilCtrl->redirectByClass("ilpersonaldesktopgui", "show");
1285  }
1286  }
1287 
1292  {
1293  global $ilUser, $ilCtrl;
1294 
1295  $ilUser->writePref("pd_order_items", "type");
1296 
1297  if ($ilCtrl->isAsynch())
1298  {
1299  echo $this->getHTML();
1300  exit;
1301  }
1302  else
1303  {
1304  $ilCtrl->redirectByClass("ilpersonaldesktopgui", "show");
1305  }
1306  }
1307 
1308 }
1309 
1310 ?>