FormProcess.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. <?php
  2. namespace App\Models\Parameter;
  3. use App\Helpers\Utils;
  4. use App\Helpers\ParameterUtils;
  5. use App\Models\Parameter\Modal;
  6. class FormProcess
  7. {
  8. private $data;
  9. private $bpa;
  10. private $permissionNameList = ['is_create', 'is_update', 'is_create', 'is_read', 'is_delete', 'is_create', 'is_create'];
  11. public function __construct($bpa, $customParaName = null)
  12. {
  13. $this->ecodingBpa = $bpa;
  14. $this->bpa = Utils::bpaDecoding($bpa);
  15. if (isset($customParaName)) {
  16. $this->bpa['para_name'] = $customParaName;
  17. }
  18. // dd($this->bpa);
  19. $this->data = Utils::getParamFile($this->bpa['para_name']);
  20. $this->data['General'] = array_merge($this->data['General'], ['returnUrl' => $this->bpa['page_uri'].'?bpa='.$bpa]);
  21. $this->converterData();
  22. }
  23. public function getData($customName = null)
  24. {
  25. if (isset($customName)) {
  26. return [$customName => $this->data];
  27. }
  28. return ['formF' => $this->data];
  29. }
  30. public function getCopyPara($SelectOptionsName, $value)
  31. {
  32. return collect($this->data[$SelectOptionsName])->where('Value', $value)->pluck('Parameter');
  33. }
  34. private function resetDisplayVarsToDefaultValues()
  35. {
  36. // 사이즈 디폴트 생성
  37. if (! isset($this->data['DisplayVars'])) {
  38. $this->data['DisplayVars']['HeadHeight'] = '250';
  39. $this->data['DisplayVars']['BodyHeight'] = '400';
  40. foreach (['IsFirstCheck', 'IsSecondCheck', 'IsThirdCheck', 'IsFourthCheck'] as $displayVar) {
  41. $this->data['DisplayVars'][$displayVar] = false;
  42. }
  43. } else {
  44. if (empty($this->data['DisplayVars']['HeadHeight']))
  45. $this->data['DisplayVars']['HeadHeight'] = '250';
  46. if (empty($this->data['DisplayVars']['BodyHeight']))
  47. $this->data['DisplayVars']['BodyHeight'] = '400';
  48. foreach (['IsFirstCheck', 'IsSecondCheck', 'IsThirdCheck', 'IsFourthCheck'] as $displayVar) {
  49. if (empty($this->data['DisplayVars'][$displayVar]))
  50. $this->data['DisplayVars'][$displayVar] = false;
  51. }
  52. }
  53. }
  54. private function getListType1RangeVarsModalParameter()
  55. {
  56. if (! isset($this->data['ListType1RangeVars'])) return;
  57. // ListType1RangeVars 모달 파라메터 얻기
  58. foreach ($this->data['ListType1RangeVars']['ParameterName'] as $key => $parameterName) {
  59. if ($this->data['FormVars']['Display'][$key] == 'd-none') {
  60. $this->data['ListType1RangeVars']['Parameter'][$key] = '';
  61. continue;
  62. }
  63. $this->data['ListType1RangeVars']['Parameter'][$key] = (new Modal($parameterName))->getData();
  64. $this->data['ListType1RangeVars']['BladeRoute'][$key] = 'front.outline.static.'.$this->data['ListType1RangeVars']['Component'][$key];
  65. }
  66. }
  67. private function converterData()
  68. {
  69. foreach (['HeadSelectOptions', 'BodySelectOptions'] as $varsName) {
  70. if (array_key_exists($varsName, $this->data)) {
  71. $this->createPermission($varsName);
  72. $this->exceptionHandling($varsName);
  73. }
  74. }
  75. foreach (['FormVars', 'ListVars', 'FooterVars', 'ListType1RangeVars'] as $varsName) {
  76. if (array_key_exists($varsName, $this->data)) {
  77. ParameterUtils::separateAlignAndFormat($this->data, $varsName);
  78. ParameterUtils::checkDisplayAndCount($this->data, $varsName);
  79. ParameterUtils::mappingKeys($this->data, $varsName);
  80. }
  81. }
  82. $this->checkSaveBtnPermission();
  83. $this->resetDisplayVarsToDefaultValues();
  84. $this->getListType1RangeVarsModalParameter();
  85. }
  86. private function createPermission($SelectOptionsName)
  87. {
  88. $this->data[$SelectOptionsName] = collect($this->data[$SelectOptionsName])->map(function ($selectBtnOption, $index) {
  89. return array_merge($selectBtnOption, ['Permission' => $this->permissionNameList[$index] ?? 'is_create']);
  90. })->toArray();
  91. }
  92. private function exceptionHandling($SelectOptionsName)
  93. {
  94. $this->data[$SelectOptionsName] = collect($this->data[$SelectOptionsName])->filter(function ($selectBtnOption) {
  95. return $selectBtnOption['Value'] != NULL;
  96. })->filter(function ($selectBtnOption) {
  97. return $this->bpa['permission'][$selectBtnOption['Permission']] == 1;
  98. })->values()->toArray();
  99. }
  100. private function checkSaveBtnPermission()
  101. {
  102. if (isset($this->data['FormVars']['Title']['SaveButton']) && !$this->bpa['permission']['is_update']) {
  103. $this->data['FormVars']['Hidden']['SaveButton'] = 'hidden';
  104. }
  105. }
  106. }