MerchantConfig.php 3.3KB

пре 4 година
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. <?php
  2. namespace Lc\ShopBundle\Model;
  3. use Doctrine\ORM\Mapping as ORM;
  4. use Symfony\Component\HttpFoundation\File\File;
  5. use Vich\UploaderBundle\Mapping\Annotation as Vich;
  6. /**
  7. * @ORM\MappedSuperclass()
  8. * @Vich\Uploadable
  9. */
  10. abstract class MerchantConfig extends AbstractEntity
  11. {
  12. /**
  13. * @ORM\ManyToOne(targetEntity="Lc\ShopBundle\Context\MerchantInterface", inversedBy="merchantConfigs")
  14. * @ORM\JoinColumn(nullable=false)
  15. */
  16. protected $merchant;
  17. /**
  18. * @ORM\Column(type="string", length=63)
  19. */
  20. protected $name;
  21. /**
  22. * @ORM\Column(type="text", nullable=true)
  23. */
  24. protected $value;
  25. /**
  26. * @Vich\UploadableField(mapping="images", fileNameProperty="value")
  27. * @var File
  28. */
  29. protected $imageFile;
  30. public static $availableOptions = [] ;
  31. public function getMerchant(): ?Merchant
  32. {
  33. return $this->merchant;
  34. }
  35. public function setMerchant(?Merchant $merchant): self
  36. {
  37. $this->merchant = $merchant;
  38. return $this;
  39. }
  40. public function getName(): ?string
  41. {
  42. return $this->name;
  43. }
  44. public function setName(string $name): self
  45. {
  46. $this->name = $name;
  47. return $this;
  48. }
  49. public function getValue(): ?string
  50. {
  51. return $this->value;
  52. }
  53. public function setValue($value): self
  54. {
  55. $this->value = $value;
  56. return $this;
  57. }
  58. public function setImageFile(File $image = null)
  59. {
  60. $this->imageFile = $image;
  61. // VERY IMPORTANT:
  62. // It is required that at least one field changes if you are using Doctrine,
  63. // otherwise the event listeners won't be called and the file is lost
  64. if ($image) {
  65. // if 'updatedAt' is not defined in your entity, use another property
  66. $this->updatedAt = new \DateTime('now');
  67. }
  68. }
  69. public function getImageFile()
  70. {
  71. return $this->imageFile;
  72. }
  73. public static function getAvailableOptions(): array
  74. {
  75. return static::$availableOptions ;
  76. }
  77. public function getOption()
  78. {
  79. if(isset(static::$availableOptions[$this->getName()])) {
  80. return static::$availableOptions[$this->getName()] ;
  81. }
  82. return false ;
  83. }
  84. public function getOptionValue($key, $default = '')
  85. {
  86. $option = $this->getOption() ;
  87. if($option) {
  88. if(isset($option[$key])) {
  89. return $option[$key] ;
  90. }
  91. }
  92. return $default ;
  93. }
  94. public function getLabel()
  95. {
  96. return 'field.MerchantConfig.'.$this->getOptionValue('id') ;
  97. }
  98. public function getFieldType()
  99. {
  100. return $this->getOptionValue('type', 'text') ;
  101. }
  102. public function getDefaultValue()
  103. {
  104. return $this->getOptionValue('default') ;
  105. }
  106. }