Option.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. <?php
  2. namespace ModulesGarden\Servers\KerioEmail\App\Services\ConfigurableOptions\Models;
  3. use ModulesGarden\Servers\KerioEmail\App\Services\ConfigurableOptions\Abstracts\AbstractSerialize;
  4. use ModulesGarden\Servers\KerioEmail\App\Services\ConfigurableOptions\Helper\TypeConstans;
  5. /**
  6. * Description of Option
  7. *
  8. * @author Mateusz Pawłowski <mateusz.pa@modulesgarden.com>
  9. */
  10. class Option extends AbstractSerialize
  11. {
  12. /*
  13. * @var string $optionname
  14. */
  15. protected $gid;
  16. /*
  17. * @var string $optionname
  18. */
  19. protected $optionname;
  20. /*
  21. * @var string $optiontype
  22. */
  23. protected $optiontype = 1;
  24. /*
  25. * @var integer $min
  26. */
  27. protected $qtyminimum = 0;
  28. /*
  29. * @var integer $max
  30. */
  31. protected $qtymaximum = 0;
  32. /*
  33. * @var integer $order
  34. */
  35. protected $order = 0;
  36. /*
  37. * @var integer $hidden
  38. */
  39. protected $hidden = 0;
  40. /*
  41. * @var array $subOptions
  42. */
  43. protected $subOptions = [];
  44. /*
  45. * Alternative method to set required fields
  46. *
  47. * @param string $name, \ModulesGarden\Servers\KerioEmail\App\Service\ConfigurableOptions\Helper\TypeConstans $type
  48. */
  49. public function __construct($key, $name = null, $type = null)
  50. {
  51. $this->optionname = $this->prepareName($key, $name);
  52. $this->optiontype = $type;
  53. }
  54. /*
  55. * Add additional suboptions
  56. *
  57. * @params \ModulesGarden\Servers\KerioEmail\App\Service\ConfigurableOptions\Models\SubOption $option
  58. * @return $this
  59. */
  60. public function addSubOption(SubOption $option)
  61. {
  62. $this->subOptions[] = $option;
  63. return $this;
  64. }
  65. /*
  66. * Set Option Name
  67. *
  68. * @param string $name;
  69. *
  70. * @return object $this
  71. */
  72. public function setName($name)
  73. {
  74. $this->optionname = $name;
  75. return $this;
  76. }
  77. /*
  78. * Set Option Name
  79. *
  80. * @param object \ModulesGarden\Servers\KerioEmail\App\Service\ConfigurableOptions\Helper\TypeConstans
  81. *
  82. * @return object $this
  83. */
  84. public function setType(TypeConstans $type)
  85. {
  86. $this->optiontype = $type;
  87. return $this;
  88. }
  89. /*
  90. * Set option min, require for quantity
  91. *
  92. * @param string $min;
  93. *
  94. * @return object $this
  95. */
  96. public function setMin($min)
  97. {
  98. $this->qtyminimum = $min;
  99. return $this;
  100. }
  101. /*
  102. * Set option max, require for quantity
  103. *
  104. * @param string $max;
  105. *
  106. * @return object $this
  107. */
  108. public function setMax($max)
  109. {
  110. $this->qtymaximum = $max;
  111. return $this;
  112. }
  113. /*
  114. * Set Order
  115. *
  116. * @param integer $order;
  117. *
  118. * @return object $this
  119. */
  120. public function setOrder($order)
  121. {
  122. $this->order = $order;
  123. return $this;
  124. }
  125. /*
  126. * Set Option Name
  127. *
  128. * @param string $name;
  129. *
  130. * @return object $this
  131. */
  132. public function setHidden($hidden)
  133. {
  134. $this->hidden = $hidden;
  135. return $this;
  136. }
  137. /*
  138. * Set Group Option ID
  139. *
  140. * @param integer $gid;
  141. *
  142. * @return object $this
  143. */
  144. public function setGid($gid)
  145. {
  146. $this->gid = $gid;
  147. return $this;
  148. }
  149. public function getSubOptions()
  150. {
  151. return $this->subOptions;
  152. }
  153. public function getName()
  154. {
  155. $expoldeName = explode('|', $this->optionname);
  156. if (!empty($expoldeName[1]))
  157. {
  158. return $expoldeName[1];
  159. }
  160. return $this->optionname;
  161. }
  162. public function getKey()
  163. {
  164. return explode('|', $this->optionname)[0];
  165. }
  166. }