Domains.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. <?php
  2. namespace ModulesGarden\Servers\KerioEmail\App\Libs\Kerio\Components\Api\Soap\Repository;
  3. use ModulesGarden\Servers\KerioEmail\App\Libs\Kerio\Components\Api\Soap\Interfaces\AbstractApiClient;
  4. use ModulesGarden\Servers\KerioEmail\App\Libs\Kerio\Components\Api\Soap\Interfaces\AbstractRepository;
  5. use ModulesGarden\Servers\KerioEmail\App\Libs\Kerio\Components\Api\Soap\Models\DistributionList;
  6. use ModulesGarden\Servers\KerioEmail\App\Libs\Kerio\Components\Api\Soap\Models\Domain;
  7. use ModulesGarden\Servers\KerioEmail\Core\Models\Whmcs\Hosting;
  8. /**
  9. *
  10. * Created by PhpStorm.
  11. * User: Tomasz Bielecki ( tomasz.bi@modulesgarden.com )
  12. * Date: 10.09.19
  13. * Time: 07:59
  14. * Class Domains
  15. */
  16. class Domains extends AbstractRepository
  17. {
  18. use \ModulesGarden\Servers\KerioEmail\Core\UI\Traits\RequestObjectHandler;
  19. /**
  20. * @param $name
  21. * @return Domain| null
  22. */
  23. public function getByName($name)
  24. {
  25. $domain = new Domain();
  26. $domain->setName($name);
  27. $result = $this->getClient()->domain->getDomainId($domain);
  28. if(!$result->getLastError())
  29. {
  30. $domain = new Domain($result->getResponseBody()['GETDOMAININFORESPONSE']['DOMAIN']);
  31. return $domain;
  32. }
  33. $this->setError($result->getLastError());
  34. return false;
  35. }
  36. public function getAliases($name)
  37. {
  38. $mainDomain = $this->getByName($name);
  39. if(!$mainDomain)
  40. {
  41. return false;
  42. }
  43. /**
  44. *
  45. * parse all domain & return aliasese
  46. */
  47. foreach($aliases = $this->getAll() as $key => $alias)
  48. {
  49. /**
  50. *
  51. * check if domain is alias
  52. */
  53. /* @var $alias Domain */
  54. if(!$alias->isAlias())
  55. {
  56. unset($aliases[$key]);
  57. continue;
  58. }
  59. /**
  60. *
  61. * check if alias belong to main domain
  62. */
  63. if($alias->getAttr(Domain::ATTR_ALIAS_TARGET_ID) !== $mainDomain->getId())
  64. {
  65. unset($aliases[$key]);
  66. continue;
  67. }
  68. }
  69. return $aliases;
  70. }
  71. public function getAll()
  72. {
  73. $result = $this->getClient()->domain->getAll();
  74. $domains = $result->getResponseBody()['GETALLDOMAINSRESPONSE']['DOMAIN'];
  75. /**
  76. * API return one or araay with accounts
  77. */
  78. if(isset($domains['NAME']))
  79. {
  80. $tmpAccount = new Domain($domains);
  81. $tmp[$tmpAccount->getId()] = $tmpAccount;
  82. }else{
  83. foreach($domains as $account)
  84. {
  85. $tmpAccount = new Domain($account);
  86. $tmp[$tmpAccount->getId()] = $tmpAccount;
  87. }
  88. }
  89. return $tmp;
  90. }
  91. public function getDomain()
  92. {
  93. $result = $this->getClient()->domain->getAll();
  94. $domains = $result->getResponseBody()['GETALLDOMAINSRESPONSE']['DOMAIN'];
  95. $domain = new Domain();
  96. $result = $this->getClient()->domain->getDomain($domain);
  97. }
  98. }