| [ Index ] |
PHP Cross Reference of Limb3 |
[Summary view] [Print] [Text view]
1 <?php 2 /* 3 * Limb PHP Framework 4 * 5 * @link http://limb-project.com 6 * @copyright Copyright © 2004-2007 BIT(http://bit-creative.com) 7 * @license LGPL http://www.gnu.org/copyleft/lesser.html 8 */ 9 //inspired by Propel Criteria(http://propel.phpdb.org) 10 lmb_require('limb/dbal/src/criteria/lmbSQLCriteria.class.php'); 11 12 /** 13 * abstract class lmbSQLBaseCriteria. 14 * 15 * @package dbal 16 * @version $Id: lmbSQLBaseCriteria.class.php 5945 2007-06-06 08:31:43Z pachanga $ 17 */ 18 abstract class lmbSQLBaseCriteria 19 { 20 const _AND_ = " AND "; 21 const _OR_ = " OR "; 22 23 protected $clauses = array(); 24 protected $conjunctions = array(); 25 26 //'and' & 'or' are keywords in php :( 27 function addAnd($criteria) 28 { 29 $this->clauses[] = lmbSQLCriteria :: objectify($criteria); 30 $this->conjunctions[] = self::_AND_; 31 return $this; 32 } 33 34 function addOr($criteria) 35 { 36 $this->clauses[] = lmbSQLCriteria :: objectify($criteria); 37 $this->conjunctions[] = self::_OR_; 38 return $this; 39 } 40 41 protected function _getClauses() 42 { 43 return $this->clauses; 44 } 45 46 protected function _getConjunctions() 47 { 48 return $this->conjunctions; 49 } 50 51 function toStatementString(&$values = array(), $conn = null) 52 { 53 $str = ''; 54 $this->appendStatementTo($str, $values, $conn); 55 return $str; 56 } 57 58 function appendStatementTo(&$str, &$values = array(), $conn = null) 59 { 60 if(!is_object($conn)) 61 $conn = lmbToolkit :: instance()->getDefaultDbConnection(); 62 63 $this->_appendOpeningParenthesisToStatement($str, $values, $conn); 64 65 $this->_appendExpressionToStatement($str, $values, $conn); 66 67 $this->_appendClosingParenthesisToStatement($str, $values, $conn); 68 } 69 70 protected function _appendExpressionToStatement(&$str, &$values, $conn){} 71 72 protected function _appendOpeningParenthesisToStatement(&$str, &$values, $conn) 73 { 74 for($j = 0; $j < count($this->clauses); $j++) 75 $str .= '('; 76 } 77 78 protected function _appendClosingParenthesisToStatement(&$str, &$values, $conn) 79 { 80 for($i=0; $i < count($this->clauses); $i++) 81 { 82 $str .= $this->conjunctions[$i]; 83 $this->clauses[$i]->appendStatementTo($str, $values, $conn); 84 $str .= ')'; 85 } 86 } 87 88 function getAttachedCriterias() 89 { 90 $crits = array(); 91 $this->_traverseCriteria($this, $crits); 92 return $crits; 93 } 94 95 protected function _traverseCriteria($c, &$a) 96 { 97 $a[] = $c; 98 $clauses = $c->_getClauses(); 99 $clausesLength = count($clauses); 100 for($i=0; $i < $clausesLength; $i++) 101 $this->_traverseCriteria($clauses[$i], $a); 102 } 103 104 protected function _makePlaceHolder($holder) 105 { 106 return 'p' . str_replace('.', '_', $holder); 107 } 108 } 109 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Sat Sep 6 04:46:52 2008 | Cross-referenced by PHPXref 0.7 |