dashboardlayout.class.inc.php 3.6 KB

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