repository.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. <?php
  2. namespace MGModule\DNSManager2\models\whmcs\service\customFields;
  3. use MGModule\DNSManager2 as main;
  4. /**
  5. * Description of repository
  6. *
  7. * @author Michal Czech <michael@modulesgarden.com>
  8. */
  9. class repository {
  10. public $serviceID;
  11. private $_customFields;
  12. /**
  13. * Mozna by bylo dodac wersje z wczytywanie po samym productid
  14. *
  15. * @author Michal Czech <michael@modulesgarden.com>
  16. * @param type $accountID
  17. */
  18. function __construct($serviceID, array $data = array()) {
  19. $this->serviceID = $serviceID;
  20. if($data)
  21. {
  22. foreach ($data as $name => $value)
  23. {
  24. $field = new customField();
  25. $field->name = $name;
  26. $field->value = $value;
  27. $this->_customFields[$field->name] = $field;
  28. }
  29. }
  30. else
  31. {
  32. $this->load();
  33. }
  34. }
  35. function __isset($name) {
  36. return $this->_customFields[$name];
  37. }
  38. function __get($name) {
  39. if(isset($this->_customFields[$name]))
  40. {
  41. return $this->_customFields[$name]->value;
  42. }
  43. }
  44. function __set($name, $value) {
  45. if(isset($this->_customFields[$name]))
  46. {
  47. $this->_customFields[$name]->value = $value;
  48. }
  49. }
  50. function load(){
  51. $query = "
  52. SELECT
  53. C.fieldname as name
  54. ,V.fieldid as fieldid
  55. ,V.value as value
  56. FROM
  57. tblcustomfieldsvalues V
  58. JOIN
  59. tblcustomfields C
  60. ON
  61. C.id = V.fieldid
  62. AND C.type = 'product'
  63. JOIN
  64. tblhosting H
  65. ON
  66. V.relid = H.id
  67. AND C.relid = H.packageid
  68. WHERE
  69. H.id = :account_id
  70. ";
  71. $result = \MGModule\DNSManager2\mgLibs\MySQL\query::query($query,array(
  72. 'account_id' => $this->serviceID
  73. ));
  74. while($row = $result->fetch())
  75. {
  76. $name = explode('|', $row['name']);
  77. if(isset($this->_customFields[$name[0]]))
  78. {
  79. $this->_customFields[$name[0]]->id = $row['fieldid'];
  80. }
  81. else
  82. {
  83. $field = new customField();
  84. $field->id = $row['fieldid'];
  85. $field->name = $name[0];
  86. $field->value = $row['value'];
  87. $this->_customFields[$field->name] = $field;
  88. }
  89. }
  90. }
  91. /**
  92. * Update Custom Fields
  93. *
  94. * @author Michal Czech <michael@modulesgarden.com>
  95. */
  96. function update(){
  97. $this->load();
  98. foreach($this->_customFields as $field){
  99. main\mgLibs\MySQL\query::update(
  100. 'tblcustomfieldsvalues'
  101. , array(
  102. 'value' => $field->value
  103. )
  104. , array(
  105. 'fieldid' => $field->id
  106. ,'relid' => $this->serviceID
  107. )
  108. );
  109. }
  110. }
  111. }