ILIAS  Release_4_0_x_branch Revision 61816
 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;
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  $ilObjDataCache->preloadReferenceCache($ref_ids);
747  }
748 
749  $output = false;
750 
751  $objtype_groups = $objDefinition->getGroupedRepositoryObjectTypes(
752  array("cat", "crs", "grp", "fold"));
753 
754  $types = array();
755  foreach($objtype_groups as $grp => $grpdata)
756  {
757  $types[] = array(
758  "grp" => $grp,
759  "title" => $this->lng->txt("objs_".$grp),
760  "types" => $grpdata["objs"]);
761  }
762 
763  foreach ($types as $t)
764  {
765 
766  $type = $t["types"];
767  $title = $t["title"];
768  $grp = $t["grp"];
769 
770  $items = $ilUser->getDesktopItems($type);
771  $item_html = array();
772 
773  if ($this->getCurrentDetailLevel() == 3)
774  {
775  $rel_header = "th_".$grp;
776  }
777 
778  if (count($items) > 0)
779  {
780  $tstCount = 0;
781  $unsetCount = 0;
782  $progressCount = 0;
783  $unsetFlag = 0;
784  $progressFlag = 0;
785  $completedFlag = 0;
786  if (strcmp($a_type, "tst") == 0) {
787  $items = $this->multiarray_sort($items, "used_tries; title");
788  foreach ($items as $tst_item) {
789  if (!isset($tst_item["used_tries"])) {
790  $unsetCount++;
791  }
792  elseif ($tst_item["used_tries"] == 0) {
793  $progressCount++;
794  }
795  }
796  }
797 
798  foreach($items as $item)
799  {
800  // get list gui class for each object type
801  if ($cur_obj_type != $item["type"])
802  {
803  $class = $objDefinition->getClassName($item["type"]);
804  $location = $objDefinition->getLocation($item["type"]);
805  $full_class = "ilObj".$class."ListGUI";
806  include_once($location."/class.".$full_class.".php");
807  $item_list_gui = new $full_class();
808  $item_list_gui->enableIcon(true);
809  $item_list_gui->enableDelete(false);
810  $item_list_gui->enableCut(false);
811  $item_list_gui->enableCopy(false);
812  $item_list_gui->enablePayment(false);
813  $item_list_gui->enableLink(false);
814  $item_list_gui->enableInfoScreen(false);
815  $item_list_gui->setContainerObject($this);
816  if ($this->getCurrentDetailLevel() < 3)
817  {
818  $item_list_gui->enableDescription(false);
819  $item_list_gui->enableProperties(false);
820  $item_list_gui->enablePreconditions(false);
821  $item_list_gui->enableNoticeProperties(false);
822  }
823  if ($this->getCurrentDetailLevel() < 2)
824  {
825  $item_list_gui->enableCommands(true, true);
826  }
827  }
828  // render item row
829  $ilBench->start("ilPersonalDesktopGUI", "getListHTML");
830 
831  $html = $item_list_gui->getListItemHTML($item["ref_id"],
832  $item["obj_id"], $item["title"], $item["description"]);
833  $ilBench->stop("ilPersonalDesktopGUI", "getListHTML");
834  if ($html != "")
835  {
836  // BEGIN WebDAV: Use $item_list_gui to determine icon image type
837  $item_html[] = array(
838  "html" => $html,
839  "item_ref_id" => $item["ref_id"],
840  "item_obj_id" => $item["obj_id"],
841  'item_icon_image_type' => (method_exists($item_list_gui, 'getIconImageType')) ?
842  $item_list_gui->getIconImageType() :
843  $item['type']
844  );
845  // END WebDAV: Use $item_list_gui to determine icon image type
846  }
847  }
848 
849  // output block for resource type
850  if (count($item_html) > 0)
851  {
852  // add a header for each resource type
853  if ($this->getCurrentDetailLevel() == 3)
854  {
855  if ($ilSetting->get("icon_position_in_lists") == "item_rows")
856  {
857  $this->addHeaderRow($tpl, $grp, false);
858  }
859  else
860  {
861  $this->addHeaderRow($tpl, $grp);
862  }
863  $this->resetRowType();
864  }
865 
866  // content row
867  foreach($item_html as $item)
868  {
869  if ($this->getCurrentDetailLevel() < 3 ||
870  $ilSetting->get("icon_position_in_lists") == "item_rows")
871  {
872  // BEGIN WebDAV: Use $item_list_gui to determine icon image type
873  $this->addStandardRow($tpl, $item["html"], $item["item_ref_id"], $item["item_obj_id"],
874  $item['item_icon_image_type'],
875  $rel_header);
876  // END WebDAV: Use $item_list_gui to determine icon image type
877  }
878  else
879  {
880  $this->addStandardRow($tpl, $item["html"], $item["item_ref_id"], $item["item_obj_id"], "", $rel_header);
881  }
882  $output = true;
883  }
884  }
885  }
886  }
887 
888  return $output;
889  }
890 
895  {
896  global $ilUser, $rbacsystem, $objDefinition, $ilBench, $ilSetting, $ilObjDataCache;
897 
898  $output = false;
899 
900  $items = $ilUser->getDesktopItems();
901  $item_html = array();
902 
903  if (count($items) > 0)
904  {
905  // preload object data cache
906  $ref_ids = array();
907  foreach($items as $item)
908  {
909  $ref_ids[] = $item["ref_id"];
910  }
911  reset($items);
912  $ilObjDataCache->preloadReferenceCache($ref_ids);
913 
914  foreach($items as $item)
915  {
916  //echo "1";
917  // get list gui class for each object type
918  if ($cur_obj_type != $item["type"])
919  {
920  $item_list_gui =& $this->getItemListGUI($item["type"]);
921 
922  $item_list_gui->enableIcon(true);
923  $item_list_gui->enableDelete(false);
924  $item_list_gui->enableCut(false);
925  $item_list_gui->enableCopy(false);
926  $item_list_gui->enablePayment(false);
927  $item_list_gui->enableLink(false);
928  $item_list_gui->enableInfoScreen(false);
929  if ($this->getCurrentDetailLevel() < 3)
930  {
931  //echo "3";
932  $item_list_gui->enableDescription(false);
933  $item_list_gui->enableProperties(false);
934  $item_list_gui->enablePreconditions(false);
935  }
936  if ($this->getCurrentDetailLevel() < 2)
937  {
938  $item_list_gui->enableCommands(true, true);
939  }
940  }
941  // render item row
942  $ilBench->start("ilPersonalDesktopGUI", "getListHTML");
943  $item_list_gui->setContainerObject($this);
944  $html = $item_list_gui->getListItemHTML($item["ref_id"],
945  $item["obj_id"], $item["title"], $item["description"]);
946  $ilBench->stop("ilPersonalDesktopGUI", "getListHTML");
947  if ($html != "")
948  {
949  // BEGIN WebDAV: Use $item_list_gui to determine icon image type
950  $item_html[] = array(
951  "html" => $html,
952  "item_ref_id" => $item["ref_id"],
953  "item_obj_id" => $item["obj_id"],
954  "parent_ref" => $item["parent_ref"],
955  "type" => $item["type"],
956  'item_icon_image_type' => $item_list_gui->getIconImageType()
957  );
958  // END WebDAV: Use $item_list_gui to determine icon image type
959  }
960  }
961 
962  // output block for resource type
963  if (count($item_html) > 0)
964  {
965  $cur_parent_ref = 0;
966 
967  // content row
968  foreach($item_html as $item)
969  {
970  // add a parent header row for each new parent
971  if ($cur_parent_ref != $item["parent_ref"])
972  {
973  if ($ilSetting->get("icon_position_in_lists") == "item_rows")
974  {
975  $this->addParentRow($tpl, $item["parent_ref"], false);
976  }
977  else
978  {
979  $this->addParentRow($tpl, $item["parent_ref"]);
980  }
981  $this->resetRowType();
982  $cur_parent_ref = $item["parent_ref"];
983  }
984 
985  // BEGIN WebDAV: Use $item_list_gui to determine icon image type.
986  $this->addStandardRow($tpl, $item["html"], $item["item_ref_id"], $item["item_obj_id"],
987  $item['item_icon_image_type'],
988  "th_".$cur_parent_ref);
989  // END WebDAV: Use $item_list_gui to determine icon image type.
990  $output = true;
991  }
992  }
993  }
994 
995  return $output;
996  }
997 
998  function resetRowType()
999  {
1000  $this->cur_row_type = "";
1001  }
1002 
1009  function &newBlockTemplate()
1010  {
1011  $tpl = new ilTemplate ("tpl.pd_list_block.html", true, true, "Services/PersonalDesktop");
1012  $this->cur_row_type = "";
1013  return $tpl;
1014  }
1015 
1019  function &getItemListGUI($a_type)
1020  {
1021  global $objDefinition;
1022  //echo "<br>+$a_type+";
1023  if (!is_object($this->item_list_guis[$a_type]))
1024  {
1025  $class = $objDefinition->getClassName($a_type);
1026  $location = $objDefinition->getLocation($a_type);
1027  $full_class = "ilObj".$class."ListGUI";
1028  //echo "<br>-".$location."/class.".$full_class.".php"."-";
1029  include_once($location."/class.".$full_class.".php");
1030  $item_list_gui = new $full_class();
1031  $this->item_list_guis[$a_type] =& $item_list_gui;
1032  }
1033  else
1034  {
1035  $item_list_gui =& $this->item_list_guis[$a_type];
1036  }
1037  return $item_list_gui;
1038  }
1039 
1047  function addHeaderRow(&$a_tpl, $a_type, $a_show_image = true)
1048  {
1049  global $objDefinition;
1050 
1051  $icon = ilUtil::getImagePath("icon_".$a_type.".gif");
1052  if (!$objDefinition->isPlugin($a_type))
1053  {
1054  $title = $this->lng->txt("objs_".$a_type);
1055  }
1056  else
1057  {
1058  include_once("./Services/Component/classes/class.ilPlugin.php");
1059  $title =
1060  ilPlugin::lookupTxt("rep_robj", $a_type, "objs_".$a_type);
1061 
1062  }
1063  $header_id = "th_".$a_type;
1064 
1065  if ($a_show_image)
1066  {
1067  $a_tpl->setCurrentBlock("container_header_row_image");
1068  $a_tpl->setVariable("HEADER_IMG", $icon);
1069  $a_tpl->setVariable("HEADER_ALT", $title);
1070  }
1071  else
1072  {
1073  $a_tpl->setCurrentBlock("container_header_row");
1074  }
1075 
1076  $a_tpl->setVariable("BLOCK_HEADER_CONTENT", $title);
1077  $a_tpl->setVariable("BLOCK_HEADER_ID", $header_id);
1078  $a_tpl->parseCurrentBlock();
1079  $a_tpl->touchBlock("container_row");
1080  }
1081 
1089  function addParentRow(&$a_tpl, $a_ref_id, $a_show_image = true)
1090  {
1091  global $tree, $ilSetting;
1092 
1093  $par_id = ilObject::_lookupObjId($a_ref_id);
1094  $type = ilObject::_lookupType($par_id);
1095  if (!in_array($type, array("lm", "dbk", "sahs", "htlm")))
1096  {
1097  $icon = ilUtil::getImagePath("icon_".$type.".gif");
1098  }
1099  else
1100  {
1101  $icon = ilUtil::getImagePath("icon_lm.gif");
1102  }
1103 
1104  // custom icon
1105  if ($ilSetting->get("custom_icons") &&
1106  in_array($type, array("cat","grp","crs", "root")))
1107  {
1108  require_once("./Services/Container/classes/class.ilContainer.php");
1109  if (($path = ilContainer::_lookupIconPath($par_id, "small")) != "")
1110  {
1111  $icon = $path;
1112  }
1113  }
1114 
1115  if ($tree->getRootId() != $par_id)
1116  {
1117  $title = ilObject::_lookupTitle($par_id);
1118  }
1119  else
1120  {
1121  $nd = $tree->getNodeData(ROOT_FOLDER_ID);
1122  $title = $nd["title"];
1123  if ($title == "ILIAS")
1124  {
1125  $title = $this->lng->txt("repository");
1126  }
1127  }
1128 
1129 /*
1130  $item_list_gui =& $this->getItemListGUI($type);
1131 
1132  $item_list_gui->enableIcon(false);
1133  $item_list_gui->enableDelete(false);
1134  $item_list_gui->enableCut(false);
1135  $item_list_gui->enablePayment(false);
1136  $item_list_gui->enableLink(false);
1137  $item_list_gui->enableDescription(false);
1138  $item_list_gui->enableProperties(false);
1139  $item_list_gui->enablePreconditions(false);
1140  $item_list_gui->enablePath(true);
1141  $item_list_gui->enableCommands(false);
1142  $html = $item_list_gui->getListItemHTML($a_ref_id,
1143  $par_id, $title, "");
1144 
1145  if ($a_show_image)
1146  {
1147  $a_tpl->setCurrentBlock("container_header_row_image");
1148  $a_tpl->setVariable("HEADER_IMG", $icon);
1149  $a_tpl->setVariable("HEADER_ALT", $title);
1150  }
1151 */
1152 // else
1153 // {
1154  $a_tpl->setCurrentBlock("container_header_row");
1155 // }
1156 
1157  $a_tpl->setVariable("BLOCK_HEADER_CONTENT", $title);
1158 /* $a_tpl->setVariable("BLOCK_HEADER_CONTENT", $html);
1159  $a_tpl->setVariable("BLOCK_HEADER_ID", "th_".$a_ref_id);*/
1160  $a_tpl->parseCurrentBlock();
1161  $a_tpl->touchBlock("container_row");
1162  }
1163 
1171  function addStandardRow(&$a_tpl, $a_html, $a_item_ref_id = "", $a_item_obj_id = "",
1172  $a_image_type = "", $a_related_header = "")
1173  {
1174  global $ilSetting;
1175 
1176  $this->cur_row_type = ($this->cur_row_type == "row_type_1")
1177  ? "row_type_2"
1178  : "row_type_1";
1179  $a_tpl->touchBlock($this->cur_row_type);
1180 
1181  if ($a_image_type != "")
1182  {
1183  if (!is_array($a_image_type) && !in_array($a_image_type, array("lm", "dbk", "htlm", "sahs")))
1184  {
1185  $icon = ilUtil::getImagePath("icon_".$a_image_type.".gif");
1186  $title = $this->lng->txt("obj_".$a_image_type);
1187  }
1188  else
1189  {
1190  $icon = ilUtil::getImagePath("icon_lm.gif");
1191  $title = $this->lng->txt("learning_resource");
1192  }
1193 
1194  // custom icon
1195  if ($ilSetting->get("custom_icons") &&
1196  in_array($a_image_type, array("cat","grp","crs")))
1197  {
1198  require_once("./Services/Container/classes/class.ilContainer.php");
1199  if (($path = ilContainer::_lookupIconPath($a_item_obj_id, "small")) != "")
1200  {
1201  $icon = $path;
1202  }
1203  }
1204 
1205  $a_tpl->setCurrentBlock("block_row_image");
1206  $a_tpl->setVariable("ROW_IMG", $icon);
1207  $a_tpl->setVariable("ROW_ALT", $title);
1208  $a_tpl->parseCurrentBlock();
1209  }
1210  else
1211  {
1212  $a_tpl->setVariable("ROW_NBSP", "&nbsp;");
1213  }
1214  $a_tpl->setCurrentBlock("container_standard_row");
1215  $a_tpl->setVariable("BLOCK_ROW_CONTENT", $a_html);
1216  $rel_headers = ($a_related_header != "")
1217  ? "th_selected_items ".$a_related_header
1218  : "th_selected_items";
1219  $a_tpl->setVariable("BLOCK_ROW_HEADERS", $rel_headers);
1220  $a_tpl->parseCurrentBlock();
1221  $a_tpl->touchBlock("container_row");
1222  }
1223 
1227  function getIntroduction()
1228  {
1229  global $ilUser, $lng, $ilCtrl, $tree;
1230 
1231  switch((int)$this->view)
1232  {
1233  case self::VIEW_MY_MEMBERSHIPS:
1234  $tpl = new ilTemplate('tpl.pd_my_memberships_intro.html', true, true, 'Services/PersonalDesktop');
1235  $tpl->setVariable('IMG_PD_LARGE', ilUtil::getImagePath('icon_pd_xxl.gif'));
1236  $tpl->setVariable('TXT_WELCOME', $lng->txt('pd_my_memberships_intro'));
1237  $tpl->setVariable('TXT_INTRO_1', $lng->txt('pd_my_memberships_intro2'));
1238  break;
1239 
1240  case self::VIEW_MY_OFFERS:
1241  default:
1242  // get repository link
1243  $nd = $tree->getNodeData(ROOT_FOLDER_ID);
1244  $title = $nd["title"];
1245  if ($title == "ILIAS")
1246  {
1247  $title = $lng->txt("repository");
1248  }
1249 
1250  $tpl = new ilTemplate("tpl.pd_intro.html", true, true, "Services/PersonalDesktop");
1251  $tpl->setVariable("IMG_PD_LARGE", ilUtil::getImagePath("icon_pd_xxl.gif"));
1252  $tpl->setVariable("TXT_WELCOME", $lng->txt("pdesk_intro"));
1253  $tpl->setVariable("TXT_INTRO_1", sprintf($lng->txt("pdesk_intro2"), $lng->txt("to_desktop")));
1254  $tpl->setVariable("TXT_INTRO_2", sprintf($lng->txt("pdesk_intro3"),
1255  '<a href="repository.php?cmd=frameset&getlast=true">'.$title.'</a>'));
1256  $tpl->setVariable("TXT_INTRO_3", $lng->txt("pdesk_intro4"));
1257  break;
1258  }
1259 
1260  return $tpl->get();
1261  }
1262 
1267  {
1268  global $ilUser, $ilCtrl;
1269 
1270  $ilUser->writePref("pd_order_items", "location");
1271 
1272  if ($ilCtrl->isAsynch())
1273  {
1274  echo $this->getHTML();
1275  exit;
1276  }
1277  else
1278  {
1279  $ilCtrl->redirectByClass("ilpersonaldesktopgui", "show");
1280  }
1281  }
1282 
1287  {
1288  global $ilUser, $ilCtrl;
1289 
1290  $ilUser->writePref("pd_order_items", "type");
1291 
1292  if ($ilCtrl->isAsynch())
1293  {
1294  echo $this->getHTML();
1295  exit;
1296  }
1297  else
1298  {
1299  $ilCtrl->redirectByClass("ilpersonaldesktopgui", "show");
1300  }
1301  }
1302 
1303 }
1304 
1305 ?>