ACTIVITY_STATUS.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. namespace App\Module\Activity\Enums;
  3. use UCore\Enum\EnumCore;
  4. use UCore\Enum\EnumToInt;
  5. /**
  6. * 活动状态枚举
  7. */
  8. enum ACTIVITY_STATUS: int
  9. {
  10. use EnumCore, EnumToInt;
  11. /**
  12. * 未开始
  13. */
  14. case NOT_STARTED = 0;
  15. /**
  16. * 进行中
  17. */
  18. case IN_PROGRESS = 1;
  19. /**
  20. * 已结束
  21. */
  22. case ENDED = 2;
  23. /**
  24. * 已关闭
  25. */
  26. case CLOSED = 3;
  27. /**
  28. * 获取所有活动状态
  29. *
  30. * @return array
  31. */
  32. public static function getAll(): array
  33. {
  34. return [
  35. self::NOT_STARTED->value => '未开始',
  36. self::IN_PROGRESS->value => '进行中',
  37. self::ENDED->value => '已结束',
  38. self::CLOSED->value => '已关闭',
  39. ];
  40. }
  41. /**
  42. * 获取活动状态名称
  43. *
  44. * @param int $status
  45. * @return string
  46. */
  47. public static function getName(int $status): string
  48. {
  49. return self::getAll()[$status] ?? '未知状态';
  50. }
  51. /**
  52. * 检查活动状态是否有效
  53. *
  54. * @param int $status
  55. * @return bool
  56. */
  57. public static function isValid(int $status): bool
  58. {
  59. return isset(self::getAll()[$status]);
  60. }
  61. }