summaryrefslogtreecommitdiff
path: root/framework/Data/ActiveRecord
diff options
context:
space:
mode:
authorwei <>2007-04-12 08:05:03 +0000
committerwei <>2007-04-12 08:05:03 +0000
commitdc3bf922d9715bfd1b2105be04a9aabc84a1d7d4 (patch)
treeff97362f718b6ebb482128527402efe03fe1ac43 /framework/Data/ActiveRecord
parent6178a99df0c722581bc61e35559ac5f8af1cc6e8 (diff)
Refactor and add TTableGateway, System.Data.Common, System.Data.DataGateway
Diffstat (limited to 'framework/Data/ActiveRecord')
-rw-r--r--framework/Data/ActiveRecord/TActiveRecord.php27
-rw-r--r--framework/Data/ActiveRecord/TActiveRecordCriteria.php146
2 files changed, 9 insertions, 164 deletions
diff --git a/framework/Data/ActiveRecord/TActiveRecord.php b/framework/Data/ActiveRecord/TActiveRecord.php
index 109ae9a6..70fd7b23 100644
--- a/framework/Data/ActiveRecord/TActiveRecord.php
+++ b/framework/Data/ActiveRecord/TActiveRecord.php
@@ -250,10 +250,7 @@ abstract class TActiveRecord extends TComponent
if(is_string($criteria))
{
if(!is_array($parameters) && func_num_args() > 1)
- {
- $parameters = func_get_args();
- array_shift($parameters);
- }
+ $parameters = array_slice(func_get_args(),1);
$criteria=new TActiveRecordCriteria($criteria,$parameters);
}
$gateway = $this->getRecordManager()->getRecordGateway();
@@ -309,10 +306,7 @@ abstract class TActiveRecord extends TComponent
if(is_string($criteria))
{
if(!is_array($parameters) && func_num_args() > 1)
- {
- $parameters = func_get_args();
- array_shift($parameters);
- }
+ $parameters = array_slice(func_get_args(),1);
$criteria=new TActiveRecordCriteria($criteria,$parameters);
}
$gateway = $this->getRecordManager()->getRecordGateway();
@@ -332,10 +326,7 @@ abstract class TActiveRecord extends TComponent
if(is_string($criteria))
{
if(!is_array($parameters) && func_num_args() > 1)
- {
- $parameters = func_get_args();
- array_shift($parameters);
- }
+ $parameters = array_slice(func_get_args(),1);
$criteria=new TActiveRecordCriteria($criteria,$parameters);
}
$gateway = $this->getRecordManager()->getRecordGateway();
@@ -407,10 +398,7 @@ abstract class TActiveRecord extends TComponent
public function findBySql($sql,$parameters=array())
{
if(!is_array($parameters) && func_num_args() > 1)
- {
- $parameters = func_get_args();
- array_shift($parameters);
- }
+ $parameters = array_slice(func_get_args(),1);
$gateway = $this->getRecordManager()->getRecordGateway();
$data = $gateway->findRecordsBySql($this,$sql,$parameters);
$results = array();
@@ -430,11 +418,8 @@ abstract class TActiveRecord extends TComponent
{
if(is_string($criteria))
{
- if(!is_array($parameters) && func_num_args() > 1)
- {
- $parameters = func_get_args();
- array_shift($parameters);
- }
+ if(!is_array($parameters) && func_num_args() > 1)
+ $parameters = array_slice(func_get_args(),1);
$criteria=new TActiveRecordCriteria($criteria,$parameters);
}
$gateway = $this->getRecordManager()->getRecordGateway();
diff --git a/framework/Data/ActiveRecord/TActiveRecordCriteria.php b/framework/Data/ActiveRecord/TActiveRecordCriteria.php
index 134632e8..cc4da7c8 100644
--- a/framework/Data/ActiveRecord/TActiveRecordCriteria.php
+++ b/framework/Data/ActiveRecord/TActiveRecordCriteria.php
@@ -10,6 +10,8 @@
* @package System.Data.ActiveRecord
*/
+Prado::using('System.Data.DataGateway.TSqlCriteria');
+
/**
* Search criteria for Active Record.
*
@@ -30,125 +32,8 @@
* @package System.Data.ActiveRecord
* @since 3.1
*/
-class TActiveRecordCriteria extends TComponent
+class TActiveRecordCriteria extends TSqlCriteria
{
- private $_condition;
- private $_parameters;
- private $_ordersBy;
- private $_limit;
- private $_offset;
-
- /**
- * Creates a new criteria with given condition;
- * @param string sql string after the WHERE stanza
- * @param mixed named or indexed parameters, accepts as multiple arguments.
- */
- public function __construct($condition=null,$parameters=array())
- {
- if(!is_array($parameters) && func_num_args() > 2)
- {
- $parameters = func_get_args();
- array_shift($parameters);
- }
- $this->setCondition($condition);
- $this->_parameters=new TAttributeCollection((array)$parameters);
- $this->_ordersBy=new TAttributeCollection;
- }
-
- /**
- * @return TAttributeCollection list of named parameters and values.
- */
- public function getParameters()
- {
- return $this->_parameters;
- }
-
- /**
- * @param ArrayAccess named parameters.
- */
- public function setParameters($value)
- {
- if(!(is_array($value) || $value instanceof ArrayAccess))
- throw new TException('value must be array or ArrayAccess');
- $this->_parameters->copyFrom($value);
- }
-
- /**
- * @return boolean true if the parameter index are string base, false otherwise.
- */
- public function getIsNamedParameters()
- {
- foreach($this->getParameters() as $k=>$v)
- return is_string($k);
- }
-
- /**
- * @return TAttributeCollection ordering clause.
- */
- public function getOrdersBy()
- {
- return $this->_ordersBy;
- }
-
- /**
- * @param ArrayAccess 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);
- }
-
- /**
- * @return string search conditions.
- */
- public function getCondition()
- {
- return $this->_condition;
- }
-
- /**
- * Sets the search conditions to be placed after the WHERE clause in the SQL.
- * @param string search conditions.
- */
- public function setCondition($value)
- {
- $this->_condition=$value;
- }
-
- /**
- * @return int maximum number of records to return.
- */
- public function getLimit()
- {
- return $this->_limit;
- }
-
- /**
- * @param int maximum number of records to return.
- */
- public function setLimit($value)
- {
- $this->_limit=$value;
- }
-
- /**
- * @return int record offset.
- */
- public function getOffset()
- {
- return $this->_offset;
- }
-
- /**
- * @param int record offset.
- */
- public function setOffset($value)
- {
- $this->_offset=$value;
- }
-
/**
* This method is invoked before the object is deleted from the database.
* The method raises 'OnDelete' event.
@@ -172,31 +57,6 @@ class TActiveRecordCriteria extends TComponent
{
$this->raiseEvent('OnSelect', $this, $param);
}
-
- /**
- * @return string string representation of the criteria. Useful for debugging.
- */
- public function __toString()
- {
- $str = '';
- if(strlen((string)$this->getCondition()) > 0)
- $str .= '"'.(string)$this->getCondition().'"';
- $params = array();
- foreach($this->getParameters() as $k=>$v)
- $params[] = "{$k} => ${v}";
- if(count($params) > 0)
- $str .= ', "'.implode(', ',$params).'"';
- $orders = array();
- foreach($this->getOrdersBy() as $k=>$v)
- $orders[] = "{$k} => ${v}";
- if(count($orders) > 0)
- $str .= ', "'.implode(', ',$orders).'"';
- if($this->_limit !==null)
- $str .= ', '.$this->_limit;
- if($this->_offset !== null)
- $str .= ', '.$this->_offset;
- return $str;
- }
}
?> \ No newline at end of file