Go to the documentation of this file.00001 <?PHP
00002
00003 require_once dirname(__FILE__) . "/class.ilElement.php";
00004
00015 class ilElementList {
00016
00023 var $dbHandle;
00024
00030 var $result;
00031
00038 var $dbTable;
00039
00046 var $idField="id";
00047
00054 var $orderField="id";
00055
00062 var $orderDirection="ASC";
00063
00070 var $whereCond="1";
00071
00072
00078 var $element;
00079
00080 function ilElementList() {
00081
00082 $this->idField="id";
00083 $this->orderField="id";
00084 $this->orderDirection="ASC";
00085 $this->whereCond="1";
00086
00087 $this->element = new ilElement();
00088 }
00089
00096 function checkDb($function) {
00097 if ($this->dbHandle == "") {
00098 die($function . ": No database handle given.");
00099 }
00100 if ($this->dbTable == "") {
00101 die($function . ": No database table given.");
00102 }
00103 }
00104
00111 function setDbTable($dbTable) {
00112 if ($dbTable == "") {
00113 die ("List::setDbTable(): No database table given.");
00114 } else {
00115 $this->dbTable = $dbTable;
00116 }
00117 }
00118
00125 function getDbTable() {
00126 return $this->dbTable;
00127 }
00128
00135 function setDbHandle($dbHandle) {
00136 if ($dbHandle == "") {
00137 die("Liste::setDbHandle(): No database handle given.");
00138 } else {
00139 $this->dbHandle = $dbHandle;
00140 }
00141 }
00142
00149 function getDbHandle() {
00150 return $this->dbHandle;
00151 }
00152
00159 function setIdField($idField) {
00160 if ($idField == "") {
00161 die ("Liste::setIdField(): No id given.");
00162 } else {
00163 $this->idField = $idField;
00164 }
00165 }
00166
00173 function setWhereCond($where) {
00174 if ($where == "") {
00175 die ("Liste::setWhereCond(): No where condition given.");
00176 } else {
00177 $this->whereCond = $where;
00178 }
00179 }
00180
00181
00188 function setOrderField($orderField) {
00189 if ($orderField == "") {
00190 die ("Liste::setOrderField(): No order field given.");
00191 } else {
00192 $this->orderField = $orderField;
00193 }
00194 }
00195
00203 function setOrderDirection($orderDirection) {
00204 if (($orderDirection != "ASC") && ($orderDirection != "DESC")) {
00205 return false;
00206 } else {
00207 $this->orderDirection = $orderDirection;
00208 }
00209 }
00210
00217 function selectDbAll()
00218 {
00219 $this->checkDb("Liste::selectDbAll()");
00220
00221 # echo "SELECT * FROM " . $this->getDbTable() . " WHERE (".$this->whereCond.") ORDER BY " . $this->orderField . " " . $this->orderDirection;
00222 $result = $this->dbHandle->query("SELECT * FROM " . $this->getDbTable() . " WHERE (".$this->whereCond.") ORDER BY " . $this->orderField . " " . $this->orderDirection);
00223 if (DB::isError($result)) {
00224 die("Liste::selectDbAll(): ".$result->getMessage());
00225 }
00226 $this->result=$result;
00227 return $result;
00228 }
00229
00238 function selectDbAllLimited($start = 0, $count = 30) {
00239 $this->checkDb("Liste::selectDbQuery()");
00240
00241 $result = $this->dbHandle->query("SELECT * FROM " . $this->getDbTable() . " WHERE (".$this->whereCond.") ORDER BY " . $this->orderField . " " . $this->orderDirection . " LIMIT " . $start . ", " . $count);
00242 if (DB::isError($result)) {
00243 die("Liste::selectDbAllLimited(): ".$result->getMessage());
00244 }
00245 $this->result=$result;
00246 return $result;
00247 }
00248
00255 function selectDbAllByQuery($query) {
00256 if ($this->dbHandle == "") {
00257 die("Liste::selectDbAllByQuery(): No database handle given.");
00258 }
00259 if ($query == "") {
00260 die("Liste::selectDbAllByQuery(): No query given.");
00261 }
00262
00263 $result = $this->dbHandle->query($query);
00264 if (DB::isError($result)) {
00265 die("Liste::selectDbAllByQuery(): ".$result->getMessage());
00266 }
00267 $this->result=$result;
00268 return $result;
00269 }
00270
00278 function getDbNextElement($result="default") {
00279
00280 if ($result=="default") {
00281 $result=$this->result;
00282 }
00283
00284 if (!is_object($result)) {
00285 die("Liste::getDbNextElement(): No result object given.");
00286 }
00287
00288 if (is_array($data = $result->fetchRow(DB_FETCHMODE_ASSOC))) {
00289 $this->element->setData($data);
00290 return true;
00291 } else {
00292 return false;
00293 }
00294 }
00295
00303 function countDb($where = "") {
00304 $this->checkDb("Liste::countDb()");
00305
00306 $q = "SELECT COUNT(*) FROM " . $this->getDbTable();
00307 if ($where != "") {
00308 $q .= " WHERE " . $where;
00309 } else {
00310 $q .= " WHERE (" . $this->whereCond . ")";
00311 }
00312 $result = $this->dbHandle->query($q);
00313 if (DB::isError($result)) {
00314 die("Liste::countDb(): ".$result->getMessage());
00315 }
00316 if (is_array($data = $result->fetchRow())) {
00317 return $data[0];
00318 } else {
00319 return 0;
00320 }
00321 }
00322
00330 function countDbByQuery($query) {
00331 if ($this->dbHandle == "") {
00332 die("Liste::countDbByQuery(): No database handle given.");
00333 }
00334 if ($query == "") {
00335 die("Liste::countDbByQuery(): No query given.");
00336 }
00337
00338 $result = $this->dbHandle->query($query);
00339 if (DB::isError($result)) {
00340 die("Liste::countDbByQuery(): ".$result->getMessage());
00341 }
00342 if (is_array($data = $result->fetchRow())) {
00343 return $data[0];
00344 } else {
00345 return 0;
00346 }
00347 }
00348
00349 }
00350
00351 ?>