DistributionList.php 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321
  1. <?php
  2. namespace ThurData\Servers\KerioEmail\App\Libs\Kerio\Components\Api\Soap\Actions;
  3. use ThurData\Servers\KerioEmail\App\Libs\Kerio\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@thurdata.com )
  11. * Date: 28.08.19
  12. * Time: 13:47
  13. * Class DistributionList
  14. */
  15. class DistributionList extends AbstractAction
  16. {
  17. /**
  18. * @param \ThurData\Servers\KerioEmail\App\Libs\Kerio\Components\Api\Soap\Models\Domain $domain
  19. * @return \ThurData\Servers\KerioEmail\App\Libs\Kerio\Components\Api\Soap\Response|null
  20. */
  21. function getAllDistributionLists(\ThurData\Servers\KerioEmail\App\Libs\Kerio\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 \ThurData\Servers\KerioEmail\App\Libs\Kerio\Components\Api\Soap\Models\DistributionList $list
  35. * @return bool|\ThurData\Servers\KerioEmail\App\Libs\Kerio\Components\Api\Soap\Models\DistributionList
  36. */
  37. public function read(\ThurData\Servers\KerioEmail\App\Libs\Kerio\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 \ThurData\Servers\KerioEmail\App\Libs\Kerio\Components\Api\Soap\Models\DistributionList $list
  55. * @return bool|\ThurData\Servers\KerioEmail\App\Libs\Kerio\Components\Api\Soap\Models\DistributionList
  56. */
  57. public function create(\ThurData\Servers\KerioEmail\App\Libs\Kerio\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['kerioDistributionListSendShareMessageToNewMembers']);
  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. $this->setLastResult($result);
  76. /**
  77. * load response to model
  78. */
  79. if($accountData = $result->getResponseBody()['CREATEDISTRIBUTIONLISTRESPONSE']['DL'])
  80. {
  81. $list->fill($accountData);
  82. return $list;
  83. }
  84. $this->setError($result->getLastError());
  85. return false;
  86. }
  87. /**
  88. * @param \ThurData\Servers\KerioEmail\App\Libs\Kerio\Components\Api\Soap\Models\DistributionList $list
  89. * @return bool|\ThurData\Servers\KerioEmail\App\Libs\Kerio\Components\Api\Soap\Models\DistributionList
  90. */
  91. public function update(\ThurData\Servers\KerioEmail\App\Libs\Kerio\Components\Api\Soap\Models\DistributionList $list)
  92. {
  93. $params = [
  94. new SoapParam($list->getId(), 'id')
  95. ];
  96. $attrs = $list->getAttrs();
  97. if($list->isDynamic())
  98. {
  99. $params[] = new SoapParam(1, "dynamic");
  100. unset($attrs['kerioDistributionListSendShareMessageToNewMembers']);
  101. }
  102. foreach($attrs as $key => $value)
  103. {
  104. $params[] = new SoapVar('<ns1:a n="' . $key . '">' . $value . '</ns1:a>', XSD_ANYXML);
  105. }
  106. $result = $result = $this->connection
  107. ->cleanResponse()
  108. ->request("ModifyDistributionListRequest",$params);
  109. $this->setLastResult($result);
  110. if($data = $result->getResponseBody()['MODIFYDISTRIBUTIONLISTRESPONSE']['DL'])
  111. {
  112. $list->fill($data);
  113. return $list;
  114. }
  115. $this->setError($result->getLastError());
  116. return false;
  117. }
  118. /**
  119. * @param \ThurData\Servers\KerioEmail\App\Libs\Kerio\Components\Api\Soap\Models\DistributionList $list
  120. * @return bool
  121. */
  122. public function delete(\ThurData\Servers\KerioEmail\App\Libs\Kerio\Components\Api\Soap\Models\DistributionList $list)
  123. {
  124. $params = array(
  125. new SoapParam($list->getId(), "id"),
  126. );
  127. $result = $result = $this->connection
  128. ->cleanResponse()
  129. ->request("DeleteDistributionListRequest",$params);
  130. $this->setLastResult($result);
  131. if($result->getResponseBody()['DELETEDISTRIBUTIONLISTRESPONSE'])
  132. {
  133. return true;
  134. }
  135. $this->setError($result->getLastError());
  136. return false;
  137. }
  138. /**
  139. * @param \ThurData\Servers\KerioEmail\App\Libs\Kerio\Components\Api\Soap\Models\DistributionList $list
  140. * @return bool
  141. */
  142. public function addMembers(\ThurData\Servers\KerioEmail\App\Libs\Kerio\Components\Api\Soap\Models\DistributionList $list)
  143. {
  144. $params = array(
  145. new SoapParam($list->getId(), "id"),
  146. );
  147. foreach($list->getMembers() as $val)
  148. {
  149. $params[] = new SoapVar('<ns1:dlm>'.$val.'</ns1:dlm>', XSD_ANYXML);
  150. }
  151. $result = $result = $this->connection
  152. ->cleanResponse()
  153. ->request("AddDistributionListMemberRequest",$params);
  154. $this->setLastResult($result);
  155. if($result->getResponseBody()['ADDDISTRIBUTIONLISTMEMBERRESPONSE'])
  156. {
  157. return true;
  158. }
  159. $this->setError($result->getLastError());
  160. return false;
  161. }
  162. public function deleteMembers(\ThurData\Servers\KerioEmail\App\Libs\Kerio\Components\Api\Soap\Models\DistributionList $list)
  163. {
  164. $params = array(
  165. new SoapParam($list->getId(), "id"),
  166. );
  167. foreach($list->getMembers() as $val)
  168. {
  169. $params[] = new SoapVar('<ns1:dlm>'.$val.'</ns1:dlm>', XSD_ANYXML);
  170. }
  171. $result = $result = $this->connection
  172. ->cleanResponse()
  173. ->request("RemoveDistributionListMemberRequest",$params);
  174. return $result;
  175. }
  176. public function addOwners(\ThurData\Servers\KerioEmail\App\Libs\Kerio\Components\Api\Soap\Models\DistributionList $list)
  177. {
  178. $params = array(
  179. new SoapVar('<ns1:dl by="id">'.$list->getId().'</ns1:dl>', XSD_ANYXML),
  180. new SoapVar('<ns1:action op="addOwners">', XSD_ANYXML),
  181. );
  182. foreach($list->getOwners() as $owner)
  183. {
  184. $params[] = new SoapVar('<ns1:owner type="usr" by="name">'.$owner.'</ns1:owner>', XSD_ANYXML);
  185. }
  186. $params[] = new SoapVar('</ns1:action>', XSD_ANYXML);
  187. $result = $this->connection
  188. ->cleanResponse()
  189. ->request("DistributionListActionRequest",$params);
  190. $this->setLastResult($result);
  191. if($result->getResponseBody()['DISTRIBUTIONLISTACTIONRESPONSE'])
  192. {
  193. return true;
  194. }
  195. $this->setError($result->getLastError());
  196. return false;
  197. }
  198. public function deleteOwners(\ThurData\Servers\KerioEmail\App\Libs\Kerio\Components\Api\Soap\Models\DistributionList $list)
  199. {
  200. $params = array(
  201. new SoapVar('<ns1:dl by="id">'.$id.'</ns1:dl>', XSD_ANYXML),
  202. new SoapVar('<ns1:action op="removeOwners">', XSD_ANYXML),
  203. );
  204. foreach($list->getOwners() as $owner) {
  205. $params[] = new SoapVar('<ns1:owner type="usr" by="name">'.$owner.'</ns1:owner>', XSD_ANYXML);
  206. }
  207. $params[] = new SoapVar('</ns1:action>', XSD_ANYXML);
  208. $result = $result = $this->connection
  209. ->cleanResponse()
  210. ->request("DistributionListActionRequest",$params);
  211. //todo
  212. }
  213. /**
  214. * @param \ThurData\Servers\KerioEmail\App\Libs\Kerio\Components\Api\Soap\Models\DistributionList $list
  215. * @return bool
  216. */
  217. public function addAlias(\ThurData\Servers\KerioEmail\App\Libs\Kerio\Components\Api\Soap\Models\DistributionList $list)
  218. {
  219. $params = array(
  220. new SoapParam($list->getId(), 'id'),
  221. new SoapParam($list->getAlias(), 'alias'),
  222. );
  223. $result = $result = $this->connection
  224. ->cleanResponse()
  225. ->request("AddDistributionListAliasRequest",$params);
  226. $this->setLastResult($result);
  227. if($result->getResponseBody()['ADDDISTRIBUTIONLISTALIASRESPONSE'])
  228. {
  229. return true;
  230. }
  231. $this->setError($result->getLastError());
  232. return false;
  233. }
  234. /**
  235. * @param \ThurData\Servers\KerioEmail\App\Libs\Kerio\Components\Api\Soap\Models\DistributionList $list
  236. * @return bool
  237. */
  238. public function deleteAlias(\ThurData\Servers\KerioEmail\App\Libs\Kerio\Components\Api\Soap\Models\DistributionList $list)
  239. {
  240. $params = array(
  241. new SoapParam($list->getId(), 'id'),
  242. new SoapParam($list->getAlias(), 'alias'),
  243. );
  244. $result = $result = $this->connection
  245. ->cleanResponse()
  246. ->request("RemoveDistributionListAliasRequest",$params);
  247. $this->setLastResult($result);
  248. if($result->getResponseBody()['REMOVEDISTRIBUTIONLISTALIASRESPONSE'])
  249. {
  250. return true;
  251. }
  252. $this->setError($result->getLastError());
  253. return false;
  254. }
  255. }