QuerySkeleton.class.php

Go to the documentation of this file.
00001 <?php
00002 /***************************************************************************
00003  *   Copyright (C) 2004-2007 by Konstantin V. Arkhipov                     *
00004  *                                                                         *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU Lesser General Public License as        *
00007  *   published by the Free Software Foundation; either version 3 of the    *
00008  *   License, or (at your option) any later version.                       *
00009  *                                                                         *
00010  ***************************************************************************/
00011 /* $Id: QuerySkeleton.class.php 4687 2007-12-09 18:57:18Z voxus $ */
00012 
00016     abstract class QuerySkeleton extends QueryIdentification
00017     {
00018         protected $where        = array();  // where clauses
00019         protected $whereLogic   = array();  // logic between where's
00020         
00025         public function where(LogicalObject $exp, $logic = null)
00026         {
00027             if ($this->where && !$logic)
00028                 throw new WrongArgumentException(
00029                     'you have to specify expression logic'
00030                 );
00031             else {
00032                 if (!$this->where && $logic)
00033                     $logic = null;
00034 
00035                 $this->whereLogic[] = $logic;
00036                 $this->where[] = $exp;
00037             }
00038             
00039             return $this;
00040         }
00041         
00045         public function andWhere(LogicalObject $exp)
00046         {
00047             return $this->where($exp, 'AND');
00048         }
00049         
00053         public function orWhere(LogicalObject $exp)
00054         {
00055             return $this->where($exp, 'OR');
00056         }
00057 
00058         public function toDialectString(Dialect $dialect)
00059         {
00060             if ($this->where) {
00061                 $clause = ' WHERE';
00062                 $outputLogic = false;
00063                 
00064                 for ($i = 0, $size = count($this->where); $i < $size; ++$i) {
00065                     
00066                     if ($exp = $this->where[$i]->toDialectString($dialect)) {
00067                         
00068                         $clause .= "{$this->whereLogic[$i]} {$exp} ";
00069                         $outputLogic = true;
00070                         
00071                     } elseif (!$outputLogic && isset($this->whereLogic[$i + 1]))
00072                         $this->whereLogic[$i + 1] = null;
00073                     
00074                 }
00075 
00076                 return $clause;
00077             }
00078             
00079             return null;
00080         }
00081     }
00082 ?>

Generated on Sun Dec 9 21:56:23 2007 for onPHP by  doxygen 1.5.4