From 07f5140771388c9e0c8a99b0dd2e5d950bdb173b Mon Sep 17 00:00:00 2001 From: Yuchen Pei Date: Thu, 14 Oct 2021 15:16:42 +1100 Subject: moving h-source subdir out. --- Application/Models/VendorsModel.php | 82 +++++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 Application/Models/VendorsModel.php (limited to 'Application/Models/VendorsModel.php') diff --git a/Application/Models/VendorsModel.php b/Application/Models/VendorsModel.php new file mode 100644 index 0000000..0b06d52 --- /dev/null +++ b/Application/Models/VendorsModel.php @@ -0,0 +1,82 @@ +. + +if (!defined('EG')) die('Direct access not allowed!'); + +class VendorsModel extends Model_Tree { + + public function __construct() { + $this->_tables = 'vendors'; + $this->_idFields = 'id_vendor'; + + parent::__construct(); + } + + public function check($id,$interface = 'USB') + { + if (preg_match('/^[a-zA-Z0-9]{4}(\:)[a-zA-Z0-9]{4}$/',$id)) + { + $clean['bus'] = strcmp($interface,'USB') === 0 ? "USB" : "PCI"; + + $temp = explode(':',$id); + $clean['vendorId'] = sanitizeAlphanum($temp[0]); + + $number = $this->clear()->where(array("vendorid" => $clean['vendorId'], "bus" => $clean['bus']))->rowNumber(); + + if ($number > 0) + { + return true; + } + } + return false; + } + + public function getName($id,$interface) + { + if ($this->check($id,$interface)) + { + $clean['bus'] = strcmp($interface,'USB') === 0 ? "USB" : "PCI"; + + $temp = explode(':',$id); + $clean['vendorId'] = sanitizeAlphanum($temp[0]); + + $res = $this->clear()->where(array("vendorid" => $clean['vendorId'], "bus" => $clean['bus']))->send(); + + if (count($res) > 0) + { + return $res[0]['vendors']['clean_name']; + } + } + return 'not-known'; + } + + public function getFullName($name) + { + $clean['name'] = sanitizeAll($name); + + $res = $this->clear()->where(array("clean_name" => $clean['name']))->send(); + + if (count($res) > 0) + { + return $res[0]['vendors']['full_name']; + } + return $clean['name']; + } +} \ No newline at end of file -- cgit v1.2.3