ListMedia1.php 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. <?php
  2. namespace App\Models\Parameter;
  3. use App\Helpers\Utils;
  4. use App\Helpers\ParameterUtils;
  5. use App\Models\Parameter\FormA;
  6. use App\Models\Parameter\FormB;
  7. use App\Models\Parameter\Modal;
  8. class ListMedia1
  9. {
  10. private $data;
  11. private $ecodingBpa;
  12. private $bpa;
  13. private $permissionNameList = ['is_create', 'is_update', 'is_create', 'is_read', 'is_delete', 'is_create', 'is_create'];
  14. public function __construct($bpa, $customParaName = null, $mode = 'erp')
  15. {
  16. $this->ecodingBpa = $bpa;
  17. $this->bpa = Utils::bpaDecoding($bpa);
  18. if (isset($customParaName)) {
  19. $this->bpa['para_name'] = $customParaName;
  20. }
  21. // dd($this->bpa);
  22. $this->data = Utils::getParamFile($this->bpa['para_name'], '.json', false, $mode);
  23. $this->data['General'] = array_merge($this->data['General'], ['returnUrl' => $this->bpa['page_uri'].'?bpa='.$bpa]);
  24. $this->converterData();
  25. }
  26. public function getData($customName = null)
  27. {
  28. if (isset($customName)) {
  29. return [$customName => $this->data];
  30. }
  31. return ['listMedia1' => $this->data];
  32. }
  33. public function getCopyPara($SelectOptionsName, $value)
  34. {
  35. return collect($this->data[$SelectOptionsName])->where('Value', $value)->pluck('Parameter');
  36. }
  37. private function resetDisplayVarsToDefaultValues()
  38. {
  39. // 사이즈 디폴트 생성
  40. if (! isset($this->data['DisplayVars'])) {
  41. $this->data['DisplayVars']['InitLines'] = 10;
  42. $this->data['DisplayVars']['HeadHeight'] = '250';
  43. $this->data['DisplayVars']['BodyHeight'] = '400';
  44. foreach (['IsListFirst', 'IsAddTotalLine', 'IsExcelColumn', 'IsDownloadList', 'IsShowOnlyClosed'] as $displayVar) {
  45. $this->data['DisplayVars'][$displayVar] = false;
  46. }
  47. } else {
  48. if (empty($this->data['DisplayVars']['InitLines']))
  49. $this->data['DisplayVars']['InitLines'] = 10;
  50. if (empty($this->data['DisplayVars']['HeadHeight']))
  51. $this->data['DisplayVars']['HeadHeight'] = '250';
  52. if (empty($this->data['DisplayVars']['BodyHeight']))
  53. $this->data['DisplayVars']['BodyHeight'] = '400';
  54. foreach (['IsListFirst', 'IsAddTotalLine', 'IsExcelColumn', 'IsDownloadList', 'IsShowOnlyClosed'] as $displayVar) {
  55. if (empty($this->data['DisplayVars'][$displayVar]))
  56. $this->data['DisplayVars'][$displayVar] = false;
  57. }
  58. }
  59. }
  60. private function resetFormVarsToDefaultValues()
  61. {
  62. if (! isset($this->data['DisplayVars']['IsSelectPopupHidden']) || ! $this->data['DisplayVars']['IsSelectPopupHidden']) {
  63. $this->data['DisplayVars']['IsSelectPopupHidden'] = false;
  64. }
  65. if (! isset($this->data['FormVars'][0]['FilterOption'])) {
  66. $this->data['FormVars'][0]['FilterOption'] = '';
  67. $this->data['FilterSelectOptions'] = [];
  68. }
  69. if (! isset($this->data['FormVars'][0]['SimpleOption'])) {
  70. $this->data['FormVars'][0]['SimpleSelectOptions'] = '';
  71. $this->data['SimpleSelectOptions'] = [];
  72. }
  73. if (! isset($this->data['DisplayVars']['IsC1Popup'])) {
  74. $this->data['DisplayVars']['IsC1Popup'] = '0';
  75. }
  76. }
  77. private function getListType1RangeVarsModalParameter()
  78. {
  79. if (! isset($this->data['ListType1RangeVars'])) return;
  80. // ListType1RangeVars 모달 파라메터 얻기
  81. foreach ($this->data['ListType1RangeVars']['ParameterName'] as $key => $parameterName) {
  82. if ($this->data['FormVars']['Display'][$key] == 'd-none') {
  83. $this->data['ListType1RangeVars']['Parameter'][$key] = '';
  84. continue;
  85. }
  86. $this->data['ListType1RangeVars']['Parameter'][$key] = (new Modal($parameterName))->getData();
  87. $this->data['ListType1RangeVars']['BladeRoute'][$key] = 'front.outline.static.'.$this->data['ListType1RangeVars']['Component'][$key];
  88. }
  89. }
  90. private function applyFormVarsSettings()
  91. {
  92. if ($this->data['DisplayVars']['IsSelectPopupHidden']) {
  93. $this->data['FormVars']['Hidden']['SelectPopup'] = 'hidden';
  94. $this->data['FormVars']['Display']['SelectPopup'] = 'd-none';
  95. }
  96. switch ($this->data['DisplayVars']['IsC1Popup']) {
  97. case '0':
  98. break;
  99. case '1':
  100. $this->data['ListVars']['Hidden']['$Radio'] = 'hidden';
  101. $this->data['ListVars']['Display']['$Radio'] = 'd-none';
  102. $this->data['ListVars']['Count']--;
  103. break;
  104. default:
  105. # code...
  106. break;
  107. }
  108. }
  109. private function converterData()
  110. {
  111. foreach (['HeadSelectOptions', 'BodySelectOptions'] as $varsName) {
  112. if (array_key_exists($varsName, $this->data)) {
  113. $this->createPermission($varsName);
  114. $this->exceptionHandling($varsName);
  115. }
  116. }
  117. $this->resetFormVarsToDefaultValues();
  118. foreach (['FormVars', 'ListVars', 'FooterVars', 'ListType1RangeVars'] as $varsName) {
  119. if (array_key_exists($varsName, $this->data)) {
  120. ParameterUtils::separateAlignAndFormat($this->data, $varsName);
  121. ParameterUtils::checkDisplayAndCount($this->data, $varsName);
  122. ParameterUtils::mappingKeys($this->data, $varsName);
  123. }
  124. }
  125. $this->checkSaveBtnPermission();
  126. $this->resetDisplayVarsToDefaultValues();
  127. $this->getListType1RangeVarsModalParameter();
  128. $this->popupOptionsConverterData('SelectPopupOptions');
  129. $this->applyFormVarsSettings();
  130. // 파라메터 읽어옴.
  131. for ($i = 0; $i < count($this->data['SelectPopupOptions']); $i++) {
  132. $parameterName = $this->data['SelectPopupOptions'][$i]['ParameterName'];
  133. if (strpos($parameterName, 'form-a') !== false) {
  134. array_merge($this->data['SelectPopupOptions'][$i] = array_merge($this->data['SelectPopupOptions'][$i], (new FormA($this->ecodingBpa, $parameterName))->getData('Parameter')));
  135. $this->data['SelectPopupOptions'][$i]['ParameterType'] = 'formA';
  136. } else if (strpos($parameterName, 'form-b') !== false) {
  137. array_merge($this->data['SelectPopupOptions'][$i] = array_merge($this->data['SelectPopupOptions'][$i], (new FormB($this->ecodingBpa, $parameterName))->getData('Parameter')));
  138. $this->data['SelectPopupOptions'][$i]['ParameterType'] = 'formB';
  139. } else if (strpos($parameterName, 'list1') !== false) {
  140. array_merge($this->data['SelectPopupOptions'][$i] = array_merge($this->data['SelectPopupOptions'][$i], (new type1($this->ecodingBpa, $parameterName))->getData('Parameter')));
  141. $this->data['SelectPopupOptions'][$i]['ParameterType'] = 'list1';
  142. } else {
  143. (new Modal('/'))->getData();
  144. }
  145. }
  146. }
  147. private function popupOptionsConverterData($popupOptions)
  148. {
  149. if (! isset($this->data[$popupOptions])) {
  150. $this->data[$popupOptions] = [];
  151. };
  152. // SelectPopupOptions 빈거 예외처리
  153. $this->emptyExceptionHandling($popupOptions);
  154. // 파라메터이름으로 네이밍 변경
  155. $this->renamingWithParameterName($popupOptions);
  156. // 블레이드라우터 생성
  157. $this->createBladeRouter($popupOptions, 'front.dabory.erp.');
  158. // 모달에서 사용 클래스이름 생성
  159. $this->createClassNameToUseInModal($popupOptions);
  160. }
  161. private function createClassNameToUseInModal($popupOptions)
  162. {
  163. $this->data[$popupOptions] = collect($this->data[$popupOptions])->map(function ($popupOption) {
  164. return array_merge($popupOption, ['ModalClassName' => Utils::kebabCase($popupOption['Component'])]);
  165. })->toArray();
  166. }
  167. private function createBladeRouter($popupOptions, $url = '')
  168. {
  169. $this->data[$popupOptions] = collect($this->data[$popupOptions])->map(function ($popupOption) use ($url) {
  170. return array_merge($popupOption, ['BladeRoute' => $url.$popupOption['Component']]);
  171. })->toArray();
  172. }
  173. private function renamingWithParameterName($popupOptions)
  174. {
  175. $this->data[$popupOptions] = collect($this->data[$popupOptions])->map(function ($popupOption) {
  176. $parameterName = $popupOption['Parameter'];
  177. return array_merge($popupOption, ['ParameterName' => $parameterName]);
  178. })->toArray();
  179. }
  180. private function emptyExceptionHandling($popupOptions)
  181. {
  182. // SelectPopupOptions 빈거 예외처리
  183. $this->data[$popupOptions] = collect($this->data[$popupOptions])->filter(function ($popupOption) {
  184. return ! empty($popupOption['Caption']) && ! empty($popupOption['Component']);
  185. })->toArray();
  186. }
  187. private function createPermission($SelectOptionsName)
  188. {
  189. $this->data[$SelectOptionsName] = collect($this->data[$SelectOptionsName])->map(function ($selectBtnOption, $index) {
  190. return array_merge($selectBtnOption, ['Permission' => $this->permissionNameList[$index] ?? 'is_create']);
  191. })->toArray();
  192. }
  193. private function exceptionHandling($SelectOptionsName)
  194. {
  195. $this->data[$SelectOptionsName] = collect($this->data[$SelectOptionsName])->filter(function ($selectBtnOption) {
  196. return $selectBtnOption['Value'] != NULL;
  197. })->filter(function ($selectBtnOption) {
  198. return $this->bpa['permission'][$selectBtnOption['Permission']] == 1;
  199. })->values()->toArray();
  200. }
  201. private function checkSaveBtnPermission()
  202. {
  203. if (isset($this->data['FormVars']['Title']['SaveButton']) && !$this->bpa['permission']['is_update']) {
  204. $this->data['FormVars']['Hidden']['SaveButton'] = 'hidden';
  205. }
  206. }
  207. }