PageRenderTime 55ms CodeModel.GetById 30ms RepoModel.GetById 0ms app.codeStats 0ms

/trunk/h-source/Application/Models/VendorsModel.php

https://gitlab.com/7slayer/h-node
PHP | 82 lines | 49 code | 16 blank | 17 comment | 6 complexity | 66f809dadcd71e21a7c9d382e155b4e1 MD5 | raw file
  1. <?php
  2. // h-source, a web software to build a community of people that want to share their hardware information.
  3. // Copyright (C) 2010 Antonio Gallo (h-source-copyright.txt)
  4. //
  5. // This file is part of h-source
  6. //
  7. // h-source is free software: you can redistribute it and/or modify
  8. // it under the terms of the GNU General Public License as published by
  9. // the Free Software Foundation, either version 3 of the License, or
  10. // (at your option) any later version.
  11. //
  12. // h-source is distributed in the hope that it will be useful,
  13. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. // GNU General Public License for more details.
  16. //
  17. // You should have received a copy of the GNU General Public License
  18. // along with h-source. If not, see <http://www.gnu.org/licenses/>.
  19. if (!defined('EG')) die('Direct access not allowed!');
  20. class VendorsModel extends Model_Tree {
  21. public function __construct() {
  22. $this->_tables = 'vendors';
  23. $this->_idFields = 'id_vendor';
  24. parent::__construct();
  25. }
  26. public function check($id,$interface = 'USB')
  27. {
  28. if (preg_match('/^[a-zA-Z0-9]{4}(\:)[a-zA-Z0-9]{4}$/',$id))
  29. {
  30. $clean['bus'] = strcmp($interface,'USB') === 0 ? "USB" : "PCI";
  31. $temp = explode(':',$id);
  32. $clean['vendorId'] = sanitizeAlphanum($temp[0]);
  33. $number = $this->clear()->where(array("vendorid" => $clean['vendorId'], "bus" => $clean['bus']))->rowNumber();
  34. if ($number > 0)
  35. {
  36. return true;
  37. }
  38. }
  39. return false;
  40. }
  41. public function getName($id,$interface)
  42. {
  43. if ($this->check($id,$interface))
  44. {
  45. $clean['bus'] = strcmp($interface,'USB') === 0 ? "USB" : "PCI";
  46. $temp = explode(':',$id);
  47. $clean['vendorId'] = sanitizeAlphanum($temp[0]);
  48. $res = $this->clear()->where(array("vendorid" => $clean['vendorId'], "bus" => $clean['bus']))->send();
  49. if (count($res) > 0)
  50. {
  51. return $res[0]['vendors']['clean_name'];
  52. }
  53. }
  54. return 'not-known';
  55. }
  56. public function getFullName($name)
  57. {
  58. $clean['name'] = sanitizeAll($name);
  59. $res = $this->clear()->where(array("clean_name" => $clean['name']))->send();
  60. if (count($res) > 0)
  61. {
  62. return $res[0]['vendors']['full_name'];
  63. }
  64. return $clean['name'];
  65. }
  66. }