ILIAS  Release_4_4_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  "ilHtmlBlockGUI" => "Services/Block/",
61  'ilPDTaggingBlockGUI' => 'Services/Tagging/',
62  'ilChatroomBlockGUI' => 'Modules/Chatroom/',
63  'ilPollBlockGUI' => 'Modules/Poll/'
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  "ilHtmlBlockGUI" => "html",
80  'ilPDTaggingBlockGUI' => 'pdtag',
81  'ilChatroomBlockGUI' => 'chatviewer',
82  'ilPollBlockGUI' => 'poll'
83  );
84 
85 
86  protected $default_blocks = array(
87  "cat" => array("ilNewsForContextBlockGUI" => IL_COL_RIGHT),
88  "crs" => array(
89  "ilNewsForContextBlockGUI" => IL_COL_RIGHT,
90  "ilCalendarBlockGUI" => IL_COL_RIGHT
91  ),
92  "grp" => array(
93  "ilNewsForContextBlockGUI" => IL_COL_RIGHT,
94  "ilCalendarBlockGUI" => IL_COL_RIGHT),
95  "frm" => array("ilNewsForContextBlockGUI" => IL_COL_RIGHT),
96  "root" => array(),
97  "info" => array(
98  "ilNewsForContextBlockGUI" => IL_COL_RIGHT),
99  "pd" => array(
100  "ilPDCalendarBlockGUI" => IL_COL_RIGHT,
101  "ilPDSysMessageBlockGUI" => IL_COL_LEFT,
102  "ilPDNewsBlockGUI" => IL_COL_LEFT,
103  "ilPDSelectedItemsBlockGUI" => IL_COL_CENTER,
104  "ilPDMailBlockGUI" => IL_COL_RIGHT,
105  "ilPDNotesBlockGUI" => IL_COL_RIGHT,
106  "ilUsersOnlineBlockGUI" => IL_COL_RIGHT,
107  "ilBookmarkBlockGUI" => IL_COL_RIGHT,
108  "ilPDTaggingBlockGUI" => IL_COL_RIGHT,
109  "ilChatroomBlockGUI" => IL_COL_RIGHT
110  )
111  );
112 
113  // these are only for pd blocks
114  // other blocks are rep objects now
115  protected $custom_blocks = array(
116  "cat" => array(),
117  "crs" => array(),
118  "grp" => array(),
119  "frm" => array(),
120  "root" => array(),
121  "info" => array(),
122  "pd" => array("ilPDExternalFeedBlockGUI")
123  );
124 
125  // check global activation for these block types
126  // @todo: add calendar
128  array("news" => true,
129  "cal" => true,
130  "pdcal" => true,
131  "pdnews" => true,
132  "pdfeed" => true,
133  "pdusers" => true,
134  "pdbookm" => true,
135  "pdtag" => true,
136  "pdnotes" => true,
137  "chatviewer" => true);
138 
139  protected $check_nr_limit =
140  array("pdfeed" => true);
141 
147  public function __construct($a_col_type = "", $a_side = "", $use_std_context = false)
148  {
149  $this->setColType($a_col_type);
150  $this->setSide($a_side);
151  }
152 
163  public static function addCustomBlockLocation($className, $path)
164  {
165  self::$locations[$className] = $path;
166  }
167 
178  public static function addCustomBlockType($className, $identifier)
179  {
180  self::$block_types[$className] = $identifier;
181  }
182 
188  static function getCmdSide()
189  {
190  return $_GET["col_side"];
191  }
192 
198  function setColType($a_coltype)
199  {
200  $this->coltype = $a_coltype;
201  }
202 
208  function getColType()
209  {
210  return $this->coltype;
211  }
212 
218  function setSide($a_side)
219  {
220  $this->side = $a_side;
221  }
222 
228  function getSide()
229  {
230  return $this->side;
231  }
232 
238  function setEnableEdit($a_enableedit)
239  {
240  $this->enableedit = $a_enableedit;
241  }
242 
248  function getEnableEdit()
249  {
250  return $this->enableedit;
251  }
252 
258  function setRepositoryMode($a_repositorymode)
259  {
260  $this->repositorymode = $a_repositorymode;
261  }
262 
268  function getRepositoryMode()
269  {
270  return $this->repositorymode;
271  }
272 
278  function setAdminCommands($a_admincommands)
279  {
280  $this->admincommands = $a_admincommands;
281  }
282 
288  function getAdminCommands()
289  {
290  return $this->admincommands;
291  }
292 
298  function setMovementMode($a_movementmode)
299  {
300  $this->movementmode = $a_movementmode;
301  }
302 
308  function getMovementMode()
309  {
310  return $this->movementmode;
311  }
312 
318  function setEnableMovement($a_enablemovement)
319  {
320  $this->enablemovement = $a_enablemovement;
321  }
322 
328  function getEnableMovement()
329  {
330  return $this->enablemovement;
331  }
332 
336  static function getScreenMode()
337  {
338  global $ilCtrl;
339 
340  if ($ilCtrl->getCmdClass() == "ilcolumngui")
341  {
342  switch ($ilCtrl->getCmd())
343  {
344  case "addBlock":
345  return IL_SCREEN_CENTER;
346  }
347  }
348 
349  $cur_block_type = "";
350  if (isset($_GET["block_type"]) && $_GET["block_type"])
351  {
352  $cur_block_type = $_GET["block_type"];
353  }
354  else if (isset($_POST["block_type"]))
355  {
356  $cur_block_type = $_POST["block_type"];
357  }
358 
359  if ($class = array_search($cur_block_type, self::$block_types))
360  {
361  include_once("./".self::$locations[$class]."classes/".
362  "class.".$class.".php");
363  return call_user_func(array($class, 'getScreenMode'));
364  }
365 
366  return IL_SCREEN_SIDE;
367  }
368 
376  function setBlockProperty($a_block_type, $a_property, $a_value)
377  {
378  $this->block_property[$a_block_type][$a_property] = $a_value;
379  }
380 
381  function getBlockProperties($a_block_type)
382  {
383  return $this->block_property[$a_block_type];
384  }
385 
386  function setAllBlockProperties($a_block_properties)
387  {
388  $this->block_property = $a_block_properties;
389  }
390 
396  function setRepositoryItems($a_repositoryitems)
397  {
398  $this->repositoryitems = $a_repositoryitems;
399  }
400 
407  {
408  return $this->repositoryitems;
409  }
410 
414  function &executeCommand()
415  {
416  global $ilCtrl;
417 
418  $ilCtrl->setParameter($this, "col_side" ,$this->getSide());
419  //$ilCtrl->saveParameter($this, "col_side");
420 
421  $next_class = $ilCtrl->getNextClass();
422  $cmd = $ilCtrl->getCmd("getHTML");
423 
424  $cur_block_type = ($_GET["block_type"])
425  ? $_GET["block_type"]
426  : $_POST["block_type"];
427 
428  if ($next_class != "")
429  {
430  // forward to block
431  if ($gui_class = array_search($cur_block_type, self::$block_types))
432  {
433  include_once("./".self::$locations[$gui_class]."classes/".
434  "class.".$gui_class.".php");
435  $ilCtrl->setParameter($this, "block_type", $cur_block_type);
436  $block_gui = new $gui_class();
437  $block_gui->setProperties($this->block_property[$cur_block_type]);
438  $block_gui->setRepositoryMode($this->getRepositoryMode());
439  $block_gui->setEnableEdit($this->getEnableEdit());
440  $block_gui->setAdminCommands($this->getAdminCommands());
441 
442  if (in_array($gui_class, $this->custom_blocks[$this->getColType()]) ||
443  in_array($cur_block_type, $this->rep_block_types))
444  {
445  $block_class = substr($gui_class, 0, strlen($gui_class)-3);
446  include_once("./".self::$locations[$gui_class]."classes/".
447  "class.".$block_class.".php");
448  $app_block = new $block_class($_GET["block_id"]);
449  $block_gui->setBlock($app_block);
450  }
451  $html = $ilCtrl->forwardCommand($block_gui);
452  $ilCtrl->setParameter($this, "block_type", "");
453 
454  return $html;
455  }
456  }
457  else
458  {
459  return $this->$cmd();
460  }
461  }
462 
466  function getHTML()
467  {
468  global $ilCtrl, $ilBench;
469 
470  $ilBench->start("Column", "getHTML");
471 
472  $ilCtrl->setParameter($this, "col_side" ,$this->getSide());
473 
474  $this->tpl = new ilTemplate("tpl.column.html", true, true, "Services/Block");
475 
476  $ilBench->start("Column", "determineBlocks");
477  $this->determineBlocks();
478  $ilBench->stop("Column", "determineBlocks");
479 
480  $ilBench->start("Column", "showBlocks");
481  $this->showBlocks();
482  $ilBench->stop("Column", "showBlocks");
483 
484  if ($this->getEnableEdit() || !$this->getRepositoryMode())
485  {
486  $this->addHiddenBlockSelector();
487  }
488 
489  $ilBench->stop("Column", "getHTML");
490 
491  return $this->tpl->get();
492  }
493 
497  function showBlocks()
498  {
499  global $ilCtrl, $lng, $ilUser, $ilBench;
500 
501  $i = 1;
502  $sum_moveable = count($this->blocks[$this->getSide()]);
503 
504  foreach($this->blocks[$this->getSide()] as $block)
505  {
506  if ($ilCtrl->getContextObjType() != "user" ||
507  ilBlockSetting::_lookupDetailLevel($block["type"],
508  $ilUser->getId(), $block["id"]) > 0)
509  {
510  $gui_class = $block["class"];
511  $block_class = substr($block["class"], 0, strlen($block["class"])-3);
512 
513  // get block gui class
514  include_once("./".self::$locations[$gui_class]."classes/".
515  "class.".$gui_class.".php");
516  $ilBench->start("Column", "instantiate-".$block["type"]);
517  $block_gui = new $gui_class();
518  $ilBench->stop("Column", "instantiate-".$block["type"]);
519  if (isset($this->block_property[$block["type"]]))
520  {
521  $block_gui->setProperties($this->block_property[$block["type"]]);
522  }
523  $block_gui->setRepositoryMode($this->getRepositoryMode());
524  $block_gui->setEnableEdit($this->getEnableEdit());
525  $block_gui->setAdminCommands($this->getAdminCommands());
526 
527  // get block for custom blocks
528  if ($block["custom"])
529  {
530  include_once("./".self::$locations[$gui_class]."classes/".
531  "class.".$block_class.".php");
532  $app_block = new $block_class($block["id"]);
533  $block_gui->setBlock($app_block);
534  if (isset($block["ref_id"]))
535  {
536  $block_gui->setRefId($block["ref_id"]);
537  }
538  }
539 
540  $ilCtrl->setParameter($this, "block_type", $block_gui->getBlockType());
541  $this->tpl->setCurrentBlock("col_block");
542 
543  $ilBench->start("Column", "showBlocks-".$block_gui->getBlockType());
544  $html = $ilCtrl->getHTML($block_gui);
545  $ilBench->stop("Column", "showBlocks-".$block_gui->getBlockType());
546 
547  // dummy block, if non visible, but movement is ongoing
548  if ($html == "" && $this->getRepositoryMode() &&
549  $this->getMovementMode())
550  {
551  include_once("./Services/Block/classes/class.ilDummyBlockGUI.php");
552  $bl = new ilDummyBlockGUI();
553  $bl->setBlockId($block["id"]);
554  $bl->setBlockType($block["type"]);
555  $bl->setTitle($lng->txt("invisible_block"));
556  $bl->setConfigMode($this->getMovementMode());
557  $html = $bl->getHTML();
558  }
559 
560  // don't render a block if it's empty
561  if ($html != "")
562  {
563  $this->tpl->setVariable("BLOCK", $html);
564  $this->tpl->parseCurrentBlock();
565  $ilCtrl->setParameter($this, "block_type", "");
566  }
567 
568  // count (moveable) blocks
569  if ($block["type"] != "pdsysmess" && $block["type"] != "pdfeedb" &&
570  $block["type"] != "news")
571  {
572  $i++;
573  }
574  else
575  {
576  $sum_moveable--;
577  }
578  }
579  }
580  }
581 
585  function addHiddenBlockSelector()
586  {
593  global $lng, $ilUser, $ilCtrl, $tpl;
594 
595  // show selector for hidden blocks
596  include_once("Services/Block/classes/class.ilBlockSetting.php");
597  $hidden_blocks = array();
598 
599  foreach($this->blocks[$this->getSide()] as $block)
600  {
601  include_once("./".self::$locations[$block["class"]]."classes/".
602  "class.".$block["class"].".php");
603 
604  if ($block["custom"] == false)
605  {
606  if ($ilCtrl->getContextObjType() == "user") // personal desktop
607  {
608  if (ilBlockSetting::_lookupDetailLevel($block["type"], $ilUser->getId()) == 0)
609  {
610  $hidden_blocks[$block["type"]] = $lng->txt('block_show_'.$block["type"]);
611  }
612  }
613  else if ($ilCtrl->getContextObjType() != "")
614  {
615  if (ilBlockSetting::_lookupDetailLevel($block["type"], $ilUser->getId(),
616  $ilCtrl->getContextObjId()) == 0)
617  {
618  $hidden_blocks[$block["type"]."_".$ilCtrl->getContextObjId()] = $lng->txt('block_show_'.$block["type"]);
619  }
620  }
621  }
622  else
623  {
624  if (ilBlockSetting::_lookupDetailLevel($block["type"], $ilUser->getId(),
625  $block["id"]) == 0)
626  {
627  include_once("./Services/Block/classes/class.ilCustomBlock.php");
628  $cblock = new ilCustomBlock($block["id"]);
629  $hidden_blocks[$block["type"]."_".$block["id"]] = sprintf($lng->txt('block_show_x'), $cblock->getTitle());
630  }
631  }
632  }
633  if(count($hidden_blocks) > 0)
634  {
635  foreach($hidden_blocks as $id => $title)
636  {
637  $ilCtrl->setParameter($this, 'block', $id);
638  $this->action_menu->addItem($title, '', $ilCtrl->getLinkTarget($this, 'activateBlock'));
639  $ilCtrl->setParameter($this, 'block', '');
640  }
641  }
642 
643  // create block selection list
644  if (!$this->getRepositoryMode() || $this->getEnableEdit())
645  {
646  $add_blocks = array();
647  if ($this->getSide() == IL_COL_RIGHT)
648  {
649  if (is_array($this->custom_blocks[$this->getColType()]))
650  {
651  foreach($this->custom_blocks[$this->getColType()] as $block_class)
652  {
653  include_once("./".self::$locations[$block_class]."classes/".
654  "class.".$block_class.".php");
655  $block_type = call_user_func(array($block_class, 'getBlockType'));
656 
657  // check if block type is globally (de-)activated
658  if ($this->isGloballyActivated($block_type))
659  {
660  // check if number of blocks is limited
661  if (!$this->exceededLimit($block_type))
662  {
663  $add_blocks[$block_type] = $lng->txt('block_create_'.$block_type);
664  }
665  }
666  }
667  }
668  }
669  if(count($add_blocks) > 0)
670  {
671  foreach($add_blocks as $id => $title)
672  {
673  $ilCtrl->setParameter($this, 'block_type', $id);
674  $this->action_menu->addItem($title, '', $ilCtrl->getLinkTarget($this, 'addBlock'));
675  $ilCtrl->setParameter($this, 'block_type', '');
676  }
677  }
678  }
679 
680  $this->addBlockSorting();
681  }
682 
686  protected function addBlockSorting()
687  {
688  if($this->getSide() == IL_COL_CENTER && $this->getEnableMovement())
689  {
695  global $ilBrowser, $tpl, $ilCtrl;
696 
697  include_once 'Services/jQuery/classes/class.iljQueryUtil.php';
700 
701  if($ilBrowser->isMobile() || $ilBrowser->isIpad())
702  {
703  $tpl->addJavaScript('./Services/jQuery/js/jquery.ui.touch-punch.min.js');
704  }
705  $tpl->addJavaScript('./Services/Block/js/block_sorting.js');
706 
707  // set the col_side parameter to pass the ctrl structure flow
708  $ilCtrl->setParameter($this, 'col_side', IL_COL_CENTER);
709 
710  $this->tpl->setVariable('BLOCK_SORTING_STORAGE_URL', $ilCtrl->getLinkTarget($this, 'saveBlockSortingAsynch', '', true, false));
711  $this->tpl->setVariable('BLOCK_COLUMNS', json_encode(array('il_left_col', 'il_right_col')));
712  $this->tpl->setVariable('BLOCK_COLUMNS_SELECTOR', '#il_left_col,#il_right_col');
713  $this->tpl->setVariable('BLOCK_COLUMNS_PARAMETERS', json_encode(array(IL_COL_LEFT, IL_COL_RIGHT)));
714 
715  // restore col_side parameter
716  $ilCtrl->setParameter($this, 'col_side', $this->getSide());
717  }
718  }
719 
723  function updateBlock()
724  {
725  global $ilCtrl, $ilBench;
726 
727  $this->determineBlocks();
728  $i = 1;
729  $sum_moveable = count($this->blocks[$this->getSide()]);
730 
731  foreach ($this->blocks[$this->getSide()] as $block)
732  {
733 
734  include_once("./".self::$locations[$block["class"]]."classes/".
735  "class.".$block["class"].".php");
736 
737  // set block id to context obj id,
738  // if block is not a custom block and context is not personal desktop
739  if (!$block["custom"] && $ilCtrl->getContextObjType() != "" && $ilCtrl->getContextObjType() != "user")
740  {
741  $block["id"] = $ilCtrl->getContextObjId();
742  }
743 
744  //if (is_int(strpos($_GET["block_id"], "block_".$block["type"]."_".$block["id"])))
745 
746  if ($_GET["block_id"] == "block_".$block["type"]."_".$block["id"])
747  {
748  $gui_class = $block["class"];
749  $block_class = substr($block["class"], 0, strlen($block["class"])-3);
750 
751  $block_gui = new $gui_class();
752  $block_gui->setProperties($this->block_property[$block["type"]]);
753  $block_gui->setRepositoryMode($this->getRepositoryMode());
754  $block_gui->setEnableEdit($this->getEnableEdit());
755  $block_gui->setAdminCommands($this->getAdminCommands());
756 
757  // get block for custom blocks
758  if ($block["custom"])
759  {
760  include_once("./".self::$locations[$gui_class]."classes/".
761  "class.".$block_class.".php");
762  $app_block = new $block_class($block["id"]);
763  $block_gui->setBlock($app_block);
764  $block_gui->setRefId($block["ref_id"]);
765  }
766 
767  $ilCtrl->setParameter($this, "block_type", $block["type"]);
768  echo $ilCtrl->getHTML($block_gui);
769  $ilBench->save();
770  exit;
771  }
772 
773  // count (moveable) blocks
774  if ($block["type"] != "pdsysmess" && $block["type"] != "pdfeedb"
775  && $block["type"] != "news")
776  {
777  $i++;
778  }
779  else
780  {
781  $sum_moveable--;
782  }
783  }
784  echo "Error: ilColumnGUI::updateBlock: Block '".
785  $_GET["block_id"]."' unknown.";
786  exit;
787  }
788 
792  function activateBlock()
793  {
794  global $ilUser, $ilCtrl;
795 
796  if ($_GET["block"] != "")
797  {
798  $block = explode("_", $_GET["block"]);
799  include_once("Services/Block/classes/class.ilBlockSetting.php");
800  ilBlockSetting::_writeDetailLevel($block[0], 2, $ilUser->getId(), $block[1]);
801  }
802 
803  $ilCtrl->returnToParent($this);
804  }
805 
809  function addBlock()
810 
811  {
812  global $ilCtrl;
813 
814  $class = array_search($_GET["block_type"], self::$block_types);
815 
816  $ilCtrl->setCmdClass($class);
817  $ilCtrl->setCmd("create");
818  include_once("./".self::$locations[$class]."classes/class.".$class.".php");
819  $block_gui = new $class();
820  $block_gui->setProperties($this->block_property[$_GET["block_type"]]);
821  $block_gui->setRepositoryMode($this->getRepositoryMode());
822  $block_gui->setEnableEdit($this->getEnableEdit());
823  $block_gui->setAdminCommands($this->getAdminCommands());
824 
825  $ilCtrl->setParameter($this, "block_type", $_GET["block_type"]);
826  $html = $ilCtrl->forwardCommand($block_gui);
827  $ilCtrl->setParameter($this, "block_type", "");
828  return $html;
829  }
830 
834  function determineBlocks()
835  {
836  global $ilUser, $ilCtrl, $ilSetting;
837 
838  include_once("./Services/Block/classes/class.ilBlockSetting.php");
839  $this->blocks[IL_COL_LEFT] = array();
840  $this->blocks[IL_COL_RIGHT] = array();
841  $this->blocks[IL_COL_CENTER] = array();
842 
843  $user_id = ($this->getColType() == "pd")
844  ? $ilUser->getId()
845  : 0;
846 
847  $def_nr = 1000;
848  if (is_array($this->default_blocks[$this->getColType()]))
849  {
850  foreach($this->default_blocks[$this->getColType()] as $class => $def_side)
851  {
852  $type = self::$block_types[$class];
853 
854  if ($this->isGloballyActivated($type))
855  {
856  $nr = ilBlockSetting::_lookupNr($type, $user_id);
857  if ($nr === false)
858  {
859  $nr = $def_nr++;
860  }
861 
862 
863  // extra handling for system messages, feedback block and news
864  if ($type == "news") // always show news first
865  {
866  $nr = -15;
867  }
868  if ($type == "cal")
869  {
870  $nr = -8;
871  }
872  if ($type == "pdsysmess") // always show sys mess first
873  {
874 // $nr = -15;
875  }
876  if ($type == "pdfeedb") // always show feedback request second
877  {
878  $nr = -10;
879  }
881  if ($side === false)
882  {
883  $side = $def_side;
884  }
885 
886  $this->blocks[$side][] = array(
887  "nr" => $nr,
888  "class" => $class,
889  "type" => $type,
890  "id" => 0,
891  "custom" => false);
892  }
893  }
894  }
895 
896  if (!$this->getRepositoryMode())
897  {
898  include_once("./Services/Block/classes/class.ilCustomBlock.php");
899  $costum_block = new ilCustomBlock();
900  $costum_block->setContextObjId($ilCtrl->getContextObjId());
901  $costum_block->setContextObjType($ilCtrl->getContextObjType());
902  $c_blocks = $costum_block->queryBlocksForContext();
903 
904  foreach($c_blocks as $c_block)
905  {
906  $type = $c_block["type"];
907 
908  if ($this->isGloballyActivated($type))
909  {
910  $class = array_search($type, self::$block_types);
911  $nr = ilBlockSetting::_lookupNr($type, $user_id, $c_block["id"]);
912  if ($nr === false)
913  {
914  $nr = $def_nr++;
915  }
916  $side = ilBlockSetting::_lookupSide($type, $user_id, $c_block["id"]);
917  if ($side === false)
918  {
920  }
921 
922  $this->blocks[$side][] = array(
923  "nr" => $nr,
924  "class" => $class,
925  "type" => $type,
926  "id" => $c_block["id"],
927  "custom" => true);
928  }
929  }
930  }
931  else // get all subitems
932  {
933  include_once("./Services/Block/classes/class.ilCustomBlock.php");
934  $rep_items = $this->getRepositoryItems();
935 
936  foreach($this->rep_block_types as $block_type)
937  {
938  if ($this->isGloballyActivated($block_type))
939  {
940  if (!is_array($rep_items[$block_type]))
941  {
942  continue;
943  }
944  foreach($rep_items[$block_type] as $item)
945  {
946  $costum_block = new ilCustomBlock();
947  $costum_block->setContextObjId($item["obj_id"]);
948  $costum_block->setContextObjType($block_type);
949  $c_blocks = $costum_block->queryBlocksForContext();
950  $c_block = $c_blocks[0];
951 
952  $type = $block_type;
953  $class = array_search($type, self::$block_types);
954  $nr = ilBlockSetting::_lookupNr($type, $user_id, $c_block["id"]);
955  if ($nr === false)
956  {
957  $nr = $def_nr++;
958  }
959  $side = ilBlockSetting::_lookupSide($type, $user_id, $c_block["id"]);
960  if ($side === false)
961  {
963  }
964 
965  $this->blocks[$side][] = array(
966  "nr" => $nr,
967  "class" => $class,
968  "type" => $type,
969  "id" => $c_block["id"],
970  "custom" => true,
971  "ref_id" => $item["ref_id"]);
972  }
973  }
974  }
975  }
976 
977 
978  $this->blocks[IL_COL_LEFT] =
979  ilUtil::sortArray($this->blocks[IL_COL_LEFT], "nr", "asc", true);
980  $this->blocks[IL_COL_RIGHT] =
981  ilUtil::sortArray($this->blocks[IL_COL_RIGHT], "nr", "asc", true);
982  $this->blocks[IL_COL_CENTER] =
983  ilUtil::sortArray($this->blocks[IL_COL_CENTER], "nr", "asc", true);
984 
985  }
986 
990  protected function isGloballyActivated($a_type)
991  {
992 
993  global $ilSetting;
994  if (isset($this->check_global_activation[$a_type]) && $this->check_global_activation[$a_type])
995  {
996  if ($a_type == 'pdbookm')
997  {
998  if (!$ilSetting->get("disable_bookmarks"))
999  {
1000  return true;
1001  }
1002  return false;
1003  }
1004  else if ($a_type == 'pdnotes')
1005  {
1006  if (!$ilSetting->get("disable_notes"))
1007  {
1008  return true;
1009  }
1010  return false;
1011  }
1012  elseif($a_type == 'news')
1013  {
1014  include_once 'Services/Container/classes/class.ilContainer.php';
1015  return
1016  $ilSetting->get('block_activated_news') &&
1018  $GLOBALS['ilCtrl']->getContextObjId(),
1019  'cont_show_news',
1020  true
1021  );
1022  }
1023  else if ($ilSetting->get("block_activated_".$a_type))
1024  {
1025  return true;
1026  }
1027  elseif($a_type == 'cal')
1028  {
1029  include_once('./Services/Calendar/classes/class.ilCalendarSettings.php');
1030  return ilCalendarSettings::lookupCalendarActivated($GLOBALS['ilCtrl']->getContextObjId());
1031 
1032  }
1033  elseif($a_type == 'pdcal')
1034  {
1035  include_once('./Services/Calendar/classes/class.ilCalendarSettings.php');
1036  return ilCalendarSettings::_getInstance()->isEnabled();
1037  }
1038  return false;
1039  }
1040  return true;
1041  }
1042 
1046  protected function exceededLimit($a_type)
1047  {
1048  global $ilSetting, $ilCtrl;
1049 
1050  if ($this->check_nr_limit[$a_type])
1051  {
1052  if (!$this->getRepositoryMode())
1053  {
1054  include_once("./Services/Block/classes/class.ilCustomBlock.php");
1055  $costum_block = new ilCustomBlock();
1056  $costum_block->setContextObjId($ilCtrl->getContextObjId());
1057  $costum_block->setContextObjType($ilCtrl->getContextObjType());
1058  $costum_block->setType($a_type);
1059  $res = $costum_block->queryCntBlockForContext();
1060  $cnt = (int) $res[0]["cnt"];
1061  }
1062  else
1063  {
1064  return false; // not implemented for repository yet
1065  }
1066 
1067 
1068  if ($ilSetting->get("block_limit_".$a_type) > $cnt)
1069  {
1070  return false;
1071  }
1072  else
1073  {
1074  return true;
1075  }
1076  }
1077  return false;
1078  }
1079 
1083  public function saveBlockSortingAsynch()
1084  {
1088  global $ilUser;
1089 
1090  $response = new stdClass();
1091  $response->success = false;
1092 
1093  if(!isset($_POST[IL_COL_LEFT]['sequence']) && !isset($_POST[IL_COL_RIGHT]['sequence']))
1094  {
1095  echo json_encode($response);
1096  return;
1097  };
1098 
1099  if(in_array($this->getColType(), array('pd')))
1100  {
1101  $response->success = true;
1102 
1103  foreach(array(IL_COL_LEFT => (array)$_POST[IL_COL_LEFT]['sequence'], IL_COL_RIGHT => (array)$_POST[IL_COL_RIGHT]['sequence']) as $side => $blocks)
1104  {
1105  $i = 2;
1106  foreach($blocks as $block)
1107  {
1108  $bid = explode('_', $block);
1109  ilBlockSetting::_writeNumber($bid[1], $i, $ilUser->getId(), $bid[2]);
1110  ilBlockSetting::_writeSide($bid[1], $side, $ilUser->getId(), $bid[2]);
1111 
1112  $i +=2;
1113  }
1114  }
1115  }
1116 
1117  echo json_encode($response);
1118  exit();
1119  }
1120 
1125  public function setActionMenu($action_menu)
1126  {
1127  $this->action_menu = $action_menu;
1128  return $this;
1129  }
1130 
1134  public function getActionMenu()
1135  {
1136  return $this->action_menu;
1137  }
1138 }