group.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. <?php
  2. namespace MGModule\DNSManager2\models\whmcs\product\configOptions;
  3. use MGModule\DNSManager2 as main;
  4. /**
  5. * Description of group
  6. * @Table(name=tblproductconfiggroups,preventUpdate,prefixed=false)
  7. * @author Michal Czech <michael@modulesgarden.com>
  8. */
  9. class group extends main\mgLibs\models\orm{
  10. private $_relatedPID = array();
  11. private $_configOptions = array();
  12. /**
  13. * @Column()
  14. * @var int
  15. */
  16. public $id;
  17. /**
  18. *
  19. * @Column()
  20. * @var string
  21. */
  22. public $name;
  23. /**
  24. *
  25. * @Column()
  26. * @var string
  27. */
  28. public $description;
  29. function addPID($pid)
  30. {
  31. $this->_relatedPID[] = $pid;
  32. }
  33. function getRelatedPIDs(){
  34. if(empty($this->_relatedPID))
  35. {
  36. $result = main\mgLibs\MySQL\query::select(array(
  37. 'pid'
  38. )
  39. , 'tblproductconfiglinks'
  40. ,array(
  41. 'gid' => $this->id
  42. ));
  43. while($row = $result->fetch())
  44. {
  45. $this->_relatedPID[] = $row['pid'];
  46. }
  47. }
  48. return $this->_relatedPID;
  49. }
  50. function save() {
  51. parent::save();
  52. if($this->_relatedPID)
  53. {
  54. $result = main\mgLibs\MySQL\query::select(array(
  55. 'pid'
  56. )
  57. , 'tblproductconfiglinks'
  58. ,array(
  59. 'gid' => $this->id
  60. ));
  61. $exists = array();
  62. while($row = $result->fetch())
  63. {
  64. $exists[$row['pid']] = $row['pid'];
  65. }
  66. foreach($this->_relatedPID as $pid)
  67. {
  68. if(!isset($exists[$pid]))
  69. {
  70. main\mgLibs\MySQL\query::insert('tblproductconfiglinks', array(
  71. 'pid' => $pid
  72. ,'gid' => $this->id
  73. ));
  74. }
  75. }
  76. }
  77. }
  78. function getConfigOptions(){
  79. if(empty($this->_configOptions))
  80. {
  81. $this->_configOptions = array();
  82. $result = main\mgLibs\MySQL\query::select(
  83. configOption::fieldDeclaration()
  84. , configOption::tableName()
  85. ,array(
  86. 'gid' => $this->id
  87. ));
  88. while($row = $result->fetch())
  89. {
  90. $this->_configOptions[] = new configOption($row['id'],$row);
  91. }
  92. }
  93. return $this->_configOptions;
  94. }
  95. }