DictionaryObj.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. <?php
  2. namespace common\util;
  3. use JsonSerializable;
  4. /**
  5. * Class DictionaryObj
  6. * @package common\util
  7. * @property int $id
  8. * @property int $pid
  9. * @property string $name
  10. * @property int $status
  11. * @property array $children
  12. * @property int $multiple
  13. * @property array $derive
  14. * @property int $sort
  15. */
  16. class DictionaryObj implements JsonSerializable
  17. {
  18. /**
  19. * ID
  20. */
  21. private $id;
  22. /**
  23. * 父ID
  24. */
  25. private $pid;
  26. /**
  27. * 名称
  28. */
  29. private $name;
  30. /**
  31. * 状态
  32. */
  33. private $status;
  34. /**
  35. * 节点属性
  36. */
  37. private $children = [];
  38. private $multiple;
  39. private $derive = [];
  40. private $has_children = [];
  41. private $can_change = [];
  42. private $can_children;
  43. private $can_multiple;
  44. private $sort;
  45. /**
  46. * @return mixed
  47. */
  48. public function getId()
  49. {
  50. return $this->id;
  51. }
  52. /**
  53. * @param mixed $id
  54. */
  55. public function setId($id)
  56. {
  57. $this->id = $id;
  58. }
  59. /**
  60. * @return mixed
  61. */
  62. public function getPid(): int
  63. {
  64. return $this->pid;
  65. }
  66. /**
  67. * @param mixed $pid
  68. */
  69. public function setPid($pid)
  70. {
  71. $this->pid = $pid;
  72. }
  73. /**
  74. * @return mixed
  75. */
  76. public function getName(): string
  77. {
  78. return $this->name;
  79. }
  80. /**
  81. * @param mixed $name
  82. */
  83. public function setName($name)
  84. {
  85. $this->name = $name;
  86. }
  87. /**
  88. * @return mixed
  89. */
  90. public function getStatus(): int
  91. {
  92. return $this->status;
  93. }
  94. /**
  95. * @param mixed $status
  96. */
  97. public function setStatus($status)
  98. {
  99. $this->status = $status;
  100. }
  101. /**
  102. * @return array
  103. */
  104. public function getChildren(): array
  105. {
  106. return $this->children;
  107. }
  108. /**
  109. * @param array $children
  110. */
  111. public function setChildren(array $children)
  112. {
  113. $this->children = $children;
  114. }
  115. /**
  116. * @param DictionaryObj $children
  117. */
  118. public function addChildrenToTop(DictionaryObj $children)
  119. {
  120. array_unshift($this->children, $children);
  121. }
  122. /**
  123. * @param DictionaryObj $children
  124. */
  125. public function addChildrenToBottom(DictionaryObj $children)
  126. {
  127. $this->children[] = $children;
  128. }
  129. /**
  130. * @return mixed
  131. */
  132. public function getMultiple(): int
  133. {
  134. return $this->multiple;
  135. }
  136. /**
  137. * @param mixed $multiple
  138. */
  139. public function setMultiple($multiple)
  140. {
  141. $this->multiple = $multiple;
  142. }
  143. /**
  144. * @return array
  145. */
  146. public function getDerive(): array
  147. {
  148. return $this->derive;
  149. }
  150. /**
  151. * @param DeriveObj $derive
  152. */
  153. public function addDeriveToTop(DeriveObj $derive)
  154. {
  155. array_unshift($this->derive, $derive);
  156. }
  157. /**
  158. * @param DeriveObj $derive
  159. */
  160. public function addDeriveToBottom(DeriveObj $derive)
  161. {
  162. $this->derive[] = $derive;
  163. }
  164. /**
  165. * @param array $derive
  166. */
  167. public function setDerive(array $derive)
  168. {
  169. $this->derive = $derive;
  170. }
  171. public function __construct($id, $pid, $name, $status, $multiple, $has_children, $can_change, $can_children, $can_multiple,$sort)
  172. {
  173. $this->id = $id;
  174. $this->pid = $pid;
  175. $this->name = $name;
  176. $this->status = $status;
  177. $this->multiple = $multiple;
  178. $this->has_children = $has_children;
  179. $this->can_change = $can_change;
  180. $this->can_children = $can_children;
  181. $this->can_multiple = $can_multiple;
  182. $this->sort = $sort;
  183. }
  184. /**
  185. * json_encode无法转化私有属性,需要使用jsonSerialize自定义转换私有的属性
  186. * @return array
  187. */
  188. public function jsonSerialize(): array
  189. {
  190. return [
  191. "id" => $this->id,
  192. "pid" => $this->pid,
  193. "name" => $this->name,
  194. "status" => $this->status,
  195. "multiple" => $this->multiple,
  196. "children" => $this->children,
  197. "derive" => $this->derive,
  198. "has_children" => $this->has_children,
  199. "can_change" => $this->can_change,
  200. "can_children" => $this->can_children,
  201. "can_multiple" => $this->can_multiple,
  202. "sort" => $this->sort,
  203. ];
  204. }
  205. }