v1.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. <?php
  2. namespace zin;
  3. require_once dirname(__DIR__) . DS . 'idlabel' . DS . 'v1.php';
  4. /**
  5. * @deprecated Use entityTitle instead.
  6. */
  7. class entityLabel extends wg
  8. {
  9. /**
  10. * @var mixed[]
  11. */
  12. protected static $defineProps = array(
  13. 'entityID?: string|int', // 实体编号
  14. 'level?: string|int', // 标题层级
  15. 'text?: string', // 实体文本
  16. 'reverse?: bool=false', // 编号与文本是否交换顺序
  17. 'textClass?: string', // 文本样式类
  18. 'idClass?: string', // 编号样式类
  19. 'href?: string', // 实体链接
  20. 'titlePrefix?: array', // 标题前缀
  21. 'labelProps?: array' // 标签属性
  22. );
  23. /**
  24. * @var mixed[]
  25. */
  26. protected static $defineBlocks = array(
  27. 'prefix' => array(),
  28. 'suffix' => array()
  29. );
  30. public static function getPageCSS()
  31. {
  32. return file_get_contents(__DIR__ . DS . 'css' . DS . 'v1.css');
  33. }
  34. /**
  35. * @param mixed $child
  36. */
  37. protected function onAddChild($child)
  38. {
  39. if(is_string($child) && !$this->props->has('text'))
  40. {
  41. $this->props->set('text', $child);
  42. return false;
  43. }
  44. else
  45. {
  46. $this->props->addToList('titlePrefix', $child);
  47. return false;
  48. }
  49. }
  50. private function buildEntityID()
  51. {
  52. $entityID = $this->prop('entityID');
  53. $className = $this->prop('idClass');
  54. if(!isset($entityID)) return null;
  55. return idLabel::create($entityID, array('class' => $className));
  56. }
  57. private function buildEntityName()
  58. {
  59. $text = $this->prop('text');
  60. $level = $this->prop('level');
  61. $className = $this->prop('textClass');
  62. $href = $this->prop('href');
  63. $labelProps = $this->prop('labelProps');
  64. $titlePrefix = $this->prop('titlePrefix');
  65. $titleClass = empty($level)
  66. ? 'entity-title'
  67. : "entity-title entity-title-$level";
  68. if(empty($href)) return span
  69. (
  70. setClass($titleClass, $className),
  71. set($labelProps),
  72. $titlePrefix,
  73. $text
  74. );
  75. return a
  76. (
  77. setClass($titleClass, $className),
  78. set::href($href),
  79. set($labelProps),
  80. $titlePrefix,
  81. $text
  82. );
  83. }
  84. protected function build()
  85. {
  86. $reverse = $this->prop('reverse');
  87. $prefix = $this->block('prefix');
  88. $suffix = $this->block('suffix');
  89. $entityID = $this->buildEntityID();
  90. $entityName = $this->buildEntityName();
  91. return div
  92. (
  93. setClass('entity-label space-x-1.5 overflow-hidden nowrap flex items-center'),
  94. set($this->getRestProps()),
  95. $prefix,
  96. $reverse ? array($entityName, ' ', $entityID) : array($entityID, ' ', $entityName),
  97. $suffix
  98. );
  99. }
  100. }