User.class.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. <?php
  2. include_once(__DIR__."/../../utils/Utils.class.php");
  3. class ExtattrItem
  4. {
  5. public $name = null;
  6. public $value = null;
  7. public function __construct($name = null, $value = null)
  8. {
  9. $this->name = $name;
  10. $this->value = $value;
  11. }
  12. }
  13. class ExtattrList
  14. {
  15. public $attrs = null; // ExtattrItem array
  16. }
  17. class User
  18. {
  19. public $userid = null; // string
  20. public $name = null; // string
  21. public $english_name = null; // string
  22. public $mobile = null; // string
  23. public $department = null; // uint array
  24. public $order = null; // uint array
  25. public $position = null; // string
  26. public $gender = null; // uint [bug]
  27. public $email = null; // string
  28. public $telephone = null; // string
  29. public $isleader = null; // uint
  30. public $avatar_mediaid = null; // string
  31. public $enable = null; // uint
  32. public $extattr = null; // ExtattrList
  33. public $status = null; // uint, 激活状态: 1=已激活,2=已禁用,4=未激活。已激活代表已激活企业微信或已关注微信插件。未激活代表既未激活企业微信又未关注微信插件。
  34. static public function Array2User($arr)
  35. {
  36. $user = new User();
  37. $user->userid = Utils::arrayGet($arr, "userid");
  38. $user->name = Utils::arrayGet($arr, "name");
  39. $user->english_name = Utils::arrayGet($arr, "english_name");
  40. $user->mobile = Utils::arrayGet($arr, "mobile");
  41. $user->department = Utils::arrayGet($arr, "department");
  42. $user->order = Utils::arrayGet($arr, "order");
  43. $user->position = Utils::arrayGet($arr, "position");
  44. $user->gender = Utils::arrayGet($arr, "gender");
  45. $user->email = Utils::arrayGet($arr, "email");
  46. $user->telephone = Utils::arrayGet($arr, "telephone");
  47. $user->isleader = Utils::arrayGet($arr, "isleader");
  48. $user->avatar_mediaid = Utils::arrayGet($arr, "avatar_mediaid");
  49. $user->enable = Utils::arrayGet($arr, "enable");
  50. $user->status = Utils::arrayGet($arr, "status");
  51. if (array_key_exists("extattr", $arr)) {
  52. $attrs = $arr["extattr"]["attrs"];
  53. if (is_array($attrs)) {
  54. $user->extattr = new ExtattrList();
  55. foreach ($attrs as $item) {
  56. $name = $item["name"];
  57. $value = $item["value"];
  58. $user->extattr->attrs[] = new ExtattrItem($name, $value);
  59. }
  60. }
  61. }
  62. return $user;
  63. }
  64. static public function Array2UserList($arr)
  65. {
  66. $userList = $arr["userlist"];
  67. $retUserList = array();
  68. if (is_array($userList)) {
  69. foreach ($userList as $item) {
  70. $user = User::Array2User($item);
  71. $retUserList[] = $user;
  72. }
  73. }
  74. return $retUserList;
  75. }
  76. static public function CheckUserCreateArgs($user)
  77. {
  78. Utils::checkNotEmptyStr($user->userid, "userid");
  79. Utils::checkNotEmptyStr($user->name, "name");
  80. Utils::checkNotEmptyArray($user->department, "department");
  81. }
  82. static public function CheckUserUpdateArgs($user)
  83. {
  84. Utils::checkNotEmptyStr($user->userid, "userid");
  85. }
  86. static public function CheckuserBatchDeleteArgs($userIdList)
  87. {
  88. Utils::checkNotEmptyArray($userIdList, "userid list");
  89. foreach ($userIdList as $userId) {
  90. Utils::checkNotEmptyStr($userId, "userid");
  91. }
  92. if (count($userIdList) > 200) {
  93. throw QyApiError("no more than 200 userid once");
  94. }
  95. }
  96. }