blob: 90bbe5bd8d61d030ea4298c725163429afa9607c (
plain)
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
|
<?
class Supplier extends Model
{
public function __construct($id = null)
{
parent::__construct($id, "suppliers");
}
public static function byName($name)
{
$id = db()->getValue("
SELECT id
FROM suppliers
WHERE name = '$name'
LIMIT 1
");
if ($id)
return new Supplier($id);
return false;
}
public static function lookupUrl($url)
{
$data = parse_url($url);
$domain = $data['domain'];
$id = db()->getValue("
SELECT id
FROM suppliers
WHERE website LIKE '%$domain%'
LIMIT 1
");
if ($id)
return new Supplier($id);
return false;
}
public function getViewUrl()
{
return "/supplier/" . urlencode($this->get('name'));
}
public function getHost()
{
$data = parse_url($this->get('website'));
return $data['host'];
}
public static function lookupKey($key)
{
$id = db()->getValue("
SELECT id
FROM suppliers
WHERE prefix = '$key'
LIMIT 1
");
if ($id)
return new Supplier($id);
return false;
}
public function getSuppliedParts()
{
$sql = "
SELECT sp.id, sp.part_id
FROM supplier_parts sp
INNER JOIN unique_parts u
ON u.id = sp.part_id
WHERE sp.supplier_id = '$this->id'
ORDER BY u.name
";
return new Collection($sql, array(
'SupplierPart' => 'id',
'UniquePart' => 'part_id'
));
}
}
?>
|