| 1 | <?php |
|---|
| 2 | |
|---|
| 3 | class Package |
|---|
| 4 | { |
|---|
| 5 | |
|---|
| 6 | private $_id; |
|---|
| 7 | private $_pkgname; |
|---|
| 8 | private $_developer; |
|---|
| 9 | private $_distro; |
|---|
| 10 | private $_status = FALSE; |
|---|
| 11 | |
|---|
| 12 | private $_db; |
|---|
| 13 | private $_update = FALSE; |
|---|
| 14 | |
|---|
| 15 | public function __construct($id=NULL) |
|---|
| 16 | { |
|---|
| 17 | $this->_id = $id; |
|---|
| 18 | |
|---|
| 19 | if($id != NULL) { |
|---|
| 20 | $this->_connect(); |
|---|
| 21 | } |
|---|
| 22 | } |
|---|
| 23 | |
|---|
| 24 | private function _connect() |
|---|
| 25 | { |
|---|
| 26 | $this->_db = sqlite_open(SQLITE_LOCATION); |
|---|
| 27 | } |
|---|
| 28 | |
|---|
| 29 | private function _disconnect() |
|---|
| 30 | { |
|---|
| 31 | if($this->_db) { |
|---|
| 32 | $this->_db = sqlite_open(SQLITE_LOCATION); |
|---|
| 33 | } |
|---|
| 34 | } |
|---|
| 35 | |
|---|
| 36 | private function _query($query) |
|---|
| 37 | { |
|---|
| 38 | if(!$this->_db) { |
|---|
| 39 | die("OOPS, call Alan ! 001"); |
|---|
| 40 | } |
|---|
| 41 | |
|---|
| 42 | return sqlite_query($this->_db,$query); |
|---|
| 43 | } |
|---|
| 44 | |
|---|
| 45 | private function _fetch($result) |
|---|
| 46 | { |
|---|
| 47 | if(!$this->_db) { |
|---|
| 48 | die("OOPS, Call Alan ! 002"); |
|---|
| 49 | } |
|---|
| 50 | |
|---|
| 51 | return sqlite_fetch_array($result); |
|---|
| 52 | } |
|---|
| 53 | |
|---|
| 54 | public function setPkgName($name) |
|---|
| 55 | { |
|---|
| 56 | $this->_pkgname = $name; |
|---|
| 57 | $this->_update = TRUE; |
|---|
| 58 | } |
|---|
| 59 | |
|---|
| 60 | public function getPkgName() |
|---|
| 61 | { |
|---|
| 62 | return $this->_pkgname; |
|---|
| 63 | } |
|---|
| 64 | |
|---|
| 65 | public function setId($id) |
|---|
| 66 | { |
|---|
| 67 | $this->_id = $id; |
|---|
| 68 | $this->_update = TRUE; |
|---|
| 69 | } |
|---|
| 70 | |
|---|
| 71 | public function getId() |
|---|
| 72 | { |
|---|
| 73 | return $this->_id; |
|---|
| 74 | } |
|---|
| 75 | |
|---|
| 76 | public function setDeveloper($name) |
|---|
| 77 | { |
|---|
| 78 | $this->_developer = $name; |
|---|
| 79 | $this->_update = TRUE; |
|---|
| 80 | } |
|---|
| 81 | |
|---|
| 82 | public function getDeveloper() |
|---|
| 83 | { |
|---|
| 84 | return $this->_developer; |
|---|
| 85 | } |
|---|
| 86 | |
|---|
| 87 | public function setDistro($name) |
|---|
| 88 | { |
|---|
| 89 | $this->_distro = $name; |
|---|
| 90 | $this->_update = TRUE; |
|---|
| 91 | } |
|---|
| 92 | |
|---|
| 93 | public function getDistro() |
|---|
| 94 | { |
|---|
| 95 | return $this->_distro; |
|---|
| 96 | } |
|---|
| 97 | |
|---|
| 98 | public function setStatus($bool) |
|---|
| 99 | { |
|---|
| 100 | $this->_status = $bool; |
|---|
| 101 | $this->_update = TRUE; |
|---|
| 102 | } |
|---|
| 103 | |
|---|
| 104 | public function getStatus() |
|---|
| 105 | { |
|---|
| 106 | return $this->_status; |
|---|
| 107 | } |
|---|
| 108 | |
|---|
| 109 | private function _new() |
|---|
| 110 | { |
|---|
| 111 | $this->_connect(); |
|---|
| 112 | $this->_query("insert into queue values (NULL,'{$this->_pkgname}','{$this->_developer}','{$this->_distro}','{$this->_status}')"); |
|---|
| 113 | } |
|---|
| 114 | |
|---|
| 115 | private function _edit() |
|---|
| 116 | { |
|---|
| 117 | $this->_query("update queue set pkgname='{$this->_pkgname}', developer='{$this->_developer}', ". |
|---|
| 118 | "distro='{$this->_distro}', status='{$this->_status}' where id='{$this->_id}'"); |
|---|
| 119 | } |
|---|
| 120 | |
|---|
| 121 | public function __destruct() |
|---|
| 122 | { |
|---|
| 123 | if($this->_update == TRUE && $this->_id == NULL) { |
|---|
| 124 | $this->_new(); |
|---|
| 125 | } else if ($this->_update == TRUE) { |
|---|
| 126 | $this->_edit(); |
|---|
| 127 | } |
|---|
| 128 | |
|---|
| 129 | $this->_disconnect(); |
|---|
| 130 | } |
|---|
| 131 | |
|---|
| 132 | } |
|---|
| 133 | |
|---|
| 134 | class packages extends package { |
|---|
| 135 | |
|---|
| 136 | public function getAll() { |
|---|
| 137 | $this->_connect(); |
|---|
| 138 | $result = $this->_query("select * from queue"); |
|---|
| 139 | |
|---|
| 140 | $objs=array(); |
|---|
| 141 | while($row = $this->_fetch($result)) { |
|---|
| 142 | |
|---|
| 143 | } |
|---|
| 144 | } |
|---|
| 145 | |
|---|
| 146 | public function deleteAll() { |
|---|
| 147 | |
|---|
| 148 | } |
|---|
| 149 | |
|---|
| 150 | |
|---|
| 151 | } |
|---|