Poster.php 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | Niucloud-admin 企业快速开发的saas管理平台
  4. // +----------------------------------------------------------------------
  5. // | 官方网址:https://www.niucloud.com
  6. // +----------------------------------------------------------------------
  7. // | niucloud团队 版权所有 开源版本可自由商用
  8. // +----------------------------------------------------------------------
  9. // | Author: Niucloud Team
  10. // +----------------------------------------------------------------------
  11. namespace core\dict;
  12. class Poster extends BaseDict
  13. {
  14. /**
  15. * 加载海报模板配置
  16. * @param array $data
  17. * @return array|mixed
  18. */
  19. public function load(array $data = [])
  20. {
  21. $addon = $data[ 'addon' ] ?? '';
  22. $type = $data[ 'type' ] ?? '';
  23. $schedule_files = [];
  24. if (empty($addon)) {
  25. $system_path = $this->getDictPath() . 'poster' . DIRECTORY_SEPARATOR . 'template.php';
  26. if (is_file($system_path)) {
  27. $schedule_files[] = $system_path;
  28. }
  29. $addons = $this->getLocalAddons();
  30. foreach ($addons as $v) {
  31. $addon_path = $this->getAddonDictPath($v) . 'poster' . DIRECTORY_SEPARATOR . 'template.php';
  32. if (is_file($addon_path)) {
  33. $schedule_files[] = $addon_path;
  34. }
  35. }
  36. } else {
  37. $schedule_files = [];
  38. if ($addon == 'system') {
  39. $system_path = $this->getDictPath() . 'poster' . DIRECTORY_SEPARATOR . 'template.php';
  40. if (is_file($system_path)) {
  41. $schedule_files[] = $system_path;
  42. }
  43. } else {
  44. $addon_path = $this->getAddonDictPath($addon) . 'poster' . DIRECTORY_SEPARATOR . 'template.php';
  45. if (is_file($addon_path)) {
  46. $schedule_files[] = $addon_path;
  47. }
  48. }
  49. }
  50. $schedule_files_data = $this->loadFiles($schedule_files);
  51. $schedule_data_array = [];
  52. foreach ($schedule_files_data as $file_data) {
  53. $schedule_data_array = empty($schedule_data_array) ? $file_data : array_merge($schedule_data_array, $file_data);
  54. }
  55. if (!empty($type)) {
  56. foreach ($schedule_data_array as $k => $v) {
  57. if ($v[ 'type' ] != $type) {
  58. unset($schedule_data_array[ $k ]);
  59. }
  60. }
  61. $schedule_data_array = array_values($schedule_data_array);
  62. }
  63. return $schedule_data_array;
  64. }
  65. /**
  66. * 获取海报组件
  67. * @param array $data
  68. * @return array|mixed
  69. */
  70. public function loadComponents(array $data = [])
  71. {
  72. $addons = $this->getLocalAddons();
  73. $components_files = [];
  74. foreach ($addons as $v) {
  75. $components_path = $this->getAddonDictPath($v) . "poster" . DIRECTORY_SEPARATOR . "components.php";
  76. if (is_file($components_path)) {
  77. $components_files[] = $components_path;
  78. }
  79. }
  80. $components_files_data = $this->loadFiles($components_files);
  81. $components = $data;
  82. foreach ($components_files_data as $file_data) {
  83. $components = empty($components) ? $file_data : array_merge2($components, $file_data);
  84. }
  85. return $components;
  86. }
  87. }