CreateRessource.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. <?php
  2. /**
  3. * Class CreateRessource
  4. * User: Nessandro
  5. * Date: 2019-10-07
  6. * Time: 10:41
  7. * @package ModulesGarden\Servers\ZimbraEmail\App\Libs\Zimbra\Components\Api\Soap\Services\Create
  8. */
  9. namespace ModulesGarden\Servers\ZimbraEmail\App\Libs\Zimbra\Components\Api\Soap\Services\Create;
  10. use ModulesGarden\Servers\ZimbraEmail\App\Enums\ProductParams;
  11. use ModulesGarden\Servers\ZimbraEmail\App\Enums\Size;
  12. use ModulesGarden\Servers\ZimbraEmail\App\Enums\Zimbra;
  13. use ModulesGarden\Servers\ZimbraEmail\App\Libs\Product\ProductManager;
  14. use ModulesGarden\Servers\ZimbraEmail\App\Libs\Zimbra\Components\Api\Soap\Interfaces\ApiService;
  15. use ModulesGarden\Servers\ZimbraEmail\App\Libs\Zimbra\Components\Api\Soap\Models\Ressource;
  16. use ModulesGarden\Servers\ZimbraEmail\App\Libs\Zimbra\Components\Api\Soap\Traits\ProductManagerHandler;
  17. use ModulesGarden\Servers\ZimbraEmail\Core\Helper\ConfigOptionsHelper;
  18. class CreateRessource extends ApiService
  19. {
  20. use ProductManagerHandler;
  21. use \ModulesGarden\Servers\ZimbraEmail\Core\UI\Traits\RequestObjectHandler;
  22. /**
  23. * added more conditions
  24. * @return bool
  25. */
  26. protected function isValid()
  27. {
  28. /**
  29. * check if product manager is set
  30. */
  31. if(!$this->productManager)
  32. {
  33. $this->setError('Product Manager Not Found');
  34. return false;
  35. }
  36. /**
  37. * domain name
  38. */
  39. if(!$this->formData['domain'])
  40. {
  41. $this->setError('Domain name can not be found.');
  42. return false;
  43. }
  44. /**
  45. *
  46. */
  47. return parent::isValid();
  48. }
  49. /**
  50. * @return mixed
  51. */
  52. protected function getRessources()
  53. {
  54. $ressources = $this->api->repository()->ressources->getRessources($this->formData['domain']);
  55. return $ressources;
  56. }
  57. /**
  58. * @return Ressource
  59. */
  60. protected function getModel()
  61. {
  62. /**
  63. * create new ressource in zimbra
  64. */
  65. $ressource = new Ressource();
  66. logModuleCall(
  67. 'zimbraEmail',
  68. __FUNCTION__,
  69. $ressource,
  70. 'Debug Ressource',
  71. $this->formData
  72. );
  73. $ressource->setName($this->formData['name'].'@'.$this->formData['domain']);
  74. $ressource->setPassword(html_entity_decode($this->formData['password']), ENT_QUOTES);
  75. /**
  76. * set ressource attributes
  77. */
  78. $ressource->setAttr(Ressource::ATTR_NAME, $this->formData['name']);
  79. $ressource->setAttr(Ressource::ATTR_STATUS, $this->formData['status']);
  80. $ressource->setAttr(Ressource::ATTR_TYPE, $this->formData['type']);
  81. $ressource->setAttr(Ressource::ATTR_DESC, $this->formData['description']);
  82. $ressource->setAttr(Ressource::ATTR_NOTE, $this->formData['notes']);
  83. $ressource->setAttr(Ressource::ATTR_CONT, $this->formData['contact']);
  84. $ressource->setAttr(Ressource::ATTR_CONT_EMAIL, $this->formData['contact_mail']);
  85. $ressource->setAttr(Ressource::ATTR_CONT_PHONE, $this->formData['contact_phone']);
  86. $ressource->setAttr(Ressource::ATTR_SITE, $this->formData['site']);
  87. $ressource->setAttr(Ressource::ATTR_BUILDING, $this->formData['building']);
  88. $ressource->setAttr(Ressource::ATTR_FLOOR, $this->formData['floor']);
  89. $ressource->setAttr(Ressource::ATTR_ROOM, $this->formData['room']);
  90. $ressource->setAttr(Ressource::ATTR_CAPACITY, $this->formData['capacity']);
  91. $ressource->setAttr(Ressource::ATTR_STREET, $this->formData['street']);
  92. $ressource->setAttr(Ressource::ATTR_TOWN, $this->formData['town']);
  93. $ressource->setAttr(Ressource::ATTR_POSTAL_CODE, $this->formData['post_code']);
  94. $ressource->setAttr(Ressource::ATTR_STATE, $this->formData['state']);
  95. $ressource->setAttr(Ressource::ATTR_COUNTRY, $this->formData['country']);
  96. $ressource->setAttr(Ressource::ATTR_DISPLAY_NAME, $this->formData['display_name']);
  97. $ressource->setAttr(Ressource::ATTR_AUTO, $this->formData['auto']);
  98. $ressource->setAttr(Ressource::ATTR_BUSY, $this->formData['busy']);
  99. foreach($this->productManager->getZimbraConfiguration() as $key => $value)
  100. {
  101. $value = $value === ProductParams::SWITCHER_ENABLED ? Zimbra::ATTR_ENABLED : Zimbra::ATTR_DISABLED;
  102. $ressource->setAttr($key, $value);
  103. }
  104. return $ressource;
  105. }
  106. /**
  107. * @return bool|mixed|Ressource|void
  108. */
  109. protected function process()
  110. {
  111. /**
  112. *
  113. */
  114. $model = $this->getModel();
  115. /**
  116. * create ressource in ZIMBRA
  117. */
  118. $result = $this->api->ressource->create($model);
  119. /**
  120. * problem with create ressource
  121. */
  122. if(!$result)
  123. {
  124. $this->setError($this->api->ressource->getLastResult()->getLastErrorCode());
  125. return false;
  126. }
  127. return $result;
  128. }
  129. }