dashboardlayout.class.inc.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. <?php
  2. abstract class DashboardLayout
  3. {
  4. public function __construct()
  5. {
  6. }
  7. abstract public function Render($oPage, $aDashlets, $bEditMode = false);
  8. static public function GetInfo()
  9. {
  10. return array(
  11. 'label' => '',
  12. 'icon' => '',
  13. 'description' => '',
  14. );
  15. }
  16. }
  17. abstract class DashboardLayoutMultiCol extends DashboardLayout
  18. {
  19. protected $iNbCols;
  20. public function __construct()
  21. {
  22. $this->iNbCols = 1;
  23. }
  24. public function Render($oPage, $aDashlets, $bEditMode = false, $aExtraParams = array())
  25. {
  26. $oPage->add('<table style="width:100%"><tbody>');
  27. $iDashletIdx = 0;
  28. $fColSize = 100 / $this->iNbCols;
  29. $sStyle = $bEditMode ? 'style="border: 1px #ccc dashed; width:'.$fColSize.'%;" class="layout_cell edit_mode"' : 'style="width: '.$fColSize.'%; "';
  30. $iNbRows = ceil(count($aDashlets) / $this->iNbCols);
  31. for($iRows = 0; $iRows < $iNbRows; $iRows++)
  32. {
  33. $oPage->add('<tr>');
  34. for($iCols = 0; $iCols < $this->iNbCols; $iCols++)
  35. {
  36. $oPage->add("<td $sStyle>");
  37. if (array_key_exists($iDashletIdx, $aDashlets))
  38. {
  39. $oDashlet = $aDashlets[$iDashletIdx];
  40. $oDashlet->DoRender($oPage, $bEditMode, $aExtraParams);
  41. }
  42. else
  43. {
  44. $oPage->add('&nbsp;');
  45. }
  46. $oPage->add('</td>');
  47. $iDashletIdx++;
  48. }
  49. $oPage->add('</tr>');
  50. }
  51. if ($bEditMode) // Add one row for extensibility
  52. {
  53. $oPage->add('<tr>');
  54. for($iCols = 0; $iCols < $this->iNbCols; $iCols++)
  55. {
  56. $oPage->add("<td $sStyle>");
  57. $oPage->add('&nbsp;');
  58. $oPage->add('</td>');
  59. }
  60. $oPage->add('</tr>');
  61. }
  62. $oPage->add('</tbody></table>');
  63. }
  64. }
  65. class DashboardLayoutOneCol extends DashboardLayoutMultiCol
  66. {
  67. public function __construct()
  68. {
  69. parent::__construct();
  70. $this->iNbCols = 1;
  71. }
  72. static public function GetInfo()
  73. {
  74. return array(
  75. 'label' => 'One Column',
  76. 'icon' => 'images/layout_1col.png',
  77. 'description' => '',
  78. );
  79. }
  80. }
  81. class DashboardLayoutTwoCols extends DashboardLayoutMultiCol
  82. {
  83. public function __construct()
  84. {
  85. parent::__construct();
  86. $this->iNbCols = 2;
  87. }
  88. static public function GetInfo()
  89. {
  90. return array(
  91. 'label' => 'Two Columns',
  92. 'icon' => 'images/layout_2col.png',
  93. 'description' => '',
  94. );
  95. }
  96. }
  97. class DashboardLayoutThreeCols extends DashboardLayoutMultiCol
  98. {
  99. public function __construct()
  100. {
  101. parent::__construct();
  102. $this->iNbCols = 3;
  103. }
  104. static public function GetInfo()
  105. {
  106. return array(
  107. 'label' => 'Two Columns',
  108. 'icon' => 'images/layout_3col.png',
  109. 'description' => '',
  110. );
  111. }
  112. }