DeleteListDataProvider.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. <?php
  2. namespace ThurData\Servers\KerioEmail\App\UI\Client\DistributionList\Providers;
  3. use ThurData\Servers\KerioEmail\App\Helpers\KerioManager;
  4. use ThurData\Servers\KerioEmail\App\Libs\Product\ProductManager;
  5. use ThurData\Servers\KerioEmail\App\Libs\Kerio\Components\Api\Soap\Services\Create\CreateDistributionList;
  6. use ThurData\Servers\KerioEmail\App\Libs\Kerio\Components\Api\Soap\Services\Delete\DeleteDistributionList;
  7. use ThurData\Servers\KerioEmail\Core\UI\ResponseTemplates\HtmlDataJsonResponse;
  8. use ThurData\Servers\KerioEmail\Core\UI\Widget\Forms\DataProviders\BaseDataProvider;
  9. use ThurData\Servers\KerioEmail\Api\KerioWhmcs;
  10. /**
  11. *
  12. * Created by PhpStorm.
  13. * User: ThurData
  14. * Date: 02.10.19
  15. * Time: 08:21
  16. * Class DeleteListDataProvider
  17. */
  18. class DeleteListDataProvider extends BaseDataProvider
  19. {
  20. public function read()
  21. {
  22. $this->data['id'] = $this->actionElementId;
  23. }
  24. public function update()
  25. {
  26. // TODO: Implement update() method.
  27. }
  28. public function delete()
  29. {
  30. /**
  31. * hosting id
  32. */
  33. $hid = $this->request->get('id');
  34. $api = new KerioWhmcs('whmcsKerioEmail', 'Thurdata', '1.0');
  35. try {
  36. $api->login($this->getWhmcsParamByKey('serverhostname'), $this->getWhmcsParamByKey('serverusername'), $this->getWhmcsParamByKey('serverpassword'));
  37. } catch (KerioApiException $error) {
  38. logModuleCall(
  39. 'kerioEmail',
  40. __FUNCTION__,
  41. $error,
  42. 'Debug Error',
  43. $error->getMessage()
  44. );
  45. return ['error' => $error->getMessage()];
  46. }
  47. try {
  48. $result = $api->deleteMailinglist($this->formData['id']);
  49. } catch (KerioApiException $error) {
  50. logModuleCall(
  51. 'kerioEmail',
  52. __FUNCTION__,
  53. $error,
  54. 'Debug Error',
  55. $error->getMessage()
  56. );
  57. return ['error' => $error->getMessage()];
  58. }
  59. $api->logout();
  60. return (new HtmlDataJsonResponse())->setMessageAndTranslate('distributionListHasBeenDeleted')->setStatusSuccess();
  61. }
  62. public function massDelete()
  63. {
  64. /**
  65. * hosting id
  66. */
  67. $hid = $this->request->get('id');
  68. $api = new KerioWhmcs('whmcsKerioEmail', 'Thurdata', '1.0');
  69. try {
  70. $api->login($this->getWhmcsParamByKey('serverhostname'), $this->getWhmcsParamByKey('serverusername'), $this->getWhmcsParamByKey('serverpassword'));
  71. } catch (KerioApiException $error) {
  72. logModuleCall(
  73. 'kerioEmail',
  74. __FUNCTION__,
  75. $error,
  76. 'Debug Error',
  77. $error->getMessage()
  78. );
  79. return ['error' => $error->getMessage()];
  80. }
  81. /**
  82. *
  83. */
  84. foreach($this->request->get('massActions') as $id)
  85. {
  86. try {
  87. $result = $api->deleteMailinglist($id);
  88. } catch (KerioApiException $error) {
  89. logModuleCall(
  90. 'kerioEmail',
  91. __FUNCTION__,
  92. $error,
  93. 'Debug Error',
  94. $error->getMessage()
  95. );
  96. return ['error' => $error->getMessage()];
  97. }
  98. }
  99. $api->logout();
  100. return (new HtmlDataJsonResponse())->setMessageAndTranslate('massDistributionListHasBeenDeleted')->setStatusSuccess();
  101. }
  102. }