diff options
author | 2010-02-11 20:17:46 -0700 | |
---|---|---|
committer | 2010-02-11 20:17:46 -0700 | |
commit | 32a7a5f8d8b36ae6acb6e566ff3d371b7a145c4b (patch) | |
tree | f9b8efa8def14998bc8f7a4fed123cc34c98f8db /class.db.ebuild.php | |
parent | Zero (diff) | |
download | znurt-org-frontend-32a7a5f8d8b36ae6acb6e566ff3d371b7a145c4b.tar.gz znurt-org-frontend-32a7a5f8d8b36ae6acb6e566ff3d371b7a145c4b.tar.bz2 znurt-org-frontend-32a7a5f8d8b36ae6acb6e566ff3d371b7a145c4b.zip |
initial commit
Diffstat (limited to 'class.db.ebuild.php')
-rw-r--r-- | class.db.ebuild.php | 150 |
1 files changed, 150 insertions, 0 deletions
diff --git a/class.db.ebuild.php b/class.db.ebuild.php new file mode 100644 index 0000000..1ff654e --- /dev/null +++ b/class.db.ebuild.php @@ -0,0 +1,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; + + } + + } + +?>
\ No newline at end of file |