RessourceDataProvider.php 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. <?php
  2. namespace ThurData\Servers\KerioEmail\App\UI\Client\Ressource\Providers;
  3. use ThurData\Servers\KerioEmail\App\Enums\ProductParams;
  4. use ThurData\Servers\KerioEmail\App\Enums\Size;
  5. use ThurData\Servers\KerioEmail\App\Enums\Kerio;
  6. use ThurData\Servers\KerioEmail\App\Helpers\KerioManager;
  7. use ThurData\Servers\KerioEmail\App\Http\Admin\ProductConfiguration;
  8. use ThurData\Servers\KerioEmail\App\Libs\Product\ProductManager;
  9. use ThurData\Servers\KerioEmail\App\Libs\Kerio\Components\Api\Soap\Helpers\ServiceFactory;
  10. use ThurData\Servers\KerioEmail\App\Libs\Kerio\Components\Api\Soap\Models\Ressource;
  11. use ThurData\Servers\KerioEmail\App\Libs\Kerio\Components\Api\Soap\Models\ClassOfService;
  12. use ThurData\Servers\KerioEmail\App\Libs\Kerio\Components\Api\Soap\Repository\ClassOfServices;
  13. use ThurData\Servers\KerioEmail\App\Services\ConfigurableOptions\Strategy\Types\ClassOfServicesOptions;
  14. use function ThurData\Servers\KerioEmail\Core\Helper\di;
  15. use ThurData\Servers\KerioEmail\Core\Http\JsonResponse;
  16. use ThurData\Servers\KerioEmail\Core\Models\Whmcs\Hosting;
  17. use ThurData\Servers\KerioEmail\Core\UI\ResponseTemplates\HtmlDataJsonResponse;
  18. use ThurData\Servers\KerioEmail\Core\UI\Widget\Forms\DataProviders\BaseDataProvider;
  19. /**
  20. *
  21. * Created by PhpStorm.
  22. * User: Tomasz Bielecki ( tomasz.bi@thurdata.com )
  23. * Date: 10.09.19
  24. * Time: 13:06
  25. * Class RessourceDataProvider
  26. */
  27. class RessourceDataProvider extends BaseDataProvider
  28. {
  29. public function read()
  30. {
  31. /**
  32. * hosting id
  33. */
  34. $hid = $this->request->get('id');
  35. $hosting = Hosting::where('id', $hid)->first();
  36. //todo refactor
  37. $this->data['domain'] = $hosting->domain;
  38. $lang = di('lang');
  39. $this->availableValues['status'] = [
  40. Kerio::ACC_STATUS_ACTIVE => $lang->absoluteT('kerio','account','status','active'),
  41. Kerio::ACC_STATUS_LOCKED => $lang->absoluteT('kerio','account','status','locked'),
  42. Kerio::ACC_STATUS_MAINTENANCE => $lang->absoluteT('kerio','account','status','maintenance'),
  43. Kerio::ACC_STATUS_CLOSED => $lang->absoluteT('kerio','account','status','closed'),
  44. Kerio::ACC_STATUS_LOCKOUT => $lang->absoluteT('kerio','account','status','lockout'),
  45. Kerio::ACC_STATUS_PENDING => $lang->absoluteT('kerio','account','status','pending')
  46. ];
  47. $this->availableValues['type'] = [
  48. Kerio::RES_TYPE_LOCATION => $lang->absoluteT('kerio','ressource','type','location'),
  49. Kerio::RES_TYPE_EQUIPMENT => $lang->absoluteT('kerio','ressource','type','equipment')
  50. ];
  51. }
  52. public function create()
  53. {
  54. /**
  55. * hosting id
  56. */
  57. $hid = $this->request->get('id');
  58. $fieldToProtection = [
  59. 'display_name',
  60. 'status',
  61. 'type',
  62. 'capacity',
  63. 'description',
  64. 'notes',
  65. 'contact',
  66. 'site',
  67. 'contact_mail',
  68. 'contact_phone',
  69. 'street',
  70. 'building',
  71. 'floor',
  72. 'room',
  73. 'post_code',
  74. 'town',
  75. 'state',
  76. 'county',
  77. 'auto_accept',
  78. 'auto_busy'
  79. ];
  80. foreach ($this->formData as $field => &$value)
  81. {
  82. $value = in_array($field, $fieldToProtection) ? htmlentities($value) : $value;
  83. }
  84. /**
  85. * product manager allow to check product settings
  86. */
  87. $productManager = new ProductManager();
  88. $productManager->loadByHostingId($hid);
  89. /**
  90. *
  91. * get soap create domain service
  92. */
  93. $service =(new KerioManager())
  94. ->getApiByHosting($hid)
  95. ->soap
  96. ->service()
  97. ->createRessource();
  98. /**
  99. *
  100. * set product manager & form data to service
  101. */
  102. $service
  103. ->setProductManager($productManager)
  104. ->setFormData($this->formData);
  105. /**
  106. *
  107. * run service
  108. */
  109. $result = $service->run();
  110. /**
  111. *
  112. * return success or error response
  113. */
  114. if(!$result)
  115. {
  116. return (new HtmlDataJsonResponse())->setMessageAndTranslate($service->getError())->setStatusError();
  117. }
  118. return (new HtmlDataJsonResponse())->setMessageAndTranslate('ressourceHasBeenAdded')->setStatusSuccess();
  119. }
  120. public function updateStatus()
  121. {
  122. }
  123. public function update()
  124. {
  125. /**
  126. * hosting id
  127. */
  128. $hid = $this->request->get('id');
  129. /**
  130. * product manager allow to check product settings
  131. */
  132. $productManager = new ProductManager();
  133. $productManager->loadByHostingId($hid);
  134. /**
  135. *
  136. * get soap create domain service
  137. */
  138. $service =(new KerioManager())
  139. ->getApiByHosting($hid)
  140. ->soap
  141. ->service()
  142. ->updateRessourceStatus()
  143. ->setProductManager($productManager)
  144. ;
  145. /**
  146. *
  147. * set product manager & form data to service
  148. */
  149. /**
  150. * run service for each id
  151. */
  152. foreach($this->request->get('massActions') as $id)
  153. {
  154. $service->setFormData(['status' => $this->formData['status'], 'id' => $id]);
  155. $result = $service->run();
  156. }
  157. /**
  158. * return success
  159. */
  160. return (new HtmlDataJsonResponse())->setMessageAndTranslate('massRessourceStatusHasBeenUpdated')->setStatusSuccess();
  161. }
  162. }