Ressources.php 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. <?php
  2. namespace ThurData\Servers\KerioEmail\App\UI\Client\Ressource\Pages;
  3. use ThurData\Servers\KerioEmail\App\Helpers\BuildUrlExtended;
  4. use ThurData\Servers\KerioEmail\App\Helpers\KerioManager;
  5. use ThurData\Servers\KerioEmail\App\Libs\Product\ProductManager;
  6. use ThurData\Servers\KerioEmail\App\Libs\Kerio\Components\Api\Soap\Connection;
  7. use ThurData\Servers\KerioEmail\App\Libs\Kerio\Components\Api\Soap\Helpers\RessourceHelper;
  8. use ThurData\Servers\KerioEmail\App\Libs\Kerio\Components\Api\Soap\Models\Ressource;
  9. use ThurData\Servers\KerioEmail\App\Libs\Kerio\Components\Api\Soap\Repository\ClassOfServices;
  10. use ThurData\Servers\KerioEmail\App\Libs\Kerio\Components\Filters\Ressources\FilterByCosId;
  11. use ThurData\Servers\KerioEmail\App\UI\Admin\Custom\Fields\EnabledField;
  12. use ThurData\Servers\KerioEmail\App\UI\Client\Ressource\Buttons\AddRessourceButton;
  13. use ThurData\Servers\KerioEmail\App\UI\Client\Ressource\Buttons\ChangePasswordButton;
  14. use ThurData\Servers\KerioEmail\App\UI\Client\Ressource\Buttons\ChangeStatusButton;
  15. use ThurData\Servers\KerioEmail\App\UI\Client\Ressource\Buttons\DeleteRessourceButton;
  16. use ThurData\Servers\KerioEmail\App\UI\Client\Ressource\Buttons\EditRessourceButton;
  17. use ThurData\Servers\KerioEmail\App\UI\Client\Ressource\Buttons\LoginToPanelButton;
  18. use ThurData\Servers\KerioEmail\App\UI\Client\Ressource\Buttons\MassChangeStatusButton;
  19. use ThurData\Servers\KerioEmail\App\UI\Client\Ressource\Buttons\MassDeleteRessourceButton;
  20. use ThurData\Servers\KerioEmail\App\UI\Client\Ressource\Buttons\SpanDropdownButton;
  21. use function ThurData\Servers\KerioEmail\Core\Helper\di;
  22. use ThurData\Servers\KerioEmail\Core\Models\Whmcs\Hosting;
  23. use ThurData\Servers\KerioEmail\Core\UI\Widget\Buttons\DropdawnButtonWrappers\ButtonDropdown;
  24. use ThurData\Servers\KerioEmail\Core\UI\Widget\DataTable\Column;
  25. use ThurData\Servers\KerioEmail\Core\UI\Widget\DataTable\DataProviders\DataProvider;
  26. use ThurData\Servers\KerioEmail\Core\UI\Interfaces\ClientArea;
  27. use ThurData\Servers\KerioEmail\Core\UI\Widget\DataTable\DataProviders\Providers\ArrayDataProvider;
  28. use ThurData\Servers\KerioEmail\Core\UI\Widget\DataTable\DataTable;
  29. /**
  30. *
  31. * Created by PhpStorm.
  32. * User: ThurData
  33. * Date: 10.09.19
  34. * Time: 10:51
  35. * Class Ressources
  36. */
  37. class Ressources extends DataTable implements ClientArea
  38. {
  39. /**
  40. * labels for statuses
  41. */
  42. const STATUS_LABEL = [
  43. 'active' => 'success',
  44. 'locked' => 'default',
  45. 'maintenance' => 'warning',
  46. 'closed' => 'default',
  47. 'lockout' => 'info',
  48. 'pending' => 'warning',
  49. 'default' => 'default'
  50. ];
  51. protected $id = 'ressources';
  52. protected $name = 'ressources';
  53. protected $title = null;
  54. /**
  55. * load columns
  56. */
  57. protected function loadHtml()
  58. {
  59. $this
  60. ->addColumn((new Column('ressource'))
  61. ->setOrderable(DataProvider::SORT_ASC)
  62. ->setSearchable(true, Column::TYPE_STRING))
  63. ->addColumn((new Column('date_created'))
  64. ->setOrderable()
  65. ->setSearchable(true))
  66. ->addColumn((new Column('capacity'))
  67. ->setOrderable()
  68. ->setSearchable(true))
  69. ->addColumn((new Column('type'))
  70. ->setOrderable()
  71. ->setSearchable(true, Column::TYPE_INT))
  72. ->addColumn((new Column('status'))
  73. ->setOrderable()
  74. ->setSearchable(true));
  75. }
  76. /**
  77. * @param $key
  78. * @param $row
  79. * @return mixed
  80. */
  81. public function replaceFieldStatus($key, $row)
  82. {
  83. $status = self::STATUS_LABEL[$row[$key]] ? self::STATUS_LABEL[$row[$key]] : self::STATUS_LABEL['default'];
  84. $label = di('lang')->absoluteT('kerio','account','status',$row[$key]);
  85. $field = new EnabledField();
  86. $field->setRawType($status);
  87. $field->setRawTitle($label);
  88. return $field->getHtml();
  89. }
  90. /**
  91. * @param $key
  92. * @param $row
  93. * @return mixed
  94. */
  95. public function replaceFieldLast_login($key, $row)
  96. {
  97. return $row[$key] ? $row[$key] : '-';
  98. }
  99. /**
  100. * @param $key
  101. * @param $row
  102. * @return mixed
  103. */
  104. public function replaceFieldType($key, $row)
  105. {
  106. return $row[$key] == 'Location' ? di('lang')->absoluteT('kerio','ressource','type','location') : di('lang')->absoluteT('kerio','ressource','type','equipment');
  107. }
  108. /**
  109. * load buttons
  110. */
  111. public function initContent()
  112. {
  113. $productManager = new ProductManager();
  114. $productManager->loadByHostingId($this->getRequestValue('id'));
  115. $this->addMassActionButton(new MassChangeStatusButton());
  116. $this->addMassActionButton(new MassDeleteRessourceButton());
  117. $this->addButton(new AddRessourceButton());
  118. $this->addActionButton(new EditRessourceButton());
  119. $this->addActionButton(new DeleteRessourceButton());
  120. $mailBox = new LoginToPanelButton();
  121. $mailBox
  122. ->setRawUrl(BuildUrlExtended::getProvisioningUrl('webmail', true, true,'clientSso'))
  123. ->setRedirectParams(['actionElementId' => 'true']);
  124. $actions = new SpanDropdownButton('actions');
  125. $actions->addButton(new ChangeStatusButton());
  126. $actions->addButton(new ChangePasswordButton());
  127. if ($productManager->get('ca_logInToMailboxButton') === 'on')
  128. {
  129. $actions->addButton($mailBox);
  130. }
  131. $this->addActionButton($actions);
  132. }
  133. /**
  134. * load data
  135. */
  136. public function loadData()
  137. {
  138. /**
  139. * load hosting
  140. */
  141. $hosting = Hosting::where('id', $this->getRequestValue('id'))->first();
  142. $ressources = (new KerioManager())
  143. ->getApiByServer($hosting->server)
  144. ->soap
  145. ->repository()
  146. ->ressources
  147. ->getByDomainName($hosting->domain);
  148. /**
  149. * format model to array
  150. */
  151. $data = [];
  152. foreach ($ressources as $ressource)
  153. {
  154. /* @var $account Ressource */
  155. $ressourceArray = [
  156. 'id' => $ressource->getId(),
  157. 'ressource' => $ressource->getDataResourceA('displayName'),
  158. 'date_created' => RessourceHelper::getFormattedData($ressource->getDataResourceA('kerioCreateTimestamp')),
  159. // 'last_login' => RessourceHelper::getFormattedData($ressource->getDataResourceA('kerioLastLogonTimestamp'), 'd/m/Y H:i'),
  160. 'capacity' => $ressource->getDataResourceA('kerioCalResCapacity'),
  161. 'type' => $ressource->getDataResourceA('kerioCalResType'),
  162. 'status' => $ressource->getDataResourceA('kerioAccountStatus')
  163. ];
  164. $data[] = $ressourceArray;
  165. }
  166. $dataProv = new ArrayDataProvider();
  167. $dataProv->setDefaultSorting('ressource', 'ASC')->setData($data);
  168. $this->setDataProvider($dataProv);
  169. }
  170. }