LogicUtils.class.php

Go to the documentation of this file.
00001 <?php
00002 /***************************************************************************
00003  *   Copyright (C) 2005-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: LogicUtils.class.php 4687 2007-12-09 18:57:18Z voxus $ */
00012 
00016     final class LogicUtils extends StaticFactory
00017     {
00022         public static function getOpenRange(
00023             $left, $right, $min = null, $max = null
00024         )
00025         {
00026             Assert::isFalse(
00027                 ($min === null) && ($max === null),
00028                 'how can i build logic from emptyness?'
00029             );
00030             
00031             if ($min !== null)
00032                 $min = new DBValue($min);
00033             
00034             if ($max !== null)
00035                 $max = new DBValue($max);
00036             
00037             $chain = new LogicalChain();
00038             
00039             if ($min !== null && $max !== null) {
00040                 $chain->expOr(
00041                     Expression::orBlock(
00042                         Expression::andBlock(
00043                             Expression::notNull($left),
00044                             Expression::notNull($right),
00045                             Expression::expOr(
00046                                 Expression::between($min, $left, $right),
00047                                 Expression::between($left, $min, $max)
00048                             )
00049                         ),
00050                         Expression::andBlock(
00051                             Expression::isNull($left),
00052                             Expression::ltEq($min, $right)
00053                         ),
00054                         Expression::andBlock(
00055                             Expression::isNull($right),
00056                             Expression::ltEq($left, $max)
00057                         ),
00058                         Expression::andBlock(
00059                             Expression::isNull($left),
00060                             Expression::isNull($right)
00061                         )
00062                     )
00063                 );
00064             } elseif ($min !== null && $max === null) {
00065                 $chain->expOr(
00066                     Expression::orBlock(
00067                         Expression::andBlock(
00068                             Expression::notNull($right),
00069                             Expression::ltEq($min, $right)
00070                         ),
00071                         Expression::isNull($right)
00072                     )
00073                 );
00074             } elseif ($max !== null && $min === null) {
00075                 $chain->expOr(
00076                     Expression::orBlock(
00077                         Expression::andBlock(
00078                             Expression::notNull($left),
00079                             Expression::ltEq($left, $max)
00080                         ),
00081                         Expression::isNull($left)
00082                     )
00083                 );
00084             }
00085             
00086             return $chain;
00087         }
00088         
00089         
00094         public static function getOpenPoint(
00095             $left, $right, $point
00096         )
00097         {
00098             Assert::isFalse(
00099                 ($point === null),
00100                 'how can i build logic from emptyness?'
00101             );
00102             
00103             $point = new DBValue($point);
00104             
00105             $chain = new LogicalChain();
00106             
00107             $chain->expOr(
00108                 Expression::orBlock(
00109                     Expression::andBlock(
00110                         Expression::notNull($left),
00111                         Expression::notNull($right),
00112                         Expression::between($point, $left, $right)
00113                     ),
00114                     Expression::andBlock(
00115                         Expression::isNull($left),
00116                         Expression::ltEq($point, $right)
00117                     ),
00118                     Expression::andBlock(
00119                         Expression::isNull($right),
00120                         Expression::ltEq($left, $point)
00121                     ),
00122                     Expression::andBlock(
00123                         Expression::isNull($left),
00124                         Expression::isNull($right)
00125                     )
00126                 )
00127             );
00128             
00129             return $chain;
00130         }
00131     }
00132 ?>

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