Modal.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. namespace App\Models\Parameter;
  3. use App\Helpers\Utils;
  4. use App\Helpers\ParameterUtils;
  5. use App\Exceptions\ParameterException;
  6. class Modal
  7. {
  8. protected $data;
  9. public function __construct($para_name, $themeDir = null, $mode = 'erp', $customVar = '')
  10. {
  11. try {
  12. if ($themeDir && $themeDir !== 'empty') {
  13. $this->data = Utils::getThemeParamFile($para_name, '.json', $themeDir);
  14. } else {
  15. $this->data = Utils::getParamFile($para_name, '.json', false, $mode);
  16. }
  17. } catch (ParameterException $e) {
  18. return redirect()->route('dashboard')->with('error', $e->getMessage());
  19. }
  20. $this->data['General'] = array_merge($this->data['General'] ?? [], ['CustomVar' => $customVar]);
  21. $this->converterData();
  22. }
  23. public function getData($customName = null)
  24. {
  25. if (isset($customName)) {
  26. return [$customName => $this->data];
  27. }
  28. return $this->data;
  29. }
  30. protected function converterData()
  31. {
  32. foreach (['FormVars', 'ListVars', 'FooterVars'] as $varsName) {
  33. if (array_key_exists($varsName, $this->data)) {
  34. ParameterUtils::separateAlignAndFormat($this->data, $varsName);
  35. ParameterUtils::checkDisplayAndCount($this->data, $varsName);
  36. ParameterUtils::mappingKeys($this->data, $varsName);
  37. }
  38. }
  39. }
  40. }