AddEmailAliasDataProvider.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. <?php
  2. namespace ModulesGarden\Servers\ZimbraEmail\App\UI\Client\EmailAlias\Providers;
  3. use ModulesGarden\Servers\ZimbraEmail\App\Helpers\ZimbraManager;
  4. use ModulesGarden\Servers\ZimbraEmail\App\Libs\Product\ProductManager;
  5. use ModulesGarden\Servers\ZimbraEmail\App\Libs\Zimbra\Components\Api\Soap\Models\AccountAlias;
  6. use ModulesGarden\Servers\ZimbraEmail\App\Libs\Zimbra\Components\Api\Soap\Repository;
  7. use ModulesGarden\Servers\ZimbraEmail\Core\Models\Whmcs\Hosting;
  8. use ModulesGarden\Servers\ZimbraEmail\Core\UI\ResponseTemplates\HtmlDataJsonResponse;
  9. use ModulesGarden\Servers\ZimbraEmail\Core\UI\Widget\Forms\DataProviders\BaseDataProvider;
  10. /**
  11. *
  12. * Created by PhpStorm.
  13. * User: Tomasz Bielecki ( tomasz.bi@modulesgarden.com )
  14. * Date: 18.09.19
  15. * Time: 11:50
  16. * Class AddEmailAliasDataProvider
  17. */
  18. class AddEmailAliasDataProvider extends BaseDataProvider
  19. {
  20. public function read()
  21. {
  22. /**
  23. * hosting id
  24. */
  25. $hid = $this->getRequestValue('id');
  26. /**
  27. * hosting model
  28. */
  29. $hosting = Hosting::where('id', $hid)->first();
  30. /**
  31. * hosting domain
  32. */
  33. $this->data['domain'] = $hosting->domain;
  34. /**
  35. * load api
  36. * load repo
  37. * load accounts from repo
  38. */
  39. $accounts =(new ZimbraManager())
  40. ->getApiByHosting($hid)
  41. ->soap
  42. ->repository()
  43. ->accounts
  44. ->getByDomainName($hosting->domain);
  45. /**
  46. * available accounts
  47. */
  48. foreach($accounts as $account)
  49. {
  50. $this->availableValues['mailbox'][$account->getId()] = $account->getName();
  51. }
  52. }
  53. public function create()
  54. {
  55. /**
  56. * hosting id
  57. */
  58. $hid = $this->request->get('id');
  59. /**
  60. * product manager allow to check product settings
  61. */
  62. $productManager = new ProductManager();
  63. $productManager->loadByHostingId($hid);
  64. /**
  65. *
  66. * get soap create alias service
  67. * set service configuration
  68. */
  69. $service =(new ZimbraManager())
  70. ->getApiByHosting($hid)
  71. ->soap
  72. ->service()
  73. ->createAccountAlias()
  74. ->setProductManager($productManager)
  75. ->setFormData($this->formData);
  76. /**
  77. *
  78. * run service
  79. */
  80. $result = $service->run();
  81. logModuleCall(
  82. 'zimbraEmail',
  83. __FUNCTION__,
  84. $result,
  85. 'Debug API Response',
  86. $service->getError()
  87. );
  88. /**
  89. *
  90. * return success or error response
  91. */
  92. if(!$result)
  93. {
  94. return (new HtmlDataJsonResponse())->setMessage($service->getError())->setStatusError();
  95. }
  96. return (new HtmlDataJsonResponse())->setMessageAndTranslate('emailAliasHasBeenCreated')->setStatusSuccess();
  97. }
  98. public function update()
  99. {
  100. // TODO: Implement update() method.
  101. }
  102. }