product.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. <?php
  2. namespace MGModule\DNSManager2\models\whmcs\product;
  3. use MGModule\DNSManager2 as main;
  4. /**
  5. * Description of product
  6. *
  7. * @Table(name=tblproducts,preventUpdate,prefixed=false)
  8. * @author Michal Czech <michael@modulesgarden.com>
  9. */
  10. class product extends main\mgLibs\models\orm{
  11. /**
  12. *
  13. * @Column(int)
  14. * @var int
  15. */
  16. public $id;
  17. /**
  18. *
  19. * @Column()
  20. * @var string
  21. */
  22. public $type;
  23. /**
  24. *
  25. * @Column(int)
  26. * @var int
  27. */
  28. public $gid;
  29. /**
  30. * @Column()
  31. * @var string
  32. */
  33. public $name;
  34. /**
  35. * @Column(name=servertype)
  36. * @var string
  37. */
  38. public $serverType;
  39. /**
  40. * @Column(name=servergroup)
  41. * @var int
  42. */
  43. public $serverGroupID;
  44. /**
  45. *
  46. * @var main\models\service\server
  47. */
  48. private $_server;
  49. /**
  50. *
  51. * @var configuration
  52. */
  53. private $_configuration;
  54. /**
  55. *
  56. * @var main\models\whmcs\customFields\repository
  57. */
  58. private $_customFields;
  59. /**
  60. * Create Product
  61. *
  62. * @author Michal Czech <michael@modulesgarden.com>
  63. * @param int $id
  64. * @param array $params
  65. */
  66. function __construct($id = null, $params = array()) {
  67. $this->id = $id;
  68. $this->load($params);
  69. }
  70. /**
  71. * Load Product
  72. *
  73. * @author Michal Czech <michael@modulesgarden.com>
  74. * @param array $params
  75. */
  76. function load($params = array()){
  77. if(empty($params))
  78. {
  79. $fields = static::fieldDeclaration();
  80. for($i=1;$i<25;$i++)
  81. {
  82. $fields['configoption'.$i] = 'configoption'.$i;
  83. }
  84. $params = main\mgLibs\MySQL\query::select(
  85. $fields
  86. , static::tableName()
  87. , array(
  88. 'id' => $this->id
  89. )
  90. )->fetch();
  91. }
  92. $this->fillProperties($params);
  93. if(isset($params['serverGroupID']))
  94. {
  95. $this->serverGroupID = $params['serverGroupID'];
  96. }
  97. if(isset($params['configoption1']))
  98. {
  99. $this->_configuration = $this->loadConfiguration($params);
  100. }
  101. }
  102. /**
  103. * Load Server
  104. *
  105. * @return \MGModule\DNSManager2\models\service\server
  106. */
  107. protected function loadServer(){
  108. if(empty($this->serverGroupID))
  109. {
  110. $this->load();
  111. }
  112. $server = main\mgLibs\MySQL\query::query("
  113. SELECT
  114. S.id
  115. FROM
  116. tblservers S
  117. JOIN
  118. tblservergroupsrel R
  119. ON S.id = R.serverid
  120. WHERE
  121. R.groupid = :groupID
  122. AND disabled = 0
  123. ",array(
  124. 'groupID' => $this->serverGroupID
  125. ))->fetchColumn();
  126. return new main\models\whmcs\servers\server($server);
  127. }
  128. /**
  129. * Get Server
  130. *
  131. * @author Michal Czech <michael@modulesgarden.com>
  132. * @return main\models\service\server
  133. */
  134. function getServer(){
  135. if(empty($this->_server))
  136. {
  137. $this->_server = $this->loadServer();
  138. }
  139. return $this->_server;
  140. }
  141. /**
  142. * Load Configuration
  143. *
  144. * @author Michal Czech <michael@modulesgarden.com>
  145. * @param array $params
  146. * @return \MGModule\DNSManager2\models\product\configuration
  147. */
  148. protected function loadConfiguration($params = array()){
  149. return new configuration($this->id,$params);
  150. }
  151. /**
  152. * Get Configuration
  153. *
  154. * @author Michal Czech <michael@modulesgarden.com>
  155. * @return configuration
  156. */
  157. function configuration(){
  158. if(empty($this->_configuration))
  159. {
  160. $this->_configuration = $this->loadConfiguration();
  161. }
  162. return $this->_configuration;
  163. }
  164. /**
  165. * Get Custom Fields
  166. *
  167. * @author Michal Czech <michael@modulesgarden.com>
  168. * @return main\models\whmcs\customFields\repository
  169. */
  170. function customFields(){
  171. if(empty($this->_customFields))
  172. {
  173. $this->_customFields = new main\models\whmcs\customFields\repository('product', $this->id);
  174. }
  175. return $this->_customFields;
  176. }
  177. function configOptionsGroups(){
  178. }
  179. }