summaryrefslogtreecommitdiff
path: root/trunk/reprap/web/part-lister/controllers/parts.php
blob: 4855021ad7cf9746455a4be78d90a1cdacb9b260 (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
87
88
89
<?
	class PartsController extends Controller
	{
		public function bysupplier()
		{
			$supplier = Supplier::byName($this->args('name'));
			$parts = $supplier->getSuppliedParts()->getAll();
			
			$this->set('parts', $parts);
			$this->set('supplier', $supplier);
		}
		
		public function bytype()
		{
			$type = $this->args('type');
			$collection = UniquePart::byType($type);
			
			$this->set('type', $type);
			$this->set('collection', $collection);
		}
		
		public function uniquedetail()
		{
			if ($this->args('id'))
				$part = new UniquePart($this->args('id'));
			else if ($this->args('name') && $this->args('type'))
				$part = UniquePart::byName($this->args('name'), $this->args('type'));
			else
				$this->set('error', "You didn't pass in the right parameters.");
				
			if ($part->id)
			{
				$list = $part->getUniquePartList();
				$suppliers = $part->getSupplierParts()->getAll();
				$modules = $part->getParentModules()->getAll();
			
				$this->set('list', $list);
				$this->set('suppliers', $suppliers);
				$this->set('part', $part);
				$this->set('modules', $modules);
			}
			else
				$this->set('error', "We could not find the part you are looking for.");

		}
		
		public function embed()
		{
			if ($this->args('id'))
				$part = new UniquePart($this->args('id'));
			else if ($this->args('name') && $this->args('type'))
				$part = UniquePart::byName($this->args('name'), $this->args('type'));
			else
				$this->set('error', "You didn't pass in the right parameters.");
				
			if ($part->id)
			{
				$list = $part->getUniquePartList();
				$this->set('list', $list);
				$this->set('part', $part);
			}
			else
				$this->set('error', "We could not find the part you are looking for.");

		}
		
		public function all()
		{
			$sql = "
				SELECT id
				FROM unique_parts
				ORDER BY type, name
			";
			$coll = new Collection($sql, array(
				'UniquePart' => 'id'
			));
			
			$this->set('parts', $coll->getAll());
		}
		
		public function tree()
		{
			$root = $this->args('root');
			
			$this->set('root', $root);
			$this->set('kids', $root->getUniqueComponents());
		}
	}
?>