v1.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. namespace zin;
  3. class priLabel extends wg
  4. {
  5. /**
  6. * @var mixed[]
  7. */
  8. protected static $defineProps = array(
  9. 'pri: int|string', // 优先级的值。
  10. 'text?: string|array' // 优先级显示的文本或优先级文本映射对象,如果不指定从 $lang->$moduleName->priList 中获取。
  11. );
  12. /**
  13. * @param mixed $child
  14. */
  15. protected function onAddChild($child)
  16. {
  17. if(is_string($child) || is_int($child))
  18. {
  19. if(!$this->props->has('pri'))
  20. {
  21. $this->props->set('pri', $child);
  22. return false;
  23. }
  24. if(!$this->props->has('text') && is_string($child))
  25. {
  26. $this->props->set('text', $child);
  27. return false;
  28. }
  29. }
  30. return $child;
  31. }
  32. protected function build()
  33. {
  34. $pri = $this->prop('pri', 0);
  35. $text = $this->prop('text');
  36. if(is_null($text))
  37. {
  38. global $app, $lang;
  39. $moduleName = $app->getModuleName();
  40. if(isset($lang->$moduleName->priList)) $text = $lang->$moduleName->priList;
  41. }
  42. if(is_array($text)) $text = isset($text[$pri]) ? $text[$pri] : null;
  43. $pri = trim("$pri");
  44. if($text === null) $text = ($pri === '0' || $pri === '') ? '' : $pri;
  45. return span
  46. (
  47. set($this->getRestProps()),
  48. setClass("pri-$pri"),
  49. $text
  50. );
  51. }
  52. }