summaryrefslogtreecommitdiff
blob: dd7ecbd3886c61ff3f72e5caf3ab626379acd444 (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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
<?

	class DBPackage {
	
		private $id;
		private $name;
		private $table;
		private $arr_keys;
		private $arr_db;
		private $changelog;
		private $recent_changes;
	
		function __construct($id) {
		
			if(!is_numeric($id))
				$id = 0;
			
			$db =& MDB2::singleton();
			$this->table = 'package';
			
			// Go ahead and query as much as we can
			$sql = "SELECT * FROM ".$this->table." WHERE id = ".$db->quote($id).";";
			$this->arr_db = $db->getRow($sql);
			
			$this->arr_keys = array_keys($this->arr_db);
			unset($this->arr_keys['id']);
			
			$this->id = $id;
			
		}
		
		public function __get($var) {
			if(in_array($var, $this->arr_keys)) {
				return $this->arr_db[$var];
			} else {
			
				switch($var) {
					case 'changelog':
						return $this->getChangelog();
						break;
					
					case 'recent_changes':
						return $this->getRecentChanges();
						break;
				}
			
				return $this->$var;
			}
		}
		
		public function __set($var, $value) {
		
			$db =& MDB2::singleton();
		
			if(in_array($var, $this->arr_keys)) {
				$arr_update = array($var => $value);
				$db->autoExecute($this->table, $arr_update, MDB2_AUTOQUERY_UPDATE, "id = ".$db->quote($this->id));
				$this->arr_db[$var] = $value;
			}
		}
		
		public function getLicenses() {
		
			$db =& MDB2::singleton();
		
			$var = 'licenses';
			
			if(!is_null($this->$var))
				return $this->$var;
			
			$sql = "SELECT DISTINCT license, name FROM view_licenses WHERE package = ".$db->quote($this->id)." ORDER BY name;";
			$value = $db->getAssoc($sql);
			
			return $this->$var = $value;
		
		}
		
		public function getChangelog() {
		
			$db =& MDB2::singleton();
			
			$var = 'changelog';
			
			if(!is_null($this->$var))
				return $this->$var;
			
			$sql = "SELECT $var FROM package_changelog WHERE package = ".$db->quote($this->id).";";
			$value = $db->getOne($sql);
			
			return $this->$var = $value;
		
		}
		
		public function getRecentChanges() {
		
			$db =& MDB2::singleton();
			
			$var = 'recent_changes';
			
			if(!is_null($this->$var))
				return $this->$var;
			
			$sql = "SELECT $var FROM package_changelog WHERE package = ".$db->quote($this->id).";";
			$value = $db->getOne($sql);
			
			return $this->$var = $value;
			
		}
		
	}

?>