summaryrefslogtreecommitdiff
path: root/framework/Data/DataGateway
diff options
context:
space:
mode:
authorxue <>2007-12-04 18:59:48 +0000
committerxue <>2007-12-04 18:59:48 +0000
commitbe7deeed610871839ba166a5d4c8237e5cdbe864 (patch)
tree1d0f0f6b51848d0c173beacf45bf8ee8b455d7e7 /framework/Data/DataGateway
parent021780a79c2adb46438b3e350bfc7e8ca955cbcd (diff)
Active Record now supports query criteria for implicitly declared related properties
Diffstat (limited to 'framework/Data/DataGateway')
-rw-r--r--framework/Data/DataGateway/TSqlCriteria.php28
1 files changed, 23 insertions, 5 deletions
diff --git a/framework/Data/DataGateway/TSqlCriteria.php b/framework/Data/DataGateway/TSqlCriteria.php
index d073cd10..a17ac0c6 100644
--- a/framework/Data/DataGateway/TSqlCriteria.php
+++ b/framework/Data/DataGateway/TSqlCriteria.php
@@ -51,6 +51,7 @@ class TSqlCriteria extends TComponent
$this->_parameters->copyFrom((array)$parameters);
$this->_ordersBy=new TAttributeCollection;
$this->_ordersBy->setCaseSensitive(true);
+
$this->setCondition($condition);
}
@@ -68,7 +69,14 @@ class TSqlCriteria extends TComponent
*/
public function setCondition($value)
{
- $this->_condition=$value;
+ if(!empty($value) && preg_match('/ORDER\s+BY\s+(.*?)$/i',$value,$matches)>0)
+ {
+ // condition contains ORDER BY, we need to strip it output
+ $this->_condition=substr($value,0,strpos($value,$matches[0]));
+ $this->setOrdersBy($matches[1]);
+ }
+ else
+ $this->_condition=$value;
}
/**
@@ -107,13 +115,23 @@ class TSqlCriteria extends TComponent
}
/**
- * @param ArrayAccess ordering clause.
+ * @param mixed ordering clause.
*/
public function setOrdersBy($value)
{
- if(!(is_array($value) || $value instanceof ArrayAccess))
- throw new TException('value must be array or ArrayAccess');
- $this->_ordersBy->copyFrom($value);
+ if(is_array($value) || $value instanceof Traversable)
+ $this->_ordersBy->copyFrom($value);
+ else
+ {
+ $value=trim(preg_replace('/\s+/',' ',(string)$value));
+ $orderBys=array();
+ foreach(explode(',',$value) as $orderBy)
+ {
+ $vs=explode(' ',trim($orderBy));
+ $orderBys[$vs[0]]=isset($vs[1])?$vs[1]:'asc';
+ }
+ $this->_ordersBy->copyFrom($orderBys);
+ }
}
/**