EditListDataProvider.php 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. <?php
  2. namespace ThurData\Servers\KerioEmail\App\UI\Client\DistributionList\Providers;
  3. use ThurData\Servers\KerioEmail\App\Enums\ProductParams;
  4. use ThurData\Servers\KerioEmail\App\Enums\Kerio;
  5. use ThurData\Servers\KerioEmail\App\Helpers\KerioManager;
  6. use ThurData\Servers\KerioEmail\App\Libs\Product\ProductManager;
  7. use ThurData\Servers\KerioEmail\App\Libs\Kerio\Components\Api\Soap\Models\DistributionList;
  8. use ThurData\Servers\KerioEmail\App\Libs\Kerio\Components\Api\Soap\Repository;
  9. use ThurData\Servers\KerioEmail\App\Libs\Kerio\Components\Api\Soap\Services\Create\CreateDistributionList;
  10. use ThurData\Servers\KerioEmail\App\Libs\Kerio\Components\Api\Soap\Services\Update\UpdateDistributionList;
  11. use function ThurData\Servers\KerioEmail\Core\Helper\di;
  12. use ThurData\Servers\KerioEmail\Core\Models\Whmcs\Hosting;
  13. use ThurData\Servers\KerioEmail\Core\UI\ResponseTemplates\HtmlDataJsonResponse;
  14. use ThurData\Servers\KerioEmail\Core\UI\Widget\Forms\DataProviders\BaseDataProvider;
  15. /**
  16. *
  17. * Created by PhpStorm.
  18. * User: ThurData
  19. * Date: 02.10.19
  20. * Time: 08:36
  21. * Class EditListDataProvider
  22. */
  23. class EditListDataProvider extends AddListDataProvider
  24. {
  25. public function read()
  26. {
  27. logModuleCall(
  28. 'kerioEmail',
  29. __FUNCTION__,
  30. $this,
  31. 'Debug Error',
  32. $this->actionElementId
  33. );
  34. /**
  35. * load hosting
  36. */
  37. $hosting = Hosting::where('id', $this->getRequestValue('id'))->first();
  38. /**
  39. * load api
  40. */
  41. // $list = $repository->lists()->getDistributionListBydId($this->actionElementId);
  42. // $this->data['id'] = $list->getId();
  43. // $res = explode('@', $list->getName());
  44. // $this->data['listmail'] = $res[0];
  45. // $this->data['domain'] = $res[1];
  46. // $this->data['emailAliases'] = implode(',', $list->getResourceAliases());
  47. // $this->data['owners'] = implode(',', $list->getResourceOwners());
  48. /**
  49. * allow to check which should be removed
  50. */
  51. // $this->availableValues['memberListActually'] = $this->data['memberListActually'] = $list->getResourceMembers();
  52. // $this->availableValues['emailAliasesActually'] = $this->data['emailAliasesActually'] = $list->getResourceAliases();
  53. // $this->availableValues['ownersActually'] = $this->data['ownersActually'] = $list->getResourceOwners();
  54. // $this->data['displayName'] = $list->getDataResourceA(DistributionList::ATTR_DISPLAY_NAME);
  55. // $this->data['description'] = $list->getDataResourceA(DistributionList::ATTR_DESCRIPTION);
  56. // $this->data['subscriptionRequest'] = $list->getDataResourceA(DistributionList::ATTR_SUBSCRIPTION_REQUEST);
  57. // $this->data['unsubscriptionRequest'] = $list->getDataResourceA(DistributionList::ATTR_UNSUBSCRIPTION_REQUEST);
  58. // $this->data['replyDisplayName'] = $list->getDataResourceA(DistributionList::REPLY_TO_DISPLAY);
  59. // $this->data['replyEmailAddress'] = $list->getDataResourceA(DistributionList::REPLY_TO_ADDRESS);
  60. // $this->data['sharesNotify'] = $list->getDataResourceA(DistributionList::ATTR_NOTIFY_SHARES) === Kerio::ATTR_ENABLED ? ProductParams::SWITCHER_ENABLED : ProductParams::SWITCHER_DISABLED;
  61. // $this->data['hideGal'] = $list->getDataResourceA(DistributionList::ATTR_HIDE_IN_GAL) === Kerio::ATTR_ENABLED ? ProductParams::SWITCHER_ENABLED : ProductParams::SWITCHER_DISABLED;
  62. // $this->data['receiveMail'] = $list->getDataResourceA(DistributionList::ATTR_MAIL_STATUS) === Kerio::ENABLED ? ProductParams::SWITCHER_ENABLED : ProductParams::SWITCHER_DISABLED;
  63. // $this->data['replyEmail'] = $list->getDataResourceA(DistributionList::REPLY_TO_ENABLED) === Kerio::ATTR_ENABLED ? ProductParams::SWITCHER_ENABLED : ProductParams::SWITCHER_DISABLED;
  64. /**
  65. * is dynamic group
  66. */
  67. // $this->data['dynamicGroup'] = (int)$list->isDynamic() === Kerio::ENABLED_AS_INT ? ProductParams::SWITCHER_ENABLED : ProductParams::SWITCHER_DISABLED;
  68. /**
  69. * available members
  70. */
  71. // $accounts = $repository->accounts->getByDomainName($hosting->domain);
  72. /**
  73. * load lang
  74. */
  75. $lang = di('lang');
  76. /**
  77. * subscription requests
  78. */
  79. // $this->availableValues['subscriptionRequest'] = [
  80. // Kerio::STATUS_ACCEPT => $lang->absoluteT('Automatically accept'),
  81. // Kerio::STATUS_APPROVAL => $lang->absoluteT('Require list owner approval'),
  82. // Kerio::STATUS_REJECT => $lang->absoluteT('Automatically reject')
  83. // ];
  84. /**
  85. * unsubscription requests
  86. */
  87. // $this->availableValues['unsubscriptionRequest'] = [
  88. // Kerio::STATUS_ACCEPT => $lang->absoluteT('Automatically accept'),
  89. // Kerio::STATUS_APPROVAL => $lang->absoluteT('Require list owner approval'),
  90. // Kerio::STATUS_REJECT => $lang->absoluteT('Automatically reject')
  91. // ];
  92. // $members = $list->getResourceMembers();
  93. /**
  94. *
  95. */
  96. // foreach ($accounts as $account)
  97. // {
  98. // if(in_array($account->getName(),$members))
  99. // {
  100. // $this->data['memberList'][] = $account->getName();
  101. // }
  102. // $this->availableValues['memberList'][$account->getName()] = $account->getName();
  103. // }
  104. /**
  105. * add custom members to array
  106. */
  107. // $ownMembers = $this->data['memberList'] ? $this->data['memberList'] : [];
  108. // $this->data['customMember'] = implode(',',array_diff($members, $ownMembers));
  109. // if($this->formData)
  110. // {
  111. // $this->loadReloadedData();
  112. // }
  113. }
  114. /**
  115. *
  116. */
  117. public function update()
  118. {
  119. /**
  120. *
  121. * provided aliases
  122. */
  123. $customEmails = explode(',',$this->formData['emailAliases']);
  124. $this->formData['emailAliases'] = [];
  125. foreach($customEmails as $email)
  126. {
  127. if ($email !== '')
  128. {
  129. $this->formData['emailAliases'][] = $email;
  130. }
  131. }
  132. /**
  133. * provided owners
  134. */
  135. $owners = explode(',',$this->formData['owners']);
  136. $this->formData['owners'] = [];
  137. foreach($owners as $email)
  138. {
  139. if ($email !== '')
  140. {
  141. $this->formData['owners'][] = $email;
  142. }
  143. }
  144. /**
  145. * display name
  146. */
  147. $this->formData['displayName'] = htmlentities($this->formData['displayName']);
  148. /**
  149. * reply display name
  150. */
  151. $this->formData['replyDisplayName'] = htmlentities($this->formData['replyDisplayName']);
  152. /**
  153. * custom members
  154. */
  155. $customMembers = explode(',',$this->formData['customMember']);
  156. foreach($customMembers as $customMember)
  157. {
  158. if($customMember !== '' && !in_array($customMember, $this->formData['memberList']))
  159. {
  160. $this->formData['memberList'][] = $customMember;
  161. }
  162. }
  163. $members = $this->formData['memberList'] ? $this->formData['memberList'] : [];
  164. $this->formData['memberList'] = array_merge($customMembers, $members);
  165. /**
  166. * hosting id
  167. */
  168. $hid = $this->request->get('id');
  169. /**
  170. * get product manager
  171. */
  172. $productManager = new ProductManager();
  173. $productManager->loadByHostingId($hid);
  174. /**
  175. * load kerio manager by hosting id
  176. */
  177. $service = (new KerioManager())
  178. ->getApiByHosting($hid)
  179. ->soap
  180. ->service()
  181. ->updateDistributionList()
  182. ->setFormData($this->formData)
  183. ->setProductManager($productManager)
  184. ;
  185. /**
  186. *
  187. */
  188. $result = $service->run();
  189. if(!$result)
  190. {
  191. return (new HtmlDataJsonResponse())->setMessageAndTranslate($service->getError())->setStatusError();
  192. }
  193. return (new HtmlDataJsonResponse())->setMessageAndTranslate('distributionListHasBeenUpdated')->setStatusSuccess();
  194. }
  195. }