Author: sergiovier
Date: 2010-04-07 00:32:12 +0200 (Wed, 07 Apr 2010)
New Revision: 29025

Modified:
   plugins/sfDataSourcePlugin/trunk/lib/sfDataSourceDoctrine.class.php
Log:
Updated to the same features with sfDataSourcePropel:
 - added support for sfAlyssaDoctrineObjectPath.
 - implemented required method by interface.


Modified: plugins/sfDataSourcePlugin/trunk/lib/sfDataSourceDoctrine.class.php
===================================================================
--- plugins/sfDataSourcePlugin/trunk/lib/sfDataSourceDoctrine.class.php 
2010-04-06 22:09:14 UTC (rev 29024)
+++ plugins/sfDataSourcePlugin/trunk/lib/sfDataSourceDoctrine.class.php 
2010-04-06 22:32:12 UTC (rev 29025)
@@ -61,8 +61,8 @@
 class sfDataSourceDoctrine extends sfDataSource
 {
   protected
-    $query    = null,
-    $data     = null;
+  $query    = null,
+  $data     = null;
 
   /**
    * Constructor.
@@ -158,7 +158,16 @@
    */
   public function offsetGet($field)
   {
-    return $this->current()->get($field);
+    $obj = $this->current();
+    $accessors = explode('.', $field);
+
+    foreach ($accessors as $accessor)
+    {
+      $method = 'get'.$accessor; //TODO: maybe move to ObjectPath Plugin? 
object->getValueByPropertyPath($field)...
+      $obj = $obj->$method();
+    }
+
+    return $obj;
   }
 
   /**
@@ -243,8 +252,21 @@
    */
   public function requireColumn($column)
   {
-    if (!$this->getTable()->hasColumn($column))
+    // 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);
+
+      //TODO: if we don't have sfAlyssaDoctrineObjectPathPlugin installed?
+    }
+    // check if the given column is valid
+    elseif(!$this->getTable()->hasColumn($column))
+    {
       throw new LogicException(sprintf('The column "%s" has not been defined 
in the datasource', $column));
     }
   }
@@ -307,17 +329,19 @@
       throw new RuntimeException('A data source based on a Doctrine_Collection 
cannot be sorted');
     }
 
-    $this->query->orderBy($column.' '.strtoupper($order));
+    $this->query->orderByProperyPath($column.' '.strtoupper($order));
     $this->refresh();
   }
 
-
   /**
    * @see sfDataSourceInterface
    */
-  public function setFilter($fields)
+  public function addFilter($column, $value, $comparison = sfDataSource::EQUAL)
   {
-    throw new Exception('This method has not been implemented yet');
+    $this->requireColumn($column);
+
+    $expr = $column.' '.$comparison.' ?';
+    return $this->query->addWhereProperyPath($expr, $value);
   }
 
   /**

-- 
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.

Reply via email to