dashboardlayout.class.inc.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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. // Trim the list of dashlets to remove the invisible ones at the end of the array
  27. $aKeys = array_reverse(array_keys($aDashlets));
  28. $idx = 0;
  29. $bNoVisibleFound = true;
  30. while($idx < count($aKeys) && $bNoVisibleFound)
  31. {
  32. $oDashlet = $aDashlets[$aKeys[$idx]];
  33. if ($oDashlet->IsVisible())
  34. {
  35. $bNoVisibleFound = false;
  36. }
  37. else
  38. {
  39. unset($aDashlets[$aKeys[$idx]]);
  40. }
  41. $idx++;
  42. }
  43. $oPage->add('<table style="width:100%"><tbody>');
  44. $iDashletIdx = 0;
  45. $fColSize = 100 / $this->iNbCols;
  46. $sStyle = $bEditMode ? 'style="border: 1px #ccc dashed; width:'.$fColSize.'%;" class="layout_cell edit_mode"' : 'style="width: '.$fColSize.'%; "';
  47. $iNbRows = ceil(count($aDashlets) / $this->iNbCols);
  48. for($iRows = 0; $iRows < $iNbRows; $iRows++)
  49. {
  50. $oPage->add('<tr>');
  51. for($iCols = 0; $iCols < $this->iNbCols; $iCols++)
  52. {
  53. $oPage->add("<td $sStyle>");
  54. if (array_key_exists($iDashletIdx, $aDashlets))
  55. {
  56. $oDashlet = $aDashlets[$iDashletIdx];
  57. if ($oDashlet->IsVisible())
  58. {
  59. $oDashlet->DoRender($oPage, $bEditMode, $aExtraParams);
  60. }
  61. else
  62. {
  63. $oPage->add('&nbsp;');
  64. }
  65. }
  66. else
  67. {
  68. $oPage->add('&nbsp;');
  69. }
  70. $oPage->add('</td>');
  71. $iDashletIdx++;
  72. }
  73. $oPage->add('</tr>');
  74. }
  75. if ($bEditMode) // Add one row for extensibility
  76. {
  77. $oPage->add('<tr>');
  78. for($iCols = 0; $iCols < $this->iNbCols; $iCols++)
  79. {
  80. $oPage->add("<td $sStyle>");
  81. $oPage->add('&nbsp;');
  82. $oPage->add('</td>');
  83. }
  84. $oPage->add('</tr>');
  85. }
  86. $oPage->add('</tbody></table>');
  87. }
  88. }
  89. class DashboardLayoutOneCol extends DashboardLayoutMultiCol
  90. {
  91. public function __construct()
  92. {
  93. parent::__construct();
  94. $this->iNbCols = 1;
  95. }
  96. static public function GetInfo()
  97. {
  98. return array(
  99. 'label' => 'One Column',
  100. 'icon' => 'images/layout_1col.png',
  101. 'description' => '',
  102. );
  103. }
  104. }
  105. class DashboardLayoutTwoCols extends DashboardLayoutMultiCol
  106. {
  107. public function __construct()
  108. {
  109. parent::__construct();
  110. $this->iNbCols = 2;
  111. }
  112. static public function GetInfo()
  113. {
  114. return array(
  115. 'label' => 'Two Columns',
  116. 'icon' => 'images/layout_2col.png',
  117. 'description' => '',
  118. );
  119. }
  120. }
  121. class DashboardLayoutThreeCols extends DashboardLayoutMultiCol
  122. {
  123. public function __construct()
  124. {
  125. parent::__construct();
  126. $this->iNbCols = 3;
  127. }
  128. static public function GetInfo()
  129. {
  130. return array(
  131. 'label' => 'Two Columns',
  132. 'icon' => 'images/layout_3col.png',
  133. 'description' => '',
  134. );
  135. }
  136. }