FormB.php 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. <?php
  2. namespace App\Models\Parameter;
  3. use App\Helpers\Utils;
  4. use App\Helpers\ParameterUtils;
  5. use App\Models\Parameter\CopyToAnother;
  6. use Illuminate\Support\Str;
  7. class FormB
  8. {
  9. protected $data;
  10. protected $bpa;
  11. protected $permissionNameList = ['is_create', 'is_update', 'is_create', 'is_read', 'is_delete', 'is_create', 'is_create'];
  12. public function __construct($bpa, $customParaName = null, $themeDir = null, $popupOptions = false, $mode = 'erp')
  13. {
  14. if (empty($bpa)) {
  15. $this->initBpa();
  16. } else {
  17. $this->bpa = Utils::bpaDecoding($bpa);
  18. }
  19. if (isset($customParaName)) {
  20. $this->bpa['para_name'] = $customParaName;
  21. }
  22. // dd($this->bpa);
  23. $themeDir = $themeDir ?? $this->bpa['theme_dir'];
  24. if ($themeDir && $themeDir !== 'empty') {
  25. $this->data = Utils::getThemeParamFile($this->bpa['para_name'], '.json', $themeDir, $popupOptions);
  26. } else {
  27. $this->data = Utils::getParamFile($this->bpa['para_name'], '.json', $popupOptions, $mode);
  28. }
  29. $this->data['General'] = array_merge($this->data['General'], ['returnUrl' => $this->bpa['page_uri'].'?bpa='.$bpa]);
  30. $this->converterData();
  31. }
  32. public function initBpa()
  33. {
  34. $this->bpa['theme_dir'] = 'empty';
  35. $this->bpa['page_uri'] = '/';
  36. $this->bpa['permission'] = [
  37. 'is_mymenu' => '0',
  38. 'is_list' => '1',
  39. 'is_read' => '1',
  40. 'is_create' => '1',
  41. 'is_update' => '1',
  42. 'is_delete' => '1',
  43. 'is_newtab' => '0',
  44. ];
  45. }
  46. public function getData($customName = null)
  47. {
  48. if (isset($customName)) {
  49. return [$customName => $this->data];
  50. }
  51. return ['formB' => $this->data];
  52. }
  53. public function getCopyPara($SelectOptionsName, $value)
  54. {
  55. return collect($this->data[$SelectOptionsName])->where('Value', $value)->pluck('ParameterName');
  56. }
  57. protected function converterData()
  58. {
  59. foreach (['HeadSelectOptions', 'BodySelectOptions'] as $varsName) {
  60. if (array_key_exists($varsName, $this->data)) {
  61. $this->createPermission($varsName);
  62. $this->exceptionHandling($varsName);
  63. $this->renamingWithParameterName($varsName);
  64. $this->getCopyParameter($varsName);
  65. }
  66. }
  67. foreach (['FormVars', 'ListVars', 'FooterVars', 'EyeTestVars'] as $varsName) {
  68. if (array_key_exists($varsName, $this->data)) {
  69. ParameterUtils::separateAlignAndFormat($this->data, $varsName);
  70. ParameterUtils::checkDisplayAndCount($this->data, $varsName);
  71. ParameterUtils::mappingKeys($this->data, $varsName);
  72. }
  73. }
  74. $this->checkSaveBtnPermission();
  75. }
  76. protected function getCopyParameter($selectOptions)
  77. {
  78. // SelectOptions 모달 파라메터 얻기
  79. for ($i = 0; $i < count($this->data[$selectOptions]); $i++) {
  80. if (empty($this->data[$selectOptions][$i]['ParameterName'])) continue;
  81. $themeDir = $this->data[$selectOptions][$i]['ThemeDir'] ?? 'empty';
  82. $this->data[$selectOptions][$i]['OptionsType'] = $selectOptions;
  83. $popupOption = $this->data[$selectOptions][$i];
  84. $parameterUrl = "/copy/{$this->data[$selectOptions][$i]['Value']}/{$this->data[$selectOptions][$i]['ParameterName']}";
  85. if ($this->data[$selectOptions][$i]['Value'] == 'copy-to-another') {
  86. $this->data[$selectOptions][$i]['Parameter'] = (new CopyToAnother($parameterUrl, $themeDir, $popupOption))->getData();
  87. } elseif ($this->data[$selectOptions][$i]['Value'] == 'body-copy') {
  88. $this->data[$selectOptions][$i]['Parameter'] = (new BodyCopy($parameterUrl, $themeDir, $popupOption))->getData();
  89. }
  90. $this->data[$selectOptions][$i]['BladeRoute'] = 'front.outline.static.'.$this->data[$selectOptions][$i]['Value'];
  91. }
  92. }
  93. protected function renamingWithParameterName($selectOptions)
  94. {
  95. $this->data[$selectOptions] = collect($this->data[$selectOptions])->map(function ($selectOption) {
  96. $parameterName = $selectOption['Parameter'] ?? '';
  97. return array_merge($selectOption, ['ParameterName' => $parameterName, 'ModalClassName' => Str::replace('/', '-', $parameterName)]);
  98. })->toArray();
  99. }
  100. protected function createPermission($SelectOptionsName)
  101. {
  102. $this->data[$SelectOptionsName] = collect($this->data[$SelectOptionsName])->map(function ($selectBtnOption, $index) {
  103. return array_merge($selectBtnOption, ['Permission' => $this->permissionNameList[$index] ?? 'is_create']);
  104. })->toArray();
  105. }
  106. protected function exceptionHandling($SelectOptionsName)
  107. {
  108. $this->data[$SelectOptionsName] = collect($this->data[$SelectOptionsName])->filter(function ($selectBtnOption) {
  109. return $selectBtnOption['Value'] != NULL;
  110. })->filter(function ($selectBtnOption) {
  111. return $this->bpa['permission'][$selectBtnOption['Permission']] == 1;
  112. })->values()->toArray();
  113. }
  114. protected function checkSaveBtnPermission()
  115. {
  116. if (isset($this->data['FormVars']['Title']['SaveButton']) && !$this->bpa['permission']['is_update']) {
  117. $this->data['FormVars']['Hidden']['SaveButton'] = 'hidden';
  118. }
  119. }
  120. }