v1.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. <?php
  2. /**
  3. * The overview block widget class file of zin module of ZenTaoPMS.
  4. *
  5. * @copyright Copyright 2009-2023 禅道软件(青岛)有限公司(ZenTao Software (Qingdao) Co., Ltd. www.zentao.net)
  6. * @license ZPL(https://zpl.pub/page/zplv12.html) or AGPL(https://www.gnu.org/licenses/agpl-3.0.en.html)
  7. * @author Gang Liu <liugang@easycorp.ltd>
  8. * @package zin
  9. * @link https://www.zentao.net
  10. */
  11. namespace zin;
  12. require_once dirname(__DIR__) . DS . 'blockpanel' . DS . 'v1.php';
  13. class overviewBlock extends wg
  14. {
  15. /**
  16. * @var mixed[]
  17. */
  18. protected static $defineProps = array(
  19. 'id?: string',
  20. 'title?: string',
  21. 'block?: object',
  22. 'groups?: array'
  23. );
  24. protected function buildCard($card)
  25. {
  26. $class = array('text-2xl text-center leading-relaxed num', isset($card->class) ? $card->class : '');
  27. return col
  28. (
  29. setClass('justify-center w-1/2'),
  30. empty($card->url) ? span
  31. (
  32. setClass($class),
  33. $card->value
  34. ) : a
  35. (
  36. setClass($class),
  37. set::href($card->url),
  38. $card->value
  39. ),
  40. span
  41. (
  42. setClass('text-center text-sm'),
  43. $card->label
  44. )
  45. );
  46. }
  47. protected function buildCards($group)
  48. {
  49. $cards = array();
  50. foreach($group->cards as $index => $card)
  51. {
  52. if($index > 0) $cards[] = divider(setClass('h-10 self-center'));
  53. $cards[] = $this->buildCard($card);
  54. }
  55. return row
  56. (
  57. setClass('w-1/2'),
  58. setStyle(array('margin-top' => '-20px')),
  59. $cards
  60. );
  61. }
  62. protected function buildBarChart($group)
  63. {
  64. $bars = array();
  65. $labels = array();
  66. foreach($group->bars as $bar)
  67. {
  68. $bars[] = h::li
  69. (
  70. setStyle(array('display' => 'contents')),
  71. span
  72. (
  73. set::title($bar->value),
  74. setClass('block primary bg-opacity-70 w-2'),
  75. setStyle(array('height' => $bar->rate))
  76. )
  77. );
  78. $labels[] = span
  79. (
  80. setClass('text-center text-gray text-sm'),
  81. $bar->label
  82. );
  83. }
  84. return div
  85. (
  86. setClass('bar-chart flex justify-center w-1/2'),
  87. col
  88. (
  89. setClass('basis-48'),
  90. span
  91. (
  92. setClass('mb-3 text-sm text-gray'),
  93. $group->title
  94. ),
  95. div
  96. (
  97. setClass('border-b'),
  98. h::ul
  99. (
  100. setClass('flex justify-around items-end w-full'),
  101. setStyle(array('height' => '60px')),
  102. $bars
  103. )
  104. ),
  105. div
  106. (
  107. setClass('flex justify-around mt-1.5'),
  108. $labels
  109. )
  110. )
  111. );
  112. }
  113. protected function buildBody($groups)
  114. {
  115. $body = array();
  116. foreach($groups as $group)
  117. {
  118. if($group->type == 'cards') $body[] = $this->buildCards($group);
  119. if($group->type == 'barChart') $body[] = $this->buildBarChart($group);
  120. }
  121. return $body;
  122. }
  123. protected function build()
  124. {
  125. list($id, $title, $block, $groups) = $this->prop(array('id', 'title', 'block', 'groups'));
  126. return new blockPanel
  127. (
  128. to::titleSuffix($this->block('titleSuffix')),
  129. set::block($block),
  130. set::title($title),
  131. set::id($id),
  132. set::headingClass('border-0'),
  133. set::bodyClass('flex block-base p-0'),
  134. $this->buildBody($groups)
  135. );
  136. }
  137. }