http://modulesgarden.com
* CONTACT -> contact@modulesgarden.com
*
*
* This software is furnished under a license and may be used and copied
* only in accordance with the terms of such license and with the
* inclusion of the above copyright notice. This software or any other
* copies thereof may not be provided or otherwise made available to any
* other person. No title to and ownership of the software is hereby
* transferred.
*
*
* ******************************************************************** */
namespace ModulesGarden\Servers\ProxmoxVps\App\UI\Admin\User\Pages;
use MGProvision\Proxmox\v2\models\User;
use ModulesGarden\ProxmoxAddon\App\Services\ApiService;
use ModulesGarden\ProxmoxAddon\App\Services\Vps\ProductService;
use ModulesGarden\ProxmoxAddon\App\Services\Vps\UserService;
use ModulesGarden\Servers\ProxmoxVps\Core\UI\Interfaces\AdminArea;
use ModulesGarden\Servers\ProxmoxVps\Core\UI\Widget\DataTable\Column;
use ModulesGarden\Servers\ProxmoxVps\Core\UI\Widget\DataTable\DataProviders\Providers\ArrayDataProvider;
use ModulesGarden\Servers\ProxmoxVps\Core\UI\Widget\DataTable\DataTable;
use function ModulesGarden\Servers\ProxmoxVps\Core\Helper\sl;
class UserDataTable extends DataTable implements AdminArea
{
use ProductService;
use UserService;
use ApiService;
protected $id = 'userDataTable';
protected $title = 'userDataTable';
protected $searchable = false;
protected $tableLength = "100";
protected function loadHtml()
{
$this->addColumn((new Column('username')))
->addColumn((new Column('realm')))
->addColumn((new Column('password')))
->addColumn((new Column('enable')))
->addColumn((new Column('expire')))
->addColumn((new Column('name')))
->addColumn((new Column('comment')));
}
public function replaceFieldExpire($key, $row)
{
if ($row[$key] == 0)
{
return sl("lang")->tr("Never");
}
return $row[$key];
}
public function replaceFieldEnable($key, $row)
{
if ($row[$key])
{
return '' . sl('lang')->tr("Yes") . '';
}
return '' . sl('lang')->tr("No") . '';
}
protected function loadData()
{
$data = [];
if ($this->isUser())
{
$user = $this->getUser();
$userService = new User("{$user->username}@{$user->realm}");
$userService->setApi($this->api());
$configuration = $userService->configuration();
$data[] = [
'username' => $user->username,
'password' => $user->getPassword(),
'realm' => $user->realm,
'enable' => $configuration['enable'],
'expire' => $configuration['expire'],
'name' => $configuration['firstname'] . " " . $configuration['lastname'],
'comment' => $configuration['comment'],
];
}
$dataProv = new ArrayDataProvider();
$dataProv->setData($data);
$this->setDataProvider($dataProv);
}
public function initContent()
{
}
public function isViewFooter()
{
return false;
}
public function isViewTopBody()
{
return false;
}
}