blob: 524aea5e274305fde413e62e16f1b295e92f41a6 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
<?php
class Passthrough
{
public static function getGroupDropdown(array &$row): array
{
$out = [];
if ($row['class'] === '0300') {
foreach (['GPU', 'GVT'] as $id) {
$out[] = [
'ptid' => $id,
'ptname' => $id,
'selected' => ($row['@PASSTHROUGH'] === $id ? 'selected' : ''),
];
}
return $out;
}
static $list = false;
if ($list === false) {
$list = Database::queryKeyValueList("SELECT groupid, title FROM passthrough_group ORDER BY groupid");
self::ensurePrepopulated($list);
}
$row['custom_groups'] = true;
foreach ($list as $id => $title) {
if ($id === 'GPU' || $id === 'GVT')
continue;
$item = ['ptid' => $id, 'ptname' => $id . ' (' . $title . ')'];
if ($row['@PASSTHROUGH'] === $id) {
$item['selected'] = 'selected';
}
$out[] = $item;
}
return $out;
}
private static function ensurePrepopulated(&$list)
{
$want = [
'GPU' => '[Special] GPU passthrough default group',
'GVT' => '[Special] Intel GVT-g default group',
];
foreach ($want as $id => $title) {
if (!isset($list[$id])) {
Database::exec("INSERT INTO passthrough_group (groupid, title) VALUES (:id, :title)
ON DUPLICATE KEY UPDATE title = VALUES(title)",
['id' => $id, 'title' => $title]);
$list[$id] = $title;
}
}
}
}
|