diff options
Diffstat (limited to 'modules-available/passthrough/inc/passthrough.inc.php')
-rw-r--r-- | modules-available/passthrough/inc/passthrough.inc.php | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/modules-available/passthrough/inc/passthrough.inc.php b/modules-available/passthrough/inc/passthrough.inc.php new file mode 100644 index 00000000..51fe7214 --- /dev/null +++ b/modules-available/passthrough/inc/passthrough.inc.php @@ -0,0 +1,42 @@ +<?php + +class Passthrough +{ + + public static function getGroupDropdown(array $row): array + { + static $list = false; + if ($list === false) { + $list = Database::queryKeyValueList("SELECT groupid, title FROM passthrough_group ORDER BY groupid"); + self::ensurePrepopulated($list); + } + $out = []; + foreach ($list as $id => $title) { + if ($row['class'] !== '0300' && ($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; + } + } + } + +}
\ No newline at end of file |