SQLChain.class.php

Go to the documentation of this file.
00001 <?php
00002 /****************************************************************************
00003  *   Copyright (C) 2004-2007 by Konstantin V. Arkhipov, Anton E. Lebedevich *
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: SQLChain.class.php 4687 2007-12-09 18:57:18Z voxus $ */
00012 
00016     abstract class SQLChain implements LogicalObject, MappableObject
00017     {
00018         protected $chain = array();
00019         protected $logic = array();
00020         
00024         protected function exp(DialectString $exp, $logic)
00025         {
00026             $this->chain[] = $exp;
00027             $this->logic[] = $logic;
00028             
00029             return $this;
00030         }
00031         
00032         public function getSize()
00033         {
00034             return count($this->chain);
00035         }
00036         
00040         public function toMapped(StorableDAO $dao, JoinCapableQuery $query)
00041         {
00042             $size = count($this->chain);
00043             
00044             Assert::isTrue($size > 0, 'empty chain');
00045             
00046             $chain = new $this;
00047             
00048             for ($i = 0; $i < $size; ++$i) {
00049                 $chain->exp(
00050                     $dao->guessAtom($this->chain[$i], $query),
00051                     $this->logic[$i]
00052                 );
00053             }
00054             
00055             return $chain;
00056         }
00057         
00058         public function toDialectString(Dialect $dialect)
00059         {
00060             if ($this->chain) {
00061                 $out = $this->chain[0]->toDialectString($dialect).' ';
00062                 for ($i = 1, $size = count($this->chain); $i < $size; ++$i) {
00063                     $out .=
00064                         $this->logic[$i]
00065                         .' '
00066                         .$this->chain[$i]->toDialectString($dialect)
00067                         .' ';
00068                 }
00069                 
00070                 if ($size > 1)
00071                     $out = rtrim($out); // trailing space
00072                 
00073                 if ($size === 1)
00074                     return $out;
00075                 
00076                 return '('.$out.')';
00077             }
00078             
00079             return null;
00080         }
00081     }
00082 ?>

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