DistributionList.php 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  1. <?php
  2. namespace ModulesGarden\Servers\ZimbraEmail\App\Libs\Zimbra\Components\Api\Soap\Actions;
  3. use ModulesGarden\Servers\ZimbraEmail\App\Libs\Zimbra\Components\Api\Soap\Interfaces\AbstractAction;
  4. use SoapFault;
  5. use SoapParam;
  6. use SoapVar;
  7. /**
  8. *
  9. * Created by PhpStorm.
  10. * User: Tomasz Bielecki ( tomasz.bi@modulesgarden.com )
  11. * Date: 28.08.19
  12. * Time: 13:47
  13. * Class DistributionList
  14. */
  15. class DistributionList extends AbstractAction
  16. {
  17. /**
  18. * @param \ModulesGarden\Servers\ZimbraEmail\App\Libs\Zimbra\Components\Api\Soap\Models\Domain $domain
  19. * @return \ModulesGarden\Servers\ZimbraEmail\App\Libs\Zimbra\Components\Api\Soap\Response|null
  20. */
  21. function getAllDistributionLists(\ModulesGarden\Servers\ZimbraEmail\App\Libs\Zimbra\Components\Api\Soap\Models\Domain $domain)
  22. {
  23. $result = null;
  24. $params = array(
  25. new SoapVar('<ns1:domain by="name">'.$domain->getName().'</ns1:domain>', XSD_ANYXML),
  26. );
  27. $this->connection->cleanResponse();
  28. $result = $this->connection
  29. ->cleanResponse()
  30. ->request("GetAllDistributionListsRequest", $params);
  31. return $result;
  32. }
  33. /**
  34. * @param \ModulesGarden\Servers\ZimbraEmail\App\Libs\Zimbra\Components\Api\Soap\Models\DistributionList $list
  35. * @return bool|\ModulesGarden\Servers\ZimbraEmail\App\Libs\Zimbra\Components\Api\Soap\Models\DistributionList
  36. */
  37. public function read(\ModulesGarden\Servers\ZimbraEmail\App\Libs\Zimbra\Components\Api\Soap\Models\DistributionList $list)
  38. {
  39. $params = array(
  40. new SoapVar('<ns1:dl by="id">'.$list->getId().'</ns1:dl>', XSD_ANYXML),
  41. );
  42. $result = $result = $this->connection
  43. ->cleanResponse()
  44. ->request("GetDistributionListRequest",$params);
  45. if($data = $result->getResponseBody()['GETDISTRIBUTIONLISTRESPONSE']['DL'])
  46. {
  47. $list->fill($data);
  48. return $list;
  49. }
  50. $this->setError($result->getLastError());
  51. return false;
  52. }
  53. /**
  54. * @param \ModulesGarden\Servers\ZimbraEmail\App\Libs\Zimbra\Components\Api\Soap\Models\DistributionList $list
  55. * @return bool|\ModulesGarden\Servers\ZimbraEmail\App\Libs\Zimbra\Components\Api\Soap\Models\DistributionList
  56. */
  57. public function create(\ModulesGarden\Servers\ZimbraEmail\App\Libs\Zimbra\Components\Api\Soap\Models\DistributionList $list)
  58. {
  59. $params = array(
  60. new SoapParam($list->getName(), "name"),
  61. );
  62. $attrs = $list->getAttrs();
  63. if($list->isDynamic())
  64. {
  65. $params[] = new SoapParam(1, "dynamic");
  66. unset($attrs['zimbraDistributionListSendShareMessageToNewMembers']);
  67. }
  68. foreach($attrs as $key => $value)
  69. {
  70. $params[] = new SoapVar('<ns1:a n="' . $key . '">' . $value . '</ns1:a>', XSD_ANYXML);
  71. }
  72. $result = $result = $this->connection
  73. ->cleanResponse()
  74. ->request("CreateDistributionListRequest",$params);
  75. /**
  76. * load response to model
  77. */
  78. if($accountData = $result->getResponseBody()['CREATEDISTRIBUTIONLISTRESPONSE']['DL'])
  79. {
  80. $list->fill($accountData);
  81. return $list;
  82. }
  83. $this->setError($result->getLastError());
  84. return false;
  85. }
  86. /**
  87. * @param \ModulesGarden\Servers\ZimbraEmail\App\Libs\Zimbra\Components\Api\Soap\Models\DistributionList $list
  88. * @return bool|\ModulesGarden\Servers\ZimbraEmail\App\Libs\Zimbra\Components\Api\Soap\Models\DistributionList
  89. */
  90. public function update(\ModulesGarden\Servers\ZimbraEmail\App\Libs\Zimbra\Components\Api\Soap\Models\DistributionList $list)
  91. {
  92. $params = [
  93. new SoapParam($list->getId(), 'id')
  94. ];
  95. $attrs = $list->getAttrs();
  96. if($list->isDynamic())
  97. {
  98. $params[] = new SoapParam(1, "dynamic");
  99. unset($attrs['zimbraDistributionListSendShareMessageToNewMembers']);
  100. }
  101. foreach($attrs as $key => $value)
  102. {
  103. $params[] = new SoapVar('<ns1:a n="' . $key . '">' . $value . '</ns1:a>', XSD_ANYXML);
  104. }
  105. $result = $result = $this->connection
  106. ->cleanResponse()
  107. ->request("ModifyDistributionListRequest",$params);
  108. if($data = $result->getResponseBody()['MODIFYDISTRIBUTIONLISTRESPONSE']['DL'])
  109. {
  110. $list->fill($data);
  111. return $list;
  112. }
  113. $this->setError($result->getLastError());
  114. return false;
  115. }
  116. /**
  117. * @param \ModulesGarden\Servers\ZimbraEmail\App\Libs\Zimbra\Components\Api\Soap\Models\DistributionList $list
  118. * @return bool
  119. */
  120. public function delete(\ModulesGarden\Servers\ZimbraEmail\App\Libs\Zimbra\Components\Api\Soap\Models\DistributionList $list)
  121. {
  122. $params = array(
  123. new SoapParam($list->getId(), "id"),
  124. );
  125. $result = $result = $this->connection
  126. ->cleanResponse()
  127. ->request("DeleteDistributionListRequest",$params);
  128. if($result->getResponseBody()['DELETEDISTRIBUTIONLISTRESPONSE'])
  129. {
  130. return true;
  131. }
  132. $this->setError($result->getLastError());
  133. return false;
  134. }
  135. /**
  136. * @param \ModulesGarden\Servers\ZimbraEmail\App\Libs\Zimbra\Components\Api\Soap\Models\DistributionList $list
  137. * @return bool
  138. */
  139. public function addMembers(\ModulesGarden\Servers\ZimbraEmail\App\Libs\Zimbra\Components\Api\Soap\Models\DistributionList $list)
  140. {
  141. $params = array(
  142. new SoapParam($list->getId(), "id"),
  143. );
  144. foreach($list->getMembers() as $val)
  145. {
  146. $params[] = new SoapVar('<ns1:dlm>'.$val.'</ns1:dlm>', XSD_ANYXML);
  147. }
  148. $result = $result = $this->connection
  149. ->cleanResponse()
  150. ->request("AddDistributionListMemberRequest",$params);
  151. if($result->getResponseBody()['ADDDISTRIBUTIONLISTMEMBERRESPONSE'])
  152. {
  153. return true;
  154. }
  155. $this->setError($result->getLastError());
  156. return false;
  157. }
  158. public function deleteMembers(\ModulesGarden\Servers\ZimbraEmail\App\Libs\Zimbra\Components\Api\Soap\Models\DistributionList $list)
  159. {
  160. $params = array(
  161. new SoapParam($list->getId(), "id"),
  162. );
  163. foreach($list->getMembers() as $val)
  164. {
  165. $params[] = new SoapVar('<ns1:dlm>'.$val.'</ns1:dlm>', XSD_ANYXML);
  166. }
  167. $result = $result = $this->connection
  168. ->cleanResponse()
  169. ->request("RemoveDistributionListMemberRequest",$params);
  170. return $result;
  171. }
  172. public function addOwners(\ModulesGarden\Servers\ZimbraEmail\App\Libs\Zimbra\Components\Api\Soap\Models\DistributionList $list)
  173. {
  174. $params = array(
  175. new SoapVar('<ns1:dl by="id">'.$list->getId().'</ns1:dl>', XSD_ANYXML),
  176. new SoapVar('<ns1:action op="addOwners">', XSD_ANYXML),
  177. );
  178. foreach($list->getOwners() as $owner)
  179. {
  180. $params[] = new SoapVar('<ns1:owner type="usr" by="name">'.$owner.'</ns1:owner>', XSD_ANYXML);
  181. }
  182. $params[] = new SoapVar('</ns1:action>', XSD_ANYXML);
  183. $result = $this->connection
  184. ->cleanResponse()
  185. ->request("DistributionListActionRequest",$params);
  186. if($result->getResponseBody()['DISTRIBUTIONLISTACTIONRESPONSE'])
  187. {
  188. return true;
  189. }
  190. $this->setError($result->getLastError());
  191. return false;
  192. }
  193. public function deleteOwners(\ModulesGarden\Servers\ZimbraEmail\App\Libs\Zimbra\Components\Api\Soap\Models\DistributionList $list)
  194. {
  195. $params = array(
  196. new SoapVar('<ns1:dl by="id">'.$id.'</ns1:dl>', XSD_ANYXML),
  197. new SoapVar('<ns1:action op="removeOwners">', XSD_ANYXML),
  198. );
  199. foreach($list->getOwners() as $owner) {
  200. $params[] = new SoapVar('<ns1:owner type="usr" by="name">'.$owner.'</ns1:owner>', XSD_ANYXML);
  201. }
  202. $params[] = new SoapVar('</ns1:action>', XSD_ANYXML);
  203. $result = $result = $this->connection
  204. ->cleanResponse()
  205. ->request("DistributionListActionRequest",$params);
  206. //todo
  207. }
  208. /**
  209. * @param \ModulesGarden\Servers\ZimbraEmail\App\Libs\Zimbra\Components\Api\Soap\Models\DistributionList $list
  210. * @return bool
  211. */
  212. public function addAlias(\ModulesGarden\Servers\ZimbraEmail\App\Libs\Zimbra\Components\Api\Soap\Models\DistributionList $list)
  213. {
  214. $params = array(
  215. new SoapParam($list->getId(), 'id'),
  216. new SoapParam($list->getAlias(), 'alias'),
  217. );
  218. $result = $result = $this->connection
  219. ->cleanResponse()
  220. ->request("AddDistributionListAliasRequest",$params);
  221. if($result->getResponseBody()['ADDDISTRIBUTIONLISTALIASRESPONSE'])
  222. {
  223. return true;
  224. }
  225. $this->setError($result->getLastError());
  226. return false;
  227. }
  228. /**
  229. * @param \ModulesGarden\Servers\ZimbraEmail\App\Libs\Zimbra\Components\Api\Soap\Models\DistributionList $list
  230. * @return bool
  231. */
  232. public function deleteAlias(\ModulesGarden\Servers\ZimbraEmail\App\Libs\Zimbra\Components\Api\Soap\Models\DistributionList $list)
  233. {
  234. $params = array(
  235. new SoapParam($list->getId(), 'id'),
  236. new SoapParam($list->getAlias(), 'alias'),
  237. );
  238. $result = $result = $this->connection
  239. ->cleanResponse()
  240. ->request("RemoveDistributionListAliasRequest",$params);
  241. if($result->getResponseBody()['REMOVEDISTRIBUTIONLISTALIASRESPONSE'])
  242. {
  243. return true;
  244. }
  245. $this->setError($result->getLastError());
  246. return false;
  247. }
  248. }