dashboardlayout.class.inc.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  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, true /* bEnclosingDiv */, $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. $sStyle = 'style="border: 1px #ccc dashed; width:'.$fColSize.'%;" class="layout_cell edit_mode layout_extension"';
  113. $oPage->add('<tr>');
  114. for($iCols = 0; $iCols < $this->iNbCols; $iCols++)
  115. {
  116. $oPage->add("<td $sStyle>");
  117. $oPage->add('&nbsp;');
  118. $oPage->add('</td>');
  119. }
  120. $oPage->add('</tr>');
  121. }
  122. $oPage->add('</tbody></table>');
  123. }
  124. }
  125. class DashboardLayoutOneCol extends DashboardLayoutMultiCol
  126. {
  127. public function __construct()
  128. {
  129. parent::__construct();
  130. $this->iNbCols = 1;
  131. }
  132. static public function GetInfo()
  133. {
  134. return array(
  135. 'label' => 'One Column',
  136. 'icon' => 'images/layout_1col.png',
  137. 'description' => '',
  138. );
  139. }
  140. }
  141. class DashboardLayoutTwoCols extends DashboardLayoutMultiCol
  142. {
  143. public function __construct()
  144. {
  145. parent::__construct();
  146. $this->iNbCols = 2;
  147. }
  148. static public function GetInfo()
  149. {
  150. return array(
  151. 'label' => 'Two Columns',
  152. 'icon' => 'images/layout_2col.png',
  153. 'description' => '',
  154. );
  155. }
  156. }
  157. class DashboardLayoutThreeCols extends DashboardLayoutMultiCol
  158. {
  159. public function __construct()
  160. {
  161. parent::__construct();
  162. $this->iNbCols = 3;
  163. }
  164. static public function GetInfo()
  165. {
  166. return array(
  167. 'label' => 'Two Columns',
  168. 'icon' => 'images/layout_3col.png',
  169. 'description' => '',
  170. );
  171. }
  172. }