| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184 |
- <?php
- namespace MGModule\DNSManager2\models\custom\zone;
- use Exception;
- use MGModule\DNSManager2 as main;
- use MGModule\DNSManager2\mgLibs\custom\dns\SubmoduleAbstract;
- use MGModule\DNSManager2\mgLibs\custom\relateditem\RelatedItem;
- use MGModule\DNSManager2\models\custom\server\Server;
- use MGModule\DNSManager2\models\custom\server\setting\ServerSettingEnum;
- /**
- *
- *
- * @Table(name=zone)
- */
- class Zone extends main\mgLibs\models\orm{
- /**
- * ID field
- *
- * @Column(id)
- * @var int
- */
- public $id;
-
- /**
- *
- * @Column(int=11)
- * @var int
- */
- public $clientid;
-
- /**
- *
- * @Column(int=11,uniqueKey=1)
- * @var int
- */
- public $serverid;
-
- /**
- *
- * @Column(varchar,uniqueKey=1)
- * @var string
- */
- public $name;
-
- /**
- *
- * @Column(varchar)
- * @var string
- */
- public $ip;
-
- /**
- *
- * @Column(int)
- * @var string
- */
- public $type;
-
- /**
- *
- * @Column(int)
- * @var int
- */
- public $relid;
-
- /**
- *
- * @Column(varchar)
- * @var string
- */
- public $status;
- /**
- *
- * @Column(varchar)
- * @var string
- */
- public $connectedWithType;
- /**
- *
- * @Column(int)
- * @var string
- */
- public $connectedWithRelid;
- /**
- *
- * @Column(datetime)
- * @var string
- */
- public $created_at;
-
- /**
- *
- * @Column(datetime)
- * @var string
- */
- public $updated_at;
- /**
- *
- * @Column(boolean)
- * @var bool
- */
- public $is_locked;
- public function setType($type) { //TODO: usunąć globalnie
- if(!ZoneTypeEnum::isValidValue($type))
- throw new Exception ("Wrong type provided");
- $this->type = $type;
- }
-
- public function save($data = array()) {
- $data['updated_at'] = date('Y-m-d H:i:s');
- $data['name'] = strtolower($this->name);
- if(!ZoneTypeEnum::isValidValue($this->type)) {
- throw new Exception('Invalid Zone Type ('. $this->type .')');
- }
- if($this->type != ZoneTypeEnum::OTHER && empty($this->relid)) {
- throw new Exception('Zone relid cannto be empty when type is not empty');
- }
-
- $this->name = strtolower($this->name);
-
- parent::save($data);
- }
-
- public function getRelatedItem()
- {
- $item = new RelatedItem($this->type, $this->relid, $this->clientid);
- return $item;
- }
-
- public function getPackageItem() {
- return $this->getRelatedItem()->getPackageItem();
- }
- /**
- * @return main\models\custom\package\Package
- */
- public function getPackage() {
- return $this->getRelatedItem()->getPackage();
- }
-
- public function getServer() {
- return new Server($this->serverid);
- }
-
- public function setThatExist() {
- $this->status = 1;
- $this->save();
- }
-
- public function setThatNotExist() {
- $this->status = 0;
- $this->save();
- }
- public function setLocked()
- {
- $this->is_locked = 1;
- $this->save();
- }
- public function setUnlocked()
- {
- $this->is_locked = 0;
- $this->save();
- }
- /** @return SubmoduleAbstract */
- public function getModule() {
- $server = $this->getServer();
- $module = $server->getModule();
- $module->setDomain($this->name);
-
- if($server->getSettings(ServerSettingEnum::ENABLE_CACHE) == 'on') {
- $module->enableCache($server->id, $this->name);
- }
- return $module;
- }
- }
|