ILIAS  Release_5_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilColumnGUI.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 define ("IL_COL_LEFT", "left");
5 define ("IL_COL_RIGHT", "right");
6 define ("IL_COL_CENTER", "center");
7 
8 define ("IL_SCREEN_SIDE", "");
9 define ("IL_SCREEN_CENTER", "center");
10 define ("IL_SCREEN_FULL", "full");
11 
23 {
24  protected $side = IL_COL_RIGHT;
25  protected $type;
26  protected $enableedit = false;
27  protected $repositorymode = false;
28  protected $repositoryitems = array();
29 
30  // all blocks that are repository objects
31  protected $rep_block_types = array("feed","poll");
32  protected $block_property = array();
33  protected $admincommands = null;
34  protected $movementmode = null;
35  protected $enablemovement = false;
36 
40  protected $action_menu;
41 
42  //
43  // This two arrays may be replaced by some
44  // xml or other magic in the future...
45  //
46 
47  static protected $locations = array(
48  "ilNewsForContextBlockGUI" => "Services/News/",
49  "ilCalendarBlockGUI" => "Services/Calendar/",
50  "ilPDCalendarBlockGUI" => "Services/Calendar/",
51  "ilPDNotesBlockGUI" => "Services/Notes/",
52  "ilPDMailBlockGUI" => "Services/Mail/",
53  "ilUsersOnlineBlockGUI" => "Services/PersonalDesktop/",
54  "ilPDSysMessageBlockGUI" => "Services/Mail/",
55  "ilPDSelectedItemsBlockGUI" => "Services/PersonalDesktop/",
56  "ilBookmarkBlockGUI" => "Services/Bookmarks/",
57  "ilPDNewsBlockGUI" => "Services/News/",
58  "ilExternalFeedBlockGUI" => "Services/Block/",
59  "ilPDExternalFeedBlockGUI" => "Services/Feeds/",
60  'ilPDTaggingBlockGUI' => 'Services/Tagging/',
61  'ilChatroomBlockGUI' => 'Modules/Chatroom/',
62  'ilPollBlockGUI' => 'Modules/Poll/',
63  'ilClassificationBlockGUI' => 'Services/Classification/',
64  );
65 
66  static protected $block_types = array(
67  "ilPDMailBlockGUI" => "pdmail",
68  "ilPDNotesBlockGUI" => "pdnotes",
69  "ilUsersOnlineBlockGUI" => "pdusers",
70  "ilPDNewsBlockGUI" => "pdnews",
71  "ilBookmarkBlockGUI" => "pdbookm",
72  "ilNewsForContextBlockGUI" => "news",
73  "ilCalendarBlockGUI" => "cal",
74  "ilPDCalendarBlockGUI" => "pdcal",
75  "ilExternalFeedBlockGUI" => "feed",
76  "ilPDExternalFeedBlockGUI" => "pdfeed",
77  "ilPDSysMessageBlockGUI" => "pdsysmess",
78  "ilPDSelectedItemsBlockGUI" => "pditems",
79  'ilPDTaggingBlockGUI' => 'pdtag',
80  'ilChatroomBlockGUI' => 'chatviewer',
81  'ilPollBlockGUI' => 'poll',
82  'ilClassificationBlockGUI' => 'clsfct',
83  );
84 
85 
86  protected $default_blocks = array(
87  "cat" => array(
88  "ilNewsForContextBlockGUI" => IL_COL_RIGHT,
89  "ilClassificationBlockGUI" => IL_COL_RIGHT
90  ),
91  "crs" => array(
92  "ilNewsForContextBlockGUI" => IL_COL_RIGHT,
93  "ilCalendarBlockGUI" => IL_COL_RIGHT,
94  "ilClassificationBlockGUI" => IL_COL_RIGHT
95  ),
96  "grp" => array(
97  "ilNewsForContextBlockGUI" => IL_COL_RIGHT,
98  "ilCalendarBlockGUI" => IL_COL_RIGHT,
99  "ilClassificationBlockGUI" => IL_COL_RIGHT
100  ),
101  "frm" => array("ilNewsForContextBlockGUI" => IL_COL_RIGHT),
102  "root" => array(),
103  "info" => array(
104  "ilNewsForContextBlockGUI" => IL_COL_RIGHT),
105  "pd" => array(
106  "ilPDCalendarBlockGUI" => IL_COL_RIGHT,
107  "ilPDSysMessageBlockGUI" => IL_COL_LEFT,
108  "ilPDNewsBlockGUI" => IL_COL_LEFT,
109  "ilPDSelectedItemsBlockGUI" => IL_COL_CENTER,
110  "ilPDMailBlockGUI" => IL_COL_RIGHT,
111  "ilPDNotesBlockGUI" => IL_COL_RIGHT,
112  "ilUsersOnlineBlockGUI" => IL_COL_RIGHT,
113  "ilBookmarkBlockGUI" => IL_COL_RIGHT,
114  "ilPDTaggingBlockGUI" => IL_COL_RIGHT,
115  "ilChatroomBlockGUI" => IL_COL_RIGHT
116  )
117  );
118 
119  // these are only for pd blocks
120  // other blocks are rep objects now
121  protected $custom_blocks = array(
122  "cat" => array(),
123  "crs" => array(),
124  "grp" => array(),
125  "frm" => array(),
126  "root" => array(),
127  "info" => array(),
128  "fold" => array(),
129  "pd" => array("ilPDExternalFeedBlockGUI")
130  );
131 
132  // check global activation for these block types
133  // @todo: add calendar
135  array("news" => true,
136  "cal" => true,
137  "pdcal" => true,
138  "pdnews" => true,
139  "pdfeed" => true,
140  "pdusers" => true,
141  "pdbookm" => true,
142  "pdtag" => true,
143  "pdnotes" => true,
144  "chatviewer" => true,
145  "tagcld" => true);
146 
147  protected $check_nr_limit =
148  array("pdfeed" => true);
149 
155  public function __construct($a_col_type = "", $a_side = "", $use_std_context = false)
156  {
157  $this->setColType($a_col_type);
158  $this->setSide($a_side);
159  }
160 
171  public static function addCustomBlockLocation($className, $path)
172  {
173  self::$locations[$className] = $path;
174  }
175 
186  public static function addCustomBlockType($className, $identifier)
187  {
188  self::$block_types[$className] = $identifier;
189  }
190 
196  static function getCmdSide()
197  {
198  return $_GET["col_side"];
199  }
200 
206  function setColType($a_coltype)
207  {
208  $this->coltype = $a_coltype;
209  }
210 
216  function getColType()
217  {
218  return $this->coltype;
219  }
220 
226  function setSide($a_side)
227  {
228  $this->side = $a_side;
229  }
230 
236  function getSide()
237  {
238  return $this->side;
239  }
240 
246  function setEnableEdit($a_enableedit)
247  {
248  $this->enableedit = $a_enableedit;
249  }
250 
256  function getEnableEdit()
257  {
258  return $this->enableedit;
259  }
260 
266  function setRepositoryMode($a_repositorymode)
267  {
268  $this->repositorymode = $a_repositorymode;
269  }
270 
276  function getRepositoryMode()
277  {
278  return $this->repositorymode;
279  }
280 
286  function setAdminCommands($a_admincommands)
287  {
288  $this->admincommands = $a_admincommands;
289  }
290 
296  function getAdminCommands()
297  {
298  return $this->admincommands;
299  }
300 
306  function setMovementMode($a_movementmode)
307  {
308  $this->movementmode = $a_movementmode;
309  }
310 
316  function getMovementMode()
317  {
318  return $this->movementmode;
319  }
320 
326  function setEnableMovement($a_enablemovement)
327  {
328  $this->enablemovement = $a_enablemovement;
329  }
330 
336  function getEnableMovement()
337  {
338  return $this->enablemovement;
339  }
340 
344  static function getScreenMode()
345  {
346  global $ilCtrl;
347 
348  if ($ilCtrl->getCmdClass() == "ilcolumngui")
349  {
350  switch ($ilCtrl->getCmd())
351  {
352  case "addBlock":
353  return IL_SCREEN_CENTER;
354  }
355  }
356 
357  $cur_block_type = "";
358  if (isset($_GET["block_type"]) && $_GET["block_type"])
359  {
360  $cur_block_type = $_GET["block_type"];
361  }
362  else if (isset($_POST["block_type"]))
363  {
364  $cur_block_type = $_POST["block_type"];
365  }
366 
367  if ($class = array_search($cur_block_type, self::$block_types))
368  {
369  include_once("./".self::$locations[$class]."classes/".
370  "class.".$class.".php");
371  return call_user_func(array($class, 'getScreenMode'));
372  }
373 
374  return IL_SCREEN_SIDE;
375  }
376 
384  function setBlockProperty($a_block_type, $a_property, $a_value)
385  {
386  $this->block_property[$a_block_type][$a_property] = $a_value;
387  }
388 
389  function getBlockProperties($a_block_type)
390  {
391  return $this->block_property[$a_block_type];
392  }
393 
394  function setAllBlockProperties($a_block_properties)
395  {
396  $this->block_property = $a_block_properties;
397  }
398 
404  function setRepositoryItems($a_repositoryitems)
405  {
406  $this->repositoryitems = $a_repositoryitems;
407  }
408 
415  {
416  return $this->repositoryitems;
417  }
418 
422  function &executeCommand()
423  {
424  global $ilCtrl;
425 
426  $ilCtrl->setParameter($this, "col_side" ,$this->getSide());
427  //$ilCtrl->saveParameter($this, "col_side");
428 
429  $next_class = $ilCtrl->getNextClass();
430  $cmd = $ilCtrl->getCmd("getHTML");
431 
432  $cur_block_type = ($_GET["block_type"])
433  ? $_GET["block_type"]
434  : $_POST["block_type"];
435 
436  if ($next_class != "")
437  {
438  // forward to block
439  if ($gui_class = array_search($cur_block_type, self::$block_types))
440  {
441  include_once("./".self::$locations[$gui_class]."classes/".
442  "class.".$gui_class.".php");
443  $ilCtrl->setParameter($this, "block_type", $cur_block_type);
444  $block_gui = new $gui_class();
445  $block_gui->setProperties($this->block_property[$cur_block_type]);
446  $block_gui->setRepositoryMode($this->getRepositoryMode());
447  $block_gui->setEnableEdit($this->getEnableEdit());
448  $block_gui->setAdminCommands($this->getAdminCommands());
449 
450  if (in_array($gui_class, $this->custom_blocks[$this->getColType()]) ||
451  in_array($cur_block_type, $this->rep_block_types))
452  {
453  $block_class = substr($gui_class, 0, strlen($gui_class)-3);
454  include_once("./".self::$locations[$gui_class]."classes/".
455  "class.".$block_class.".php");
456  $app_block = new $block_class($_GET["block_id"]);
457  $block_gui->setBlock($app_block);
458  }
459  $html = $ilCtrl->forwardCommand($block_gui);
460  $ilCtrl->setParameter($this, "block_type", "");
461 
462  return $html;
463  }
464  }
465  else
466  {
467  return $this->$cmd();
468  }
469  }
470 
474  function getHTML()
475  {
476  global $ilCtrl, $ilBench;
477 
478  $ilBench->start("Column", "getHTML");
479 
480  $ilCtrl->setParameter($this, "col_side" ,$this->getSide());
481 
482  $this->tpl = new ilTemplate("tpl.column.html", true, true, "Services/Block");
483 
484  $ilBench->start("Column", "determineBlocks");
485  $this->determineBlocks();
486  $ilBench->stop("Column", "determineBlocks");
487 
488  $ilBench->start("Column", "showBlocks");
489  $this->showBlocks();
490  $ilBench->stop("Column", "showBlocks");
491 
492  if ($this->getEnableEdit() || !$this->getRepositoryMode())
493  {
494  $this->addHiddenBlockSelector();
495  }
496 
497  $ilBench->stop("Column", "getHTML");
498 
499  return $this->tpl->get();
500  }
501 
505  function showBlocks()
506  {
507  global $ilCtrl, $lng, $ilUser, $ilBench;
508 
509  $i = 1;
510  $sum_moveable = count($this->blocks[$this->getSide()]);
511 
512  foreach($this->blocks[$this->getSide()] as $block)
513  {
514  if ($ilCtrl->getContextObjType() != "user" ||
515  ilBlockSetting::_lookupDetailLevel($block["type"],
516  $ilUser->getId(), $block["id"]) > 0)
517  {
518  $gui_class = $block["class"];
519  $block_class = substr($block["class"], 0, strlen($block["class"])-3);
520 
521  // get block gui class
522  include_once("./".self::$locations[$gui_class]."classes/".
523  "class.".$gui_class.".php");
524  $ilBench->start("Column", "instantiate-".$block["type"]);
525  $block_gui = new $gui_class();
526  $ilBench->stop("Column", "instantiate-".$block["type"]);
527  if (isset($this->block_property[$block["type"]]))
528  {
529  $block_gui->setProperties($this->block_property[$block["type"]]);
530  }
531  $block_gui->setRepositoryMode($this->getRepositoryMode());
532  $block_gui->setEnableEdit($this->getEnableEdit());
533  $block_gui->setAdminCommands($this->getAdminCommands());
534 
535  // get block for custom blocks
536  if ($block["custom"])
537  {
538  $path = "./".self::$locations[$gui_class]."classes/".
539  "class.".$block_class.".php";
540  if(file_exists($path))
541  {
542  include_once($path);
543  $app_block = new $block_class($block["id"]);
544  }
545  else
546  {
547  // we only need generic block
548  $app_block = new ilCustomBlock($block["id"]);
549  }
550  $block_gui->setBlock($app_block);
551  if (isset($block["ref_id"]))
552  {
553  $block_gui->setRefId($block["ref_id"]);
554  }
555  }
556 
557  $ilCtrl->setParameter($this, "block_type", $block_gui->getBlockType());
558  $this->tpl->setCurrentBlock("col_block");
559 
560  $ilBench->start("Column", "showBlocks-".$block_gui->getBlockType());
561  $html = $ilCtrl->getHTML($block_gui);
562  $ilBench->stop("Column", "showBlocks-".$block_gui->getBlockType());
563 
564  // dummy block, if non visible, but movement is ongoing
565  if ($html == "" && $this->getRepositoryMode() &&
566  $this->getMovementMode())
567  {
568  include_once("./Services/Block/classes/class.ilDummyBlockGUI.php");
569  $bl = new ilDummyBlockGUI();
570  $bl->setBlockId($block["id"]);
571  $bl->setBlockType($block["type"]);
572  $bl->setTitle($lng->txt("invisible_block"));
573  $bl->setConfigMode($this->getMovementMode());
574  $html = $bl->getHTML();
575  }
576 
577  // don't render a block if it's empty
578  if ($html != "")
579  {
580  $this->tpl->setVariable("BLOCK", $html);
581  $this->tpl->parseCurrentBlock();
582  $ilCtrl->setParameter($this, "block_type", "");
583  }
584 
585  // count (moveable) blocks
586  if ($block["type"] != "pdsysmess" && $block["type"] != "pdfeedb" &&
587  $block["type"] != "news")
588  {
589  $i++;
590  }
591  else
592  {
593  $sum_moveable--;
594  }
595  }
596  }
597  }
598 
602  function addHiddenBlockSelector()
603  {
610  global $lng, $ilUser, $ilCtrl, $tpl;
611 
612  // show selector for hidden blocks
613  include_once("Services/Block/classes/class.ilBlockSetting.php");
614  $hidden_blocks = array();
615 
616  foreach($this->blocks[$this->getSide()] as $block)
617  {
618  include_once("./".self::$locations[$block["class"]]."classes/".
619  "class.".$block["class"].".php");
620 
621  if ($block["custom"] == false)
622  {
623  if ($ilCtrl->getContextObjType() == "user") // personal desktop
624  {
625  if (ilBlockSetting::_lookupDetailLevel($block["type"], $ilUser->getId()) == 0)
626  {
627  $hidden_blocks[$block["type"]] = $lng->txt('block_show_'.$block["type"]);
628  }
629  }
630  else if ($ilCtrl->getContextObjType() != "")
631  {
632  if (ilBlockSetting::_lookupDetailLevel($block["type"], $ilUser->getId(),
633  $ilCtrl->getContextObjId()) == 0)
634  {
635  $hidden_blocks[$block["type"]."_".$ilCtrl->getContextObjId()] = $lng->txt('block_show_'.$block["type"]);
636  }
637  }
638  }
639  else
640  {
641  if (ilBlockSetting::_lookupDetailLevel($block["type"], $ilUser->getId(),
642  $block["id"]) == 0)
643  {
644  include_once("./Services/Block/classes/class.ilCustomBlock.php");
645  $cblock = new ilCustomBlock($block["id"]);
646  $hidden_blocks[$block["type"]."_".$block["id"]] = sprintf($lng->txt('block_show_x'), $cblock->getTitle());
647  }
648  }
649  }
650  if(count($hidden_blocks) > 0)
651  {
652  foreach($hidden_blocks as $id => $title)
653  {
654  $ilCtrl->setParameter($this, 'block', $id);
655  $this->action_menu->addItem($title, '', $ilCtrl->getLinkTarget($this, 'activateBlock'));
656  $ilCtrl->setParameter($this, 'block', '');
657  }
658  }
659 
660  // create block selection list
661  if (!$this->getRepositoryMode() || $this->getEnableEdit())
662  {
663  $add_blocks = array();
664  if ($this->getSide() == IL_COL_RIGHT)
665  {
666  if (is_array($this->custom_blocks[$this->getColType()]))
667  {
668  foreach($this->custom_blocks[$this->getColType()] as $block_class)
669  {
670  include_once("./".self::$locations[$block_class]."classes/".
671  "class.".$block_class.".php");
672  $block_type = call_user_func(array($block_class, 'getBlockType'));
673 
674  // check if block type is globally (de-)activated
675  if ($this->isGloballyActivated($block_type))
676  {
677  // check if number of blocks is limited
678  if (!$this->exceededLimit($block_type))
679  {
680  $add_blocks[$block_type] = $lng->txt('block_create_'.$block_type);
681  }
682  }
683  }
684  }
685  }
686  if(count($add_blocks) > 0)
687  {
688  foreach($add_blocks as $id => $title)
689  {
690  $ilCtrl->setParameter($this, 'block_type', $id);
691  $this->action_menu->addItem($title, '', $ilCtrl->getLinkTarget($this, 'addBlock'));
692  $ilCtrl->setParameter($this, 'block_type', '');
693  }
694  }
695  }
696 
697  $this->addBlockSorting();
698  }
699 
703  protected function addBlockSorting()
704  {
705  if($this->getSide() == IL_COL_CENTER && $this->getEnableMovement())
706  {
712  global $ilBrowser, $tpl, $ilCtrl;
713 
714  include_once 'Services/jQuery/classes/class.iljQueryUtil.php';
717 
718  if($ilBrowser->isMobile() || $ilBrowser->isIpad())
719  {
720  $tpl->addJavaScript('./Services/jQuery/js/jquery.ui.touch-punch.min.js');
721  }
722  $tpl->addJavaScript('./Services/Block/js/block_sorting.js');
723 
724  // set the col_side parameter to pass the ctrl structure flow
725  $ilCtrl->setParameter($this, 'col_side', IL_COL_CENTER);
726 
727  $this->tpl->setVariable('BLOCK_SORTING_STORAGE_URL', $ilCtrl->getLinkTarget($this, 'saveBlockSortingAsynch', '', true, false));
728  $this->tpl->setVariable('BLOCK_COLUMNS', json_encode(array('il_left_col', 'il_right_col')));
729  $this->tpl->setVariable('BLOCK_COLUMNS_SELECTOR', '#il_left_col,#il_right_col');
730  $this->tpl->setVariable('BLOCK_COLUMNS_PARAMETERS', json_encode(array(IL_COL_LEFT, IL_COL_RIGHT)));
731 
732  // restore col_side parameter
733  $ilCtrl->setParameter($this, 'col_side', $this->getSide());
734  }
735  }
736 
740  function updateBlock()
741  {
742  global $ilCtrl, $ilBench;
743 
744  $this->determineBlocks();
745  $i = 1;
746  $sum_moveable = count($this->blocks[$this->getSide()]);
747 
748  foreach ($this->blocks[$this->getSide()] as $block)
749  {
750 
751  include_once("./".self::$locations[$block["class"]]."classes/".
752  "class.".$block["class"].".php");
753 
754  // set block id to context obj id,
755  // if block is not a custom block and context is not personal desktop
756  if (!$block["custom"] && $ilCtrl->getContextObjType() != "" && $ilCtrl->getContextObjType() != "user")
757  {
758  $block["id"] = $ilCtrl->getContextObjId();
759  }
760 
761  //if (is_int(strpos($_GET["block_id"], "block_".$block["type"]."_".$block["id"])))
762 
763  if ($_GET["block_id"] == "block_".$block["type"]."_".$block["id"])
764  {
765  $gui_class = $block["class"];
766  $block_class = substr($block["class"], 0, strlen($block["class"])-3);
767 
768  $block_gui = new $gui_class();
769  $block_gui->setProperties($this->block_property[$block["type"]]);
770  $block_gui->setRepositoryMode($this->getRepositoryMode());
771  $block_gui->setEnableEdit($this->getEnableEdit());
772  $block_gui->setAdminCommands($this->getAdminCommands());
773 
774  // get block for custom blocks
775  if ($block["custom"])
776  {
777  include_once("./".self::$locations[$gui_class]."classes/".
778  "class.".$block_class.".php");
779  $app_block = new $block_class($block["id"]);
780  $block_gui->setBlock($app_block);
781  $block_gui->setRefId($block["ref_id"]);
782  }
783 
784  $ilCtrl->setParameter($this, "block_type", $block["type"]);
785  echo $ilCtrl->getHTML($block_gui);
786  $ilBench->save();
787  exit;
788  }
789 
790  // count (moveable) blocks
791  if ($block["type"] != "pdsysmess" && $block["type"] != "pdfeedb"
792  && $block["type"] != "news")
793  {
794  $i++;
795  }
796  else
797  {
798  $sum_moveable--;
799  }
800  }
801  echo "Error: ilColumnGUI::updateBlock: Block '".
802  $_GET["block_id"]."' unknown.";
803  exit;
804  }
805 
809  function activateBlock()
810  {
811  global $ilUser, $ilCtrl;
812 
813  if ($_GET["block"] != "")
814  {
815  $block = explode("_", $_GET["block"]);
816  include_once("Services/Block/classes/class.ilBlockSetting.php");
817  ilBlockSetting::_writeDetailLevel($block[0], 2, $ilUser->getId(), $block[1]);
818  }
819 
820  $ilCtrl->returnToParent($this);
821  }
822 
826  function addBlock()
827 
828  {
829  global $ilCtrl;
830 
831  $class = array_search($_GET["block_type"], self::$block_types);
832 
833  $ilCtrl->setCmdClass($class);
834  $ilCtrl->setCmd("create");
835  include_once("./".self::$locations[$class]."classes/class.".$class.".php");
836  $block_gui = new $class();
837  $block_gui->setProperties($this->block_property[$_GET["block_type"]]);
838  $block_gui->setRepositoryMode($this->getRepositoryMode());
839  $block_gui->setEnableEdit($this->getEnableEdit());
840  $block_gui->setAdminCommands($this->getAdminCommands());
841 
842  $ilCtrl->setParameter($this, "block_type", $_GET["block_type"]);
843  $html = $ilCtrl->forwardCommand($block_gui);
844  $ilCtrl->setParameter($this, "block_type", "");
845  return $html;
846  }
847 
851  function determineBlocks()
852  {
853  global $ilUser, $ilCtrl, $ilSetting;
854 
855  include_once("./Services/Block/classes/class.ilBlockSetting.php");
856  $this->blocks[IL_COL_LEFT] = array();
857  $this->blocks[IL_COL_RIGHT] = array();
858  $this->blocks[IL_COL_CENTER] = array();
859 
860  $user_id = ($this->getColType() == "pd")
861  ? $ilUser->getId()
862  : 0;
863 
864  $def_nr = 1000;
865  if (is_array($this->default_blocks[$this->getColType()]))
866  {
867  foreach($this->default_blocks[$this->getColType()] as $class => $def_side)
868  {
869  $type = self::$block_types[$class];
870 
871  if ($this->isGloballyActivated($type))
872  {
873  $nr = ilBlockSetting::_lookupNr($type, $user_id);
874  if ($nr === false)
875  {
876  $nr = $def_nr++;
877  }
878 
879 
880  // extra handling for system messages, feedback block and news
881  if ($type == "news") // always show news first
882  {
883  $nr = -15;
884  }
885  if ($type == "cal")
886  {
887  $nr = -8;
888  }
889  if ($type == "pdsysmess") // always show sys mess first
890  {
891 // $nr = -15;
892  }
893  if ($type == "pdfeedb") // always show feedback request second
894  {
895  $nr = -10;
896  }
898  if ($side === false)
899  {
900  $side = $def_side;
901  }
902 
903  $this->blocks[$side][] = array(
904  "nr" => $nr,
905  "class" => $class,
906  "type" => $type,
907  "id" => 0,
908  "custom" => false);
909  }
910  }
911  }
912 
913  if (!$this->getRepositoryMode())
914  {
915  include_once("./Services/Block/classes/class.ilCustomBlock.php");
916  $custom_block = new ilCustomBlock();
917  $custom_block->setContextObjId($ilCtrl->getContextObjId());
918  $custom_block->setContextObjType($ilCtrl->getContextObjType());
919  $c_blocks = $custom_block->queryBlocksForContext();
920 
921  foreach($c_blocks as $c_block)
922  {
923  $type = $c_block["type"];
924 
925  if ($this->isGloballyActivated($type))
926  {
927  $class = array_search($type, self::$block_types);
928  $nr = ilBlockSetting::_lookupNr($type, $user_id, $c_block["id"]);
929  if ($nr === false)
930  {
931  $nr = $def_nr++;
932  }
933  $side = ilBlockSetting::_lookupSide($type, $user_id, $c_block["id"]);
934  if ($side === false)
935  {
937  }
938 
939  $this->blocks[$side][] = array(
940  "nr" => $nr,
941  "class" => $class,
942  "type" => $type,
943  "id" => $c_block["id"],
944  "custom" => true);
945  }
946  }
947  }
948  else // get all subitems
949  {
950  include_once("./Services/Block/classes/class.ilCustomBlock.php");
951  $rep_items = $this->getRepositoryItems();
952 
953  foreach($this->rep_block_types as $block_type)
954  {
955  if ($this->isGloballyActivated($block_type))
956  {
957  if (!is_array($rep_items[$block_type]))
958  {
959  continue;
960  }
961  foreach($rep_items[$block_type] as $item)
962  {
963  $costum_block = new ilCustomBlock();
964  $costum_block->setContextObjId($item["obj_id"]);
965  $costum_block->setContextObjType($block_type);
966  $c_blocks = $costum_block->queryBlocksForContext();
967  $c_block = $c_blocks[0];
968 
969  $type = $block_type;
970  $class = array_search($type, self::$block_types);
971  $nr = ilBlockSetting::_lookupNr($type, $user_id, $c_block["id"]);
972  if ($nr === false)
973  {
974  $nr = $def_nr++;
975  }
976  $side = ilBlockSetting::_lookupSide($type, $user_id, $c_block["id"]);
977  if ($side === false)
978  {
980  }
981 
982  $this->blocks[$side][] = array(
983  "nr" => $nr,
984  "class" => $class,
985  "type" => $type,
986  "id" => $c_block["id"],
987  "custom" => true,
988  "ref_id" => $item["ref_id"]);
989  }
990  }
991  }
992 
993  // repository object custom blocks
994  include_once("./Services/Block/classes/class.ilCustomBlock.php");
995  $custom_block = new ilCustomBlock();
996  $custom_block->setContextObjId($ilCtrl->getContextObjId());
997  $custom_block->setContextObjType($ilCtrl->getContextObjType());
998  $c_blocks = $custom_block->queryBlocksForContext(false); // get all sub-object types
999 
1000  foreach($c_blocks as $c_block)
1001  {
1002  $type = $c_block["type"];
1003  $class = array_search($type, self::$block_types);
1004 
1005  if($class)
1006  {
1007  $nr = $def_nr++;
1008  $side = IL_COL_RIGHT;
1009 
1010  $this->blocks[$side][] = array(
1011  "nr" => $nr,
1012  "class" => $class,
1013  "type" => $type,
1014  "id" => $c_block["id"],
1015  "custom" => true);
1016  }
1017  }
1018  }
1019 
1020 
1021  $this->blocks[IL_COL_LEFT] =
1022  ilUtil::sortArray($this->blocks[IL_COL_LEFT], "nr", "asc", true);
1023  $this->blocks[IL_COL_RIGHT] =
1024  ilUtil::sortArray($this->blocks[IL_COL_RIGHT], "nr", "asc", true);
1025  $this->blocks[IL_COL_CENTER] =
1026  ilUtil::sortArray($this->blocks[IL_COL_CENTER], "nr", "asc", true);
1027 
1028  }
1029 
1033  protected function isGloballyActivated($a_type)
1034  {
1035 
1036  global $ilSetting;
1037  if (isset($this->check_global_activation[$a_type]) && $this->check_global_activation[$a_type])
1038  {
1039  if ($a_type == 'pdbookm')
1040  {
1041  if (!$ilSetting->get("disable_bookmarks"))
1042  {
1043  return true;
1044  }
1045  return false;
1046  }
1047  else if ($a_type == 'pdnotes')
1048  {
1049  if (!$ilSetting->get("disable_notes"))
1050  {
1051  return true;
1052  }
1053  return false;
1054  }
1055  elseif($a_type == 'news')
1056  {
1057  include_once 'Services/Container/classes/class.ilContainer.php';
1058  return
1059  $ilSetting->get('block_activated_news') &&
1061  $GLOBALS['ilCtrl']->getContextObjId(),
1062  'cont_show_news',
1063  true
1064  );
1065  }
1066  else if ($ilSetting->get("block_activated_".$a_type))
1067  {
1068  return true;
1069  }
1070  elseif($a_type == 'cal')
1071  {
1072  include_once('./Services/Calendar/classes/class.ilCalendarSettings.php');
1073  return ilCalendarSettings::lookupCalendarActivated($GLOBALS['ilCtrl']->getContextObjId());
1074 
1075  }
1076  elseif($a_type == 'pdcal')
1077  {
1078  include_once('./Services/Calendar/classes/class.ilCalendarSettings.php');
1079  return ilCalendarSettings::_getInstance()->isEnabled();
1080  }
1081  elseif($a_type == "tagcld")
1082  {
1083  $tags_active = new ilSetting("tags");
1084  return (bool)$tags_active->get("enable", false);
1085  }
1086  return false;
1087  }
1088  return true;
1089  }
1090 
1094  protected function exceededLimit($a_type)
1095  {
1096  global $ilSetting, $ilCtrl;
1097 
1098  if ($this->check_nr_limit[$a_type])
1099  {
1100  if (!$this->getRepositoryMode())
1101  {
1102  include_once("./Services/Block/classes/class.ilCustomBlock.php");
1103  $costum_block = new ilCustomBlock();
1104  $costum_block->setContextObjId($ilCtrl->getContextObjId());
1105  $costum_block->setContextObjType($ilCtrl->getContextObjType());
1106  $costum_block->setType($a_type);
1107  $res = $costum_block->queryCntBlockForContext();
1108  $cnt = (int) $res[0]["cnt"];
1109  }
1110  else
1111  {
1112  return false; // not implemented for repository yet
1113  }
1114 
1115 
1116  if ($ilSetting->get("block_limit_".$a_type) > $cnt)
1117  {
1118  return false;
1119  }
1120  else
1121  {
1122  return true;
1123  }
1124  }
1125  return false;
1126  }
1127 
1131  public function saveBlockSortingAsynch()
1132  {
1136  global $ilUser;
1137 
1138  $response = new stdClass();
1139  $response->success = false;
1140 
1141  if(!isset($_POST[IL_COL_LEFT]['sequence']) && !isset($_POST[IL_COL_RIGHT]['sequence']))
1142  {
1143  echo json_encode($response);
1144  return;
1145  };
1146 
1147  if(in_array($this->getColType(), array('pd')))
1148  {
1149  $response->success = true;
1150 
1151  foreach(array(IL_COL_LEFT => (array)$_POST[IL_COL_LEFT]['sequence'], IL_COL_RIGHT => (array)$_POST[IL_COL_RIGHT]['sequence']) as $side => $blocks)
1152  {
1153  $i = 2;
1154  foreach($blocks as $block)
1155  {
1156  $bid = explode('_', $block);
1157  ilBlockSetting::_writeNumber($bid[1], $i, $ilUser->getId(), $bid[2]);
1158  ilBlockSetting::_writeSide($bid[1], $side, $ilUser->getId(), $bid[2]);
1159 
1160  $i +=2;
1161  }
1162  }
1163  }
1164 
1165  echo json_encode($response);
1166  exit();
1167  }
1168 
1173  public function setActionMenu($action_menu)
1174  {
1175  $this->action_menu = $action_menu;
1176  return $this;
1177  }
1178 
1182  public function getActionMenu()
1183  {
1184  return $this->action_menu;
1185  }
1186 }