Zone.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. <?php
  2. namespace MGModule\DNSManager2\models\custom\zone;
  3. use Exception;
  4. use MGModule\DNSManager2 as main;
  5. use MGModule\DNSManager2\mgLibs\custom\dns\SubmoduleAbstract;
  6. use MGModule\DNSManager2\mgLibs\custom\relateditem\RelatedItem;
  7. use MGModule\DNSManager2\models\custom\server\Server;
  8. use MGModule\DNSManager2\models\custom\server\setting\ServerSettingEnum;
  9. /**
  10. *
  11. *
  12. * @Table(name=zone)
  13. */
  14. class Zone extends main\mgLibs\models\orm{
  15. /**
  16. * ID field
  17. *
  18. * @Column(id)
  19. * @var int
  20. */
  21. public $id;
  22. /**
  23. *
  24. * @Column(int=11)
  25. * @var int
  26. */
  27. public $clientid;
  28. /**
  29. *
  30. * @Column(int=11,uniqueKey=1)
  31. * @var int
  32. */
  33. public $serverid;
  34. /**
  35. *
  36. * @Column(varchar,uniqueKey=1)
  37. * @var string
  38. */
  39. public $name;
  40. /**
  41. *
  42. * @Column(varchar)
  43. * @var string
  44. */
  45. public $ip;
  46. /**
  47. *
  48. * @Column(int)
  49. * @var string
  50. */
  51. public $type;
  52. /**
  53. *
  54. * @Column(int)
  55. * @var int
  56. */
  57. public $relid;
  58. /**
  59. *
  60. * @Column(varchar)
  61. * @var string
  62. */
  63. public $status;
  64. /**
  65. *
  66. * @Column(varchar)
  67. * @var string
  68. */
  69. public $connectedWithType;
  70. /**
  71. *
  72. * @Column(int)
  73. * @var string
  74. */
  75. public $connectedWithRelid;
  76. /**
  77. *
  78. * @Column(datetime)
  79. * @var string
  80. */
  81. public $created_at;
  82. /**
  83. *
  84. * @Column(datetime)
  85. * @var string
  86. */
  87. public $updated_at;
  88. /**
  89. *
  90. * @Column(boolean)
  91. * @var bool
  92. */
  93. public $is_locked;
  94. public function setType($type) { //TODO: usunąć globalnie
  95. if(!ZoneTypeEnum::isValidValue($type))
  96. throw new Exception ("Wrong type provided");
  97. $this->type = $type;
  98. }
  99. public function save($data = array()) {
  100. $data['updated_at'] = date('Y-m-d H:i:s');
  101. $data['name'] = strtolower($this->name);
  102. if(!ZoneTypeEnum::isValidValue($this->type)) {
  103. throw new Exception('Invalid Zone Type ('. $this->type .')');
  104. }
  105. if($this->type != ZoneTypeEnum::OTHER && empty($this->relid)) {
  106. throw new Exception('Zone relid cannto be empty when type is not empty');
  107. }
  108. $this->name = strtolower($this->name);
  109. parent::save($data);
  110. }
  111. public function getRelatedItem()
  112. {
  113. $item = new RelatedItem($this->type, $this->relid, $this->clientid);
  114. return $item;
  115. }
  116. public function getPackageItem() {
  117. return $this->getRelatedItem()->getPackageItem();
  118. }
  119. /**
  120. * @return main\models\custom\package\Package
  121. */
  122. public function getPackage() {
  123. return $this->getRelatedItem()->getPackage();
  124. }
  125. public function getServer() {
  126. return new Server($this->serverid);
  127. }
  128. public function setThatExist() {
  129. $this->status = 1;
  130. $this->save();
  131. }
  132. public function setThatNotExist() {
  133. $this->status = 0;
  134. $this->save();
  135. }
  136. public function setLocked()
  137. {
  138. $this->is_locked = 1;
  139. $this->save();
  140. }
  141. public function setUnlocked()
  142. {
  143. $this->is_locked = 0;
  144. $this->save();
  145. }
  146. /** @return SubmoduleAbstract */
  147. public function getModule() {
  148. $server = $this->getServer();
  149. $module = $server->getModule();
  150. $module->setDomain($this->name);
  151. if($server->getSettings(ServerSettingEnum::ENABLE_CACHE) == 'on') {
  152. $module->enableCache($server->id, $this->name);
  153. }
  154. return $module;
  155. }
  156. }