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.package.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.package.php')
-rw-r--r-- | class.db.package.php | 112 |
1 files changed, 112 insertions, 0 deletions
diff --git a/class.db.package.php b/class.db.package.php new file mode 100644 index 0000000..dd7ecbd --- /dev/null +++ b/class.db.package.php @@ -0,0 +1,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; + + } + + } + +?>
\ No newline at end of file |