LogicalBetween.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 
00017     final class LogicalBetween implements LogicalObject, MappableObject
00018     {
00019         private $field  = null;
00020         private $left   = null;
00021         private $right  = null;
00022         
00023         public function __construct($field, $left, $right)
00024         {
00025             $this->left     = $left;
00026             $this->right    = $right;
00027             $this->field    = $field;
00028         }
00029         
00030         public function toDialectString(Dialect $dialect)
00031         {
00032             return
00033                 '('
00034                 .$dialect->toFieldString($this->field)
00035                 .' BETWEEN '
00036                 .$dialect->toValueString($this->left)
00037                 .' AND '
00038                 .$dialect->toValueString($this->right)
00039                 .')';
00040         }
00041         
00045         public function toMapped(ProtoDAO $dao, JoinCapableQuery $query)
00046         {
00047             return new self(
00048                 $dao->guessAtom($this->field, $query),
00049                 $dao->guessAtom($this->left, $query),
00050                 $dao->guessAtom($this->right, $query)
00051             );
00052         }
00053         
00054         public function toBoolean(Form $form)
00055         {
00056             $left   = $form->toFormValue($this->left);
00057             $right  = $form->toFormValue($this->right);
00058             $value  = $form->toFormValue($this->field);
00059             
00060             return ($left   <= $value)
00061                 && ($value  <= $right);
00062         }
00063     }
00064 ?>