Author: Leon.van.der.Ree
Date: 2010-03-26 16:57:45 +0100 (Fri, 26 Mar 2010)
New Revision: 28806
Modified:
plugins/sfDataSourcePlugin/trunk/lib/sfDataSourceArray.class.php
plugins/sfDataSourcePlugin/trunk/lib/sfDataSourceInterface.class.php
plugins/sfDataSourcePlugin/trunk/lib/sfDataSourcePropel.class.php
Log:
minor fixes
removed support for PropelModelQuery
Modified: plugins/sfDataSourcePlugin/trunk/lib/sfDataSourceArray.class.php
===================================================================
--- plugins/sfDataSourcePlugin/trunk/lib/sfDataSourceArray.class.php
2010-03-26 15:57:03 UTC (rev 28805)
+++ plugins/sfDataSourcePlugin/trunk/lib/sfDataSourceArray.class.php
2010-03-26 15:57:45 UTC (rev 28806)
@@ -50,7 +50,7 @@
$data = array(),
$originalData = array();
- private
+ protected
$sortColumn = null,
$sortOrder = null;
@@ -216,26 +216,22 @@
/**
* @see sfDataSourceInterface
*/
- public function setFilter($fields)
+ public function addFilter($column, $value, $comparison = sfDataSource::EQUAL)
{
// TODO: because of this, you should first Filter before you sort!
// TODO: possibly add sortState (asc,desc, none (per field)), and sort
after filtering
$this->data = array();
- foreach ($fields as $columnName => $column)
+ $this->requireColumn($columnName);
+
+ if (!isset($column['value']))
{
- $this->requireColumn($columnName);
+ throw new Exception("key 'value' not set for filter on column
".$columnName);
+ }
- if (!isset($column['value']))
- {
- throw new Exception("key 'value' not set for filter on column
".$columnName);
- }
+ $value = $column['value'];
- $value = $column['value'];
- $operator = isset($column['operator']) ? $column['operator'] :
sfDataSource::EQUAL;
-
- $this->data = array_filter($this->originalData, array($this,
'filterCallback'));
- }
+ $this->data = array_filter($this->originalData, array($this,
'filterCallback'));
}
//TODO: implement filtering on an array
Modified: plugins/sfDataSourcePlugin/trunk/lib/sfDataSourceInterface.class.php
===================================================================
--- plugins/sfDataSourcePlugin/trunk/lib/sfDataSourceInterface.class.php
2010-03-26 15:57:03 UTC (rev 28805)
+++ plugins/sfDataSourcePlugin/trunk/lib/sfDataSourceInterface.class.php
2010-03-26 15:57:45 UTC (rev 28806)
@@ -111,7 +111,7 @@
*
* @param array[array[string, string]] $columns
*/
- public function addFilter($column, $value, $comparison = Criteria::EQUAL);
+ public function addFilter($column, $value, $comparison =
sfDataSource::EQUAL);
/**
* Sets the number of rows to skip in the beginning of the data source when
Modified: plugins/sfDataSourcePlugin/trunk/lib/sfDataSourcePropel.class.php
===================================================================
--- plugins/sfDataSourcePlugin/trunk/lib/sfDataSourcePropel.class.php
2010-03-26 15:57:03 UTC (rev 28805)
+++ plugins/sfDataSourcePlugin/trunk/lib/sfDataSourcePropel.class.php
2010-03-26 15:57:45 UTC (rev 28806)
@@ -12,8 +12,7 @@
* This class implements the interface sfDataSourceInterface for accessing
* data stored in Propel (1.5) tables.
*
- * You can either pass a model name, an instance of PropelModelQuery
- * TODO: instance of PropelCollection to the constructor.
+ * You can either pass a model name or an instance of PropelModelQuery
*
* <code>
* // fetches all user objects
@@ -23,15 +22,9 @@
* $q = PropelQuery::from('User')->where('id BETWEEN ? AND ?', array(1, 100));
* $source = new sfDataSourcePropel($q);
*
- * // uses the objects in the given collection
- * $coll = PropelQuery::from('User')->find();
- * $source = new sfDataSourcePropel($coll);
* </code>
*
- * This class will work the same way no matter how you instantiate it. Most of
the
- * time, however, it is better to base the source on a model name or on a
- * PropelModelQuery, because sorting and limiting result sets is more efficient
- * when done by the database than when done by Php.
+ * This class will work the same way no matter how you instantiate it.
*
* You can iterate the data source like any other data source. If you iterate
* this class with foreach, the current row will always be an instance of
@@ -64,7 +57,7 @@
*
* @var ObjectPathCriteria
*/
- public
+ protected
$query = null;
/**
@@ -77,9 +70,9 @@
/**
* Constructor.
*
- * The dataSourcePropel (1.5) can be given string, as instance of
PropelModelQuery or as
- * instance of PropelCollection. If you pass in a PropelModelQuery, the
- * object will be cloned because it needs to be modified internally.
+ * The dataSourcePropel (1.5) can be given string or as instance of
PropelModelQuery
+ * If you pass an instance of PropelModelQuery, the object will be cloned
because
+ * it needs to be modified internally.
*
* <code>
* // fetches all user objects
@@ -88,10 +81,6 @@
* // fetches user objects with IDs 1 to 100
* $q = PropelQuery::from('User')->where('id BETWEEN ? AND ?', array(1,
100));
* $source = new sfDataSourcePropel($q);
- *
- * // uses the objects in the given collection
- * $coll = PropelQuery::from('User')->find();
- * $source = new sfDataSourcePropel($coll);
* </code>
*
* @param mixed $source The propel source as described above
@@ -129,11 +118,6 @@
{
$this->query = clone $source;
}
- // ... and there is support for PropelCollection result-sets (TODO:
although not fully implemented yet)
- elseif ($source instanceof PropelCollection)
- {
- $this->data = $source;
- }
else
{
throw new InvalidArgumentException('The source must be an instance of
ObjectPathCriteria, PropelCollection or a record class name');
@@ -168,12 +152,12 @@
*/
public function offsetGet($field)
{
+ $obj = $this->current();
$accessors = explode('.', $field);
- $obj = $this->current();
foreach ($accessors as $accessor)
{
- $method = 'get'.$accessor; //TODO: ucfirst? // TODO: move to
sfPropelObjectPathBehaviorPlugin?
+ $method = 'get'.$accessor; //TODO: maybe move to
sfPropelObjectPathBehaviorPlugin? object->getValueByPropertyPath($field)...
$obj = $obj->$method();
}
@@ -289,21 +273,17 @@
*/
public function requireColumn($column)
{
- // is you have a query object
- if ($this->query)
+ // check if an objectPath has been given
+ $lastDot = strrpos($column, '.');
+ if ($lastDot !== false)
{
- // check if an objectPath has been given
- $lastDot = strrpos($column, '.');
- if ($lastDot !== false)
- {
- // get the objectPath
- $objectPath = substr($column, 0, $lastDot);
-
- // and join accordingly
- $this->query->joinByObjectPath($objectPath);
- }
+ // get the objectPath
+ $objectPath = substr($column, 0, $lastDot);
+
+ // and join accordingly
+ $this->query->joinByObjectPath($objectPath);
}
- // TODO: in no query-object is used
+
}
/**
@@ -385,31 +365,11 @@
/**
* @see sfDataSourceInterface
*/
- // TODO: remove Criteria dependancy
- public function addFilter($column, $value, $comparison = Criteria::EQUAL)
+ public function addFilter($column, $value, $comparison = sfDataSource::EQUAL)
{
$this->requireColumn($column);
- $query = $this->query;
-
- // is you have a query object
- if ($this->query)
- {
- // check if an objectPath has been given
- $lastDot = strrpos($column, '.');
- if ($lastDot !== false)
- {
- // get the objectPath
- $objectPath = substr($column, 0, $lastDot);
-
- // and get Related Query Class
- $strRelated = $query->translateObjectPathToAlias($objectPath);
- $query = $query->useQuery($strRelated);
- $column = substr($column, $lastDot + 1);
- }
- }
-
- $query->filterBy($column, $value, $comparison);
+ return $this->query->filterBy($column, $value, $comparison);
}
}
\ No newline at end of file
--
You received this message because you are subscribed to the Google Groups
"symfony SVN" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/symfony-svn?hl=en.