summaryrefslogtreecommitdiff
blob: 1ff654eb872f9ab35895c8e15d880a192f2b67db (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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
<?

	class DBEbuild {
		
		private $package;
		private $arr_db;
		private $arr_cols;
		private $arr_keys;
		private $table;
		private $id;
		private $description;
		private $homepage;
		private $keywords;
		
		function __construct($id) {
		
			if(!is_numeric($id))
				$id = 0;
			$this->id = $id;
			
			$db =& MDB2::singleton();
			
			$this->table = 'ebuild';
			
			// Go ahead and query as much as we can
			$sql = "SELECT * FROM view_ebuild WHERE id = $id;";
			$this->arr_db = $db->getRow($sql);
			
			$this->arr_keys = array_keys($this->arr_db);
			unset($this->arr_keys['id']);
			
			$this->arr_cols = array('package', 'pf', 'pv', 'pr', 'pvr', 'alpha', 'beta', 'pre', 'rc', 'p', 'version', 'slot', 'portage_mtime', 'cache_mtime', 'status', 'ev', 'lvl');
			
		}
		
		public function __get($var) {
		
			if($var == 'masked') {
				return ( $this->arr_db['masked'] == 't' ? true : false );
			}
		
			if(is_null($this->$var)) {
			
				if(in_array($var, $this->arr_keys))
					return $this->arr_db[$var];
			
				switch($var) {
				
					case 'description':
						return $this->getDescription();
						break;
				
					case 'homepage':
						return $this->getHomepage();
						break;
					
					case 'licenses':
						return $this->getLicenses();
						break;
					
					case 'keywords':
						return $this->getKeywords();
						break;
						
				}
			
			}
		
			return $this->$var;
		}
		
		public function __set($var, $value) {
		
			$db =& MDB2::singleton();
		
			if(in_array($var, $this->arr_cols)) {
				$arr_update = array($var => $value);
				$db->autoExecute($this->table, $arr_update, MDB2_AUTOQUERY_UPDATE, "id = ".$db->quote($this->id));
				$this->arr_db[$var] = $value;
			}
		}
		
		// Strings
		public function getDescription() {
		
			$db =& MDB2::singleton();
			
			$var = 'description';
			
			if(!is_null($this->$var))
				return $this->$var;
			
			$sql = "SELECT TRIM(em.value) FROM ebuild_metadata em INNER JOIN ebuild e ON em.ebuild = e.id AND e.id = ".$db->quote($this->id)." WHERE em.keyword = 'description'ORDER BY e.cache_mtime DESC LIMIT 1;";
			$value = $db->getOne($sql);
			
			return $this->$var = $value;
			
		}
		
		public function getHomepage() {
		
			$db =& MDB2::singleton();
			
			$var = 'homepage';
			
			if(!is_null($this->$var))
				return $this->$var;
			
			$sql = "SELECT TRIM(eh.homepage) FROM ebuild_homepage eh INNER JOIN ebuild e ON eh.ebuild = e.id AND e.id = ".$db->quote($this->id)." ORDER BY e.cache_mtime DESC LIMIT 1;";
			$value = $db->getOne($sql);
			
			return $this->$var = $value;
			
		}
		
		public function getLicenses() {
		
			$db =& MDB2::singleton();
		
			$var = 'licenses';
			
			if(!is_null($this->$var))
				return $this->$var;
			
			$sql = "SELECT license, name FROM view_licenses WHERE ebuild = ".$db->quote($this->id)." ORDER BY name;";
			$value = $db->getAssoc($sql);
			
			return $this->$var = $value;
		
		}
		
		public function getKeywords() {
		
			$db =& MDB2::singleton();
		
			$var = 'keywords';
			
			if(!is_null($this->$var))
				return $this->$var;
			
			$sql = "SELECT name, status FROM view_arches WHERE ebuild = ".$db->quote($this->id)." ORDER BY name;";
			$value = $db->getAssoc($sql);
			
			return $this->$var = $value;
		
		}
	
	}

?>