dashboardlayout.class.inc.php 2.3 KB

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