DeleteListDataProvider.php 3.0 KB

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