| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203 |
- <?php
- namespace ThurData\Servers\KerioEmail\App\UI\Client\EmailAccount\Pages;
- use ThurData\Servers\KerioEmail\App\Helpers\BuildUrlExtended;
- use ThurData\Servers\KerioEmail\App\Helpers\KerioManager;
- use ThurData\Servers\KerioEmail\App\Libs\Product\ProductManager;
- use ThurData\Servers\KerioEmail\App\Libs\Kerio\Components\Api\Soap\Connection;
- use ThurData\Servers\KerioEmail\App\Libs\Kerio\Components\Api\Soap\Helpers\AccountHelper;
- use ThurData\Servers\KerioEmail\App\Libs\Kerio\Components\Api\Soap\Models\Account;
- use ThurData\Servers\KerioEmail\App\Libs\Kerio\Components\Api\Soap\Repository\ClassOfServices;
- use ThurData\Servers\KerioEmail\App\Libs\Kerio\Components\Filters\EmailAccounts\FilterByCosId;
- use ThurData\Servers\KerioEmail\App\UI\Admin\Custom\Fields\EnabledField;
- use ThurData\Servers\KerioEmail\App\UI\Client\EmailAccount\Buttons\AddAccountButton;
- use ThurData\Servers\KerioEmail\App\UI\Client\EmailAccount\Buttons\ChangePasswordButton;
- use ThurData\Servers\KerioEmail\App\UI\Client\EmailAccount\Buttons\ChangeStatusButton;
- use ThurData\Servers\KerioEmail\App\UI\Client\EmailAccount\Buttons\DeleteAccountButton;
- use ThurData\Servers\KerioEmail\App\UI\Client\EmailAccount\Buttons\EditAccountButton;
- use ThurData\Servers\KerioEmail\App\UI\Client\EmailAccount\Buttons\LoginToPanelButton;
- use ThurData\Servers\KerioEmail\App\UI\Client\EmailAccount\Buttons\MassChangeStatusButton;
- use ThurData\Servers\KerioEmail\App\UI\Client\EmailAccount\Buttons\MassDeleteAccountButton;
- use ThurData\Servers\KerioEmail\App\UI\Client\EmailAccount\Buttons\SpanDropdownButton;
- use function ThurData\Servers\KerioEmail\Core\Helper\di;
- use ThurData\Servers\KerioEmail\Core\Models\Whmcs\Hosting;
- use ThurData\Servers\KerioEmail\Core\UI\Widget\Buttons\DropdawnButtonWrappers\ButtonDropdown;
- use ThurData\Servers\KerioEmail\Core\UI\Widget\DataTable\Column;
- use ThurData\Servers\KerioEmail\Core\UI\Widget\DataTable\DataProviders\DataProvider;
- use ThurData\Servers\KerioEmail\Core\UI\Interfaces\ClientArea;
- use ThurData\Servers\KerioEmail\Core\UI\Widget\DataTable\DataProviders\Providers\ArrayDataProvider;
- use ThurData\Servers\KerioEmail\Core\UI\Widget\DataTable\DataTable;
- /**
- *
- * Created by PhpStorm.
- * User: ThurData
- * Date: 10.09.19
- * Time: 10:51
- * Class Accounts
- */
- class Accounts extends DataTable implements ClientArea
- {
- /**
- * labels for statuses
- */
- const STATUS_LABEL = [
- 'active' => 'success',
- 'locked' => 'default',
- 'maintenance' => 'warning',
- 'closed' => 'default',
- 'lockout' => 'info',
- 'pending' => 'warning',
- 'default' => 'default'
- ];
- protected $id = 'accounts';
- protected $name = 'accounts';
- protected $title = null;
- /**
- * load columns
- */
- protected function loadHtml()
- {
- $this
- ->addColumn((new Column('mailbox'))
- ->setOrderable(DataProvider::SORT_ASC)
- ->setSearchable(true, Column::TYPE_STRING))
- ->addColumn((new Column('date_created'))
- ->setOrderable()
- ->setSearchable(true))
- ->addColumn((new Column('date_created'))
- ->setOrderable()
- ->setSearchable(true))
- ->addColumn((new Column('last_login'))
- ->setOrderable()
- ->setSearchable(true))
- ->addColumn((new Column('quota'))
- ->setOrderable()
- ->setSearchable(true, Column::TYPE_INT))
- ->addColumn((new Column('status'))
- ->setOrderable()
- ->setSearchable(true));
- }
- /**
- * @param $key
- * @param $row
- * @return mixed
- */
- public function replaceFieldStatus($key, $row)
- {
- $status = self::STATUS_LABEL[$row[$key]] ? self::STATUS_LABEL[$row[$key]] : self::STATUS_LABEL['default'];
- $label = di('lang')->absoluteT('kerio','account','status',$row[$key]);
- $field = new EnabledField();
- $field->setRawType($status);
- $field->setRawTitle($label);
- return $field->getHtml();
- }
- /**
- * @param $key
- * @param $row
- * @return mixed
- */
- public function replaceFieldLast_login($key, $row)
- {
- return $row[$key] ? $row[$key] : '-';
- }
- /**
- * load buttons
- */
- public function initContent()
- {
- $productManager = new ProductManager();
- $productManager->loadByHostingId($this->getRequestValue('id'));
- $this->addMassActionButton(new MassChangeStatusButton());
- $this->addMassActionButton(new MassDeleteAccountButton());
- $this->addButton(new AddAccountButton());
- $this->addActionButton(new EditAccountButton());
- $this->addActionButton(new DeleteAccountButton());
- $mailBox = new LoginToPanelButton();
- $mailBox
- ->setRawUrl(BuildUrlExtended::getProvisioningUrl('webmail', true, true,'clientSso'))
- ->setRedirectParams(['actionElementId' => 'true']);
- $actions = new SpanDropdownButton('actions');
- $actions->addButton(new ChangeStatusButton());
- $actions->addButton(new ChangePasswordButton());
- if ($productManager->get('ca_logInToMailboxButton') === 'on')
- {
- $actions->addButton($mailBox);
- }
- $this->addActionButton($actions);
- }
- /**
- * load data
- */
- public function loadData()
- {
- /**
- * load hosting
- */
- $hosting = Hosting::where('id', $this->getRequestValue('id'))->first();
- $accounts = (new KerioManager())
- ->getApiByServer($hosting->server)
- ->soap
- ->repository()
- ->accounts
- ->getByDomainName($hosting->domain);
- $productManager = new ProductManager();
- $productManager->loadByHostingId($hosting->id);
- if($productManager->get('filterAccountsByCOS') === 'on' && $productManager->get('cos_name') != ClassOfServices::CUSTOM_KERIO)
- {
- $availableCoses = is_array($productManager->getSettingCos()) ? array_keys($productManager->getSettingCos()) : [$productManager->getSettingCos()];
- $filter = new FilterByCosId();
- $filter->setAvailableCoses($availableCoses);
- $accounts = $filter->filter($accounts);
- }
- /**
- * format model to array
- */
- $data = [];
- foreach ($accounts as $account)
- {
- /* @var $account Account */
- $accountArray = [
- 'id' => $account->getId(),
- 'mailbox' => $account->getName(),
- 'date_created' => AccountHelper::getFormattedData($account->getDataResourceA('kerioCreateTimestamp')),
- 'last_login' => AccountHelper::getFormattedData($account->getDataResourceA('kerioLastLogonTimestamp'), 'd/m/Y H:i'),
- 'quota' => AccountHelper::getQuotaAsMb($account->getDataResourceA('kerioMailQuota')),
- 'status' => $account->getDataResourceA('kerioAccountStatus'),
- ];
- $data[] = $accountArray;
- }
- $dataProv = new ArrayDataProvider();
- $dataProv->setDefaultSorting('mailbox', 'ASC')->setData($data);
- $this->setDataProvider($dataProv);
- }
- }
|