106 lines
2.4KB

  1. <?php
  2. namespace Lc\ShopBundle\Model;
  3. use Doctrine\ORM\Mapping as ORM;
  4. /**
  5. * @ORM\MappedSuperclass()
  6. */
  7. abstract class MerchantConfig
  8. {
  9. /**
  10. * @ORM\ManyToOne(targetEntity="Lc\ShopBundle\Context\MerchantInterface", inversedBy="merchantConfigs")
  11. * @ORM\JoinColumn(nullable=false)
  12. */
  13. protected $merchant;
  14. /**
  15. * @ORM\Column(type="string", length=63)
  16. */
  17. protected $name;
  18. /**
  19. * @ORM\Column(type="text", nullable=true)
  20. */
  21. protected $value;
  22. public static $availableOptions = [] ;
  23. public function getMerchant(): ?Merchant
  24. {
  25. return $this->merchant;
  26. }
  27. public function setMerchant(?Merchant $merchant): self
  28. {
  29. $this->merchant = $merchant;
  30. return $this;
  31. }
  32. public function getName(): ?string
  33. {
  34. return $this->name;
  35. }
  36. public function setName(string $name): self
  37. {
  38. $this->name = $name;
  39. return $this;
  40. }
  41. public function getValue(): ?string
  42. {
  43. return $this->value;
  44. }
  45. public function setValue(string $value): self
  46. {
  47. $this->value = $value;
  48. return $this;
  49. }
  50. public static function getAvailableOptions(): array
  51. {
  52. return static::$availableOptions ;
  53. }
  54. public function getOption()
  55. {
  56. if(isset(static::$availableOptions[$this->getName()])) {
  57. return static::$availableOptions[$this->getName()] ;
  58. }
  59. return false ;
  60. }
  61. public function getOptionValue($key, $default = '')
  62. {
  63. $option = $this->getOption() ;
  64. if($option) {
  65. if(isset($option[$key])) {
  66. return $option[$key] ;
  67. }
  68. }
  69. return $default ;
  70. }
  71. public function getLabel()
  72. {
  73. return 'field.MerchantConfig.'.$this->getOptionValue('id') ;
  74. }
  75. public function getFieldType()
  76. {
  77. return $this->getOptionValue('type', 'text') ;
  78. }
  79. public function getDefaultValue()
  80. {
  81. return $this->getOptionValue('default') ;
  82. }
  83. }