repository.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. <?php
  2. namespace MGModule\DNSManager2\models\whmcs\service\configOptions;
  3. use MGModule\DNSManager2 as main;
  4. /**
  5. * Description of repository
  6. *
  7. * @author Michal Czech <michael@modulesgarden.com>
  8. */
  9. class repository {
  10. private $serviceID;
  11. /**
  12. *
  13. * @var configOption[]
  14. */
  15. private $_configOptions = array();
  16. /**
  17. * Mozna by bylo dodac wersje z wczytywanie po samym productid
  18. *
  19. * @author Michal Czech <michael@modulesgarden.com>
  20. * @param type $accountID
  21. */
  22. function __construct($serviceID, array $data = array()) {
  23. $this->serviceID = $serviceID;
  24. if($data)
  25. {
  26. foreach ($data as $name => $value)
  27. {
  28. $field = new configOption();
  29. $field->name = $name;
  30. $field->value = $value;
  31. $this->_configOptions[$field->name] = $field;
  32. }
  33. }
  34. else
  35. {
  36. $this->load();
  37. }
  38. }
  39. function __isset($name) {
  40. return $this->_configOptions[$name];
  41. }
  42. function __get($name) {
  43. if(isset($this->_configOptions[$name]))
  44. {
  45. return $this->_configOptions[$name]->value;
  46. }
  47. }
  48. function __set($name, $value) {
  49. if(isset($this->_configOptions[$name]))
  50. {
  51. $this->_configOptions[$name]->value = $value;
  52. }
  53. }
  54. function load(){
  55. $query = "
  56. SELECT
  57. V.id
  58. ,V.optionid
  59. ,V.qty
  60. ,O.optionname
  61. ,O.optiontype
  62. ,S.id as suboptionid
  63. ,S.optionname as suboptionname
  64. FROM
  65. tblhostingconfigoptions V
  66. JOIN
  67. tblproductconfigoptions O
  68. ON
  69. V.configid = O.id
  70. JOIN
  71. tblproductconfiglinks L
  72. ON
  73. L.gid = O.gid
  74. JOIN
  75. tblhosting H
  76. ON
  77. H.packageid = L.pid
  78. AND H.id = V.relid
  79. LEFT JOIN
  80. tblproductconfigoptionssub S
  81. ON
  82. S.configid = O.id
  83. WHERE
  84. H.id = :service_id
  85. ";
  86. $result = \MGModule\DNSManager2\mgLibs\MySQL\query::query($query,array(
  87. 'service_id' => $this->serviceID
  88. ));
  89. while($row = $result->fetch())
  90. {
  91. $tmp = explode('|',$row['optionname']);
  92. $name = $friendlyName = $tmp[0];
  93. if(isset($tmp[1]))
  94. {
  95. $friendlyName = $tmp[1];
  96. }
  97. if(isset($this->_configOptions[$name]))
  98. {
  99. $field = $this->_configOptions[$name];
  100. }
  101. $field = new configOption();
  102. $field->id = $row['id'];
  103. $field->name = $name;
  104. $field->frendlyName = $friendlyName;
  105. $tmp = explode('|',$row['suboptionname']);
  106. $value = $valueLabel = $tmp[0];
  107. if(isset($tmp[1]))
  108. {
  109. $valueLabel = $tmp[1];
  110. }
  111. switch ($row['optiontype'])
  112. {
  113. case 1:
  114. case 2:
  115. $field->optionsIDs[$value] = $row['suboptionid'];
  116. $field->options[$value] = $valueLabel;
  117. if($row['suboptionid'] == $row['optionid'] && empty($field->value))
  118. {
  119. $field->value = $value;
  120. }
  121. break;
  122. case 3:
  123. case 4:
  124. $field->value = $row['qty'];
  125. $field->value = $row['qty'];
  126. break;
  127. }
  128. $this->_configOptions[$field->name] = $field;
  129. }
  130. }
  131. /**
  132. * Update Custom Fields
  133. *
  134. * @author Michal Czech <michael@modulesgarden.com>
  135. */
  136. function update(){
  137. $this->load();
  138. foreach($this->_configOptions as $field){
  139. $cols = array();
  140. switch($field->type)
  141. {
  142. case 1:
  143. case 2:
  144. $cols['optionid'] = $field->optionsIDs[$field->value];
  145. break;
  146. case 3:
  147. case 4:
  148. $cols['qty'] = $field->value;
  149. break;
  150. }
  151. main\mgLibs\MySQL\query::update(
  152. 'tblhostingconfigoptions'
  153. , $cols
  154. , array(
  155. 'id' => $field->id
  156. )
  157. );
  158. }
  159. }
  160. }