diogenes.query.inc.php

00001 <?php
00002 /*
00003  * Copyright (C) 2003-2004 Polytechnique.org
00004  * http://opensource.polytechnique.org/
00005  *
00006  * This program is free software; you can redistribute it and/or modify
00007  * it under the terms of the GNU General Public License as published by
00008  * the Free Software Foundation; either version 2 of the License, or
00009  * (at your option) any later version.
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with this program; if not, write to the Free Software
00018  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019  */
00020 
00021 
00026 class DiogenesQuery {
00028   var $nArgs;
00030   var $sQuery;
00031 
00034   function DiogenesQuery($sQue = "") {
00035     $this->sQuery = $sQue;
00036     $this->nArgs = 0;
00037   }
00038 
00039 
00042   function addArg($sArg, $sSep = "") {
00043     if ($sSep && $this->nArgs)
00044        $this->sQuery .= $sSep;
00045     $this->sQuery .= $sArg;
00046     $this->nArgs++;
00047   }
00048 
00049 
00053   function getPages($qcount,$hitmax=0)
00054   {
00055     if (!$hitmax)
00056       return array(array(0,$qcount));
00057 
00058     $pages = array();
00059     $nrest = $qcount % $hitmax;
00060     $npages = ($qcount - $nrest) / $hitmax;
00061 
00062     // complete pages
00063     for($i = 0; $i < $npages; $i++)
00064       array_push($pages, array($i*$hitmax, ($i+1)*$hitmax));
00065 
00066     // leftovers
00067     if ($nrest)
00068       array_push($pages, array($npages*$hitmax, $npages*$hitmax+$nrest));
00069     return $pages;
00070   }
00071 
00072 
00075   function getResult(&$dbh,$hitmax=0,$start=0)
00076   {
00077     $query = $this->sQuery;
00078     if ($hitmax) {
00079       $query .= " LIMIT $start, $hitmax";
00080     }
00081 
00082     return $dbh->query($query);
00083   }
00084 
00085 
00088   function getQuery() {
00089     return $this->sQuery;
00090   }
00091 
00092 }
00093 
00094 ?>

Generated on Fri Jan 11 01:20:08 2008 for Diogenes by  doxygen 1.5.1