ParameterUtils.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. <?php
  2. namespace App\Helpers;
  3. use Illuminate\Support\Str;
  4. class ParameterUtils
  5. {
  6. public static function BladeRouteFor($themeDir)
  7. {
  8. $url = Str::replace('/', '.', $themeDir);
  9. return ltrim($url, '.');
  10. }
  11. public static function checkDisplayAndCount(&$vars, $type)
  12. {
  13. $basicData = $vars[$type][0];
  14. $vars[$type][] = ParameterUtils::checkCount($basicData);
  15. $vars[$type][] = ParameterUtils::checkDisplay($basicData);
  16. $vars[$type][] = ParameterUtils::checkDisplay($basicData, 1);
  17. }
  18. public static function checkDisplay($data, $type = 0)
  19. {
  20. if (empty($data)) { return $type == 0 ? 'hidden' : 'd-none'; }
  21. if (! is_array($data)) { return $type == 0 ? '' : 'd-flex'; }
  22. $hiddenList = [];
  23. foreach ($data as $key => $formVar) {
  24. $hiddenList[$key] = self::checkDisplay($formVar, $type);
  25. }
  26. return $hiddenList;
  27. }
  28. public static function checkCount($data)
  29. {
  30. $count = 0;
  31. if (empty($data)) { return 0; }
  32. if (! is_array($data)) { return 1; }
  33. foreach ($data as $key => $formVar) {
  34. $count += self::checkCount($formVar);
  35. }
  36. return $count;
  37. }
  38. // Todo: len 이용해서 수동으로 Format, Align 나누는데 파라에서 읽어서 가져오게 리팩토링 필요
  39. public static function separateAlignAndFormat(&$vars, $type)
  40. {
  41. if (Str::contains($type, 'ListVars')) {
  42. $len = 2;
  43. } else if ($type === 'FormVars' || $type === 'FormPostVars') {
  44. $len = 1;
  45. } else {
  46. return;
  47. }
  48. if (! array_key_exists($len, $vars[$type])) return;
  49. foreach ($vars[$type][$len] as $key => $listVar) {
  50. if (in_array(strtolower($listVar), ['center', 'left', 'right'])) {
  51. $formatList[$key] = '';
  52. } else if (preg_match("/decimal\s*\(\s*'(.*?)\'\s*\)\s*/", $listVar)) {
  53. $vars[$type][$len][$key] = 'right';
  54. $formatList[$key] = $listVar;
  55. // $formatList[$key] = self::formatChange($listVar);
  56. } else {
  57. $vars[$type][$len][$key] = 'center';
  58. $formatList[$key] = $listVar;
  59. }
  60. }
  61. $vars[$type][] = $formatList;
  62. }
  63. // Todo: 수동으로 배열 key 할당해주는 함수인데 전부 리팩토링 + 테스트코드 작성하기
  64. public static function mappingKeys(&$vars, $type)
  65. {
  66. if (Str::contains($type, 'ListVars')) {
  67. $vars[$type] = collect($vars[$type])->keyBy(function ($value, $key) use ($vars, $type) {
  68. if (count($vars[$type]) == 7) {
  69. switch ($key) {
  70. case 0:
  71. return 'Title';
  72. case 1:
  73. return 'Size';
  74. case 2:
  75. return 'Align';
  76. case count($vars[$type]) - 4:
  77. return 'Format';
  78. case count($vars[$type]) - 3:
  79. return 'Count';
  80. case count($vars[$type]) - 2:
  81. return 'Hidden';
  82. case count($vars[$type]) - 1:
  83. return 'Display';
  84. default:
  85. return;
  86. }
  87. } else if (count($vars[$type]) == 8) {
  88. switch ($key) {
  89. case 0:
  90. return 'Title';
  91. case 1:
  92. return 'Size';
  93. case 2:
  94. return 'Align';
  95. case count($vars[$type]) - 5:
  96. return 'Target';
  97. case count($vars[$type]) - 4:
  98. return 'Format';
  99. case count($vars[$type]) - 3:
  100. return 'Count';
  101. case count($vars[$type]) - 2:
  102. return 'Hidden';
  103. case count($vars[$type]) - 1:
  104. return 'Display';
  105. default:
  106. return;
  107. }
  108. }
  109. })->toArray();
  110. } elseif ($type == 'FooterVars') {
  111. $vars[$type] = collect($vars[$type])->keyBy(function ($value, $key) use ($vars, $type) {
  112. switch ($key) {
  113. case 0:
  114. return 'Title';
  115. case count($vars[$type]) - 3:
  116. return 'Count';
  117. case count($vars[$type]) - 2:
  118. return 'Hidden';
  119. case count($vars[$type]) - 1:
  120. return 'Display';
  121. default:
  122. return;
  123. }
  124. })->toArray();
  125. } else if ($type == 'ListType1RangeVars' || $type == 'CopyToAnotherPopupVars' || $type == 'BodyCopyPopupVars') {
  126. if (count($vars[$type]) == 6) {
  127. $vars[$type] = collect($vars[$type])->keyBy(function ($value, $key) use ($vars, $type) {
  128. switch ($key) {
  129. case 0:
  130. return 'Filter';
  131. case 1:
  132. return 'Component';
  133. case 2:
  134. return 'ParameterName';
  135. case count($vars[$type]) - 3:
  136. return 'Count';
  137. case count($vars[$type]) - 2:
  138. return 'Hidden';
  139. case count($vars[$type]) - 1:
  140. return 'Display';
  141. default:
  142. return;
  143. }
  144. })->toArray();
  145. } else if (count($vars[$type]) == 7) {
  146. $vars[$type] = collect($vars[$type])->keyBy(function ($value, $key) use ($vars, $type) {
  147. switch ($key) {
  148. case 0:
  149. return 'Filter';
  150. case 1:
  151. return 'Component';
  152. case 2:
  153. return 'ParameterName';
  154. case 3:
  155. return 'ThemeDir';
  156. case count($vars[$type]) - 3:
  157. return 'Count';
  158. case count($vars[$type]) - 2:
  159. return 'Hidden';
  160. case count($vars[$type]) - 1:
  161. return 'Display';
  162. default:
  163. return;
  164. }
  165. })->toArray();
  166. }
  167. } else if ($type == 'FormPostVars') {
  168. $vars[$type] = collect($vars[$type])->keyBy(function ($value, $key) use ($vars, $type) {
  169. switch ($key) {
  170. case 0:
  171. return 'Title';
  172. case 1:
  173. return 'Align';
  174. case 2:
  175. return 'MaxLength';
  176. case 3:
  177. return 'Required';
  178. case 4:
  179. return 'Ui';
  180. case 5:
  181. return 'Type';
  182. case count($vars[$type]) - 4:
  183. return 'Format';
  184. case count($vars[$type]) - 3:
  185. return 'Count';
  186. case count($vars[$type]) - 2:
  187. return 'Hidden';
  188. case count($vars[$type]) - 1:
  189. return 'Display';
  190. default:
  191. return;
  192. }
  193. })->toArray();
  194. } else {
  195. $vars[$type] = collect($vars[$type])->keyBy(function ($value, $key) use ($vars, $type) {
  196. if (count($vars[$type]) == 6) {
  197. switch ($key) {
  198. case 0:
  199. return 'Title';
  200. case 1:
  201. return 'Align';
  202. case count($vars[$type]) - 4:
  203. return 'Format';
  204. case count($vars[$type]) - 3:
  205. return 'Count';
  206. case count($vars[$type]) - 2:
  207. return 'Hidden';
  208. case count($vars[$type]) - 1:
  209. return 'Display';
  210. default:
  211. return;
  212. }
  213. } else if (count($vars[$type]) == 8) {
  214. switch ($key) {
  215. case 0:
  216. return 'Title';
  217. case 1:
  218. return 'Align';
  219. case 2:
  220. return 'MaxLength';
  221. case 3:
  222. return 'Required';
  223. case count($vars[$type]) - 4:
  224. return 'Format';
  225. case count($vars[$type]) - 3:
  226. return 'Count';
  227. case count($vars[$type]) - 2:
  228. return 'Hidden';
  229. case count($vars[$type]) - 1:
  230. return 'Display';
  231. default:
  232. return;
  233. }
  234. } else {
  235. switch ($key) {
  236. case 0:
  237. return 'Title';
  238. case count($vars[$type]) - 3:
  239. return 'Count';
  240. case count($vars[$type]) - 2:
  241. return 'Hidden';
  242. case count($vars[$type]) - 1:
  243. return 'Display';
  244. default:
  245. return;
  246. }
  247. }
  248. })->toArray();
  249. }
  250. }
  251. }