Manual.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. namespace App\Models\Parameter;
  3. use App\Helpers\Utils;
  4. class Manual
  5. {
  6. private $data;
  7. private $para_name;
  8. protected $bpa;
  9. private $themeDir;
  10. private $isTheme;
  11. public function __construct($para_name, $bpa)
  12. {
  13. $this->bpa = Utils::bpaDecoding($bpa);
  14. $this->para_name = $para_name;
  15. $this->themeDir = $themeDir ?? $this->bpa['theme_dir'];
  16. $this->isTheme = $this->themeDir && $this->themeDir !== 'empty';
  17. if ($this->isTheme) {
  18. $this->data = Utils::getThemeParamFile($para_name, '.json', $this->themeDir);
  19. } else {
  20. $this->data = Utils::getParamFile($para_name);
  21. }
  22. $this->converterData();
  23. }
  24. public function getData()
  25. {
  26. return $this->data;
  27. }
  28. public function getMdFile(&$vars, $type) {
  29. foreach ($vars[$type] as $key => $value) {
  30. if ($this->isTheme) {
  31. $data = Utils::getThemeParamFile($this->para_name.'/'.$vars[$type][$key]['Path'], '', $this->themeDir);
  32. } else {
  33. $data = Utils::getParamFile($this->para_name.'/'.$vars[$type][$key]['Path'], '');
  34. }
  35. $vars[$type][$key]['Parameter'] = $data;
  36. }
  37. }
  38. public function getImagePath(&$vars, $type) {
  39. foreach ($vars[$type] as $key => $value) {
  40. if ($this->isTheme) {
  41. $data = Utils::getThemeParamUrl($this->para_name.'/'.$this->data[$type][$key]['Path'], '', $this->themeDir);
  42. } else {
  43. $data = Utils::getParamUrl($this->para_name.'/'.$this->data[$type][$key]['Path'], '');
  44. }
  45. $vars[$type][$key]['Path'] = $data;
  46. }
  47. }
  48. private function converterData()
  49. {
  50. $this->getMdFile($this->data, 'Text');
  51. $this->getImagePath($this->data, 'Images');
  52. // dump($this->para_name);
  53. // dd($this->data);
  54. }
  55. }